示例#1
0
 private SVNErrorMessage readData(
     InputStream is, String method, String path, DefaultHandler handler)
     throws FactoryConfigurationError, UnsupportedEncodingException, IOException {
   try {
     if (mySAXParser == null) {
       mySAXParser = getSAXParserFactory().newSAXParser();
     }
     XMLReader reader = new XMLReader(is);
     while (!reader.isClosed()) {
       org.xml.sax.XMLReader xmlReader = mySAXParser.getXMLReader();
       xmlReader.setContentHandler(handler);
       xmlReader.setDTDHandler(handler);
       xmlReader.setErrorHandler(handler);
       xmlReader.setEntityResolver(NO_ENTITY_RESOLVER);
       xmlReader.parse(new InputSource(reader));
     }
   } catch (SAXException e) {
     if (e instanceof SAXParseException) {
       if (handler instanceof DAVErrorHandler) {
         // failed to read svn-specific error, return null.
         return null;
       }
     } else if (e.getException() instanceof SVNException) {
       return ((SVNException) e.getException()).getErrorMessage();
     } else if (e.getCause() instanceof SVNException) {
       return ((SVNException) e.getCause()).getErrorMessage();
     }
     return SVNErrorMessage.create(
         SVNErrorCode.RA_DAV_REQUEST_FAILED,
         "Processing {0} request response failed: {1} ({2}) ",
         new Object[] {method, e.getMessage(), path});
   } catch (ParserConfigurationException e) {
     return SVNErrorMessage.create(
         SVNErrorCode.RA_DAV_REQUEST_FAILED,
         "XML parser configuration error while processing {0} request response: {1} ({2}) ",
         new Object[] {method, e.getMessage(), path});
   } catch (EOFException e) {
     // skip it.
   } finally {
     if (mySAXParser != null) {
       // to avoid memory leaks when connection is cached.
       org.xml.sax.XMLReader xmlReader = null;
       try {
         xmlReader = mySAXParser.getXMLReader();
       } catch (SAXException e) {
       }
       if (xmlReader != null) {
         xmlReader.setContentHandler(DEFAULT_SAX_HANDLER);
         xmlReader.setDTDHandler(DEFAULT_SAX_HANDLER);
         xmlReader.setErrorHandler(DEFAULT_SAX_HANDLER);
         xmlReader.setEntityResolver(NO_ENTITY_RESOLVER);
       }
     }
     myRepository.getDebugLog().flushStream(is);
   }
   return null;
 }
