/[cashew-s-editor]/cashews/src/nongnu/cashews/rdf/XMLParser.java
ViewVC logotype

Diff of /cashews/src/nongnu/cashews/rdf/XMLParser.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by gnu_andrew, Sun Apr 3 17:15:39 2005 UTC revision 1.4 by gnu_andrew, Mon Apr 4 00:59:33 2005 UTC
# Line 65  public class XMLParser Line 65  public class XMLParser
65    private XMLReader reader;    private XMLReader reader;
66    
67    /**    /**
68       * The resulting graph.
69       *
70       * @serial the graph of RDF triples.
71       */
72      private Graph graph;
73      
74      /**
75     * Constructs a new XML-based RDF parser, using the specified handler     * Constructs a new XML-based RDF parser, using the specified handler
76     * for messages.     * for messages.
77     *     *
# Line 83  public class XMLParser Line 90  public class XMLParser
90     * Parse an RDF document from the specified system identifier (URI).     * Parse an RDF document from the specified system identifier (URI).
91     *     *
92     * @param systemId the URI of the RDF document.     * @param systemId the URI of the RDF document.
93       * @return the graph generated by the parsing process.
94     * @throws SAXException if an error occurs in parsing.     * @throws SAXException if an error occurs in parsing.
95     * @throws IOException if an error occurs in the underlying input.     * @throws IOException if an error occurs in the underlying input.
96     */     */
97    public void parse(String systemId)    public Graph parse(String systemId)
98      throws IOException, SAXException      throws IOException, SAXException
99    {    {
100        graph = new Graph();
101      reader.parse(systemId);      reader.parse(systemId);
102        return graph;
103    }    }
104    
105    /**    /**
106     * Parse an RDF document from the specified input source.     * Parse an RDF document from the specified input source.
107     *     *
108     * @param source the source of the RDF document.     * @param source the source of the RDF document.
109       * @return the graph generated by the parsing process.
110     * @throws SAXException if an error occurs in parsing.     * @throws SAXException if an error occurs in parsing.
111     * @throws IOException if an error occurs in the underlying input.     * @throws IOException if an error occurs in the underlying input.
112     */     */
113    public void parse(InputSource source)    public Graph parse(InputSource source)
114      throws IOException, SAXException      throws IOException, SAXException
115    {    {
116        graph = new Graph();
117      reader.parse(source);      reader.parse(source);
118        return graph;
119    }    }
120    
121    /**    /**
122     * Parse an RDF document from the specified file.     * Parse an RDF document from the specified file.
123     *     *
124     * @param file the file containing the RDF document.     * @param file the file containing the RDF document.
125       * @return the graph generated by the parsing process.
126     * @throws SAXException if an error occurs in parsing.     * @throws SAXException if an error occurs in parsing.
127     * @throws IOException if an error occurs in the underlying input.     * @throws IOException if an error occurs in the underlying input.
128     */     */
129    public void parse(File file)    public Graph parse(File file)
130      throws IOException, SAXException      throws IOException, SAXException
131    {    {
132      parse(new InputSource(new FileInputStream(file)));      return parse(new InputSource(new FileInputStream(file)));
133    }    }
134    
135    /**    /**
# Line 136  public class XMLParser Line 150  public class XMLParser
150      handler.setLevel(Level.FINE);      handler.setLevel(Level.FINE);
151      XMLParser parser = new XMLParser(handler);      XMLParser parser = new XMLParser(handler);
152      for (int a = 0; a < args.length; ++a)      for (int a = 0; a < args.length; ++a)
153          parser.parse(new File(args[a]));          System.out.println(parser.parse(new File(args[a])));
154    }    }
155    
156    /**    /**
# Line 247  public class XMLParser Line 261  public class XMLParser
261          {          {
262            if (localName.equals("RDF"))            if (localName.equals("RDF"))
263              {              {
264                  /* rdf:RDF */
265                inRDF = true;                inRDF = true;
266                logger.finer("Start of RDF block");                logger.finer("Start of RDF block");
267              }              }
268            else if (localName.equals("Description"))            else if (localName.equals("Description"))
269              {              {
270                  /* rdf:Description */
271                logger.finer("Start of RDF description block");                logger.finer("Start of RDF description block");
272                inRDF = true;                inRDF = true;
273                if (!inSubject)                if (!inSubject)
274                  {                  {
275                      /* Check for RDF URI subject */
276                    String value = attributes.getValue(RDF_NAMESPACE, "about");                    String value = attributes.getValue(RDF_NAMESPACE, "about");
277                    if (value != null)                    if (value != null)
                     {  
278                        subject = parseRDFURI(value);                        subject = parseRDFURI(value);
                     }  
279                    inSubject = true;                    inSubject = true;
280                    logger.fine("Created subject: " + subject);                    logger.fine("Created subject: " + subject);
281                  }                  }
# Line 273  public class XMLParser Line 288  public class XMLParser
288          {          {
289            if (inSubject)            if (inSubject)
290              {              {
291                  /* Predicate element */
292                predicateURI = uri + localName;                predicateURI = uri + localName;
293                logger.finer("Start of predicate: " + predicateURI);                logger.finer("Start of predicate: " + predicateURI);
294                predicate = parseRDFURI(predicateURI);                predicate = parseRDFURI(predicateURI);
295                logger.fine("Created predicate: " + predicate);                logger.fine("Created predicate: " + predicate);
296                inSubject = false;                inSubject = false;
297                inPredicate = true;                inPredicate = true;
298                  /* Check for RDF URI object */
299                  String value = attributes.getValue(RDF_NAMESPACE, "resource");
300                  if (value != null)
301                    {
302                      object = parseRDFURI(value);
303                      logger.fine("Created object: " + object);
304                    }
305              }              }
306          }          }
307      }      }
# Line 350  public class XMLParser Line 373  public class XMLParser
373            else if (localName.equals("Description"))            else if (localName.equals("Description"))
374              {              {
375                logger.finer("End of description block");                logger.finer("End of description block");
               triple = new Triple(subject, predicate, object);  
               logger.fine("Created triple: " + triple);  
376                inSubject = false;                inSubject = false;
377              }              }
378          }          }
# Line 360  public class XMLParser Line 381  public class XMLParser
381          inPredicate = false;          inPredicate = false;
382          inSubject = true;          inSubject = true;
383          predicateURI = null;          predicateURI = null;
384            triple = new Triple(subject, predicate, object);
385            logger.fine("Created triple: " + triple);
386            graph.addTriple(triple);
387          logger.finer("End of predicate block");          logger.finer("End of predicate block");
388        }        }
389      }      }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26