KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > pmti > v1 > autodoc > v1 > xml > XMLFileParser


1 /*
2  * @(#)XMLFileParser.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Part of the GroboUtils package at:
9  * http://groboutils.sourceforge.net
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */

29 package net.sourceforge.groboutils.pmti.v1.autodoc.v1.xml;
30
31
32 import java.io.File JavaDoc;
33 import java.io.Reader JavaDoc;
34 import java.io.FileReader JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 import java.net.URL JavaDoc;
38
39 import net.sourceforge.groboutils.pmti.v1.itf.parser.AbstractParser;
40 import net.sourceforge.groboutils.pmti.v1.itf.IIssueRecord;
41 import net.sourceforge.groboutils.pmti.v1.itf.ITestIssueRecord;
42
43 import net.sourceforge.groboutils.pmti.v1.itf.impl.DefaultIssueRecord;
44 import net.sourceforge.groboutils.pmti.v1.itf.impl.ImmutableTestRecord;
45 import net.sourceforge.groboutils.pmti.v1.itf.impl.DefaultTestIssueRecord;
46
47 import java.util.Locale JavaDoc;
48
49 import org.xml.sax.Locator JavaDoc;
50 import org.xml.sax.InputSource JavaDoc;
51 import org.xml.sax.HandlerBase JavaDoc;
52 import org.xml.sax.SAXException JavaDoc;
53 import org.xml.sax.SAXParseException JavaDoc;
54 import org.xml.sax.DocumentHandler JavaDoc;
55 import org.xml.sax.AttributeList JavaDoc;
56 import org.xml.sax.helpers.XMLReaderAdapter JavaDoc;
57 import org.xml.sax.Parser JavaDoc;
58
59 import org.apache.log4j.Logger;
60
61
62 /**
63  * Parses the output of XMLFileServer.
64  *
65  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
66  * @since March 17, 2002
67  * @version $Date: 2003/02/10 22:51:57 $
68  */

69 public class XMLFileParser extends AbstractParser
70 {
71     private static final Class JavaDoc THIS_CLASS = XMLFileParser.class;
72     private static final org.apache.log4j.Logger LOG =
73         org.apache.log4j.Logger.getLogger( THIS_CLASS );
74     
75     
76     private File JavaDoc file;
77     private Parser parser;
78     
79     
80     public XMLFileParser( File JavaDoc f, Parser p )
81     {
82         if ( f == null
83             || !f.exists()
84             || !f.isFile()
85             || !f.canRead() )
86         {
87             throw new IllegalArgumentException JavaDoc("not valid file: "+f);
88         }
89         if ( p == null )
90         {
91             throw new IllegalArgumentException JavaDoc("no null SAX parser");
92         }
93         
94         this.parser = p;
95         this.file = f;
96     }
97     
98     
99     protected void findRecords()
100     {
101         try
102         {
103             FileReader JavaDoc fr = new FileReader JavaDoc( this.file );
104             try
105             {
106                 InputSource JavaDoc source = new InputSource JavaDoc( fr );
107                 source.setSystemId( (new URL JavaDoc( "file:" +
108                     this.file.getAbsolutePath() )).toString() );
109             }
110             finally
111             {
112                 fr.close();
113             }
114         }
115         catch (IOException JavaDoc ioe)
116         {
117             LOG.warn( "Error accessing file: "+this.file, ioe );
118         }
119     }
120     
121     
122     //protected class
123
}
124
125
Popular Tags