示例#2
0
  /**
   * Return whether the given string contains well-formed XML.
   *
   * @param xmlString string to check
   * @return true iif the given string contains well-formed XML
   */
  public static boolean isWellFormedXML(String xmlString) {

    // Empty string is never well-formed XML
    if (xmlString.trim().length() == 0) return false;

    try {
      final XMLReader xmlReader = newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getXMLReader();
      xmlReader.setContentHandler(NULL_CONTENT_HANDLER);
      xmlReader.setEntityResolver(ENTITY_RESOLVER);
      xmlReader.setErrorHandler(
          new org.xml.sax.ErrorHandler() {
            public void error(SAXParseException exception) throws SAXException {
              throw exception;
            }

            public void fatalError(SAXParseException exception) throws SAXException {
              throw exception;
            }

            public void warning(SAXParseException exception) throws SAXException {}
          });
      xmlReader.parse(new InputSource(new StringReader(xmlString)));
      return true;
    } catch (Exception e) {
      // Ideally we would like the parser to not throw as this is time-consuming, but not sure how
      // to achieve that
      return false;
    }
  }
  public static BehavioralPatternsCatalog load(final Reader reader) {
    BehavioralPatternsCatalog catalog = null;

    try {
      final BehavioralPatternsCatalogSaxHandler handler = new BehavioralPatternsCatalogSaxHandler();

      final SAXParserFactory factory = SAXParserFactory.newInstance();
      factory.setValidating(true);
      factory.setNamespaceAware(true);

      final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
      xmlReader.setContentHandler(handler);
      xmlReader.setErrorHandler(handler);
      xmlReader.setEntityResolver(handler);

      xmlReader.parse(new InputSource(reader));

      catalog = handler.getCatalog();

      reader.close();
    } catch (final SAXException e) {
      BehavioralAnalysisPlugin.logError("Error parsing Behavioral Patterns Catalog.", e);
    } catch (final ParserConfigurationException e) {
      BehavioralAnalysisPlugin.logError("Error parsing Behavioral Patterns Catalog.", e);
    } catch (final IOException e) {
      BehavioralAnalysisPlugin.logError("Error opening Behavioral Patterns Catalog.", e);
    }

    return catalog;
  }
 /** Helper to create XSLT transformer for this instance */
 private void initTransformer() {
   // build new transformer
   final InputStream xslin =
       getClass().getResourceAsStream("/org/olat/ims/resources/xsl/" + XSLFILENAME);
   // translate xsl with velocity
   final Context vcContext = new VelocityContext();
   vcContext.put("t", pT);
   vcContext.put("staticPath", StaticMediaDispatcher.createStaticURIFor(""));
   String xslAsString = "";
   try {
     xslAsString = slurp(xslin);
   } catch (final IOException e) {
     log.error("Could not convert xsl to string!", e);
   }
   final String replacedOutput = evaluateValue(xslAsString, vcContext);
   final TransformerFactory tfactory = TransformerFactory.newInstance();
   XMLReader reader;
   try {
     reader = XMLReaderFactory.createXMLReader();
     reader.setEntityResolver(er);
     final Source xsltsource =
         new SAXSource(reader, new InputSource(new StringReader(replacedOutput)));
     this.transformer = tfactory.newTransformer(xsltsource);
   } catch (final SAXException e) {
     throw new OLATRuntimeException("Could not initialize transformer!", e);
   } catch (final TransformerConfigurationException e) {
     throw new OLATRuntimeException("Could not initialize transformer (wrong config)!", e);
   }
 }
示例#5
0
 /**
  * Starts the reading of the CML file. Whenever a new Molecule is read, a event is thrown to the
  * ReaderListener.
  */
 public void process() throws CDKException {
   logger.debug("Started parsing from input...");
   try {
     parser.setFeature("http://xml.org/sax/features/validation", false);
     logger.info("Deactivated validation");
   } catch (SAXException e) {
     logger.warn("Cannot deactivate validation.");
   }
   parser.setContentHandler(new EventCMLHandler(this, builder));
   parser.setEntityResolver(new CMLResolver());
   parser.setErrorHandler(new CMLErrorHandler());
   try {
     logger.debug("Parsing from Reader");
     parser.parse(new InputSource(input));
   } catch (IOException e) {
     String error = "Error while reading file: " + e.getMessage();
     logger.error(error);
     logger.debug(e);
     throw new CDKException(error, e);
   } catch (SAXParseException saxe) {
     SAXParseException spe = (SAXParseException) saxe;
     String error = "Found well-formedness error in line " + spe.getLineNumber();
     logger.error(error);
     logger.debug(saxe);
     throw new CDKException(error, saxe);
   } catch (SAXException saxe) {
     String error = "Error while parsing XML: " + saxe.getMessage();
     logger.error(error);
     logger.debug(saxe);
     throw new CDKException(error, saxe);
   }
 }
示例#6
0
  public Struct validate(InputSource xml) throws PageException {
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    warnings = engine.getCreationUtil().createArray();
    errors = engine.getCreationUtil().createArray();
    fatals = engine.getCreationUtil().createArray();

    try {
      XMLReader parser = new XMLUtilImpl().createXMLReader("org.apache.xerces.parsers.SAXParser");
      parser.setContentHandler(this);
      parser.setErrorHandler(this);
      parser.setEntityResolver(this);
      parser.setFeature("http://xml.org/sax/features/validation", true);
      parser.setFeature("http://apache.org/xml/features/validation/schema", true);
      parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
      // if(!validateNamespace)
      if (!Util.isEmpty(strSchema))
        parser.setProperty(
            "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
            strSchema);
      parser.parse(xml);
    } catch (SAXException e) {
    } catch (IOException e) {
      throw engine.getExceptionUtil().createXMLException(e.getMessage());
    }

    // result
    Struct result = engine.getCreationUtil().createStruct();
    result.setEL("warnings", warnings);
    result.setEL("errors", errors);
    result.setEL("fatalerrors", fatals);
    result.setEL("status", engine.getCastUtil().toBoolean(!hasErrors));
    release();
    return result;
  }
