Java Code Examples for javax.swing.text.html.parser.ParserDelegator

The following examples show how to use javax.swing.text.html.parser.ParserDelegator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@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);
  }
}
 
Example 2
Source Project: dragonwell8_jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 3
Source Project: TencentKona-8   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 4
Source Project: jdk8u60   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 6
Source Project: phoebus   Source File: ChannelFinderException.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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";
    }
}
 
Example 7
Source Project: phoebus   Source File: OlogException.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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";
           }
}
 
Example 8
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();
}
 
Example 9
Source Project: openjdk-jdk9   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 10
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");
}
 
Example 11
Source Project: jdk8u-jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 12
Source Project: hottub   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 13
Source Project: openjdk-8-source   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 14
Source Project: openjdk-8   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 15
Source Project: jdk8u_jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 16
Source Project: jdk8u-jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 17
Source Project: jdk8u-dev-jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 18
Source Project: Zettelkasten   Source File: Tools.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source Project: howsun-javaee-framework   Source File: AnalizeWebParse.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 20
Source Project: ObjectLogger   Source File: Html2Text.java    License: Apache License 2.0 4 votes vote down vote up
private void parse(String html) throws IOException {
    Reader reader = new StringReader(html);
    ParserDelegator parsers = new ParserDelegator();
    parsers.parse(reader, this, Boolean.TRUE);
}
 
Example 21
Source Project: dragonwell8_jdk   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 22
Source Project: TencentKona-8   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 23
Source Project: jdk8u60   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 25
Source Project: netbeans   Source File: RefactoringTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public void parse(StringReader in) throws IOException {
    new ParserDelegator().parse(in, this, Boolean.TRUE);
}
 
Example 26
Source Project: netbeans   Source File: ButtonsHTMLParser.java    License: Apache License 2.0 4 votes vote down vote up
void parse() throws IOException {
    ParserDelegator pd = new ParserDelegator();
    formParser = new FormHTMLParser();
    Reader r = new StringReader(definition);
    pd.parse(r, formParser, true);
}
 
Example 27
Source Project: netbeans   Source File: RefactoringPanel.java    License: Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 28
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 29
Source Project: openjdk-jdk9   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}
 
Example 30
Source Project: jdk8u-jdk   Source File: bug7011777.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
        new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
}