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.formats;
023
024import java.util.Enumeration;
025import java.util.Properties;
026
027import org.nuxeo.theme.relations.Predicate;
028
029public class DefaultFormat implements Format {
030
031    private String description;
032
033    private FormatType formatType;
034
035    private Properties properties = new Properties();
036
037    private Integer uid;
038
039    private String name;
040
041    private boolean remote = false;
042
043    private boolean customized = false;
044
045    private boolean external;
046
047    public Integer getUid() {
048        return uid;
049    }
050
051    public void setUid(final Integer uid) {
052        this.uid = uid;
053    }
054
055    public String hash() {
056        if (uid == null) {
057            return null;
058        }
059        return uid.toString();
060    }
061
062    public Predicate getPredicate() {
063        return formatType.getPredicate();
064    }
065
066    public FormatType getFormatType() {
067        return formatType;
068    }
069
070    public void setFormatType(final FormatType formatType) {
071        this.formatType = formatType;
072    }
073
074    public String getName() {
075        return name;
076    }
077
078    public void setName(final String name) {
079        this.name = name;
080    }
081
082    /* Properties */
083
084    public String getProperty(final String key) {
085        return properties.getProperty(key);
086    }
087
088    public void setProperty(final String key, final String value) {
089        properties.setProperty(key, value);
090    }
091
092    public Enumeration<?> getPropertyNames() {
093        return properties.propertyNames();
094    }
095
096    public boolean hasProperties() {
097        return !properties.isEmpty();
098    }
099
100    public Properties getProperties() {
101        return properties;
102    }
103
104    public void setProperties(final Properties properties) {
105        this.properties = properties;
106    }
107
108    public String getDescription() {
109        return description;
110    }
111
112    public void setDescription(final String description) {
113        this.description = description;
114    }
115
116    public void clonePropertiesOf(final Format source) {
117        Properties sourceProperties = source.getProperties();
118        for (Object key : sourceProperties.keySet()) {
119            String propertyName = (String) key;
120            setProperty(propertyName, sourceProperties.getProperty(propertyName));
121        }
122    }
123
124    public boolean isNamed() {
125        return false;
126    }
127
128    public boolean isRemote() {
129        return remote;
130    }
131
132    public void setRemote(boolean remote) {
133        this.remote = remote;
134    }
135
136    public boolean isCustomized() {
137        return customized;
138    }
139
140    public void setCustomized(boolean customized) {
141        this.customized = customized;
142    }
143
144    public void setExternal(boolean external) {
145        this.external = external;
146    }
147
148    public boolean isExternal() {
149        return external;
150    }
151}