示例#7
0
 static {
   try {
     xmlReader = XMLReaderFactory.createXMLReader();
     xmlReader.setFeature("http://xml.org/sax/features/validation", false);
     if (false) {
       // FIXME AK: we need  real handling for the normal case (HTML->FOP XML)
       EntityResolver resolver =
           new EntityResolver() {
             public InputSource resolveEntity(String arg0, String arg1)
                 throws SAXException, IOException {
               log.info(arg0 + "::" + arg1);
               InputSource source =
                   new InputSource(
                       (new URL("file:///Volumes/Home/Desktop/dtd/xhtml1-transitional.dtd"))
                           .openStream());
               source.setSystemId(arg1);
               return source;
             }
           };
       xmlReader.setEntityResolver(resolver);
     }
   } catch (SAXException e) {
     e.printStackTrace();
   }
 }
示例#8
0
  public void writeAsAttachment(Object obj, OutputStream out) throws IOException {
    try {
      if (obj instanceof StreamSource) {
        StreamSource source = (StreamSource) obj;
        InputSource inputSource = null;

        InputStream is = source.getInputStream();
        Reader reader = source.getReader();
        String systemId = source.getSystemId();

        if (is != null) inputSource = new InputSource(is);
        else if (reader != null) inputSource = new InputSource(reader);
        else if (systemId != null) inputSource = new InputSource(systemId);

        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
        xmlReader.setEntityResolver(_entityResolver);

        SAXSource saxSource = new SAXSource(xmlReader, inputSource);
        _transformer.transform(saxSource, new StreamResult(out));
      } else _transformer.transform((Source) obj, new StreamResult(out));
    } catch (TransformerException e) {
      IOException ioe = new IOException();
      ioe.initCause(e);

      throw ioe;
    } catch (SAXException saxe) {
      IOException ioe = new IOException();
      ioe.initCause(saxe);

      throw ioe;
    }
  }
 static Object load(InputStream is, String name, Handler handler) {
   try {
     try {
       XMLReader reader = XMLUtil.createXMLReader();
       reader.setEntityResolver(handler);
       reader.setContentHandler(handler);
       reader.parse(new InputSource(is));
       return handler.getResult();
     } finally {
       is.close();
     }
   } catch (SAXException ex) {
     if (System.getProperty("org.netbeans.optionsDialog") != null) {
       System.out.println("File: " + name);
       ex.printStackTrace();
     }
     return handler.getResult();
   } catch (IOException ex) {
     if (System.getProperty("org.netbeans.optionsDialog") != null) {
       System.out.println("File: " + name);
       ex.printStackTrace();
     }
     return handler.getResult();
   } catch (Exception ex) {
     if (System.getProperty("org.netbeans.optionsDialog") != null) {
       System.out.println("File: " + name);
       ex.printStackTrace();
     }
     return handler.getResult();
   }
 }
示例#10
0
  public void start(ContentHandler sax, Target target) throws IOException, SAXException {
    this.target = target;

    XMLReader parser;
    try {
      parser = spf.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
      throw new LagoonException(e.getMessage());
    }

    parser.setContentHandler(sax);
    parser.setEntityResolver(
        new EntityResolver() {
          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            InputSource is = new InputSource(getSourceMan().getFileURL(systemId));

            File fil = getSourceMan().getFile(systemId);

            if (fil != null) {
              InputStream istr = new FileInputStream(fil);
              is.setByteStream(istr);
            }

            return is;
          }
        });

    exception = null;

    mis = new MyInputStream();
    mos = new MyOutputStream(mis);

    thread = new Thread(this);
    thread.start();

    parser.parse(new InputSource(mis));
    mis.close();

    try {
      thread.join(1000);
    } catch (InterruptedException e) {
    }

    if (thread.isAlive()) {
      thread.interrupt();
    }

    this.target = null;

    if (exception != null) {
      if (exception instanceof SAXException) {
        throw (SAXException) exception;
      } else if (exception instanceof IOException) {
        throw (IOException) exception;
      }
    }
  }
