KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > rules > MetadataRule


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.actions.rules;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.openharmonise.vfs.*;
25
26
27 /**
28  * Rule that will return return true if a specified item of metadata, for
29  * the currently selected virtual file, matches a specified set of values.
30  *
31  * @author Matthew Large
32  * @version $Revision: 1.1 $
33  *
34  */

35 public class MetadataRule implements EnableRule {
36
37     boolean m_bComparator = true;
38
39     /**
40      * Namespace of property.
41      */

42     private String JavaDoc m_sNamespace = null;
43     
44     /**
45      * Name of property.
46      */

47     private String JavaDoc m_sName = null;
48     
49     /**
50      * Values to check against.
51      */

52     private ArrayList JavaDoc m_aValues = null;
53
54     /**
55      * Constructs a new metadata rule.
56      *
57      * @param sNamespace Namespace of property
58      * @param sName Name of property
59      * @param aValues Values to check against
60      */

61     public MetadataRule(String JavaDoc sNamespace, String JavaDoc sName, List JavaDoc aValues) {
62         super();
63         this.m_sNamespace = sNamespace;
64         this.m_sName = sName;
65         this.m_aValues = new ArrayList JavaDoc(aValues);
66     }
67     
68     /**
69      * Constructs a new metadata rule.
70      *
71      * @param sNamespace Namespace of property
72      * @param sName Name of property
73      * @param sValue Value to check against
74      */

75     public MetadataRule(String JavaDoc sNamespace, String JavaDoc sName, String JavaDoc sValue) {
76         super();
77         this.m_sNamespace = sNamespace;
78         this.m_sName = sName;
79         this.m_aValues = new ArrayList JavaDoc();
80         this.m_aValues.add(sValue);
81     }
82
83     /* (non-Javadoc)
84      * @see com.simulacramedia.contentmanager.actions.rules.EnableRule#isEnabled(com.simulacramedia.vfs.VirtualFile)
85      */

86     public boolean isEnabled(VirtualFile vfFile) {
87         boolean bEnabled = false;
88         
89         if(vfFile!=null) {
90             List JavaDoc sFileValues = vfFile.getProperty(this.m_sNamespace, this.m_sName).getValues();
91         
92             if(sFileValues.containsAll(this.m_aValues)) {
93                 bEnabled = true;
94             }
95         }
96
97         return this.m_bComparator==bEnabled;
98     }
99
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 }
108
Popular Tags