KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > metadata > range > ResourceRange


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.vfs.metadata.range;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.openharmonise.vfs.metadata.*;
26 import org.openharmonise.vfs.metadata.value.*;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.NodeList JavaDoc;
30 import org.w3c.dom.Text JavaDoc;
31
32
33 /**
34  * This is the range for resource relationship type properties.
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class ResourceRange extends AbstractRange implements Range {
41
42     /**
43      * List of full paths to collections which contain valid values.
44      */

45     private ArrayList JavaDoc m_aHREFs = new ArrayList JavaDoc();
46
47     /**
48      * List of content types which are valid for this range.
49      */

50     private ArrayList JavaDoc m_aContentTypes = new ArrayList JavaDoc();
51     /**
52      *
53      */

54     public ResourceRange() {
55         super();
56     }
57
58     /* (non-Javadoc)
59      * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
60      */

61     public ValidationResult validate(ValueInstance value) {
62         boolean bIsValid = false;
63         
64         String JavaDoc sValue = ((ResourceValue)value).getValue();
65         
66         Iterator JavaDoc iter = m_aHREFs.iterator();
67         
68         while (iter.hasNext() && bIsValid == false) {
69             String JavaDoc sPath = (String JavaDoc) iter.next();
70             if(sValue.startsWith(sPath)) {
71                 bIsValid = true;
72             }
73         }
74         
75         return new ValidationResult(bIsValid,"");
76     }
77
78     /**
79      * Returns a list of collections which contain valid values.
80      *
81      * @return List of full paths
82      */

83     public List JavaDoc getHREFs() {
84         return (List JavaDoc) this.m_aHREFs.clone();
85     }
86
87     /**
88      * Sets the list of collections which contain valid values.
89      *
90      * @param aHREFs List of full paths
91      */

92     public void setHREFs(List JavaDoc aHREFs) {
93         this.m_aHREFs = new ArrayList JavaDoc(aHREFs);
94     }
95     
96     /**
97      * Returns a list of content types which are valid for this range.
98      *
99      * @return List of content types
100      */

101     public List JavaDoc getContentTypes() {
102         return (List JavaDoc) this.m_aContentTypes.clone();
103     }
104     
105     /**
106      * Sets the list of content types which are valid for this range.
107      *
108      * @param aContentTypes List of content types
109      */

110     public void setContentTypes(List JavaDoc aContentTypes) {
111         this.m_aContentTypes = new ArrayList JavaDoc(aContentTypes);
112     }
113
114     /* (non-Javadoc)
115      * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
116      */

117     public void instantiate(Element JavaDoc elRange) {
118         NodeList JavaDoc nl = elRange.getElementsByTagNameNS("DAV:", "href");
119         for(int i=0; i<nl.getLength(); i++) {
120             Element JavaDoc elHREF = (Element JavaDoc)nl.item(i);
121             if(elHREF.getChildNodes().getLength()==1) {
122                 Node JavaDoc node = elHREF.getFirstChild();
123                 if(node.getNodeType()==Node.TEXT_NODE) {
124                     this.m_aHREFs.add( ((Text JavaDoc)node).getNodeValue() );
125                 }
126             }
127         }
128
129         nl = elRange.getElementsByTagNameNS("DAV:", "contenttype");
130         for(int i=0; i<nl.getLength(); i++) {
131             Element JavaDoc elContentType = (Element JavaDoc)nl.item(i);
132             if(elContentType.getChildNodes().getLength()==1) {
133                 Node JavaDoc node = elContentType.getFirstChild();
134                 if(node.getNodeType()==Node.TEXT_NODE) {
135                     this.m_aContentTypes.add( ((Text JavaDoc)node).getNodeValue() );
136                 }
137             }
138         }
139     }
140
141     public String JavaDoc toString() {
142         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
143         
144         sBuff.append("ResourceRange:\n");
145         Iterator JavaDoc itor = this.m_aHREFs.iterator();
146         while(itor.hasNext()) {
147             sBuff.append("HREF: ").append(((String JavaDoc)itor.next())).append("\n");
148         }
149         
150         itor = this.m_aContentTypes.iterator();
151         while(itor.hasNext()) {
152             sBuff.append("Contenttype: ").append(((String JavaDoc)itor.next())).append("\n");
153         }
154         
155         return sBuff.toString();
156     }
157
158 }
159
Popular Tags