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