001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017package org.nuxeo.apidoc.documentation;
018
019import org.nuxeo.apidoc.snapshot.SnapshotManager;
020import org.nuxeo.runtime.api.Framework;
021
022public class JavaDocHelper {
023
024    public static final String BASE_URL = "http://community.nuxeo.com/api/";
025
026    public static final String CM_BASE = "nuxeo-case-management";
027
028    public static final String DM_BASE = "nuxeo";
029
030    public static final String DAM_BASE = "nuxeo-dam";
031
032    public static final String DEFAULT_DIST = DM_BASE;
033
034    public static final String DEFAULT_VERSION = "5.5";
035
036    protected final String defaultPrefix;
037
038    protected final String docVersion;
039
040    public JavaDocHelper(String prefix, String version) {
041        defaultPrefix = prefix;
042
043        if (version.equalsIgnoreCase("current")) {
044            SnapshotManager sm = Framework.getLocalService(SnapshotManager.class);
045            version = sm.getRuntimeSnapshot().getVersion();
046        }
047
048        if (version.endsWith("-SNAPSHOT")) {
049            version = version.replace("-SNAPSHOT", "");
050        } else {
051            version = "release-" + version;
052        }
053        docVersion = version;
054    }
055
056    public String getBaseUrl(String className) {
057
058        String base = defaultPrefix;
059
060        if (!docVersion.startsWith("5.")) {
061            // version < 5.5 : before merge of DAM/DAM/CAP/CMF ...
062            if (className.contains("org.nuxeo.cm")) {
063                base = CM_BASE;
064            } else if (className.contains("org.nuxeo.dam")) {
065                base = DAM_BASE;
066            } else {
067                base = DEFAULT_DIST;
068            }
069        }
070
071        return BASE_URL + base + "/" + docVersion;
072    }
073
074    public static JavaDocHelper getHelper(String distribName, String distribVersion) {
075
076        String base = DEFAULT_DIST;
077        if (!distribVersion.startsWith("5.")) {
078            // version < 5.5 : before merge of DAM/DAM/CAP/CMF ...
079            if (distribName.toUpperCase().contains("CM") || distribName.toUpperCase().contains("CASE")) {
080                base = CM_BASE;
081            } else if (distribName.toUpperCase().contains("DAM")) {
082                base = DAM_BASE;
083            }
084        }
085        return new JavaDocHelper(base, distribVersion);
086    }
087
088}