001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Florent Guillaume
011 */
012package org.nuxeo.ecm.core.api.pathsegment;
013
014import org.nuxeo.common.utils.IdUtils;
015import org.nuxeo.ecm.core.api.DocumentModel;
016import org.nuxeo.runtime.api.Framework;
017import org.nuxeo.runtime.services.config.ConfigurationService;
018
019/**
020 * Service generating a path segment from the title by simplifying it to lowercase and dash-separated words.
021 */
022public class PathSegmentServiceCompat implements PathSegmentService {
023
024    @Override
025    public String generatePathSegment(DocumentModel doc) {
026        return generatePathSegment(doc.getTitle());
027    }
028
029    @Override
030    public String generatePathSegment(String s) {
031        return IdUtils.generateId(s, "-", true, getMaxSize());
032    }
033
034    @Override
035    public int getMaxSize() {
036        ConfigurationService cs = Framework.getService(ConfigurationService.class);
037        return Integer.parseInt(cs.getProperty(PathSegmentService.NUXEO_MAX_SEGMENT_SIZE_PROPERTY, "24"));
038    }
039
040}