001/*
002 * (C) Copyright 2006-2007 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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.runtime.deployment.preprocessor.template;
023
024import org.nuxeo.common.xmap.Resource;
025import org.nuxeo.common.xmap.annotation.XContent;
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XObject;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032@XObject
033public class TemplateContribution {
034
035    @XNode("@src")
036    private Resource src;
037
038    private String template;
039
040    private String marker;
041
042    @XContent
043    private String content;
044
045    @XNode("@mode")
046    private String mode = "append";
047
048    @XNode("@target")
049    public void setTarget(String target) {
050        int p = target.lastIndexOf('#');
051        if (p > -1) {
052            template = target.substring(0, p);
053            marker = target.substring(p + 1);
054        } else {
055            template = target;
056            marker = Template.END;
057        }
058    }
059
060    public String getContent() {
061        if (content == null) {
062            if (src == null) {
063                return "";
064            }
065            return src.toString();
066        }
067        return content;
068    }
069
070    public String getTemplate() {
071        return template;
072    }
073
074    public String getMarker() {
075        return marker;
076    }
077
078    public String getMode() {
079        return mode;
080    }
081
082    public boolean isAppending() {
083        return "append".equals(mode);
084    }
085
086    public boolean isPrepending() {
087        return "prepend".equals(mode);
088    }
089
090    public boolean isReplacing() {
091        return "replace".equals(mode);
092    }
093
094}