示例#11
0
 public static XMLReader newXMLReader(XMLUtils.ParserConfiguration parserConfiguration) {
   final SAXParser saxParser = XMLUtils.newSAXParser(parserConfiguration);
   try {
     final XMLReader xmlReader = saxParser.getXMLReader();
     xmlReader.setEntityResolver(XMLUtils.ENTITY_RESOLVER);
     xmlReader.setErrorHandler(XMLUtils.ERROR_HANDLER);
     return xmlReader;
   } catch (Exception e) {
     throw new OXFException(e);
   }
 }
示例#12
0
 private static void parse(final org.xml.sax.InputSource input, final FormatParser recognizer)
     throws SAXException, ParserConfigurationException, IOException {
   javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
   // factory.setValidating(true); //the code was generated according DTD
   // factory.setNamespaceAware(false); //the code was generated according DTD
   XMLReader parser = factory.newSAXParser().getXMLReader();
   parser.setContentHandler(recognizer);
   parser.setErrorHandler(recognizer.getDefaultErrorHandler());
   if (recognizer.resolver != null) parser.setEntityResolver(recognizer.resolver);
   parser.parse(input);
 }
示例#13
0
 private static void parse(final InputSource input, final JDOParser recognizer)
     throws SAXException, ParserConfigurationException, IOException {
   SAXParserFactory factory = SAXParserFactory.newInstance();
   factory.setValidating(true);
   factory.setNamespaceAware(true);
   XMLReader parser = factory.newSAXParser().getXMLReader();
   parser.setEntityResolver(new JDOEntityResolver());
   parser.setContentHandler(recognizer);
   parser.setErrorHandler(recognizer.getDefaultErrorHandler());
   parser.parse(input);
 }
示例#14
0
  @Override
  public URI call() throws Exception {
    // System.out.println( "SVGLoad start"+xmlBase.toString());
    SVGLoader handler = new SVGLoader(xmlBase, univ, false);

    // Place this docment in the universe before it is completely loaded
    // so that the load process can refer to references within it's current
    // document
    univ.loadedDocs.put(xmlBase, handler.getLoadedDiagram());
    XMLReader reader = null;
    InputSource is = null;
    try {
      is = input == null ? univ.getInputSource(xmlBase) : input;
      // Parse the input
      reader = univ.getXMLReaderCached();
      reader.setEntityResolver(
          new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId) {
              // Ignore all DTDs
              return new InputSource(new ByteArrayInputStream(new byte[0]));
            }
          });
      reader.setContentHandler(handler);
      reader.parse(is);

      for (SVGLoaderClient eachRunnable : doAfter) {
        eachRunnable.imageLoaded(xmlBase);
      }

      //            SAXParser saxParser = factory.newSAXParser();
      //            saxParser.parse(new InputSource(new BufferedReader(is)), handler);
      // System.out.println( "SVGLoad end"+xmlBase.toString());
      return xmlBase;
    } catch (SAXParseException sex) {
      System.err.println("Error processing " + xmlBase);
      System.err.println(sex.getMessage());
      sex.printStackTrace();

      univ.loadedDocs.remove(xmlBase);
      return null;
    } catch (Throwable t) {
      System.err.println(xmlBase.toASCIIString());
      t.printStackTrace();
    } finally {

      SVGUniverse.closeStreamQuietly(is.getByteStream());
      SVGUniverse.closeReaderQuietly(is.getCharacterStream());
    }
    return null;
  }
