001/*
002 * (C) Copyright 2012 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.template.jaxrs.context;
020
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.runtime.api.Framework;
023import org.nuxeo.template.api.context.DocumentWrapper;
024
025public class JAXRSExtensions {
026
027    protected final DocumentModel doc;
028
029    protected final DocumentWrapper nuxeoWrapper;
030
031    protected final String templateName;
032
033    public JAXRSExtensions(DocumentModel doc, DocumentWrapper nuxeoWrapper, String templateName) {
034        this.doc = doc;
035        this.nuxeoWrapper = nuxeoWrapper;
036        this.templateName = templateName;
037    }
038
039    protected static String getContextPathProperty() {
040        return Framework.getProperty("org.nuxeo.ecm.contextPath", "/nuxeo");
041    }
042
043    public String getResourceUrl(String resourceName) {
044        StringBuffer sb = new StringBuffer(getContextPathProperty());
045        sb.append("/site/templates/doc/");
046        sb.append(doc.getId());
047        sb.append("/resource/");
048        sb.append(templateName);
049        sb.append("/");
050        sb.append(resourceName);
051        return sb.toString();
052    }
053}