Source Code Cross Referenced for DAVRangeValue.java in  » Content-Management-System » harmonise » org » openharmonise » webdav » client » value » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » harmonise » org.openharmonise.webdav.client.value 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.webdav.client.value;
020:
021:        import java.text.*;
022:        import java.util.*;
023:
024:        import org.openharmonise.commons.xml.namespace.*;
025:        import org.openharmonise.vfs.metadata.*;
026:        import org.openharmonise.vfs.metadata.range.*;
027:        import org.openharmonise.vfs.metadata.value.*;
028:        import org.w3c.dom.*;
029:
030:        /**
031:         * WebDAV range value implementation.
032:         * 
033:         * @author Matthew Large
034:         * @version $Revision: 1.2 $
035:         *
036:         */
037:        public class DAVRangeValue extends RangeValue {
038:
039:            /**
040:             * Date and time format.
041:             */
042:            private static final String XSD_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
043:
044:            /**
045:             * Date format.
046:             */
047:            private static final String XSD_DATE_FORMAT = "yyyy-MM-dd";
048:
049:            /**
050:             * 
051:             */
052:            public DAVRangeValue() {
053:                super ();
054:            }
055:
056:            /**
057:             * Constructs new WebDAV range value implementation.
058:             * 
059:             * @param range Value
060:             */
061:            public DAVRangeValue(Range range) {
062:                super (range);
063:            }
064:
065:            /**
066:             * Publishes WebDAV range values to a XML element.
067:             * 
068:             * @param xmlDoc Owning XML document
069:             * @param propEl Element to append to
070:             * @param aValues List of {@link DAVBooleanValue} objects
071:             */
072:            public static void toXML(Document xmlDoc, Element elProp,
073:                    List aValues) {
074:                if (aValues.size() > 0) {
075:                    RangeValue value = (RangeValue) aValues.get(0);
076:                    Range range = value.getRange();
077:                    if (range != null) {
078:                        if (range instanceof  BooleanRange) {
079:                            Element elRestriction = xmlDoc.createElementNS(
080:                                    NamespaceType.XML_SCHEMA.getURI(),
081:                                    "restriction");
082:                            elProp.appendChild(elRestriction);
083:                            elRestriction.setAttributeNS(
084:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
085:                                    NamespaceType.XML_SCHEMA.getPrefix()
086:                                            + ":boolean");
087:
088:                            Element elLabels = xmlDoc.createElementNS(
089:                                    NamespaceType.OHRM.getURI(), "labels");
090:                            elRestriction.appendChild(elLabels);
091:
092:                            elLabels.setAttributeNS(
093:                                    NamespaceType.OHRM.getURI(), "trueLabel",
094:                                    ((BooleanRange) range).getTrueText());
095:                            elLabels.setAttributeNS(
096:                                    NamespaceType.OHRM.getURI(), "falseLabel",
097:                                    ((BooleanRange) range).getFalseText());
098:                        } else if (range instanceof  CollectionRange) {
099:                            Element elResourceType = xmlDoc.createElementNS(
100:                                    NamespaceType.DAV.getURI(), "resourcetype");
101:                            elProp.appendChild(elResourceType);
102:
103:                            Element elPropRes = xmlDoc.createElementNS(
104:                                    NamespaceType.DAV.getURI(), "collection");
105:                            elResourceType.appendChild(elPropRes);
106:
107:                            List aHREFs = ((CollectionRange) range).getHREFs();
108:                            Iterator itor = aHREFs.iterator();
109:                            while (itor.hasNext()) {
110:                                String sHREF = (String) itor.next();
111:                                Element elHREF = xmlDoc.createElementNS(
112:                                        NamespaceType.DAV.getURI(), "href");
113:                                elProp.appendChild(elHREF);
114:                                Text txt = xmlDoc.createTextNode(sHREF);
115:                                elHREF.appendChild(txt);
116:                            }
117:                        } else if (range instanceof  DateRange) {
118:                            Element elRestriction = xmlDoc.createElementNS(
119:                                    NamespaceType.XML_SCHEMA.getURI(),
120:                                    "restriction");
121:                            elProp.appendChild(elRestriction);
122:                            elRestriction.setAttributeNS(
123:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
124:                                    NamespaceType.XML_SCHEMA.getPrefix()
125:                                            + ":date");
126:                            DateRange actualRange = (DateRange) range;
127:                            if (actualRange.getMinimum() != null) {
128:                                SimpleDateFormat format = new SimpleDateFormat(
129:                                        DateRange.XSD_DATE_FORMAT);
130:                                String sValue = format.format(actualRange
131:                                        .getMinimum());
132:                                Element elTemp = xmlDoc.createElementNS(
133:                                        NamespaceType.XML_SCHEMA.getURI(),
134:                                        "minInclusive");
135:                                elRestriction.appendChild(elTemp);
136:                                Text txt = xmlDoc.createTextNode(sValue);
137:                                elTemp.appendChild(txt);
138:                            }
139:                            if (actualRange.getMaximum() != null) {
140:                                SimpleDateFormat format = new SimpleDateFormat(
141:                                        DateRange.XSD_DATE_FORMAT);
142:                                String sValue = format.format(actualRange
143:                                        .getMaximum());
144:                                Element elTemp = xmlDoc.createElementNS(
145:                                        NamespaceType.XML_SCHEMA.getURI(),
146:                                        "maxInclusive");
147:                                elRestriction.appendChild(elTemp);
148:                                Text txt = xmlDoc.createTextNode(sValue);
149:                                elTemp.appendChild(txt);
150:                            }
151:                        } else if (range instanceof  DateTimeRange) {
152:                            Element elRestriction = xmlDoc.createElementNS(
153:                                    NamespaceType.XML_SCHEMA.getURI(),
154:                                    "restriction");
155:                            elProp.appendChild(elRestriction);
156:                            elRestriction.setAttributeNS(
157:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
158:                                    NamespaceType.XML_SCHEMA.getPrefix()
159:                                            + ":dateTime");
160:                            DateTimeRange actualRange = (DateTimeRange) range;
161:                            if (actualRange.getMinimum() != null) {
162:                                SimpleDateFormat format = new SimpleDateFormat(
163:                                        DateTimeRange.XSD_DATE_FORMAT);
164:                                String sValue = format.format(actualRange
165:                                        .getMinimum());
166:                                Element elTemp = xmlDoc.createElementNS(
167:                                        NamespaceType.XML_SCHEMA.getURI(),
168:                                        "minInclusive");
169:                                elRestriction.appendChild(elTemp);
170:                                Text txt = xmlDoc.createTextNode(sValue);
171:                                elTemp.appendChild(txt);
172:                            }
173:                            if (actualRange.getMaximum() != null) {
174:                                SimpleDateFormat format = new SimpleDateFormat(
175:                                        DateTimeRange.XSD_DATE_FORMAT);
176:                                String sValue = format.format(actualRange
177:                                        .getMaximum());
178:                                Element elTemp = xmlDoc.createElementNS(
179:                                        NamespaceType.XML_SCHEMA.getURI(),
180:                                        "maxInclusive");
181:                                elRestriction.appendChild(elTemp);
182:                                Text txt = xmlDoc.createTextNode(sValue);
183:                                elTemp.appendChild(txt);
184:                            }
185:                        } else if (range instanceof  FloatRange) {
186:                            Element elRestriction = xmlDoc.createElementNS(
187:                                    NamespaceType.XML_SCHEMA.getURI(),
188:                                    "restriction");
189:                            elProp.appendChild(elRestriction);
190:                            elRestriction.setAttributeNS(
191:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
192:                                    NamespaceType.XML_SCHEMA.getPrefix()
193:                                            + ":float");
194:                            FloatRange actualRange = (FloatRange) range;
195:                            if (actualRange.getMinimum() != null) {
196:                                String sValue = actualRange.getMinimum()
197:                                        .toString();
198:                                Element elTemp = xmlDoc.createElementNS(
199:                                        NamespaceType.XML_SCHEMA.getURI(),
200:                                        "minInclusive");
201:                                elRestriction.appendChild(elTemp);
202:                                Text txt = xmlDoc.createTextNode(sValue);
203:                                elTemp.appendChild(txt);
204:                            }
205:                            if (actualRange.getMaximum() != null) {
206:                                String sValue = actualRange.getMaximum()
207:                                        .toString();
208:                                Element elTemp = xmlDoc.createElementNS(
209:                                        NamespaceType.XML_SCHEMA.getURI(),
210:                                        "maxInclusive");
211:                                elRestriction.appendChild(elTemp);
212:                                Text txt = xmlDoc.createTextNode(sValue);
213:                                elTemp.appendChild(txt);
214:                            }
215:                        } else if (range instanceof  IntegerRange) {
216:                            Element elRestriction = xmlDoc.createElementNS(
217:                                    NamespaceType.XML_SCHEMA.getURI(),
218:                                    "restriction");
219:                            elProp.appendChild(elRestriction);
220:                            elRestriction.setAttributeNS(
221:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
222:                                    NamespaceType.XML_SCHEMA.getPrefix()
223:                                            + ":integer");
224:                            IntegerRange actualRange = (IntegerRange) range;
225:                            if (actualRange.getMinimum() != null) {
226:                                String sValue = actualRange.getMinimum()
227:                                        .toString();
228:                                Element elTemp = xmlDoc.createElementNS(
229:                                        NamespaceType.XML_SCHEMA.getURI(),
230:                                        "minInclusive");
231:                                elRestriction.appendChild(elTemp);
232:                                Text txt = xmlDoc.createTextNode(sValue);
233:                                elTemp.appendChild(txt);
234:                            }
235:                            if (actualRange.getMaximum() != null) {
236:                                String sValue = actualRange.getMaximum()
237:                                        .toString();
238:                                Element elTemp = xmlDoc.createElementNS(
239:                                        NamespaceType.XML_SCHEMA.getURI(),
240:                                        "maxInclusive");
241:                                elRestriction.appendChild(elTemp);
242:                                Text txt = xmlDoc.createTextNode(sValue);
243:                                elTemp.appendChild(txt);
244:                            }
245:                        } else if (range instanceof  PropertyRange) {
246:                            Element elResourceType = xmlDoc.createElementNS(
247:                                    NamespaceType.DAV.getURI(), "resourcetype");
248:                            elProp.appendChild(elResourceType);
249:
250:                            Element elPropRes = xmlDoc.createElementNS(
251:                                    NamespaceType.DAV.getURI(),
252:                                    "property-resource");
253:                            elResourceType.appendChild(elPropRes);
254:
255:                            List aHREFs = ((PropertyRange) range).getHREFs();
256:                            Iterator itor = aHREFs.iterator();
257:                            while (itor.hasNext()) {
258:                                String sHREF = (String) itor.next();
259:                                Element elHREF = xmlDoc.createElementNS(
260:                                        NamespaceType.DAV.getURI(), "href");
261:                                elProp.appendChild(elHREF);
262:                                Text txt = xmlDoc.createTextNode(sHREF);
263:                                elHREF.appendChild(txt);
264:                            }
265:                        } else if (range instanceof  ResourceRange) {
266:                            Element elResourceType = xmlDoc.createElementNS(
267:                                    NamespaceType.DAV.getURI(), "resourcetype");
268:                            elProp.appendChild(elResourceType);
269:
270:                            Element elPropRes = xmlDoc.createElementNS(
271:                                    NamespaceType.DAV.getURI(), "resource");
272:                            elResourceType.appendChild(elPropRes);
273:
274:                            List aHREFs = ((ResourceRange) range).getHREFs();
275:                            Iterator itor = aHREFs.iterator();
276:                            while (itor.hasNext()) {
277:                                String sHREF = (String) itor.next();
278:                                Element elHREF = xmlDoc.createElementNS(
279:                                        NamespaceType.DAV.getURI(), "href");
280:                                elProp.appendChild(elHREF);
281:                                Text txt = xmlDoc.createTextNode(sHREF);
282:                                elHREF.appendChild(txt);
283:                            }
284:
285:                        } else if (range instanceof  StringRange) {
286:                            Element elRestriction = xmlDoc.createElementNS(
287:                                    NamespaceType.XML_SCHEMA.getURI(),
288:                                    "restriction");
289:                            elProp.appendChild(elRestriction);
290:                            elRestriction.setAttributeNS(
291:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
292:                                    NamespaceType.XML_SCHEMA.getPrefix()
293:                                            + ":string");
294:                            StringRange actualRange = (StringRange) range;
295:
296:                            String sValue = Integer.toString(actualRange
297:                                    .getMinLength());
298:                            Element elTemp = xmlDoc.createElementNS(
299:                                    NamespaceType.XML_SCHEMA.getURI(),
300:                                    "minLength");
301:                            elRestriction.appendChild(elTemp);
302:                            Text txt = xmlDoc.createTextNode(sValue);
303:                            elTemp.appendChild(txt);
304:
305:                            sValue = Integer.toString(actualRange
306:                                    .getMaxLength());
307:                            elTemp = xmlDoc.createElementNS(
308:                                    NamespaceType.XML_SCHEMA.getURI(),
309:                                    "maxLength");
310:                            elRestriction.appendChild(elTemp);
311:                            txt = xmlDoc.createTextNode(sValue);
312:                            elTemp.appendChild(txt);
313:
314:                        } else if (range instanceof  URIRange) {
315:                            Element elRestriction = xmlDoc.createElementNS(
316:                                    NamespaceType.XML_SCHEMA.getURI(),
317:                                    "restriction");
318:                            elProp.appendChild(elRestriction);
319:                            elRestriction.setAttributeNS(
320:                                    NamespaceType.XML_SCHEMA.getURI(), "base",
321:                                    NamespaceType.XML_SCHEMA.getPrefix()
322:                                            + ":anyURI");
323:                        } else if (range instanceof  ValueRange) {
324:                            Element elResourceType = xmlDoc.createElementNS(
325:                                    NamespaceType.DAV.getURI(), "resourcetype");
326:                            elProp.appendChild(elResourceType);
327:
328:                            Element elPropRes = xmlDoc.createElementNS(
329:                                    NamespaceType.DAV.getURI(), "value");
330:                            elResourceType.appendChild(elPropRes);
331:
332:                            List aHREFs = ((ValueRange) range).getHREFs();
333:                            Iterator itor = aHREFs.iterator();
334:                            while (itor.hasNext()) {
335:                                String sHREF = (String) itor.next();
336:                                Element elHREF = xmlDoc.createElementNS(
337:                                        NamespaceType.DAV.getURI(), "href");
338:                                elProp.appendChild(elHREF);
339:                                Text txt = xmlDoc.createTextNode(sHREF);
340:                                elHREF.appendChild(txt);
341:                            }
342:                        }
343:                    }
344:                }
345:            }
346:
347:            /**
348:             * Populates a property instance with WebDAV range values from
349:             * XML.
350:             * 
351:             * @param propInst Property instance to populate
352:             * @param propEl Root element of property instance
353:             */
354:            public static void fromXML(PropertyInstance propInst, Element propEl) {
355:                String sResourceType = null;
356:                ArrayList aContentTypes = new ArrayList();
357:                ArrayList aHREFs = new ArrayList();
358:                Element elRestriction = null;
359:
360:                NodeList nl = propEl.getChildNodes();
361:                for (int i = 0; i < nl.getLength(); i++) {
362:                    Node node = nl.item(i);
363:                    if (node.getNodeType() == Node.ELEMENT_NODE) {
364:                        Element elTemp = (Element) node;
365:                        if (elTemp.getLocalName().equals("resourcetype")) {
366:                            Node node2 = elTemp.getFirstChild();
367:                            if (node2 != null
368:                                    && node2.getNodeType() == Node.ELEMENT_NODE) {
369:                                Element elResourceType = (Element) node2;
370:                                if (elResourceType.getLocalName().equals(
371:                                        "value")) {
372:                                    sResourceType = "value";
373:                                } else if (elResourceType.getLocalName()
374:                                        .equals("property-resource")) {
375:                                    sResourceType = "property-resource";
376:                                } else if (elResourceType.getLocalName()
377:                                        .equals("collection")) {
378:                                    sResourceType = "collection";
379:                                } else {
380:                                    sResourceType = "resource";
381:                                }
382:                            }
383:                        } else if (elTemp.getLocalName().equals("href")) {
384:                            Node node2 = elTemp.getFirstChild();
385:                            if (node2 != null
386:                                    && node2.getNodeType() == Node.TEXT_NODE) {
387:                                aHREFs.add(node2.getNodeValue());
388:                            }
389:                        } else if (elTemp.getLocalName().equals("contenttype")) {
390:                            Node node2 = elTemp.getFirstChild();
391:                            if (node2 != null
392:                                    && node2.getNodeType() == Node.TEXT_NODE) {
393:                                aContentTypes.add(node2.getNodeValue());
394:                            }
395:                        } else if (elTemp.getLocalName().equals("restriction")) {
396:                            elRestriction = elTemp;
397:                        }
398:                    }
399:                }
400:
401:                Range range = null;
402:                if (elRestriction != null) {
403:                    range = DAVRangeValue.getRestrictionRange(elRestriction);
404:                } else if (sResourceType != null) {
405:                    if (sResourceType.equals("value")) {
406:                        range = new ValueRange();
407:                        ((ValueRange) range).setValueGroups(aHREFs);
408:                    } else if (sResourceType.equals("property-resource")) {
409:                        range = new PropertyRange();
410:                        ((PropertyRange) range).setHREFs(aHREFs);
411:                    } else if (sResourceType.equals("collection")) {
412:                        range = new CollectionRange();
413:                        ((CollectionRange) range).setHREFs(aHREFs);
414:                    } else if (sResourceType.equals("resource")) {
415:                        range = new ResourceRange();
416:                        ((ResourceRange) range).setHREFs(aHREFs);
417:                    }
418:                } else {
419:                    range = new StringRange();
420:                }
421:
422:                DAVRangeValue value = (DAVRangeValue) propInst
423:                        .getNewValueInstance();
424:                value.setRange(range);
425:                propInst.addValueWithoutFiringVirtualFileEvent(value);
426:            }
427:
428:            private static Range getRestrictionRange(Element elRestriction) {
429:                Range range = null;
430:
431:                if (elRestriction.hasAttributeNS(NamespaceType.XML_SCHEMA
432:                        .getURI(), "base")) {
433:                    String sBase = elRestriction.getAttributeNS(
434:                            NamespaceType.XML_SCHEMA.getURI(), "base");
435:                    if (sBase != null && !sBase.equals("")) {
436:                        if (sBase.equals(NamespaceType.XML_SCHEMA.getPrefix()
437:                                + ":boolean")) {
438:                            range = new BooleanRange();
439:
440:                            NodeList nl = elRestriction.getChildNodes();
441:                            for (int i = 0; i < nl.getLength(); i++) {
442:                                Node node = nl.item(i);
443:                                System.out
444:                                        .println("Checking node under restriction");
445:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
446:                                    Element elTemp = (Element) node;
447:                                    System.out.println("Node is an element");
448:                                    if (elTemp.getLocalName().equals("labels")) {
449:                                        System.out.println("Found labels node");
450:                                        String sTrueText = elTemp
451:                                                .getAttributeNS(
452:                                                        NamespaceType.OHRM
453:                                                                .getURI(),
454:                                                        "trueLabel");
455:                                        String sFalseText = elTemp
456:                                                .getAttributeNS(
457:                                                        NamespaceType.OHRM
458:                                                                .getURI(),
459:                                                        "falseLabel");
460:                                        ((BooleanRange) range)
461:                                                .setTrueText(sTrueText);
462:                                        ((BooleanRange) range)
463:                                                .setFalseText(sFalseText);
464:                                    }
465:                                }
466:                            }
467:
468:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
469:                                .getPrefix()
470:                                + ":dateTime")) {
471:                            range = new DateTimeRange();
472:
473:                            String sMax = null;
474:                            String sMin = null;
475:
476:                            NodeList nl = elRestriction.getChildNodes();
477:                            for (int i = 0; i < nl.getLength(); i++) {
478:                                Node node = nl.item(i);
479:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
480:                                    Element elTemp = (Element) node;
481:                                    if (elTemp.getLocalName().equals(
482:                                            "maxInclusive")
483:                                            || elTemp.getLocalName().equals(
484:                                                    "maxExclusive")) {
485:                                        Node node2 = elTemp.getFirstChild();
486:                                        if (node2 != null
487:                                                && node2.getNodeType() == Node.TEXT_NODE) {
488:                                            sMax = node2.getNodeValue();
489:                                        }
490:                                    } else if (elTemp.getLocalName().equals(
491:                                            "minInclusive")
492:                                            || elTemp.getLocalName().equals(
493:                                                    "minExclusive")) {
494:                                        Node node2 = elTemp.getFirstChild();
495:                                        if (node2 != null
496:                                                && node2.getNodeType() == Node.TEXT_NODE) {
497:                                            sMin = node2.getNodeValue();
498:                                        }
499:                                    }
500:                                }
501:                            }
502:
503:                            if (sMax != null) {
504:                                SimpleDateFormat format = new SimpleDateFormat(
505:                                        DAVRangeValue.XSD_DATE_TIME_FORMAT);
506:                                Date dt;
507:                                try {
508:                                    dt = format.parse(sMax);
509:                                    ((DateTimeRange) range).setMaximum(dt);
510:                                } catch (ParseException e) {
511:                                    range = null;
512:                                    e.printStackTrace();
513:                                }
514:                            }
515:                            if (sMin != null) {
516:                                SimpleDateFormat format = new SimpleDateFormat(
517:                                        DAVRangeValue.XSD_DATE_TIME_FORMAT);
518:                                Date dt;
519:                                try {
520:                                    dt = format.parse(sMin);
521:                                    ((DateTimeRange) range).setMinimum(dt);
522:                                } catch (ParseException e) {
523:                                    range = null;
524:                                    e.printStackTrace();
525:                                }
526:                            }
527:
528:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
529:                                .getPrefix()
530:                                + ":date")) {
531:                            range = new DateRange();
532:
533:                            String sMax = null;
534:                            String sMin = null;
535:
536:                            NodeList nl = elRestriction.getChildNodes();
537:                            for (int i = 0; i < nl.getLength(); i++) {
538:                                Node node = nl.item(i);
539:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
540:                                    Element elTemp = (Element) node;
541:                                    if (elTemp.getLocalName().equals(
542:                                            "maxInclusive")
543:                                            || elTemp.getLocalName().equals(
544:                                                    "maxExclusive")) {
545:                                        Node node2 = elTemp.getFirstChild();
546:                                        if (node2 != null
547:                                                && node2.getNodeType() == Node.TEXT_NODE) {
548:                                            sMax = node2.getNodeValue();
549:                                        }
550:                                    } else if (elTemp.getLocalName().equals(
551:                                            "minInclusive")
552:                                            || elTemp.getLocalName().equals(
553:                                                    "minExclusive")) {
554:                                        Node node2 = elTemp.getFirstChild();
555:                                        if (node2 != null
556:                                                && node2.getNodeType() == Node.TEXT_NODE) {
557:                                            sMin = node2.getNodeValue();
558:                                        }
559:                                    }
560:                                }
561:                            }
562:
563:                            if (sMax != null) {
564:                                SimpleDateFormat format = new SimpleDateFormat(
565:                                        DAVRangeValue.XSD_DATE_FORMAT);
566:                                Date dt;
567:                                try {
568:                                    dt = format.parse(sMax);
569:                                    ((DateRange) range).setMaximum(dt);
570:                                } catch (ParseException e) {
571:                                    range = null;
572:                                    e.printStackTrace();
573:                                }
574:                            }
575:                            if (sMin != null) {
576:                                SimpleDateFormat format = new SimpleDateFormat(
577:                                        DAVRangeValue.XSD_DATE_FORMAT);
578:                                Date dt;
579:                                try {
580:                                    dt = format.parse(sMin);
581:                                    ((DateRange) range).setMinimum(dt);
582:                                } catch (ParseException e) {
583:                                    range = null;
584:                                    e.printStackTrace();
585:                                }
586:                            }
587:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
588:                                .getPrefix()
589:                                + ":float")) {
590:                            range = new FloatRange();
591:
592:                            String sMax = null;
593:                            String sMin = null;
594:
595:                            NodeList nl = elRestriction.getChildNodes();
596:                            for (int i = 0; i < nl.getLength(); i++) {
597:                                Node node = nl.item(i);
598:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
599:                                    Element elTemp = (Element) node;
600:                                    if (elTemp.getLocalName().equals(
601:                                            "maxInclusive")
602:                                            || elTemp.getLocalName().equals(
603:                                                    "maxExclusive")) {
604:                                        Node node2 = elTemp.getFirstChild();
605:                                        if (node2 != null
606:                                                && node2.getNodeType() == Node.TEXT_NODE) {
607:                                            sMax = node2.getNodeValue();
608:                                        }
609:                                    } else if (elTemp.getLocalName().equals(
610:                                            "minInclusive")
611:                                            || elTemp.getLocalName().equals(
612:                                                    "minExclusive")) {
613:                                        Node node2 = elTemp.getFirstChild();
614:                                        if (node2 != null
615:                                                && node2.getNodeType() == Node.TEXT_NODE) {
616:                                            sMin = node2.getNodeValue();
617:                                        }
618:                                    }
619:                                }
620:                            }
621:
622:                            if (sMax != null) {
623:                                ((FloatRange) range).setMaximum(Float
624:                                        .parseFloat(sMax));
625:                            }
626:                            if (sMin != null) {
627:                                ((FloatRange) range).setMinimum(Float
628:                                        .parseFloat(sMin));
629:                            }
630:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
631:                                .getPrefix()
632:                                + ":integer")) {
633:                            range = new IntegerRange();
634:
635:                            String sMax = null;
636:                            String sMin = null;
637:
638:                            NodeList nl = elRestriction.getChildNodes();
639:                            for (int i = 0; i < nl.getLength(); i++) {
640:                                Node node = nl.item(i);
641:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
642:                                    Element elTemp = (Element) node;
643:                                    if (elTemp.getLocalName().equals(
644:                                            "maxInclusive")
645:                                            || elTemp.getLocalName().equals(
646:                                                    "maxExclusive")) {
647:                                        Node node2 = elTemp.getFirstChild();
648:                                        if (node2 != null
649:                                                && node2.getNodeType() == Node.TEXT_NODE) {
650:                                            sMax = node2.getNodeValue();
651:                                        }
652:                                    } else if (elTemp.getLocalName().equals(
653:                                            "minInclusive")
654:                                            || elTemp.getLocalName().equals(
655:                                                    "minExclusive")) {
656:                                        Node node2 = elTemp.getFirstChild();
657:                                        if (node2 != null
658:                                                && node2.getNodeType() == Node.TEXT_NODE) {
659:                                            sMin = node2.getNodeValue();
660:                                        }
661:                                    }
662:                                }
663:                            }
664:
665:                            if (sMax != null) {
666:                                ((IntegerRange) range).setMaximum(Integer
667:                                        .parseInt(sMax));
668:                            }
669:                            if (sMin != null) {
670:                                ((IntegerRange) range).setMinimum(Integer
671:                                        .parseInt(sMin));
672:                            }
673:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
674:                                .getPrefix()
675:                                + ":string")) {
676:                            range = new StringRange();
677:
678:                            String sMax = null;
679:                            String sMin = null;
680:
681:                            NodeList nl = elRestriction.getChildNodes();
682:                            for (int i = 0; i < nl.getLength(); i++) {
683:                                Node node = nl.item(i);
684:                                if (node.getNodeType() == Node.ELEMENT_NODE) {
685:                                    Element elTemp = (Element) node;
686:                                    if (elTemp.getLocalName().equals(
687:                                            "maxLength")) {
688:                                        Node node2 = elTemp.getFirstChild();
689:                                        if (node2 != null
690:                                                && node2.getNodeType() == Node.TEXT_NODE) {
691:                                            sMax = node2.getNodeValue();
692:                                        }
693:                                    } else if (elTemp.getLocalName().equals(
694:                                            "minLength")) {
695:                                        Node node2 = elTemp.getFirstChild();
696:                                        if (node2 != null
697:                                                && node2.getNodeType() == Node.TEXT_NODE) {
698:                                            sMin = node2.getNodeValue();
699:                                        }
700:                                    }
701:                                }
702:                            }
703:
704:                            if (sMax != null) {
705:                                ((StringRange) range).setMaxLength(Integer
706:                                        .parseInt(sMax));
707:                            }
708:                            if (sMin != null) {
709:                                ((StringRange) range).setMinLength(Integer
710:                                        .parseInt(sMin));
711:                            }
712:                        } else if (sBase.equals(NamespaceType.XML_SCHEMA
713:                                .getPrefix()
714:                                + ":anyURI")) {
715:                            range = new URIRange();
716:                        }
717:                    }
718:                }
719:
720:                if (range == null) {
721:                    range = new StringRange();
722:                }
723:
724:                return range;
725:            }
726:
727:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.