org.ccil.cowan.tagsoup.Parser.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(195)

本文整理了Java中org.ccil.cowan.tagsoup.Parser.<init>()方法的一些代码示例,展示了Parser.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.<init>()方法的具体详情如下:
包路径:org.ccil.cowan.tagsoup.Parser
类名称:Parser
方法名:<init>

Parser.<init>介绍

暂无

代码示例

代码示例来源:origin: seven332/EhViewer

  1. /**
  2. * Returns displayable styled text from the provided HTML string.
  3. * Any &lt;img&gt; tags in the HTML will use the specified ImageGetter
  4. * to request a representation of the image (use null if you don't
  5. * want this) and the specified TagHandler to handle unknown tags
  6. * (specify null if you don't want this).
  7. *
  8. * <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
  9. */
  10. public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGetter,
  11. TagHandler tagHandler) {
  12. Parser parser = new Parser();
  13. try {
  14. parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
  15. } catch (org.xml.sax.SAXNotRecognizedException e) {
  16. // Should not happen.
  17. throw new RuntimeException(e);
  18. } catch (org.xml.sax.SAXNotSupportedException e) {
  19. // Should not happen.
  20. throw new RuntimeException(e);
  21. }
  22. HtmlToSpannedConverter converter =
  23. new HtmlToSpannedConverter(source, imageGetter, tagHandler,
  24. parser);
  25. return converter.convert();
  26. }

代码示例来源:origin: rest-assured/rest-assured

  1. slurper = new XmlSlurper(config.isValidating(), config.isNamespaceAware(), config.isAllowDocTypeDeclaration());
  2. } else {
  3. XMLReader p = new org.ccil.cowan.tagsoup.Parser();
  4. slurper = new XmlSlurper(p);

代码示例来源:origin: rest-assured/rest-assured

  1. slurper = new XmlSlurper(config.isValidating(), config.isNamespaceAware(), config.isAllowDocTypeDeclaration());
  2. } else {
  3. XMLReader p = new org.ccil.cowan.tagsoup.Parser();
  4. slurper = new XmlSlurper(p);

代码示例来源:origin: apache/tika

  1. org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser();
  2. parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema);
  3. parser.setContentHandler(handler);

代码示例来源:origin: org.ccil.cowan.tagsoup/tagsoup

  1. protected SAXParserImpl() // used by factory, for prototypes
  2. {
  3. super();
  4. parser = new org.ccil.cowan.tagsoup.Parser();
  5. }

代码示例来源:origin: net.ontopia/ontopia-classify

  1. protected XMLReader createXMLReader() throws SAXException {
  2. return new org.ccil.cowan.tagsoup.Parser();
  3. }

代码示例来源:origin: ontopia/ontopia

  1. @Override
  2. protected XMLReader createXMLReader() throws SAXException {
  3. return new org.ccil.cowan.tagsoup.Parser();
  4. }

代码示例来源:origin: apache/tika

  1. new org.ccil.cowan.tagsoup.Parser();

代码示例来源:origin: org.xml-cml/cmlxom

  1. public static Builder getTagsoupBuilder() {
  2. XMLReader tagsoup = null;
  3. // try {
  4. tagsoup = //XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser");
  5. new org.ccil.cowan.tagsoup.Parser();
  6. // } catch (SAXException e) {
  7. // throw new RuntimeException("Exception whilst creating XMLReader from org.ccil.cowan.tagsoup.Parser", e);
  8. // }
  9. return new Builder(tagsoup);
  10. }

代码示例来源:origin: net.sf.ofx4j/ofx4j

  1. private BaseFinancialInstitutionData loadInstitutionData(String href) throws IOException, SAXException {
  2. if (LOG.isInfoEnabled()) {
  3. LOG.info("Loading institution data from: " + href);
  4. }
  5. URL url = new URL(href);
  6. XMLReader xmlReader = new Parser();
  7. xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
  8. xmlReader.setFeature("http://xml.org/sax/features/validation", false);
  9. InstitutionContentHandler institutionHandler = new InstitutionContentHandler();
  10. xmlReader.setContentHandler(institutionHandler);
  11. xmlReader.parse(new InputSource(url.openStream()));
  12. return institutionHandler.data;
  13. }

