类javax.swing.text.html.parser.ParserDelegator源码实例Demo

下面列出了怎么用javax.swing.text.html.parser.ParserDelegator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: java-swing-tips   文件: MainPanel.java
@Override public void actionPerformed(ActionEvent e) {
  textArea.append(String.format("----%n%s%n", getValue(Action.NAME)));
  String id = field.getText().trim();
  String text = editorPane.getText();
  ParserDelegator delegator = new ParserDelegator();
  try {
    delegator.parse(new StringReader(text), new HTMLEditorKit.ParserCallback() {
      @Override public void handleStartTag(HTML.Tag tag, MutableAttributeSet a, int pos) {
        Object attrId = a.getAttribute(HTML.Attribute.ID);
        textArea.append(String.format("%[email protected]=%s%n", tag, attrId));
        if (id.equals(attrId)) {
          textArea.append(String.format("found: pos=%d%n", pos));
          int endOffs = text.indexOf('>', pos);
          textArea.append(String.format("%s%n", text.substring(pos, endOffs + 1)));
        }
      }
    }, Boolean.TRUE);
  } catch (IOException ex) {
    ex.printStackTrace();
    textArea.append(String.format("%s%n", ex.getMessage()));
    UIManager.getLookAndFeel().provideErrorFeedback(textArea);
  }
}
 
源代码2 项目: dragonwell8_jdk   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码3 项目: TencentKona-8   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码4 项目: jdk8u60   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码5 项目: openjdk-jdk8u   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码6 项目: phoebus   文件: ChannelFinderException.java
private static String parseErrorMsg(UniformInterfaceException ex) {
    String entity = ex.getResponse().getEntity(String.class);
    try {
        ClientResponseParser callback = new ClientResponseParser();
        Reader reader = new StringReader(entity);
        new ParserDelegator().parse(reader, callback, false);
        return callback.getMessage();
    } catch (IOException e) {
        return "Could not retrieve message from server";
    }
}
 
源代码7 项目: phoebus   文件: OlogException.java
private static String parseErrorMsg(UniformInterfaceException ex) {
           String entity = ex.getResponse().getEntity(String.class);
           try {
                   ClientResponseParser callback = new ClientResponseParser();
                   Reader reader = new StringReader(entity);
                   new ParserDelegator().parse(reader, callback, false);
                   return callback.getMessage();
           } catch (IOException e) {
               return "Could not retrieve message from server";
           }
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码9 项目: openjdk-jdk9   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码10 项目: Knowage-Server   文件: Html2String.java
public void parse() throws IOException {
	logger.debug("IN");
	// put a capo
	toConvert = toConvert.replaceAll("<BR>", "|*|");
	toConvert = toConvert.replaceAll("<BR/>", "|*|");
	toConvert = toConvert.replaceAll("<br>", "|*|");
	toConvert = toConvert.replaceAll("<br/>", "|*|");
	StringReader stringReader = new StringReader(toConvert);
	buffer = new StringBuffer();
	ParserDelegator delegator = new ParserDelegator();
	// the third parameter is TRUE to ignore charset directive
	delegator.parse(stringReader, this, Boolean.FALSE);
	stringReader.close();
	logger.debug("OUT");
}
 
源代码11 项目: jdk8u-jdk   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码12 项目: hottub   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码13 项目: openjdk-8-source   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码14 项目: openjdk-8   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码15 项目: jdk8u_jdk   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码16 项目: jdk8u-jdk   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码17 项目: jdk8u-dev-jdk   文件: bug7165725.java
static String getParsedContentOneLine(String path) throws Exception {
    File f = new File(path);
    FileReader fr = new FileReader(f);
    ParserDelegator pd = new ParserDelegator();
    SBParserCallback sbcallback = new SBParserCallback();
    pd.parse(fr, sbcallback, true);
    fr.close();
    return sbcallback.getStringOneLine();
}
 
源代码18 项目: Zettelkasten   文件: Tools.java
/**
 * This method checks the content of {@code content} for valid HTML and
 * returns {@code true} if the content could be parsed t HTML. With this, we
 * check whether an entry makes use of correct or irregular nested tags.
 *
 * @param content the html-page which should be checked for correctly nested
 * tags, usually an entry's content
 * @param zettelnummer the number of the entry that is checked for valid
 * html-tags
 * @return {@code true} when the content could be successfully parsed to
 * HTML, false otherwise
 */
public static boolean isValidHTML(String content, final int zettelnummer) {
    // check for valid html
    validhtml = true;
    // first, we parse the created web-page to catch errors that might occure when parsing
    // the entry-content. this might happen when tags are not properly used.
    HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback() {
        // in case the parsing was not succssful, log that error message.
        @Override
        public void handleError(String errorMsg, int pos) {
            if (errorMsg.toLowerCase().contains("unmatched") || errorMsg.toLowerCase().contains("missing")) {
                // if body tag is missing (which is true for all entries), don't log that message
                if (!errorMsg.toLowerCase().contains("body")) {
                    // tell function that HTML is invalid.
                    validhtml = false;
                    errorMsg = System.lineSeparator() + "Error when parsing the entry " + String.valueOf(zettelnummer) + "!" + System.lineSeparator() + errorMsg + System.lineSeparator();
                    Constants.zknlogger.log(Level.SEVERE, errorMsg);
                }
            }
        }
    };
    // create a string-reader that reads the entry's html-content
    Reader reader = new StringReader(content);
    // try to parse the html-page
    try {
        new ParserDelegator().parse(reader, callback, false);
    } catch (IOException ex) {
        Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage());
    }
    return validhtml;
}
 
源代码19 项目: howsun-javaee-framework   文件: AnalizeWebParse.java
public List<String> parse(Reader file) throws Exception {
	if (file == null) {
		return null;
	}

	ParserDelegator pd = new ParserDelegator();
	try {
		pd.parse(file, this, true);
	} catch (Exception e) {
		throw e;
	}

	return imgs;
}
 
源代码20 项目: ObjectLogger   文件: Html2Text.java
private void parse(String html) throws IOException {
    Reader reader = new StringReader(html);
    ParserDelegator parsers = new ParserDelegator();
    parsers.parse(reader, this, Boolean.TRUE);
}
 
源代码21 项目: dragonwell8_jdk   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码22 项目: TencentKona-8   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码23 项目: jdk8u60   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码24 项目: openjdk-jdk8u   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码25 项目: netbeans   文件: RefactoringTestCase.java
public void parse(StringReader in) throws IOException {
    new ParserDelegator().parse(in, this, Boolean.TRUE);
}
 
源代码26 项目: netbeans   文件: ButtonsHTMLParser.java
void parse() throws IOException {
    ParserDelegator pd = new ParserDelegator();
    formParser = new FormHTMLParser();
    Reader r = new StringReader(definition);
    pd.parse(r, formParser, true);
}
 
源代码27 项目: netbeans   文件: RefactoringPanel.java
public void parse(Reader in) throws IOException {
    s = new StringBuffer();
    ParserDelegator delegator = new ParserDelegator();
    // the third parameter is TRUE to ignore charset directive
    delegator.parse(in, this, Boolean.TRUE);
}
 
源代码28 项目: openjdk-jdk8u-backup   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码29 项目: openjdk-jdk9   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
源代码30 项目: jdk8u-jdk   文件: bug7011777.java
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
 类所在包
 类方法
 同包方法