Source Code Cross Referenced for ParserSupports.java in  » Build » ANT » org » apache » tools » ant » taskdefs » condition » 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 » Build » ANT » org.apache.tools.ant.taskdefs.condition 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant.taskdefs.condition;
019:
020:        import org.apache.tools.ant.BuildException;
021:        import org.apache.tools.ant.Project;
022:        import org.apache.tools.ant.ProjectComponent;
023:        import org.apache.tools.ant.util.JAXPUtils;
024:
025:        import org.xml.sax.SAXNotRecognizedException;
026:        import org.xml.sax.SAXNotSupportedException;
027:        import org.xml.sax.XMLReader;
028:
029:        /**
030:         * Test for the XML parser supporting a particular feature
031:         * @since Ant 1.7
032:         */
033:        public class ParserSupports extends ProjectComponent implements 
034:                Condition {
035:
036:            private String feature;
037:            private String property;
038:            private String value;
039:            // Error messages
040:            /** error - combined attributes not allowed */
041:            public static final String ERROR_BOTH_ATTRIBUTES = "Property and feature attributes are exclusive";
042:            /** feature */
043:            public static final String FEATURE = "feature";
044:            /** property */
045:            public static final String PROPERTY = "property";
046:
047:            /** error - not recognized */
048:            public static final String NOT_RECOGNIZED = " not recognized: ";
049:            /** error - not supported */
050:            public static final String NOT_SUPPORTED = " not supported: ";
051:            /** error - missing attribute */
052:            public static final String ERROR_NO_ATTRIBUTES = "Neither feature or property are set";
053:            /** error - no value */
054:            public static final String ERROR_NO_VALUE = "A value is needed when testing for property support";
055:
056:            /**
057:             * Feature to probe for.
058:             * @param feature the feature to probe for.
059:             */
060:            public void setFeature(String feature) {
061:                this .feature = feature;
062:            }
063:
064:            /**
065:             * Property to probe for
066:             * @param property the property to probe for.
067:             */
068:            public void setProperty(String property) {
069:                this .property = property;
070:            }
071:
072:            /**
073:             * Optional value to set.
074:             * Converted to a boolean value when setting a property
075:             * @param value the value to set.
076:             */
077:            public void setValue(String value) {
078:                this .value = value;
079:            }
080:
081:            /** {@inheritDoc}. */
082:            public boolean eval() throws BuildException {
083:                if (feature != null && property != null) {
084:                    throw new BuildException(ERROR_BOTH_ATTRIBUTES);
085:                }
086:                if (feature == null && property == null) {
087:                    throw new BuildException(ERROR_NO_ATTRIBUTES);
088:                }
089:                //pick a value that is good for everything
090:                if (feature != null) {
091:                    return evalFeature();
092:                }
093:                if (value == null) {
094:                    throw new BuildException(ERROR_NO_VALUE);
095:                }
096:                return evalProperty();
097:            }
098:
099:            /**
100:             * Get our reader
101:             * @return a reader
102:             */
103:            private XMLReader getReader() {
104:                JAXPUtils.getParser();
105:                return JAXPUtils.getXMLReader();
106:            }
107:
108:            /**
109:             * Set a feature
110:             * @return true if the feature could be set
111:             */
112:            public boolean evalFeature() {
113:                XMLReader reader = getReader();
114:                if (value == null) {
115:                    value = "true";
116:                }
117:                boolean v = Project.toBoolean(value);
118:                try {
119:                    reader.setFeature(feature, v);
120:                } catch (SAXNotRecognizedException e) {
121:                    log(FEATURE + NOT_RECOGNIZED + feature, Project.MSG_VERBOSE);
122:                    return false;
123:                } catch (SAXNotSupportedException e) {
124:                    log(FEATURE + NOT_SUPPORTED + feature, Project.MSG_VERBOSE);
125:                    return false;
126:                }
127:                return true;
128:            }
129:
130:            /**
131:             * Set a property
132:             * @return true if the feature could be set
133:             */
134:            public boolean evalProperty() {
135:                XMLReader reader = getReader();
136:                try {
137:                    reader.setProperty(property, value);
138:                } catch (SAXNotRecognizedException e) {
139:                    log(PROPERTY + NOT_RECOGNIZED + property,
140:                            Project.MSG_VERBOSE);
141:                    return false;
142:                } catch (SAXNotSupportedException e) {
143:                    log(PROPERTY + NOT_SUPPORTED + property,
144:                            Project.MSG_VERBOSE);
145:                    return false;
146:                }
147:                return true;
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.