示例#15
0
 public Inclusion(InclusionIntent intent) {
   super(intent.getScroll() != null ? intent.getScroll() : new Scroll());
   this.intent = intent;
   boolean xhtml = intent.getFile().endsWith(".xhtml");
   this.useMagic = !xhtml;
   try {
     parser = xhtml ? Wandler.getXHTMLParser() : Wandler.getHTMLParser();
     parser.setContentHandler(this);
     parser.setEntityResolver(new VoidResolver());
   } catch (SAXException ex) {
     throw new RuntimeException("Inclusion failed", ex);
   }
 }
示例#16
0
  public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
    SAXParser saxParser = getParser();
    SAXDocumentSerializer documentSerializer = getSerializer(finf);

    XMLReader reader = saxParser.getXMLReader();
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
    reader.setContentHandler(documentSerializer);

    if (workingDirectory != null) {
      reader.setEntityResolver(createRelativePathResolver(workingDirectory));
    }
    reader.parse(new InputSource(xml));
  }
 private static SVGFormComponent[] getFormComponents(final InputStream svgInputStream) {
   NamedElementsContentHandler ch = new NamedElementsContentHandler();
   try {
     XMLReader parser = XMLReaderFactory.createXMLReader();
     parser.setContentHandler(ch);
     parser.setEntityResolver(ch);
     parser.parse(new InputSource(svgInputStream));
   } catch (IOException ex) {
     Debug.warning(ex);
   } catch (SAXException ex) {
     Debug.warning(ex);
   }
   return ch.getFoundElements();
 }
示例#18
0
  /**
   * Parse the content given {@link org.xml.sax.InputSource} as XML using the specified {@link
   * org.xml.sax.helpers.DefaultHandler}.
   *
   * @param is The InputSource containing the content to be parsed.
   * @param dh The SAX DefaultHandler to use.
   * @throws IllegalArgumentException If the <code>InputSource</code> object is <code>null</code>.
   * @throws IOException If any IO errors occur.
   * @throws SAXException If any SAX errors occur during processing.
   * @see org.xml.sax.DocumentHandler
   */
  public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException {
    if (is == null) {
      throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
      reader.setContentHandler(dh);
      reader.setEntityResolver(dh);
      reader.setErrorHandler(dh);
      reader.setDTDHandler(dh);
    }
    reader.parse(is);
  }
示例#19
0
 public void parse(InputSource paramInputSource, DefaultHandler paramDefaultHandler)
     throws SAXException, IOException {
   if (paramInputSource == null) {
     throw new IllegalArgumentException("InputSource cannot be null");
   }
   XMLReader localXMLReader = getXMLReader();
   if (paramDefaultHandler != null) {
     localXMLReader.setContentHandler(paramDefaultHandler);
     localXMLReader.setEntityResolver(paramDefaultHandler);
     localXMLReader.setErrorHandler(paramDefaultHandler);
     localXMLReader.setDTDHandler(paramDefaultHandler);
   }
   localXMLReader.parse(paramInputSource);
 }
示例#20
0
  private static boolean checkXml(String text) {

    try {
      XMLReader reader = factory.newSAXParser().getXMLReader();
      reader.setEntityResolver(NoOpEntityResolver.getInstance());
      reader.parse(text);
      return true;
    } catch (SAXException e) {
      return false;
    } catch (IOException e) {
      return false;
    } catch (ParserConfigurationException e) {
      return false;
    }
  }
示例#21
0
 private XMLReader createXMLReader() throws SAXException {
   XMLReader reader;
   try {
     reader = XMLReaderFactory.createXMLReader();
   } catch (SAXException e) {
     reader =
         XMLReaderFactory.createXMLReader(
             System.getProperty("org.xml.sax.driver", "org.apache.crimson.parser.XMLReaderImpl"));
   }
   reader.setFeature("http://xml.org/sax/features/validation", true);
   GenericContentHandler handler = new GenericContentHandler();
   reader.setContentHandler(handler);
   reader.setErrorHandler(handler);
   reader.setEntityResolver(new GenericEntityResolver());
   return reader;
 }
