Package javax.xml.parsers

Examples of javax.xml.parsers.SAXParser


   * This method has been added, since configuration for
   * schema validation seems to be broken in digester 1.6.
   * Therefore, we directly set the JAXP properties.
   */
  protected Digester createDigester() {
    SAXParser parser = null;
    try {
      parser = factory.newSAXParser();
    } catch (Exception e) {
      // should not happen...
    }
    if (schemaResolver != null) {
      try {
        parser.setProperty(
          "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
          "http://www.w3.org/2001/XMLSchema"
        );
        parser.setProperty(
          "http://java.sun.com/xml/jaxp/properties/schemaSource",
          getSchemaResolver().getURI()
        );
      } catch (Exception e) {
        log.info("Parser doesn't support XML Schema validation, using DTD...");


    try {
      // somewhat akward work-around to avoid making MSV a compile-time dependency
      SAXParserFactory factory = (SAXParserFactory) ClassLoaderUtil.newInstance(
          "com.sun.msv.verifier.jaxp.SAXParserFactoryImpl");
      factory.setNamespaceAware(true);
      SAXParser saxParser = factory.newSAXParser();
      // would be nice to set the property on the XMLReader (instead of the SAXParser), but that wouldn't work
      saxParser.setProperty("http://www.sun.com/xml/msv/schema", source);
      parser = saxParser.getXMLReader();
     
      // find root filter, if any
      XMLReader filter = parser;
      while (filter instanceof XMLFilter && ((XMLFilter) filter).getParent() instanceof XMLFilter) {
        if (DEBUG) System.err.println("currFilter=" + filter);

        // Use the default (non-validating) parser
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try {
            // Parse the input
            SAXParser saxParser;
            saxParser = factory.newSAXParser();
            saxParser.parse(inStream, handler);
        } catch (ParserConfigurationException e) {
          if (!GPLogger.log(e)) {
            e.printStackTrace(System.err);
          }
            throw new IOException(e.getMessage());

        // Use the default (non-validating) parser
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try {

            // Parse the input
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(file, handler);
        } catch (Exception e) {
            myUIFacade.showErrorDialog(e);
            /*
            GanttDialogInfo gdi = new GanttDialogInfo((JFrame) myUIFacade,
                    GanttDialogInfo.ERROR, GanttDialogInfo.YES_OPTION, language

     * @return javax.xml.parsers.SAXParser
     */
    public SAXParser newSAXParser()
        throws ParserConfigurationException
    {
        SAXParser saxParserImpl;
        try {
            saxParserImpl = new SAXParserImpl(this, features);
        } catch (SAXException se) {
            // Translate to ParserConfigurationException
            throw new ParserConfigurationException(se.getMessage());

        final StringBuilder sb = new StringBuilder();
        String rootElementText = "";
        byte[] content = new byte[0];

        try {
            final SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
            final FreeMindHandler freeMindHandler = new FreeMindHandler();
            saxParser.parse(source, freeMindHandler);

            final List<String> nodeTextList = freeMindHandler.getNodeText();

            rootElementText = (nodeTextList.size() > 0) ? nodeTextList.get(0) : "";

                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("meta.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
                    docShortTitle  = metaData.getTitle();
                    docLongTitle   = metaData.getSubject();
                    docAuthor      = metaData.getCreator();

                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("docProps/core.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
                    docShortTitle  = metaData.getTitle();
                    docLongTitle   = metaData.getSubject();
                    docAuthor      = metaData.getCreator();

        // Use an instance of ourselves as the SAX event handler
        DefaultHandler handler = new GanttXMLParser();

        // Use the default (non-validating) parser
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(inputStream, handler);
        return true;
    }

    public ArrayList load() throws ParserConfigurationException, SAXException, IOException {
        ArrayList tasks = null;
        PreviousStateTasksTagHandler handler = new PreviousStateTasksTagHandler(
                null);
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(myFile, handler);
        tasks = handler.getTasks();
        return tasks;
    }

TOP

Related Classes of javax.xml.parsers.SAXParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.