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


001:        /*
002:         	(c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         	All rights reserved.
004:         	$Id: TestEntityOutput.java,v 1.12 2008/01/02 12:06:48 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.xmloutput.test;
008:
009:        import java.io.*;
010:
011:        import com.hp.hpl.jena.rdf.model.*;
012:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
013:        import com.hp.hpl.jena.vocabulary.RDF;
014:        import com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter;
015:
016:        /**
017:         Tests for entities being created corresponding to prefixes.
018:         @author kers
019:         */
020:        public class TestEntityOutput extends ModelTestBase {
021:            public TestEntityOutput(String name) {
022:                super (name);
023:            }
024:
025:            public void testSettingWriterEntityProperty() {
026:                FakeBaseWriter w = new FakeBaseWriter();
027:                assertEquals(false, w.getShowDoctypeDeclaration());
028:                assertEquals("false", w.setProperty("showDoctypeDeclaration",
029:                        "true"));
030:                assertEquals(true, w.getShowDoctypeDeclaration());
031:                assertEquals("true", w.setProperty("showDoctypeDeclaration",
032:                        "false"));
033:                assertEquals(false, w.getShowDoctypeDeclaration());
034:                //
035:                assertEquals("false", w.setProperty("showDoctypeDeclaration",
036:                        Boolean.TRUE));
037:                assertEquals(true, w.getShowDoctypeDeclaration());
038:                assertEquals("true", w.setProperty("showDoctypeDeclaration",
039:                        Boolean.FALSE));
040:                assertEquals(false, w.getShowDoctypeDeclaration());
041:            }
042:
043:            public void testKnownEntityNames() {
044:                BaseXMLWriter w = new FakeBaseWriter();
045:                assertEquals(true, w.isPredefinedEntityName("lt"));
046:                assertEquals(true, w.isPredefinedEntityName("gt"));
047:                assertEquals(true, w.isPredefinedEntityName("amp"));
048:                assertEquals(true, w.isPredefinedEntityName("apos"));
049:                assertEquals(true, w.isPredefinedEntityName("quot"));
050:                //
051:                assertEquals(false, w.isPredefinedEntityName("alt"));
052:                assertEquals(false, w.isPredefinedEntityName("amper"));
053:                assertEquals(false, w.isPredefinedEntityName("tapost"));
054:                assertEquals(false, w.isPredefinedEntityName("gte"));
055:                //
056:                assertEquals(false, w.isPredefinedEntityName("rdf"));
057:                assertEquals(false, w.isPredefinedEntityName("smerp"));
058:                assertEquals(false, w.isPredefinedEntityName("nl"));
059:                assertEquals(false, w.isPredefinedEntityName("acute"));
060:            }
061:
062:            public void testRDFNamespaceMissing() {
063:                Model m = createMemModel();
064:                modelAdd(m, "x R fake:uri#bogus");
065:                m.setNsPrefix("spoo", "fake:uri#");
066:                m.setNsPrefix("eh", "eh:/");
067:                String s = checkedModelToString(m);
068:                assertMatches("<!DOCTYPE rdf:RDF \\[", s);
069:                assertMatches("<!ENTITY spoo 'fake:uri#'>", s);
070:                assertMatches("rdf:resource=\"&spoo;bogus\"", s);
071:            }
072:
073:            public void testUsesEntityForPrefix() {
074:                Model m = modelWithStatements("x R fake:uri#bogus");
075:                m.setNsPrefix("spoo", "fake:uri#");
076:                m.setNsPrefix("eh", "eh:/");
077:                String s = checkedModelToString(m);
078:                assertMatches("<!DOCTYPE rdf:RDF \\[", s);
079:                assertMatches("<!ENTITY spoo 'fake:uri#'>", s);
080:                assertMatches("rdf:resource=\"&spoo;bogus\"", s);
081:            }
082:
083:            public void testCatchesBadEntities() {
084:                testCatchesBadEntity("amp");
085:                testCatchesBadEntity("lt");
086:                testCatchesBadEntity("gt");
087:                testCatchesBadEntity("apos");
088:                testCatchesBadEntity("quot");
089:            }
090:
091:            /* Old code produced:
092:            <!DOCTYPE rdf:RDF [
093:            <!ENTITY dd 'http://www.example.org/a"b#'>
094:            <!ENTITY ampersand 'http://www.example.org/a?a&b#'>
095:            <!ENTITY espace 'http://www.example.org/a%20space#'>
096:            <!ENTITY zz 'http://www.example.org/a'b#'>
097:            <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>]>
098:             * 
099:             */
100:            /**
101:             * See
102:             * http://www.w3.org/TR/xml/#NT-EntityValue
103:             * " & and % ' are all legal URI chars, but illegal
104:             * in entity defn.
105:             * @throws IOException 
106:             */
107:            public void testDifficultChars() throws IOException {
108:                Model m = createMemModel();
109:                m.read("file:testing/abbreviated/entities.rdf");
110:                StringWriter w = new StringWriter();
111:                RDFWriter wr = m.getWriter();
112:                wr.setProperty("showDoctypeDeclaration", "true");
113:                wr.write(m, w, "http://example.org/");
114:                w.close();
115:                //    	System.err.println(w.toString());
116:                Reader r = new StringReader(w.toString());
117:                Model m2 = createMemModel();
118:                m2.read(r, "http://example.org/");
119:                assertIsoModels("showDoctypeDeclaration problem", m, m2);
120:            }
121:
122:            private void testCatchesBadEntity(String bad) {
123:                Model m = modelWithStatements("ampsersand spelt '&'; x R goo:spoo/noo");
124:                m.setNsPrefix("rdf", RDF.getURI());
125:                m.setNsPrefix(bad, "goo:spoo");
126:                m.setNsPrefix("eh", "eh:/");
127:                String s = checkedModelToString(m);
128:                //assertTrue( s.toString().contains( "<!DOCTYPE rdf:RDF [" ) ); // java5-ism
129:                assertTrue(s.toString().indexOf("<!DOCTYPE rdf:RDF [") >= 0);
130:                assertMismatches("<!ENTITY " + bad + " ", s);
131:                assertMismatches("rdf:resource=\"&" + bad + ";noo\"", s);
132:            }
133:
134:            private void checkModelFromXML(Model shouldBe, String s) {
135:                Model m = createMemModel();
136:                m.read(new StringReader(s), null, "RDF/XML");
137:                assertIsoModels("model should be read back correctly",
138:                        shouldBe, m);
139:            }
140:
141:            private String checkedModelToString(Model m) {
142:                String result = modelToString(m);
143:                checkModelFromXML(m, result);
144:                return result;
145:            }
146:
147:            private String modelToString(Model m) {
148:                StringWriter s = new StringWriter();
149:                RDFWriter w = m.getWriter("RDF/XML-ABBREV");
150:                w.setProperty("showDoctypeDeclaration", Boolean.TRUE);
151:                w.write(m, s, null);
152:                return s.toString();
153:            }
154:
155:            private void assertMatches(String pattern, String x) {
156:                if (!x.matches("(?s).*(" + pattern + ").*"))
157:                    fail("pattern {" + pattern + "} does not match string {"
158:                            + x + "}");
159:            }
160:
161:            private void assertMismatches(String pattern, String x) {
162:                if (x.matches("(?s).*(" + pattern + ").*"))
163:                    fail("pattern {" + pattern + "} should not match string {"
164:                            + x + "}");
165:            }
166:
167:            private final static class FakeBaseWriter extends BaseXMLWriter {
168:                protected void unblockAll() {
169:                }
170:
171:                protected void blockRule(Resource r) {
172:                }
173:
174:                protected void writeBody(Model mdl, PrintWriter pw,
175:                        String baseUri, boolean inclXMLBase) {
176:                }
177:
178:                protected boolean getShowDoctypeDeclaration() {
179:                    return showDoctypeDeclaration.booleanValue();
180:                }
181:            }
182:        }
183:
184:        /*
185:         *  (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
186:         *  All rights reserved.
187:         *
188:         * Redistribution and use in source and binary forms, with or without
189:         * modification, are permitted provided that the following conditions
190:         * are met:
191:         * 1. Redistributions of source code must retain the above copyright
192:         *    notice, this list of conditions and the following disclaimer.
193:         * 2. Redistributions in binary form must reproduce the above copyright
194:         *    notice, this list of conditions and the following disclaimer in the
195:         *    documentation and/or other materials provided with the distribution.
196:         * 3. The name of the author may not be used to endorse or promote products
197:         *    derived from this software without specific prior written permission.
198:         *
199:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
200:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
202:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
203:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
204:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
205:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
206:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
207:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
208:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
209:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.