示例#22
0
  /**
   * This will create a SAX XMLReader capable of parsing a DTD and configure it so that the DTD
   * parsing events are routed to the handlers registered onto this SAXOutputter.
   *
   * @return <code>XMLReader</code> a SAX2 parser.
   * @throws JDOMException if no parser can be created.
   */
  private XMLReader createDTDParser() throws JDOMException {
    XMLReader parser = null;

    // Get a parser instance
    try {
      parser = createParser();
    } catch (Exception ex1) {
      throw new JDOMException("Error in SAX parser allocation", ex1);
    }

    // Register handlers
    if (this.getDTDHandler() != null) {
      parser.setDTDHandler(this.getDTDHandler());
    }
    if (this.getEntityResolver() != null) {
      parser.setEntityResolver(this.getEntityResolver());
    }
    if (this.getLexicalHandler() != null) {
      try {
        parser.setProperty(SAX_PROPERTY_LEXICAL_HANDLER, this.getLexicalHandler());
      } catch (SAXException ex1) {
        try {
          parser.setProperty(SAX_PROPERTY_LEXICAL_HANDLER_ALT, this.getLexicalHandler());
        } catch (SAXException ex2) {
          // Forget it!
        }
      }
    }
    if (this.getDeclHandler() != null) {
      try {
        parser.setProperty(SAX_PROPERTY_DECLARATION_HANDLER, this.getDeclHandler());
      } catch (SAXException ex1) {
        try {
          parser.setProperty(SAX_PROPERTY_DECLARATION_HANDLER_ALT, this.getDeclHandler());
        } catch (SAXException ex2) {
          // Forget it!
        }
      }
    }

    // Absorb errors as much as possible, per Laurent
    parser.setErrorHandler(new DefaultHandler());

    return parser;
  }
示例#23
0
  public static Reader convertRdf2Ics(InputStream is) throws SAXException, IOException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    XMLReader reader = null;
    try {
      reader = factory.newSAXParser().getXMLReader();
      reader.setEntityResolver(NoOpEntityResolver.getInstance());
    } catch (ParserConfigurationException e) {
      log.error("", e);
    }

    Rdf2IcsHandler xmlHandler = new Rdf2IcsHandler();

    reader.setContentHandler(xmlHandler);
    reader.parse(new InputSource(is));
    return new StringReader(xmlHandler.getResult());
  }
