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 *     Jean-Marc Orliaguet, Chalmers
018 *
019 * $Id$
020 */
021
022package org.nuxeo.theme.rendering;
023
024import java.util.HashMap;
025import java.util.Map;
026
027import org.nuxeo.common.xmap.annotation.XNode;
028import org.nuxeo.common.xmap.annotation.XObject;
029
030@XObject("standalone-filter")
031public final class StandaloneFilterType extends FilterType {
032
033    @XNode("@name")
034    public String name;
035
036    @XNode("engine")
037    public String engine = "*";
038
039    @XNode("@template-engine")
040    public String templateEngine = "*";
041
042    @XNode("mode")
043    public String mode = "*";
044
045    @XNode("class")
046    public String className;
047
048    private final Map<String, Filter> filters = new HashMap<String, Filter>();
049
050    @Override
051    public Filter getFilter() {
052        String typeName = getTypeName();
053        if (filters.containsKey(typeName)) {
054            return filters.get(typeName);
055        }
056        Filter filter = StandaloneFilterFactory.create(typeName);
057        filters.put(typeName, filter);
058        return filter;
059    }
060
061    @Override
062    public FilterTypeFamily getFilterTypeFamily() {
063        return FilterTypeFamily.STANDALONE;
064    }
065
066    @Override
067    public String getTypeName() {
068        return String.format("%s/%s/%s/%s", engine, templateEngine, mode, name);
069    }
070
071    @Override
072    public String getClassName() {
073        return className;
074    }
075
076}