Source Code Cross Referenced for TestXMLFeatures.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 2001, 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         * All rights reserved.
004:         * [See end of file]
005:         $Id: TestXMLFeatures.java,v 1.55 2008/01/02 12:06:48 andy_seaborne Exp $
006:         */
007:
008:        package com.hp.hpl.jena.xmloutput.test;
009:
010:        import java.io.*;
011:        import java.util.*;
012:        import java.util.regex.Pattern;
013:
014:        import com.hp.hpl.jena.graph.*;
015:        import com.hp.hpl.jena.iri.*;
016:        import com.hp.hpl.jena.rdf.model.*;
017:        import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
018:        import com.hp.hpl.jena.rdf.model.impl.Util;
019:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
020:        import com.hp.hpl.jena.shared.*;
021:        import com.hp.hpl.jena.vocabulary.RDF;
022:        import com.hp.hpl.jena.xmloutput.impl.*;
023:
024:        /**
025:         * @author bwm
026:         * @version $Name:  $ $Revision: 1.55 $ $Date: 2008/01/02 12:06:48 $
027:         */
028:
029:        public class TestXMLFeatures extends XMLOutputTestBase {
030:            // static AwkCompiler awk = PrettyWriterTest.awk;
031:            // static AwkMatcher matcher = PrettyWriterTest.matcher;
032:
033:            // static protected Log logger = LogFactory.getLog( TestXMLFeatures.class );
034:
035:            // static { logger.setLevel( Level.OFF ); }
036:
037:            private String base1 = "http://example/foobar";
038:
039:            private String base2 = "http://example/barfoo";
040:
041:            protected static String file1 = "testing/abbreviated/namespaces.rdf";
042:
043:            TestXMLFeatures(String name, String lang) {
044:                super (name, lang);
045:            }
046:
047:            public String toString() {
048:                return getName() + " " + lang;
049:            }
050:
051:            public void SUPPRESSEDtestRelativeURI() {
052:                Model m = ModelFactory.createDefaultModel();
053:                m.createResource("foo").addProperty(RDF.value, "bar");
054:                m.write(new OutputStream() {
055:                    public void write(int b) throws IOException {
056:                    }
057:                }, lang);
058:            }
059:
060:            public void SUPPRESStestNoStripes() throws IOException {
061:                check(
062:                        "testing/abbreviated/collection.rdf",
063:                        "                              <[a-zA-Z][-a-zA-Z0-9._]*:Class",
064:                        Change.blockRules("resourcePropertyElt"),
065:                        "http://example.org/foo");
066:            }
067:
068:            /**
069:             * Very specific test case to trap bug whereby a model which has a prefix
070:             * j.0 defined (eg it was read in from a model we wrote out earlier) wants
071:             * to allocate a new j.* prefix and picked j.0, BOOM.
072:             */
073:            public void SUPPRESSEDtestBrokenPrefixing() throws Exception {
074:                Model m = ModelFactory.createDefaultModel();
075:                m.add(ModelTestBase.statement(m,
076:                        "a http://bingle.bongle/booty#PP b"));
077:                m.add(ModelTestBase.statement(m,
078:                        "c http://dingle.dongle/dooty#PP d"));
079:                StringWriter sw = new StringWriter();
080:                m.write(sw);
081:                Model m2 = ModelFactory.createDefaultModel();
082:                String written = sw.toString();
083:                m2.read(new StringReader(written), "");
084:                StringWriter sw2 = new StringWriter();
085:                m2.write(sw2);
086:                String s2 = sw2.toString();
087:                int first = s2.indexOf("xmlns:j.0=");
088:                int last = s2.lastIndexOf("xmlns:j.0=");
089:                assertEquals(first, last);
090:                System.out.println(sw2.toString());
091:            }
092:
093:            /**
094:             * Writing a model with the base URI set to null should not throw a
095:             * nullpointer exception.
096:             */
097:            public void testNullBaseWithAbbrev() {
098:                ModelFactory.createDefaultModel().write(new StringWriter(),
099:                        lang, null);
100:            }
101:
102:            /**
103:             * This test checks that using a FileWriter works. It used not to work for
104:             * some encodings. The encoding used is the platform default encoding.
105:             * Because this may be MacRoman, we have to suppress warning messages.
106:             * 
107:             * @throws IOException
108:             */
109:            public void testBug696057() throws IOException {
110:                File f = File.createTempFile("jena", ".rdf");
111:                String fileName = f.getAbsolutePath();
112:                Model m = createMemModel();
113:                m.read(new FileInputStream(
114:                        "testing/wg/rdfms-syntax-incomplete/test001.rdf"), "");
115:                RDFDefaultErrorHandler.silent = true;
116:                Model m1 = null;
117:                SimpleLogger old = null;
118:                try {
119:                    old = BaseXMLWriter.setLogger(new SimpleLogger() {
120:                        public void warn(String s) {
121:                        }
122:
123:                        public void warn(String s, Exception e) {
124:                        }
125:                    });
126:                    m.write(new FileWriter(fileName), lang);
127:                    m1 = createMemModel();
128:                    m1.read(new FileInputStream(fileName), "");
129:                } finally {
130:                    RDFDefaultErrorHandler.silent = false;
131:                    BaseXMLWriter.setLogger(old);
132:                }
133:                assertTrue("Use of FileWriter", m.isIsomorphicWith(m1));
134:                f.delete();
135:            }
136:
137:            public void testXMLBase() throws IOException {
138:                check(file1, // any will do
139:                        "xml:base=['\"]" + base2 + "['\"]", new Change() {
140:                            public void modify(RDFWriter writer) {
141:                                String oldvalue = (String) writer.setProperty(
142:                                        "xmlbase", base1);
143:                                assertTrue("xmlbase valued non-null",
144:                                        oldvalue == null);
145:
146:                                oldvalue = (String) writer.setProperty(
147:                                        "xmlbase", base2);
148:                                assertEquals("xmlbase valued incorrect.",
149:                                        base1, oldvalue);
150:                            }
151:
152:                        });
153:            }
154:
155:            public void testPropertyURI() throws IOException {
156:                doBadPropTest(lang);
157:            }
158:
159:            void doBadPropTest(String lg) throws IOException {
160:                Model m = createMemModel();
161:                m.add(m.createResource(), m.createProperty("http://example/",
162:                        "foo#"), "foo");
163:                File file = File.createTempFile("rdf", ".xml");
164:                // file.deleteOnExit();
165:
166:                FileOutputStream fwriter = new FileOutputStream(file);
167:                try {
168:                    m.write(fwriter, lg);
169:                    fwriter.close();
170:                    fail("Writer did not detect bad property URI");
171:                } catch (InvalidPropertyURIException je) {
172:                    // as required, so nowt to do.
173:                }
174:                file.delete();
175:            }
176:
177:            public void testUseNamespace() throws IOException {
178:                check(file1, "xmlns:eg=['\"]http://example.org/#['\"]", Change
179:                        .setPrefix("eg", "http://example.org/#"));
180:            }
181:
182:            public void testSingleQuote() throws IOException {
183:                check(file1, "'", "\"", Change.setProperty(
184:                        "attributeQuoteChar", "'"));
185:            }
186:
187:            public void testDoubleQuote() throws IOException {
188:                check(file1, "\"", "'", Change.setProperty(
189:                        "attributeQuoteChar", "\""));
190:            }
191:
192:            public void testUseDefaultNamespace() throws IOException {
193:                check(file1, "xmlns=['\"]http://example.org/#['\"]", Change
194:                        .setPrefix("", "http://example.org/#"));
195:            }
196:
197:            public void testUseUnusedNamespace() throws IOException {
198:                check(file1, "xmlns:unused=['\"]http://unused.org/#['\"]",
199:                        Change.setPrefix("unused", "http://unused.org/#"));
200:            }
201:
202:            public void testRDFNamespace() throws IOException {
203:                check(file1, "xmlns:r=['\"]" + RDF.getURI() + "['\"]", "rdf:",
204:                        new Change() {
205:                            public void modify(Model m) {
206:                                m.removeNsPrefix("rdf");
207:                                m.setNsPrefix("r", RDF.getURI());
208:                            }
209:                        });
210:            }
211:
212:            public void testTab() throws IOException {
213:                check(file1, "          ", Change.setProperty("tab", "5"));
214:            }
215:
216:            public void testNoTab() throws IOException {
217:                check(file1, "  ", Change.setProperty("tab", "0"));
218:            }
219:
220:            public void testNoLiteral() throws IOException {
221:                check("testing/wg/rdfms-xml-literal-namespaces/test001.rdf",
222:                        "#XMLLiteral", "[\"']Literal[\"']", Change.setProperty(
223:                                "blockrules", "parseTypeLiteralPropertyElt"));
224:            }
225:
226:            public void testRDFDefaultNamespace() throws IOException {
227:                check(file1, "xmlns=['\"]" + RDF.getURI() + "['\"].*"
228:                        + "xmlns:j.cook.up=['\"]" + RDF.getURI() + "['\"]",
229:                        Change.setPrefix("", RDF.getURI()));
230:            }
231:
232:            public void testBadPrefixNamespace() throws IOException {
233:                // Trying to set the prefix should generate a warning.
234:                // check(file1, null, null, "xmlns:3", true, new Change() {
235:                // public void code( RDFWriter w ) {
236:                // w.setNsPrefix("3", "http://example.org/#");
237:                // }
238:                // });
239:            }
240:
241:            public void testDuplicateNamespace() throws IOException {
242:                check(
243:                        file1,
244:                        "xmlns:eg[12]=['\"]http://example.org/#['\"]",
245:                        "xmlns:eg[12]=['\"]http://example.org/#['\"].*xmlns:eg[12]=['\"]http://example.org/#['\"]",
246:                        new Change() {
247:                            public void modify(Model m) {
248:                                m.setNsPrefix("eg1", "http://example.org/#");
249:                                m.setNsPrefix("eg2", "http://example.org/#");
250:                            }
251:                        });
252:            }
253:
254:            public void testEntityDeclaration() throws IOException {
255:                check(file1,
256:                        "<!DOCTYPE rdf:RDF \\[[^]]*<!ENTITY spoo *'goo:boo'>",
257:                        "SPONGLE", Change.setProperty("showDoctypeDeclaration",
258:                                true).andSetPrefix("spoo", "goo:boo"));
259:            }
260:
261:            public void testEntityUse() throws IOException {
262:                check(file1, "rdf:resource=\"&ex0;spoo\"", "SPONGLE", Change
263:                        .setProperty("showDoctypeDeclaration", true));
264:            }
265:
266:            public void testDuplicatePrefix() throws IOException {
267:                check(file1, "xmlns:eg=['\"]http://example.org/file[12]#['\"]",
268:                        null, new Change() {
269:                            public void modify(Model m) {
270:                                m
271:                                        .setNsPrefix("eg",
272:                                                "http://example.org/file1#");
273:                                m
274:                                        .setNsPrefix("eg",
275:                                                "http://example.org/file2#");
276:                            }
277:                        });
278:            }
279:
280:            void setNsPrefixSysProp(String prefix, String uri) {
281:                System.setProperty(RDFWriter.NSPREFIXPROPBASE + uri, prefix);
282:            }
283:
284:            public void testUseNamespaceSysProp() throws IOException {
285:                check(file1, "xmlns:eg=['\"]http://example.org/#['\"]",
286:                        new Change() {
287:                            public void modify(RDFWriter writer) {
288:                                setNsPrefixSysProp("eg", "http://example.org/#");
289:                            }
290:                        });
291:            }
292:
293:            public void testDefaultNamespaceSysProp() throws IOException {
294:                check(file1, "xmlns=['\"]http://example.org/#['\"]",
295:                        new Change() {
296:                            public void modify(RDFWriter writer) {
297:                                setNsPrefixSysProp("", "http://example.org/#");
298:                            }
299:                        });
300:            }
301:
302:            public void testDuplicateNamespaceSysProp() throws IOException {
303:                check(
304:                        file1,
305:                        "xmlns:eg[12]=['\"]http://example.org/#['\"]",
306:                        "xmlns:eg[12]=['\"]http://example.org/#['\"].*xmlns:eg[12]=['\"]http://example.org/#['\"]",
307:                        new Change() {
308:
309:                            public void modify(RDFWriter writer) {
310:                                setNsPrefixSysProp("eg1",
311:                                        "http://example.org/#");
312:                                setNsPrefixSysProp("eg2",
313:                                        "http://example.org/#");
314:                            }
315:                        });
316:            }
317:
318:            public void testDuplicatePrefixSysProp() throws IOException {
319:                check(file1, "xmlns:eg=['\"]http://example.org/file[12]#['\"]",
320:                        null, new Change() {
321:                            public void modify(RDFWriter writer) {
322:                                setNsPrefixSysProp("eg",
323:                                        "http://example.org/file1#");
324:                                setNsPrefixSysProp("eg",
325:                                        "http://example.org/file2#");
326:                            }
327:                        });
328:            }
329:
330:            public void testDuplicatePrefixSysPropAndExplicit()
331:                    throws IOException {
332:                check(file1, "xmlns:eg=['\"]http://example.org/file[12]#['\"]",
333:                        null, new Change() {
334:                            public void modify(Model m) {
335:                                m
336:                                        .setNsPrefix("eg",
337:                                                "http://example.org/file1#");
338:                                setNsPrefixSysProp("eg",
339:                                        "http://example.org/file2#");
340:                            }
341:                        });
342:            }
343:
344:            public void testUTF8DeclAbsent() throws IOException {
345:                check(file1, "utf-8", null, "<\\?xml", Change.none());
346:            }
347:
348:            public void testUTF16DeclAbsent() throws IOException {
349:                check(file1, "utf-16", null, "<\\?xml", false, Change.none());
350:            }
351:
352:            public void testUTF8DeclPresent() throws IOException {
353:                check(file1, "utf-8", "<\\?xml", null, Change.setProperty(
354:                        "showXmlDeclaration", true));
355:            }
356:
357:            public void testUTF16DeclPresent() throws IOException {
358:                check(file1, "utf-16", "<\\?xml", null, Change.setProperty(
359:                        "showXmlDeclaration", true));
360:            }
361:
362:            public void testISO8859_1_DeclAbsent() throws IOException {
363:                check(file1, "iso-8859-1", null, "<\\?xml", Change.setProperty(
364:                        "showXmlDeclaration", false));
365:            }
366:
367:            public void testISO8859_1_DeclPresent() throws IOException {
368:                check(file1, "iso-8859-1", "<\\?xml[^?]*ISO-8859-1", null,
369:                        Change.none());
370:            }
371:
372:            public void testStringDeclAbsent() throws IOException {
373:                check(file1, null, "<\\?xml", Change.none());
374:            }
375:
376:            public void testStringDeclPresent() throws IOException {
377:                check(file1, "<\\?xml", "encoding", Change.setProperty(
378:                        "showXmlDeclaration", true));
379:            }
380:
381:            static final int BadPropURI = 1;
382:
383:            static final int NoError = 0;
384:
385:            static final int ExtraTriples = 2;
386:
387:            static final int BadURI = 3;
388:
389:            public void checkPropURI(String s, String p, Object val,
390:                    int behaviour) throws IOException {
391:                // create triple and graph.
392:                // BaseXMLWriter.dbg = true;
393:                // SystemOutAndErr.block();
394:                // TestLogger tl = new TestLogger(BaseXMLWriter.class);
395:                blockLogger();
396:                Node blank = Node.createAnon();
397:                Node prop = Node.createURI(s);
398:                Graph g = Factory.createGraphMem();
399:                g.add(Triple.create(blank, prop, blank));
400:                // create Model
401:                Model m = ModelFactory.createModelForGraph(g);
402:                // serialize
403:                StringWriter w = new StringWriter();
404:                RDFWriter rw = m.getWriter(lang);
405:                if (p != null)
406:                    rw.setProperty(p, val);
407:                try {
408:                    rw.write(m, w, "http://example.org/");
409:                    w.close();
410:                    String f = w.toString();
411:
412:                    switch (behaviour) {
413:                    case BadPropURI:
414:                        fail("Bad property URI <" + s + "> was not detected.");
415:                    case BadURI:
416:                        fail("Bad URI <" + s + "> was not detected.");
417:                    }
418:                    // read back in
419:                    Model m2 = createMemModel();
420:                    RDFReader rdr = m2.getReader("RDF/XML");
421:                    rdr.setProperty("error-mode", "lax");
422:                    rdr.read(m2, new StringReader(f), "http://example.org/");
423:                    // m2.read(, lang);
424:
425:                    // check
426:                    switch (behaviour) {
427:                    case ExtraTriples:
428:                        assertTrue("Expecting Brickley behaviour.",
429:                                m2.size() == 3);
430:                        break;
431:                    case NoError:
432:                        assertTrue("Comparing Model written out and read in.",
433:                                m.isIsomorphicWith(m2));
434:                        break;
435:
436:                    }
437:                } catch (BadURIException e) {
438:                    if (behaviour == BadURI)
439:                        return;
440:                    throw e;
441:                } catch (InvalidPropertyURIException je) {
442:                    if (behaviour == BadPropURI)
443:                        return;
444:                    throw je;
445:                } catch (JenaException e) {
446:                    throw e;
447:                } finally {
448:                    // BaseXMLWriter.dbg = false;
449:                    // tl.end();
450:                    unblockLogger();
451:                    // SystemOutAndErr.unblock();
452:                }
453:            }
454:
455:            public void testBadURIAsProperty1() throws IOException {
456:                try {
457:                    // RDFDefaultErrorHandler.logger.setLevel( Level.OFF );
458:                    checkPropURI("_:aa", null, null, BadURI);
459:                } finally { // RDFDefaultErrorHandler.logger.setLevel( Level.WARN );
460:                }
461:            }
462:
463:            public void testBadURIAsProperty2() throws IOException {
464:                try {
465:                    // RDFDefaultErrorHandler.logger.setLevel( Level.OFF );
466:                    checkPropURI("_:aa", "allowBadURIs", "true", NoError);
467:                } finally {// RDFDefaultErrorHandler.logger.setLevel( Level.WARN );
468:                }
469:            }
470:
471:            public void testLiAsProperty1() throws IOException {
472:                checkPropURI(RDF.getURI() + "li", null, null, BadPropURI);
473:            }
474:
475:            /*
476:             * public void testLiAsProperty2() throws IOException {
477:             * checkPropURI(RDF.getURI()+"li", "brickley", "true", ExtraTriples); }
478:             */
479:            public void testDescriptionAsProperty() throws IOException {
480:                checkPropURI(RDF.getURI() + "Description", null, null,
481:                        BadPropURI);
482:            }
483:
484:            public void testBadProperty1() throws IOException {
485:                checkPropURI("http://x/a.b/", null, null, BadPropURI);
486:            }
487:
488:            /*
489:             * public void testBadProperty2() throws IOException {
490:             * checkPropURI("http:/a.b/", "brickley", "http://example.org/b#",
491:             * ExtraTriples); }
492:             * 
493:             */
494:            public void testRelativeAPI() {
495:                RDFWriter w = createMemModel().getWriter(lang);
496:                String old = (String) w.setProperty("relativeURIs", "");
497:                assertEquals("default value check", old,
498:                        "same-document, absolute, relative, parent");
499:                w.setProperty("relativeURIs",
500:                        "network, grandparent,relative,  ");
501:                w.setProperty("relativeURIs",
502:                        "  parent, same-document, network, parent, absolute ");
503:                // TestLogger tl = new TestLogger(URI.class);
504:                blockLogger();
505:                w.setProperty("relativeURIs", "foo"); // will get warning
506:                assertTrue("A warning should have been generated.",
507:                        unblockLogger());
508:            }
509:
510:            private void relative(String relativeParam, String base,
511:                    Collection regexesPresent, Collection regexesAbsent)
512:                    throws IOException {
513:
514:                Model m = createMemModel();
515:                m.read("file:testing/abbreviated/relative-uris.rdf");
516:
517:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
518:                RDFWriter writer = m.getWriter(lang);
519:                writer.setProperty("relativeURIs", relativeParam);
520:                writer.write(m, bos, base);
521:                bos.close();
522:
523:                String contents = bos.toString("UTF8");
524:                try {
525:                    Model m2 = createMemModel();
526:                    m2.read(new StringReader(contents), base);
527:                    assertTrue(m.isIsomorphicWith(m2));
528:                    Iterator it = regexesPresent.iterator();
529:                    while (it.hasNext()) {
530:                        String regexPresent = (String) it.next();
531:                        assertTrue(
532:                                "Looking for /" + regexPresent + "/",
533:                                Pattern
534:                                        .compile(
535:                                                Util
536:                                                        .substituteStandardEntities(regexPresent),
537:                                                Pattern.DOTALL).matcher(
538:                                                contents).find()
539:                        //
540:                        // matcher.contains(
541:                        // contents,
542:                        // awk.compile(
543:                        // Util.substituteStandardEntities(regexPresent)))
544:                        );
545:                    }
546:                    it = regexesAbsent.iterator();
547:                    while (it.hasNext()) {
548:                        String regexAbsent = (String) it.next();
549:                        assertTrue(
550:                                "Looking for (not) /" + regexAbsent + "/",
551:                                !Pattern
552:                                        .compile(
553:                                                "[\"']"
554:                                                        + Util
555:                                                                .substituteStandardEntities(regexAbsent)
556:                                                        + "[\"']",
557:                                                Pattern.DOTALL).matcher(
558:                                                contents).find()
559:
560:                        // matcher.contains(
561:                        // contents,
562:                        // awk.compile(
563:                        // "[\"']"
564:                        // + Util.substituteStandardEntities(regexAbsent)
565:                        // + "[\"']"))
566:                        );
567:                    }
568:                    contents = null;
569:                } finally {
570:                    if (contents != null) {
571:                        System.err.println("===================");
572:                        System.err.println("Offending content - " + toString());
573:                        System.err.println("===================");
574:                        System.err.println(contents);
575:                        System.err.println("===================");
576:                    }
577:                }
578:            }
579:
580:            static String rData1[][] = {
581:                    // http://www.example.org/a/b/c/d/
582:                    { "", "http://www.example.org/a/b/c/d/",
583:                            "http://www.example.org/a/b/c/d/e/f/g/",
584:                            "http://www.example.org/a/b/C/D",
585:                            "http://www.example.org/A/B#foo/",
586:                            "http://www.example.org/a/b/c/d/X#bar",
587:                            "http://example.com/A",
588:                            "http://www.example.org/a/b/c/d/z[?]x=a", },
589:                    { "same-document", "", null, null, null, null, null, null, },
590:                    { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D",
591:                            "/A/B#foo/", "/a/b/c/d/X#bar", null,
592:                            "/a/b/c/d/z[?]x=a", },
593:                    { "relative", "[.]", "e/f/g/", null, null, "X#bar", null,
594:                            "z[?]x=a", },
595:                    { "parent", "[.][.]/d/", "[.][.]/d/e/f/g/", null, null,
596:                            "[.][.]/d/X#bar", null, "[.][.]/d/z[?]x=a", },
597:                    { "network", "//www.example.org/a/b/c/d/",
598:                            "//www.example.org/a/b/c/d/e/f/g/",
599:                            "//www.example.org/a/b/C/D",
600:                            "//www.example.org/A/B#foo/",
601:                            "//www.example.org/a/b/c/d/X#bar",
602:                            "//example.com/A",
603:                            "//www.example.org/a/b/c/d/z[?]x=a", },
604:                    { "grandparent", "[.][.]/[.][.]/c/d/",
605:                            "[.][.]/[.][.]/c/d/e/f/g/", "[.][.]/[.][.]/C/D",
606:                            null, "[.][.]/[.][.]/c/d/X#bar", null,
607:                            "[.][.]/[.][.]/c/d/z[?]x=a", }, };
608:
609:            static String rData2[][] = {
610:                    // http://www.example.org/a/b/c/d
611:                    { "", "http://www.example.org/a/b/c/d/",
612:                            "http://www.example.org/a/b/c/d/e/f/g/",
613:                            "http://www.example.org/a/b/C/D",
614:                            "http://www.example.org/A/B#foo/",
615:                            "http://www.example.org/a/b/c/d/X#bar",
616:                            "http://example.com/A",
617:                            "http://www.example.org/a/b/c/d/z[?]x=a", },
618:                    { "same-document", null, null, null, null, null, null,
619:                            null, },
620:                    { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D",
621:                            "/A/B#foo/", "/a/b/c/d/X#bar", null,
622:                            "/a/b/c/d/z[?]x=a", },
623:                    { "relative", "d/", "d/e/f/g/", null, null, "d/X#bar",
624:                            null, "d/z[?]x=a", },
625:                    { "parent", "[.][.]/c/d/", "[.][.]/c/d/e/f/g/",
626:                            "[.][.]/C/D", null, "[.][.]/c/d/X#bar", null,
627:                            "[.][.]/c/d/z[?]x=a", },
628:                    { "network", "//www.example.org/a/b/c/d/",
629:                            "//www.example.org/a/b/c/d/e/f/g/",
630:                            "//www.example.org/a/b/C/D",
631:                            "//www.example.org/A/B#foo/",
632:                            "//www.example.org/a/b/c/d/X#bar",
633:                            "//example.com/A",
634:                            "//www.example.org/a/b/c/d/z[?]x=a", },
635:                    { "grandparent", "[.][.]/[.][.]/b/c/d/",
636:                            "[.][.]/[.][.]/b/c/d/e/f/g/",
637:                            "[.][.]/[.][.]/b/C/D", null,
638:                            "[.][.]/[.][.]/b/c/d/X#bar", null,
639:                            "[.][.]/[.][.]/b/c/d/z[?]x=a", }, };
640:
641:            static String rData3[][] = {
642:                    // http://www.example.org/A/B#
643:                    { "", "http://www.example.org/a/b/c/d/",
644:                            "http://www.example.org/a/b/c/d/e/f/g/",
645:                            "http://www.example.org/a/b/C/D",
646:                            "http://www.example.org/A/B#foo/",
647:                            "http://www.example.org/a/b/c/d/X#bar",
648:                            "http://example.com/A",
649:                            "http://www.example.org/a/b/c/d/z[?]x=a", },
650:                    { "same-document", null, null, null, "#foo/", null, null,
651:                            null, },
652:                    { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D",
653:                            "/A/B#foo/", "/a/b/c/d/X#bar", null,
654:                            "/a/b/c/d/z[?]x=a", },
655:                    { "relative", null, null, null, "B#foo/", null, null, null, },
656:                    { "parent", "[.][.]/a/b/c/d/", "[.][.]/a/b/c/d/e/f/g/",
657:                            "[.][.]/a/b/C/D", "[.][.]/A/B#foo/",
658:                            "[.][.]/a/b/c/d/X#bar", null,
659:                            "[.][.]/a/b/c/d/z[?]x=a", },
660:                    { "network", "//www.example.org/a/b/c/d/",
661:                            "//www.example.org/a/b/c/d/e/f/g/",
662:                            "//www.example.org/a/b/C/D",
663:                            "//www.example.org/A/B#foo/",
664:                            "//www.example.org/a/b/c/d/X#bar",
665:                            "//example.com/A",
666:                            "//www.example.org/a/b/c/d/z[?]x=a", },
667:                    { "grandparent", null, null, null, null, null, null, null, }, };
668:
669:            private void relative(int i, String base, String d[][])
670:                    throws IOException {
671:                Set in = new HashSet();
672:                Set out = new HashSet();
673:                for (int j = 1; j < d[i].length; j++) {
674:
675:                    in.add(d[i][j] == null ? d[0][j] : d[i][j]);
676:                    if (i != 0 && d[i][j] != null)
677:                        out.add(d[0][j]);
678:                }
679:                // System.out.println(base + "["+i+"]");
680:                relative(d[i][0], base, in, out);
681:            }
682:
683:            public void testRelative() throws Exception {
684:                for (int i = 0; i < 7; i++) {
685:                    relative(i, "http://www.example.org/a/b/c/d/", rData1);
686:                    relative(i, "http://www.example.org/a/b/c/d", rData2);
687:                    relative(i, "http://www.example.org/A/B#", rData3);
688:                }
689:            }
690:
691:            private static String uris[] = { "http://www.example.org/a/b/c/d/",
692:                    "http://www.example.org/a/b/c/d/e/f/g/",
693:                    "http://www.example.org/a/b/C/D",
694:                    "http://www.example.org/A/B#foo/",
695:                    "http://www.example.org/a/b/c/d/X#bar",
696:                    "http://example.com/A",
697:                    "http://www.example.org/a/b/c/d/z?x=a", };
698:
699:            static IRIFactory factory = IRIFactory.jenaImplementation();
700:
701:            static public void main(String args[]) throws Exception {
702:                String b[] = { "http://www.example.org/a/b/c/d/",
703:                        "http://www.example.org/a/b/c/d",
704:                        "http://www.example.org/A/B#", };
705:                String n[] = { "", "same-document", "absolute", "relative",
706:                        "parent", "network", "grandparent" };
707:                for (int k = 0; k < b.length; k++) {
708:                    System.out.println("// " + b[k]);
709:                    IRI bb = factory.create(b[k]);
710:
711:                    for (int i = 0; i < n.length; i++) {
712:                        System.out.print(" { \"" + n[i] + "\", ");
713:                        int f = BaseXMLWriter.str2flags(n[i]);
714:                        for (int j = 0; j < uris.length; j++) {
715:                            String r = bb.relativize(uris[j], f).toString();
716:                            System.out
717:                                    .print((i != 0 && r.equals(uris[j])) ? "null, "
718:                                            : "\"" + r + "\"" + ", ");
719:                        }
720:                        System.out.println("},");
721:                    }
722:                }
723:            }
724:        }
725:        /*
726:         * (c) Copyright 2001, 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard
727:         * Development Company, LP All rights reserved.
728:         * 
729:         * Redistribution and use in source and binary forms, with or without
730:         * modification, are permitted provided that the following conditions are met:
731:         * 1. Redistributions of source code must retain the above copyright notice,
732:         * this list of conditions and the following disclaimer. 2. Redistributions in
733:         * binary form must reproduce the above copyright notice, this list of
734:         * conditions and the following disclaimer in the documentation and/or other
735:         * materials provided with the distribution. 3. The name of the author may not
736:         * be used to endorse or promote products derived from this software without
737:         * specific prior written permission.
738:         * 
739:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
740:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
741:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
742:         * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
743:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
744:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
745:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
746:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
747:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
748:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
749:         * 
750:         * $Id: TestXMLFeatures.java,v 1.55 2008/01/02 12:06:48 andy_seaborne Exp $
751:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.