示例#24
0
 /**
  * Get the first topic id.
  *
  * @param path file path
  * @param dir file dir
  * @param useCatalog whether use catalog file for validation
  * @return topic id
  */
 public static String getFirstTopicId(final URI path, final File dir, final boolean useCatalog) {
   if (path == null && dir == null) {
     return null;
   }
   final DITAOTLogger logger = new DITAOTJavaLogger();
   final StringBuilder firstTopicId = new StringBuilder();
   final TopicIdParser parser = new TopicIdParser(firstTopicId);
   try {
     final XMLReader reader = XMLUtils.getXMLReader();
     reader.setContentHandler(parser);
     if (useCatalog) {
       reader.setEntityResolver(CatalogUtils.getCatalogResolver());
     }
     reader.parse(dir.toURI().resolve(path).toString());
   } catch (final Exception e) {
     logger.error(e.getMessage(), e);
   }
   return firstTopicId.toString();
 }
  public int Validate(
      File inFile,
      File entitiesResolverConfigFile,
      File schemaFile,
      File schemataResolverConfigFile) {
    try {
      SAXParserFactory parserFactory = SAXParserFactory.newInstance();
      // Disable validating by DTD.
      parserFactory.setValidating(false);
      parserFactory.setNamespaceAware(true);

      SchemaEntityResolverLocal localResolver =
          new SchemaEntityResolverLocal(entitiesResolverConfigFile, schemataResolverConfigFile);

      SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      schemaFactory.setResourceResolver(localResolver);

      Source schemaSource = new StreamSource(schemaFile);
      parserFactory.setSchema(schemaFactory.newSchema(new Source[] {schemaSource}));

      SAXParser parser = parserFactory.newSAXParser();
      XMLReader reader = parser.getXMLReader();
      reader.setErrorHandler(this);
      reader.setEntityResolver(localResolver);

      // Do XML Schema validation.
      reader.parse(new InputSource(new FileReader(inFile)));
    } catch (SAXException ex) {
      ex.printStackTrace();
      System.exit(-1);
    } catch (ParserConfigurationException ex) {
      ex.printStackTrace();
      System.exit(-1);
    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
      System.exit(-1);
    } catch (IOException ex) {
      ex.printStackTrace();
      System.exit(-1);
    }

    return 0;
  }
 public void parse(java.io.Reader src) throws IOException {
   try {
     org.xml.sax.XMLReader reader = org.openide.xml.XMLUtil.createXMLReader(false, false);
     reader.setContentHandler(this);
     reader.setEntityResolver(this);
     org.xml.sax.InputSource is = new org.xml.sax.InputSource(src);
     try {
       reader.setProperty("http://xml.org/sax/properties/lexical-handler", this); // NOI18N
     } catch (SAXException sex) {
       XMLSettingsSupport.err.warning(
           "Warning: XML parser does not support lexical-handler feature."); // NOI18N
     }
     reader.parse(is);
   } catch (SAXException ex) {
     IOException ioe = new IOException();
     ioe.initCause(ex);
     throw ioe;
   }
 }
  public static DocPage parseDocsPage(final String url, String content) throws Exception {

    for (int i = 0; i < REPLACEMENTS.length; i++) {
      content = COMPILED_PATTERNS[i].matcher(content).replaceAll(REPLACEMENTS[i][1]);
    }
    try {
      DocHandler handler = new DocHandler(url);
      XMLReader xmlParser = XMLReaderFactory.createXMLReader();
      xmlParser.setContentHandler(handler);
      xmlParser.setEntityResolver(handler);
      xmlParser.parse(new InputSource(new StringReader(content)));
      return handler.getDocPage();
    } catch (SAXException | IOException e) {
      String filename = "tmp" + tmpIndex++ + ".txt";
      Files.write(new File(filename).toPath(), FXCollections.observableArrayList(content));
      throw new RuntimeException(
          "\"Failed to parse '" + url + "', see content in " + filename + ".", e);
    }
  }
示例#28
0
  public Xv4htContentHandler(XMLReader xmlReader, String catalog) {
    super();
    this.catalog = catalog;
    lexicalHandler = new Xv4htLexicalHandler();
    try {
      xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", lexicalHandler);
    } catch (SAXNotRecognizedException e) {
      System.err.println("err 1");
      return;
    } catch (SAXNotSupportedException e) {
      System.err.println("err 2");
      return;
    }

    errHandler = new Xv4htErrorHandler();
    xmlReader.setErrorHandler(errHandler);

    xmlReader.setEntityResolver(new Xv4htEntityResolver());
  }
示例#29
0
  public static void main(String[] args) throws Exception {

    folder = new File("extensions/xslt/test/src/org/exist/xslt/xslts_1_1_0");

    File xslts = new File("test/external/XSLTS_1_1_0/catalog.xml");
    FileInputStream is = new FileInputStream(xslts);
    InputSource src = new InputSource(is);

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);

    SAXParser parser = factory.newSAXParser();
    XMLReader reader = parser.getXMLReader();
    reader.setEntityResolver(new SpecialEntityResolver("test/external/XSLTS_1_1_0/"));
    XSLTStoJUnit adapter = new XSLTStoJUnit();
    reader.setContentHandler(adapter);

    reader.parse(src);
  }
  public SimpleDocTypeParser() throws SAXException {

    xmlReader = XMLReaderFactory.createXMLReader();

    xmlReader.setContentHandler(this);

    // LexicalHandler
    xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this);

    // DeclHandler
    xmlReader.setProperty("http://xml.org/sax/properties/declaration-handler", this);

    // DTD
    xmlReader.setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);
    // *skip* resolving entities like DTDs
    xmlReader.setEntityResolver(new NoEntityResolver());

    //		xmlReader.setProperty(
    //				"http://xml.org/sax/properties/declaration-handler", dh);

  }