代码示例来源:origin: stoicflame/ofx4j

  1. private BaseFinancialInstitutionData loadInstitutionData(String href) throws IOException, SAXException {
  2. if (LOG.isInfoEnabled()) {
  3. LOG.info("Loading institution data from: " + href);
  4. }
  5. URL url = new URL(href);
  6. XMLReader xmlReader = new Parser();
  7. xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
  8. xmlReader.setFeature("http://xml.org/sax/features/validation", false);
  9. InstitutionContentHandler institutionHandler = new InstitutionContentHandler();
  10. xmlReader.setContentHandler(institutionHandler);
  11. xmlReader.parse(new InputSource(url.openStream()));
  12. return institutionHandler.data;
  13. }

代码示例来源:origin: net.sf.ofx4j/ofx4j

  1. private void initializeFIData() throws IOException, SAXException {
  2. URL url = new URL(getUrl());
  3. XMLReader xmlReader = new Parser();
  4. xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
  5. xmlReader.setFeature("http://xml.org/sax/features/validation", false);
  6. xmlReader.setContentHandler(new DirectoryContentHandler());
  7. xmlReader.parse(new InputSource(url.openStream()));
  8. }

代码示例来源:origin: stoicflame/ofx4j

  1. private void initializeFIData() throws IOException, SAXException {
  2. URL url = new URL(getUrl());
  3. XMLReader xmlReader = new Parser();
  4. xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
  5. xmlReader.setFeature("http://xml.org/sax/features/validation", false);
  6. xmlReader.setContentHandler(new DirectoryContentHandler());
  7. xmlReader.parse(new InputSource(url.openStream()));
  8. }

代码示例来源:origin: org.finra.jtaf/jtaf-extwebdriver

  1. @Override
  2. public String evaluateXpath(String xpath) throws Exception {
  3. XPathFactory xpathFac = XPathFactory.newInstance();
  4. XPath theXpath = xpathFac.newXPath();
  5. String html = getHtmlSource();
  6. html = html.replaceAll(">\\s+<", "><");
  7. InputStream input = new ByteArrayInputStream(html.getBytes(Charset.forName("UTF-8")));
  8. XMLReader reader = new Parser();
  9. reader.setFeature(Parser.namespacesFeature, false);
  10. Transformer transformer = TransformerFactory.newInstance()
  11. .newTransformer();
  12. DOMResult result = new DOMResult();
  13. transformer.transform(new SAXSource(reader, new InputSource(input)),
  14. result);
  15. Node htmlNode = result.getNode(); // This code gets a Node from the
  16. // result.
  17. return (String) theXpath.evaluate(xpath, htmlNode,
  18. XPathConstants.STRING);
  19. }

代码示例来源:origin: fourlastor/dante

  1. @Override public void parse(String string) {
  2. org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser();
  3. parser.setContentHandler(this);
  4. try {
  5. parser.parse(new InputSource(new StringReader(string)));
  6. } catch (IOException | SAXException e) {
  7. throw new HtmlParsingException(e);
  8. }
  9. emptyBuffer();
  10. }

代码示例来源:origin: com.xmlcalabash/xmlcalabash

  1. private XdmNode tagSoup(String text) {
  2. StringReader inputStream = new StringReader(text);
  3. InputSource source = new InputSource(inputStream);
  4. Parser parser = new Parser();
  5. parser.setEntityResolver(runtime.getResolver());
  6. SAXSource saxSource = new SAXSource(parser, source);
  7. DocumentBuilder builder = runtime.getProcessor().newDocumentBuilder();
  8. try {
  9. XdmNode doc = builder.build(saxSource);
  10. return doc;
  11. } catch (Exception e) {
  12. throw new XProcException(e);
  13. }
  14. }

代码示例来源:origin: org.daisy.libs/com.xmlcalabash

  1. private XdmNode tagSoup(String text) {
  2. StringReader inputStream = new StringReader(text);
  3. InputSource source = new InputSource(inputStream);
  4. Parser parser = new Parser();
  5. parser.setEntityResolver(runtime.getResolver());
  6. SAXSource saxSource = new SAXSource(parser, source);
  7. DocumentBuilder builder = runtime.getProcessor().newDocumentBuilder();
  8. try {
  9. XdmNode doc = builder.build(saxSource);
  10. return doc;
  11. } catch (Exception e) {
  12. throw new XProcException(e);
  13. }
  14. }

