001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thierry Delprat
018 */
019package org.nuxeo.apidoc.documentation;
020
021import org.nuxeo.apidoc.snapshot.SnapshotManager;
022import org.nuxeo.runtime.api.Framework;
023
024public class JavaDocHelper {
025
026    public static final String BASE_URL = "http://community.nuxeo.com/api/";
027
028    public static final String CM_BASE = "nuxeo-case-management";
029
030    public static final String DM_BASE = "nuxeo";
031
032    public static final String DAM_BASE = "nuxeo-dam";
033
034    public static final String DEFAULT_DIST = DM_BASE;
035
036    public static final String DEFAULT_VERSION = "5.5";
037
038    protected final String defaultPrefix;
039
040    protected final String docVersion;
041
042    public JavaDocHelper(String prefix, String version) {
043        defaultPrefix = prefix;
044
045        if (version.equalsIgnoreCase("current")) {
046            SnapshotManager sm = Framework.getService(SnapshotManager.class);
047            version = sm.getRuntimeSnapshot().getVersion();
048        }
049
050        if (version.endsWith("-SNAPSHOT")) {
051            version = version.replace("-SNAPSHOT", "");
052        } else {
053            version = "release-" + version;
054        }
055        docVersion = version;
056    }
057
058    public String getBaseUrl(String className) {
059
060        String base = defaultPrefix;
061
062        if (!docVersion.startsWith("5.")) {
063            // version < 5.5 : before merge of DAM/DAM/CAP/CMF ...
064            if (className.contains("org.nuxeo.cm")) {
065                base = CM_BASE;
066            } else if (className.contains("org.nuxeo.dam")) {
067                base = DAM_BASE;
068            } else {
069                base = DEFAULT_DIST;
070            }
071        }
072
073        return BASE_URL + base + "/" + docVersion;
074    }
075
076    public static JavaDocHelper getHelper(String distribName, String distribVersion) {
077
078        String base = DEFAULT_DIST;
079        if (!distribVersion.startsWith("5.")) {
080            // version < 5.5 : before merge of DAM/DAM/CAP/CMF ...
081            if (distribName.toUpperCase().contains("CM") || distribName.toUpperCase().contains("CASE")) {
082                base = CM_BASE;
083            } else if (distribName.toUpperCase().contains("DAM")) {
084                base = DAM_BASE;
085            }
086        }
087        return new JavaDocHelper(base, distribVersion);
088    }
089
090}