Parser(String uri) {
   try {
     SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     SAXParser parser = parserFactory.newSAXParser();
     ConfigHandler handler = new ConfigHandler();
     parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", true);
     parser.parse(new File(uri), handler);
   } catch (IOException e) {
     System.out.println("Error reading URI: " + e.getMessage());
   } catch (SAXException e) {
     System.out.println("Error in parsing: " + e.getMessage());
   } catch (ParserConfigurationException e) {
     System.out.println("Error in XML parser configuration: " + e.getMessage());
   }
   // System.out.println("Number of Persons : " + Person.numberOfPersons());
   // nameLengthStatistics();
   // System.out.println("Number of Publications with authors/editors: " +
   //                   Publication.getNumberOfPublications());
   // System.out.println("Maximum number of authors/editors in a publication: " +
   //                           Publication.getMaxNumberOfAuthors());
   // publicationCountStatistics();
   // Person.enterPublications();
   // Person.printCoauthorTable();
   // Person.printNamePartTable();
   // Person.findSimilarNames();
 }
Esempio n. 2
0
 /**
  * Notifies the registered {@link ErrorHandler SAX error handler} (if any) of an input processing
  * error. The error handler can choose to absorb the error and let the processing continue.
  *
  * @param exception <code>JDOMException</code> containing the error information; will be wrapped
  *     in a {@link SAXParseException} when reported to the SAX error handler.
  * @throws JDOMException if no error handler has been registered or if the error handler fired a
  *     {@link SAXException}.
  */
 private void handleError(JDOMException exception) throws JDOMException {
   if (errorHandler != null) {
     try {
       errorHandler.error(new SAXParseException(exception.getMessage(), null, exception));
     } catch (SAXException se) {
       if (se.getException() instanceof JDOMException) {
         throw (JDOMException) (se.getException());
       }
       throw new JDOMException(se.getMessage(), se);
     }
   } else {
     throw exception;
   }
 }
 @Override
 public void run() {
   try {
     receive();
   } catch (IOException ioException) {
     JOptionPane.showMessageDialog(null, "Problems with a server");
   } catch (InterruptedException interruptedException) {
     JOptionPane.showMessageDialog(null, "Interrupted exception thrown");
   } catch (ParserConfigurationException parserException) {
     parserException.printStackTrace();
   } catch (SAXException saxException) {
     saxException.printStackTrace();
   }
 }
Esempio n. 4
0
  /**
   * Reads an XML document from an input source and copies its values into the specified object
   *
   * @param ob The object to receive the values
   * @param source The location of the XML document
   * @throws IOException If there is an error reading the document
   */
  public void readObject(Object ob, InputSource source) throws IOException {
    try {
      // Create a document builder to read the document
      DocumentBuilder builder = factory.newDocumentBuilder();

      // Read the document
      Document doc = builder.parse(source);

      // Get the root element
      Element element = doc.getDocumentElement();

      // Copy the root element into the bean
      readObject(ob, element);
    } catch (SAXException exc) {
      throw new IOException("Error parsing XML document: " + exc.toString());
    } catch (ParserConfigurationException exc) {
      throw new IOException("Error parsing XML document: " + exc.toString());
    }
  }
  /**
   * start the parsing
   *
   * @param file to parse
   * @return Vector containing the test cases
   */
  public XMLcpimParser(String fileLocation) {
    try {
      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
      saxParser = saxParserFactory.newSAXParser().getXMLReader();
      saxParser.setContentHandler(this);
      saxParser.setFeature("http://xml.org/sax/features/validation", true);
      // parse the xml specification for the event tags.
      saxParser.parse(fileLocation);

    } catch (SAXParseException spe) {
      spe.printStackTrace();
    } catch (SAXException sxe) {
      sxe.printStackTrace();
    } catch (IOException ioe) {
      // I/O error
      ioe.printStackTrace();
    } catch (Exception pce) {
      // Parser with specified options can't be built
      pce.printStackTrace();
    }
  }