代码示例来源:origin: com.cloudera.cdk/cdk-morphlines-saxon

  1. public ConvertHTML(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) throws SAXNotRecognizedException, SAXNotSupportedException {
  2. super(builder, config, parent, child, context);
  3. this.charset = getConfigs().getCharset(config, "charset", null);
  4. this.omitXMLDeclaration = getConfigs().getBoolean(config, "omitXMLDeclaration", false);
  5. this.xmlReader = new Parser(); // no reuse?
  6. xmlReader.setProperty(Parser.schemaProperty, htmlSchema);
  7. xmlReader.setFeature(Parser.CDATAElementsFeature, getConfigs().getBoolean(config, "noCDATA", false));
  8. xmlReader.setFeature(Parser.namespacesFeature, !getConfigs().getBoolean(config, "noNamespaces", true));
  9. xmlReader.setFeature(Parser.ignoreBogonsFeature, getConfigs().getBoolean(config, "noBogons", false)); // also see TIKA-599
  10. xmlReader.setFeature(Parser.bogonsEmptyFeature, getConfigs().getBoolean(config, "emptyBogons", false));
  11. xmlReader.setFeature(Parser.rootBogonsFeature, getConfigs().getBoolean(config, "noRootBogons", false));
  12. xmlReader.setFeature(Parser.defaultAttributesFeature, getConfigs().getBoolean(config, "noDefaultAttributes", false));
  13. xmlReader.setFeature(Parser.translateColonsFeature, getConfigs().getBoolean(config, "noColons", false));
  14. xmlReader.setFeature(Parser.restartElementsFeature, getConfigs().getBoolean(config, "noRestart", false));
  15. xmlReader.setFeature(Parser.ignorableWhitespaceFeature, !getConfigs().getBoolean(config, "suppressIgnorableWhitespace", true));
  16. validateArguments();
  17. }

代码示例来源:origin: kite-sdk/kite

  1. public ConvertHTML(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) throws SAXNotRecognizedException, SAXNotSupportedException {
  2. super(builder, config, parent, child, context);
  3. this.charset = getConfigs().getCharset(config, "charset", null);
  4. this.omitXMLDeclaration = getConfigs().getBoolean(config, "omitXMLDeclaration", false);
  5. this.xmlReader = new Parser(); // no reuse?
  6. xmlReader.setProperty(Parser.schemaProperty, htmlSchema);
  7. xmlReader.setFeature(Parser.CDATAElementsFeature, getConfigs().getBoolean(config, "noCDATA", false));
  8. xmlReader.setFeature(Parser.namespacesFeature, !getConfigs().getBoolean(config, "noNamespaces", true));
  9. xmlReader.setFeature(Parser.ignoreBogonsFeature, getConfigs().getBoolean(config, "noBogons", false)); // also see TIKA-599
  10. xmlReader.setFeature(Parser.bogonsEmptyFeature, getConfigs().getBoolean(config, "emptyBogons", false));
  11. xmlReader.setFeature(Parser.rootBogonsFeature, getConfigs().getBoolean(config, "noRootBogons", false));
  12. xmlReader.setFeature(Parser.defaultAttributesFeature, getConfigs().getBoolean(config, "noDefaultAttributes", false));
  13. xmlReader.setFeature(Parser.translateColonsFeature, getConfigs().getBoolean(config, "noColons", false));
  14. xmlReader.setFeature(Parser.restartElementsFeature, getConfigs().getBoolean(config, "noRestart", false));
  15. xmlReader.setFeature(Parser.ignorableWhitespaceFeature, !getConfigs().getBoolean(config, "suppressIgnorableWhitespace", true));
  16. validateArguments();
  17. }

代码示例来源:origin: net.sf.ofx4j/ofx4j

  1. public void parseV1FromFirstElement(Reader reader) throws IOException, OFXParseException {
  2. Parser parser = new Parser();
  3. try {
  4. parser.setFeature(Parser.restartElementsFeature, false);
  5. }
  6. catch (Exception e) {
  7. throw new OFXParseException(e);
  8. }
  9. parser.setContentHandler(new TagSoupHandler(getContentHandler()));
  10. try {
  11. parser.parse(new InputSource(reader));
  12. }
  13. catch (SAXException e) {
  14. if (e.getCause() instanceof OFXParseException) {
  15. throw (OFXParseException) e.getCause();
  16. }
  17. throw new OFXParseException("Error parsing OFX document.", e);
  18. }
  19. }

相关文章