1 package org.apache.maven.archetype.old.descriptor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.InputStream;
24
25 import javax.xml.parsers.SAXParser;
26 import javax.xml.parsers.SAXParserFactory;
27
28 import org.codehaus.plexus.PlexusTestCase;
29 import org.xml.sax.InputSource;
30 import org.xml.sax.SAXException;
31 import org.xml.sax.SAXParseException;
32 import org.xml.sax.helpers.DefaultHandler;
33
34
35 public class ArchetypeXsdTest
36 extends PlexusTestCase
37 {
38 private static final String ARCHETYPE_XSD = "archetype-1.0.0.xsd";
39
40 public void testXsd()
41 throws Exception
42 {
43 File archetypeXsd = new File( getBasedir(), "/target/generated-site/resources/xsd/" + ARCHETYPE_XSD );
44
45 SAXParserFactory factory = SAXParserFactory.newInstance();
46 factory.setValidating( true );
47 factory.setNamespaceAware( true );
48 SAXParser saxParser = factory.newSAXParser();
49 saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
50 "http://www.w3.org/2001/XMLSchema" );
51 saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", archetypeXsd );
52
53 try ( InputStream in = getClass().getResourceAsStream( "sample-archetype.xml" ); )
54 {
55 saxParser.parse( new InputSource( in ), new Handler() );
56 }
57 }
58
59 private static class Handler
60 extends DefaultHandler
61 {
62 @Override
63 public void warning ( SAXParseException e )
64 throws SAXException
65 {
66 throw e;
67 }
68
69 @Override
70 public void error ( SAXParseException e )
71 throws SAXException
72 {
73 throw e;
74 }
75 }
76 }