001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.actions.rules;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import org.openharmonise.vfs.*;
025:
026: /**
027: * Rule that will return return true if a specified item of metadata, for
028: * the currently selected virtual file, matches a specified set of values.
029: *
030: * @author Matthew Large
031: * @version $Revision: 1.1 $
032: *
033: */
034: public class MetadataRule implements EnableRule {
035:
036: boolean m_bComparator = true;
037:
038: /**
039: * Namespace of property.
040: */
041: private String m_sNamespace = null;
042:
043: /**
044: * Name of property.
045: */
046: private String m_sName = null;
047:
048: /**
049: * Values to check against.
050: */
051: private ArrayList m_aValues = null;
052:
053: /**
054: * Constructs a new metadata rule.
055: *
056: * @param sNamespace Namespace of property
057: * @param sName Name of property
058: * @param aValues Values to check against
059: */
060: public MetadataRule(String sNamespace, String sName, List aValues) {
061: super ();
062: this .m_sNamespace = sNamespace;
063: this .m_sName = sName;
064: this .m_aValues = new ArrayList(aValues);
065: }
066:
067: /**
068: * Constructs a new metadata rule.
069: *
070: * @param sNamespace Namespace of property
071: * @param sName Name of property
072: * @param sValue Value to check against
073: */
074: public MetadataRule(String sNamespace, String sName, String sValue) {
075: super ();
076: this .m_sNamespace = sNamespace;
077: this .m_sName = sName;
078: this .m_aValues = new ArrayList();
079: this .m_aValues.add(sValue);
080: }
081:
082: /* (non-Javadoc)
083: * @see com.simulacramedia.contentmanager.actions.rules.EnableRule#isEnabled(com.simulacramedia.vfs.VirtualFile)
084: */
085: public boolean isEnabled(VirtualFile vfFile) {
086: boolean bEnabled = false;
087:
088: if (vfFile != null) {
089: List sFileValues = vfFile.getProperty(this .m_sNamespace,
090: this .m_sName).getValues();
091:
092: if (sFileValues.containsAll(this .m_aValues)) {
093: bEnabled = true;
094: }
095: }
096:
097: return this .m_bComparator == bEnabled;
098: }
099:
100: /* (non-Javadoc)
101: * @see com.simulacramedia.contentmanager.actions.rules.EnableRule#setResultComparator(boolean)
102: */
103: public void setResultComparator(boolean bComparator) {
104: this.m_bComparator = bComparator;
105: }
106:
107: }
|