001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.formats; 016 017import java.util.HashMap; 018import java.util.Map; 019 020import org.nuxeo.common.xmap.annotation.XNode; 021import org.nuxeo.common.xmap.annotation.XObject; 022import org.nuxeo.theme.Manager; 023import org.nuxeo.theme.rendering.Filter; 024import org.nuxeo.theme.rendering.FilterType; 025import org.nuxeo.theme.rendering.FilterTypeFamily; 026import org.nuxeo.theme.types.TypeFamily; 027 028@XObject("format-filter") 029public final class FormatFilterType extends FilterType { 030 031 @XNode("@name") 032 public String name; 033 034 @XNode("engine") 035 public String engine = "*"; 036 037 @XNode("template-engine") 038 public String templateEngine = "*"; 039 040 @XNode("mode") 041 public String mode = "*"; 042 043 @XNode("format-type") 044 public String formatName; 045 046 private final Map<String, Filter> filters = new HashMap<String, Filter>(); 047 048 public FormatFilterType() { 049 } 050 051 public FormatFilterType(@SuppressWarnings("unused") final String name, final String formatName) { 052 this.formatName = formatName; 053 } 054 055 @Override 056 public Filter getFilter() { 057 if (filters.containsKey(formatName)) { 058 return filters.get(formatName); 059 } 060 FormatType formatType = (FormatType) Manager.getTypeRegistry().lookup(TypeFamily.FORMAT, formatName); 061 FormatFilter filter = new FormatFilter(); 062 filter.setFormatType(formatType); 063 filters.put(formatName, filter); 064 return filter; 065 } 066 067 @Override 068 public FilterTypeFamily getFilterTypeFamily() { 069 return FilterTypeFamily.FORMAT; 070 } 071 072 public String getFormatName() { 073 return formatName; 074 } 075 076 public void setFormatName(final String formatName) { 077 this.formatName = formatName; 078 } 079 080 @Override 081 public String getTypeName() { 082 return String.format("%s/%s/%s/%s", engine, templateEngine, mode, name); 083 } 084 085 @Override 086 public String getClassName() { 087 return FormatFilter.class.getName(); 088 } 089 090}