Java 8 ParserDelegator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ParserDelegator class.

This code example shows how to use the following methods:parse
 
	 public Html2text() {} 
 
	 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.FALSE);
	 } 
 
	 public void handleText(char[] text, int pos) {
	   s.append(text);
	 } 
 
	 public String getText() {
	   return s.toString();
	 } 
 
//	 public static void main (String[] args) { 
//	   try { 
5
CodeRank
This code example shows how to use the following methods:parse
public class AnchorParser { 
    public List<String> parseAnchors(String stringWithAnchors) throws IOException {
        final List<String> result = new ArrayList<>();
 
        Reader reader = new StringReader(stringWithAnchors);
        HTMLEditorKit.Parser parser = new ParserDelegator();
        parser.parse(reader, new HTMLEditorKit.ParserCallback() {
            public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
                if (t == HTML.Tag.A) {
                    Object link = a.getAttribute(HTML.Attribute.HREF);
                    if (link != null) { 
                        result.add(String.valueOf(link));
                    } 
                } 
            } 
        }, true); 
        reader.close();
        return result;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:parse
  } 
 
  @Override 
  public void parse(Reader in) throws IOException {
    texte = new StringBuilder(1024);
    ParserDelegator delegator = new ParserDelegator();
    delegator.parse(in, this, true);
  } 
 
  @Override 
  public void handleText(char[] text, int pos) {
    if (register && inScript <= 0 && !hasError && texte.length() <= maxSize) {
      for (int i = 0; i < text.length; i++) {
        if (Character.isLetterOrDigit(text[i])) {
          texte.append(text[i]);
        } else if (Character.isSpaceChar(text[i])) {
          texte.append(' ');
        } else { 
          texte.append(text[i]);
        } 
5
CodeRank
This code example shows how to use the following methods:parse
	 
	public static String extractText(String text) {
	    final StringBuilder stringBuilder = new StringBuilder();
	    stringBuilder.append("");
	     
	    ParserDelegator parserDelegator = new ParserDelegator();
	     
	    ParserCallback parserCallback = new ParserCallback() {
	       
	    	public void handleText(final char[] data, final int pos) {
	    		stringBuilder.append(data);
	    	} 
	       
	    	public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) { }
	       
	    	public void handleEndTag(Tag t, final int pos) {  }
	       
	    	public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) { }
	       
	    	public void handleComment(final char[] data, final int pos) { }

5
CodeRank
This code example shows how to use the following methods:
        Object dtdValue = appContext.get(dtdKey);
 
        assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized"); 
 
        // Try reinit default DTD 
        new ParserDelegator();
 
        assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");
 
        HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
 
        if (styleSheet == null) {
            // First AppContext 
            styleSheet = htmlEditorKit.getStyleSheet();
 
            assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
            assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
        } else { 
            assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
        } 
4
CodeRank
This code example shows how to use the following methods:
 
import com.dell.doradus.common.FieldType; 
import com.dell.doradus.search.analyzer.SimpleText; 
 
public class HTMLAnalyzer extends FieldAnalyzer { 
	private static final ParserDelegator s_parser = new ParserDelegator();
	 
    private static final HTMLAnalyzer INSTANCE = new HTMLAnalyzer();
    public static HTMLAnalyzer instance() { return INSTANCE; }
    private HTMLAnalyzer() { } 
     
    class HTMLParserCallback extends ParserCallback {
    	List<String> m_tokens = new LinkedList<String>();
    	 
    	@Override 
    	public void handleText(char[] data, int pos) {
    		String value = new String(data);
    		m_tokens.addAll(new SimpleText().tokenize(value));
    	} 
    } 
3
CodeRank
This code example shows how to use the following methods:
        Object dtdValue = appContext.get(dtdKey);
 
        assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized"); 
 
        // Try reinit default DTD 
        new ParserDelegator();
 
        assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");
 
        HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
 
        if (styleSheet == null) {
            // First AppContext 
            styleSheet = htmlEditorKit.getStyleSheet();
 
            assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
            assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
        } else { 
            assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
        } 
3
CodeRank
See Code Examples for Java 8 ParserDelegator Methods: