Source Code Cross Referenced for SourceProperty.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » source » helpers » 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 » apache lenya 2.0 » org.apache.cocoon.components.source.helpers 
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:        package org.apache.cocoon.components.source.helpers;
018:
019:        import org.apache.cocoon.xml.XMLUtils;
020:        import org.apache.cocoon.xml.dom.DOMBuilder;
021:        import org.apache.cocoon.xml.dom.DOMStreamer;
022:
023:        import org.apache.excalibur.xml.sax.XMLizable;
024:        import org.w3c.dom.Document;
025:        import org.w3c.dom.Element;
026:        import org.w3c.dom.Node;
027:        import org.w3c.dom.NodeList;
028:        import org.xml.sax.ContentHandler;
029:        import org.xml.sax.SAXException;
030:        import org.xml.sax.helpers.AttributesImpl;
031:
032:        /**
033:         * The interface for a property of a source
034:         *
035:         * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
036:         * @author <a href="mailto:holz@fiz-chemie.de">Martin Holz</a>
037:         * @version $Id: SourceProperty.java 433543 2006-08-22 06:22:54Z crossley $
038:         */
039:        public class SourceProperty implements  XMLizable {
040:
041:            private static final String URI = "http://www.w3.org/2000/xmlns/";
042:            private static final String NS_PREFIX = "property";
043:            private static final String D_PREFIX = NS_PREFIX + ":";
044:
045:            private String namespace;
046:            private String name;
047:            private Element value;
048:
049:            /**
050:             * Creates a new property for a source
051:             *
052:             * @param namespace The namespace of the property
053:             * @param name The name of the property
054:             */
055:            public SourceProperty(String namespace, String name) {
056:
057:                this .namespace = namespace;
058:                this .name = name;
059:
060:                try {
061:                    DOMBuilder builder = new DOMBuilder();
062:                    builder.startDocument();
063:                    builder.startPrefixMapping(NS_PREFIX, namespace);
064:                    AttributesImpl attrs = new AttributesImpl();
065:                    attrs.addAttribute(URI, NS_PREFIX, "xmlns:" + NS_PREFIX,
066:                            "NMTOKEN", namespace);
067:                    builder.startElement(namespace, name, D_PREFIX + name,
068:                            attrs);
069:                    builder.endElement(namespace, name, D_PREFIX + name);
070:                    builder.endPrefixMapping(NS_PREFIX);
071:                    Document doc = builder.getDocument();
072:                    this .value = doc.getDocumentElement();
073:                } catch (SAXException se) {
074:                    // do nothing
075:                }
076:            }
077:
078:            /**
079:             * Creates a new property for a source
080:             *
081:             * @param namespace The namespace of the property
082:             * @param name The name of the property
083:             * @param value The value of the property
084:             */
085:            public SourceProperty(String namespace, String name, String value) {
086:                this .namespace = namespace;
087:                this .name = name;
088:                setValue(value);
089:            }
090:
091:            /**
092:             * Creates a new property for a source
093:             *
094:             * @param property The property in DOM representation
095:             */
096:            public SourceProperty(Element property) {
097:                this .namespace = property.getNamespaceURI();
098:                this .name = property.getLocalName();
099:                this .value = property;
100:            }
101:
102:            /**
103:             * Sets the namespace for this property
104:             *
105:             * @param namespace The namespace of the property
106:             * @deprecated buggy
107:             */
108:            public void setNamespace(String namespace) {
109:                this .namespace = namespace;
110:            }
111:
112:            /**
113:             * Return the namespace of the property
114:             *
115:             * @return The namespace of the property
116:             */
117:            public String getNamespace() {
118:                return this .namespace;
119:            }
120:
121:            /**
122:             * Sets the name of the property
123:             *
124:             * @param name Name of the property
125:             * @deprecated buggy
126:             */
127:            public void setName(String name) {
128:                this .name = name;
129:            }
130:
131:            /**
132:             * Return the name of the property
133:             *
134:             * @return Name of the property
135:             */
136:            public String getName() {
137:                return this .name;
138:            }
139:
140:            /**
141:             * Sets the value of the property
142:             *
143:             * @param value Value of the property
144:             */
145:            public void setValue(String value) {
146:                try {
147:                    DOMBuilder builder = new DOMBuilder();
148:                    builder.startDocument();
149:                    builder.startPrefixMapping(NS_PREFIX, namespace);
150:                    AttributesImpl attrs = new AttributesImpl();
151:                    attrs.addAttribute(URI, NS_PREFIX, "xmlns:" + NS_PREFIX,
152:                            "NMTOKEN", namespace);
153:                    builder.startElement(namespace, name, D_PREFIX + name,
154:                            attrs);
155:                    builder.characters(value.toCharArray(), 0, value.length());
156:                    builder.endElement(namespace, name, D_PREFIX + name);
157:                    builder.endPrefixMapping(NS_PREFIX);
158:                    builder.endDocument();
159:                    Document doc = builder.getDocument();
160:                    this .value = doc.getDocumentElement();
161:                } catch (SAXException se) {
162:                    // do nothing
163:                }
164:            }
165:
166:            /**
167:             * Returns the value of the property
168:             *
169:             * @return Value of the property
170:             */
171:            public String getValueAsString() {
172:                NodeList nodeslist = this .value.getChildNodes();
173:                StringBuffer buffer = new StringBuffer();
174:                for (int i = 0; i < nodeslist.getLength(); i++) {
175:                    if ((nodeslist.item(i).getNodeType() == Node.TEXT_NODE)
176:                            || (nodeslist.item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
177:
178:                        buffer.append(nodeslist.item(i).getNodeValue());
179:                    }
180:                }
181:
182:                return buffer.toString();
183:            }
184:
185:            /**
186:             * Sets the value of the property
187:             *
188:             * @param values
189:             */
190:            public void setValue(NodeList values) {
191:                try {
192:                    DOMBuilder builder = new DOMBuilder();
193:                    builder.startDocument();
194:                    builder.startElement(namespace, name, name,
195:                            XMLUtils.EMPTY_ATTRIBUTES);
196:                    DOMStreamer stream = new DOMStreamer(builder);
197:                    for (int i = 0; i < values.getLength(); i++) {
198:                        stream.stream(values.item(i));
199:                    }
200:                    builder.endElement(namespace, name, name);
201:                    builder.endDocument();
202:                    Document doc = builder.getDocument();
203:                    this .value = doc.getDocumentElement();
204:                } catch (SAXException se) {
205:                    // do nothing
206:                }
207:            }
208:
209:            /**
210:             * Get the property value as DOM Element.
211:             */
212:            public Element getValue() {
213:                return this .value;
214:            }
215:
216:            /**
217:             * Generates SAX events representing the object's state.<br/>
218:             * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
219:             * that <code>handler</code> can actually be a {@link org.apache.cocoon.xml.XMLConsumer} that accepts such
220:             * events.
221:             *
222:             * @param handler
223:             */
224:            public void toSAX(ContentHandler handler) throws SAXException {
225:                DOMStreamer stream = new DOMStreamer(handler);
226:                stream.stream(this.value);
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.