Source Code Cross Referenced for XMLLiteralType.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » datatypes » xsd » impl » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.datatypes.xsd.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************
002:         * File:        XMLLiteralType.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  08-Dec-02
005:         * 
006:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: XMLLiteralType.java,v 1.12 2008/01/02 12:04:01 andy_seaborne Exp $
009:         *****************************************************************/package com.hp.hpl.jena.datatypes.xsd.impl;
010:
011:        import com.hp.hpl.jena.datatypes.*;
012:        import com.hp.hpl.jena.vocabulary.RDF;
013:        import com.hp.hpl.jena.rdf.arp.*;
014:        import org.xml.sax.ErrorHandler;
015:        import org.xml.sax.SAXParseException;
016:        import org.xml.sax.SAXException;
017:        import com.hp.hpl.jena.shared.BrokenException;
018:        import java.io.*;
019:
020:        /**
021:         * Builtin data type to represent XMLLiteral (i.e. items created
022:         * by use of <code>rdf:parsetype='literal'</code>.
023:         * 
024:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
025:         * @version $Revision: 1.12 $ on $Date: 2008/01/02 12:04:01 $
026:         */
027:        public class XMLLiteralType extends BaseDatatype implements  RDFDatatype {
028:            /** Singleton instance */
029:            public static final RDFDatatype theXMLLiteralType = new XMLLiteralType(
030:                    RDF.getURI() + "XMLLiteral");
031:
032:            /**
033:             * Private constructor.
034:             */
035:            private XMLLiteralType(String uri) {
036:                super (uri);
037:            }
038:
039:            /**
040:             * Convert a serialize a value of this datatype out
041:             * to lexical form.
042:             */
043:            public String unparse(Object value) {
044:                return value.toString();
045:            }
046:
047:            /**
048:             * Parse a lexical form of this datatype to a value
049:             * @throws DatatypeFormatException if the lexical form is not legal
050:             */
051:            public Object parse(String lexicalForm)
052:                    throws DatatypeFormatException {
053:                if (!isValid(lexicalForm))
054:                    throw new DatatypeFormatException("Bad rdf:XMLLiteral");
055:                return lexicalForm;
056:            }
057:
058:            /**
059:             * Test whether the given string is a legal lexical form
060:             * of this datatype.
061:             */
062:            public boolean isValid(final String lexicalForm) {
063:                /*
064:                 * To check the lexical form we construct
065:                 * a dummy RDF/XML document and parse it with
066:                 * ARP. ARP performs an exclusive canonicalization,
067:                 * the dummy document has exactly one triple.
068:                 * If the lexicalForm is valid then the resulting
069:                 * literal found by ARP is unchanged.
070:                 * All other scenarios are either impossible
071:                 * or occur because the lexical form is invalid.
072:                 */
073:                final boolean status[] = new boolean[] { false, false, false };
074:                // status[0] true on error or other reason to know that this is not well-formed
075:                // status[1] true once first triple found
076:                // status[2] the result (good if status[1] and not status[0]).
077:
078:                ARP arp = new ARP();
079:
080:                arp.getHandlers().setErrorHandler(new ErrorHandler() {
081:                    public void fatalError(SAXParseException e) {
082:                        status[0] = true;
083:                    }
084:
085:                    public void error(SAXParseException e) {
086:                        status[0] = true;
087:                    }
088:
089:                    public void warning(SAXParseException e) {
090:                        status[0] = true;
091:                    }
092:                });
093:                arp.getHandlers().setStatementHandler(new StatementHandler() {
094:                    public void statement(AResource a, AResource b, ALiteral l) {
095:                        /* this method is invoked exactly once
096:                         * while parsing the dummy document.
097:                         * The l argument is in exclusive canonical XML and
098:                         * corresponds to where the lexical form has been 
099:                         * in the dummy document. The lexical form is valid
100:                         * iff it is unchanged.
101:                         */
102:                        if (status[1] || !l.isWellFormedXML()) {
103:                            status[0] = true;
104:                        }
105:                        //throw new BrokenException("plain literal in XMLLiteral code.");
106:                        status[1] = true;
107:                        status[2] = l.toString().equals(lexicalForm);
108:                    }
109:
110:                    public void statement(AResource a, AResource b, AResource l) {
111:                        status[0] = true;
112:                        //throw new BrokenException("resource valued RDF/XML in XMLLiteral code.");
113:                    }
114:                });
115:                try {
116:
117:                    arp
118:                            .load(new StringReader(
119:                                    "<rdf:RDF  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
120:                                            + "<rdf:Description><rdf:value rdf:parseType='Literal'>"
121:                                            + lexicalForm + "</rdf:value>\n"
122:                                            + "</rdf:Description></rdf:RDF>"));
123:
124:                } catch (IOException ioe) {
125:                    throw new BrokenException(ioe);
126:                } catch (SAXException s) {
127:                    return false;
128:                }
129:
130:                return (!status[0]) && status[1] && status[2];
131:            }
132:
133:        }
134:
135:        /*
136:         (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
137:         All rights reserved.
138:
139:         Redistribution and use in source and binary forms, with or without
140:         modification, are permitted provided that the following conditions
141:         are met:
142:
143:         1. Redistributions of source code must retain the above copyright
144:         notice, this list of conditions and the following disclaimer.
145:
146:         2. Redistributions in binary form must reproduce the above copyright
147:         notice, this list of conditions and the following disclaimer in the
148:         documentation and/or other materials provided with the distribution.
149:
150:         3. The name of the author may not be used to endorse or promote products
151:         derived from this software without specific prior written permission.
152:
153:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
154:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
155:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
156:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
157:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
158:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
159:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
160:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
161:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
162:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
163:         */
w__w___w__.__j___a_v___a_2s.___com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.