本文整理匯總了Java中javax.swing.text.html.parser.ParserDelegator類的典型用法代碼示例。如果您正苦於以下問題:Java ParserDelegator類的具體用法?Java ParserDelegator怎麽用?Java ParserDelegator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParserDelegator類屬於javax.swing.text.html.parser包,在下文中一共展示了ParserDelegator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cleanWikiTest
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
private String cleanWikiTest(String markup) throws IOException
{
StringWriter writer = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer);
builder.setEmitAsDocument(false);
MarkupParser parser = new MarkupParser(new MediaWikiDialect());
parser.setBuilder(builder);
parser.parse(markup);
final String html = writer.toString();
final StringBuilder cleaned = new StringBuilder();
HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback()
{
public void handleText(char[] data, int pos)
{
cleaned.append(new String(data)).append(' ');
}
};
new ParserDelegator().parse(new StringReader(html), callback, false);
return cleaned.toString();
}
示例2: processFileHierarchy
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void processFileHierarchy(String urlString) {
try {
System.out.println(urlString);
URL url = new URL(urlString);
InputStream in = url.openStream();
InputStreamReader reader = new InputStreamReader(in);
// ParserCallback class to handle the href tags
LinkHandler callback = new LinkHandler();
// key step to enable recursion
callback.setCurrentPath(urlString);
// parse the HTML document
new ParserDelegator().parse(reader, callback, false);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: actionPerformed
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
@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();
}
}
示例4: testInsertAfterEnd_Specs2
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertAfterEnd_Specs2() throws Exception {
htmlDoc.setParser(new ParserDelegator());
htmlDoc.setEditable(false);
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
htmlDoc.insertAfterEnd(p, "<a>link</a>");
Marker insertMarker = htmlDoc.getInsertMarker();
assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
insertMarker.reset();
assertEquals(2, specs.length);
checkEndTagSpec(specs[0]);
assertSpec(specs[1], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
AttributeSet specAttr = specs[1].getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}
示例5: testInsertAfterEnd_Events
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertAfterEnd_Events() throws Exception {
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
addElement();
htmlDoc.setParser(new ParserDelegator());
DocumentController listener = new DocumentController();
htmlDoc.addDocumentListener(listener);
htmlDoc.insertAfterEnd(p, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
checkEvent(body, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 4);
listener.reset();
htmlDoc.insertAfterEnd(body, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
checkEvent(root, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 12);
}
示例6: testInsertAfterEnd_Exceptions
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertAfterEnd_Exceptions() throws Exception {
addElements();
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
Element leaf = p.getElement(0);
try {
htmlDoc.insertAfterEnd(leaf, "<a>link</a>");
fail("IllegalStateException should be thrown");
} catch (IllegalStateException e) {
}
htmlDoc.setParser(new ParserDelegator());
htmlDoc.insertAfterEnd(null, "<a>link</a>");
}
示例7: testInsertAfterStart_Specs2
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertAfterStart_Specs2() throws Exception {
htmlDoc.setParser(new ParserDelegator());
htmlDoc.setEditable(false);
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
htmlDoc.insertAfterStart(p, "<a>link</a>");
Marker insertMarker = htmlDoc.getInsertMarker();
assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
insertMarker.reset();
assertEquals(1, specs.length);
assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
AttributeSet specAttr = specs[0].getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}
示例8: testInsertAfterStart_Events
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertAfterStart_Events() throws Exception {
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
addElement();
htmlDoc.setParser(new ParserDelegator());
DocumentController listener = new DocumentController();
htmlDoc.addDocumentListener(listener);
htmlDoc.insertAfterStart(p, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
checkEvent(p, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 0);
listener.reset();
htmlDoc.insertAfterStart(body, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
if (!isHarmony()) {
checkEvent(body, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 0);
} else {
checkEvent(body, listener.getEvent(0), DocumentEvent.EventType.INSERT, 2, 8, 0);
}
}
示例9: testInsertBeforeEnd_Specs2
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertBeforeEnd_Specs2() throws Exception {
htmlDoc.setParser(new ParserDelegator());
htmlDoc.setEditable(false);
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
htmlDoc.insertBeforeEnd(p, "<a>link</a>");
Marker insertMarker = htmlDoc.getInsertMarker();
assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
insertMarker.reset();
assertEquals(1, specs.length);
assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
AttributeSet specAttr = specs[0].getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}
示例10: testInsertBeforeEnd_Events
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertBeforeEnd_Events() throws Exception {
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
addElement();
htmlDoc.setParser(new ParserDelegator());
DocumentController listener = new DocumentController();
htmlDoc.addDocumentListener(listener);
htmlDoc.insertBeforeEnd(p, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
checkEvent(p, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 4);
listener.reset();
htmlDoc.insertBeforeEnd(body, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
checkEvent(body, listener.getEvent(0), DocumentEvent.EventType.INSERT, 2, 8, 13);
}
示例11: testInsertBeforeStart_Specs2
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertBeforeStart_Specs2() throws Exception {
htmlDoc.setParser(new ParserDelegator());
htmlDoc.setEditable(false);
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
htmlDoc.insertBeforeStart(p, "<a>link</a>");
Marker insertMarker = htmlDoc.getInsertMarker();
assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
insertMarker.reset();
assertEquals(2, specs.length);
checkEndTagSpec(specs[0]);
assertSpec(specs[1], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
AttributeSet specAttr = specs[1].getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}
示例12: testInsertBeforeStart_Events
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertBeforeStart_Events() throws Exception {
Element root = htmlDoc.getDefaultRootElement();
Element branch1 = root.getElement(0);
Element branch2 = branch1.getElement(0);
addElement();
htmlDoc.setParser(new ParserDelegator());
DocumentController listener = new DocumentController();
htmlDoc.addDocumentListener(listener);
htmlDoc.insertBeforeStart(branch2, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
if (!isHarmony()) {
checkEvent(branch1, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 0);
} else {
checkEvent(branch1, listener.getEvent(0), DocumentEvent.EventType.INSERT, 2, 8, 0);
}
listener.reset();
htmlDoc.insertBeforeStart(branch1, "<a>link</a><b>bold</b>");
assertEquals(1, listener.getNumEvents());
if (!isHarmony()) {
checkEvent(root, listener.getEvent(0), DocumentEvent.EventType.INSERT, 3, 8, 0);
} else {
checkEvent(root, listener.getEvent(0), DocumentEvent.EventType.INSERT, 2, 8, 0);
}
}
示例13: testInsertBeforeStart_Exceptions
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testInsertBeforeStart_Exceptions() throws Exception {
addElements();
Element root = htmlDoc.getDefaultRootElement();
Element branch1 = root.getElement(0);
Element branch2 = branch1.getElement(0);
Element branch3 = branch2.getElement(0);
try {
htmlDoc.insertBeforeStart(branch3, "<a>link</a>");
fail("IllegalStateException should be thrown");
} catch (IllegalStateException e) {
}
htmlDoc.setParser(new ParserDelegator());
htmlDoc.insertBeforeStart(null, "<a>link</a>");
}
示例14: testSetInnerHTML_Specs2
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testSetInnerHTML_Specs2() throws Exception {
htmlDoc.setParser(new ParserDelegator());
htmlDoc.setEditable(false);
Element root = htmlDoc.getDefaultRootElement();
Element body = root.getElement(0);
Element p = body.getElement(0);
htmlDoc.setInnerHTML(p, "<a>link</a>");
Marker insertMarker = htmlDoc.getInsertMarker();
assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
insertMarker.reset();
assertEquals(4, specs.length);
assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
AttributeSet specAttr = specs[0].getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
assertSpec(specs[1], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[]{'\n'});
checkEndTagSpec(specs[2]);
checkEndTagSpec(specs[3]);
}
示例15: testSetInnerHTML_Events
import javax.swing.text.html.parser.ParserDelegator; //導入依賴的package包/類
public void testSetInnerHTML_Events() throws Exception {
addElements();
Element root = htmlDoc.getDefaultRootElement();
Element branch1 = root.getElement(0);
final Element branch2 = branch1.getElement(0);
Element branch3 = branch2.getElement(0);
htmlDoc.setParser(new ParserDelegator());
DocumentController listener = new DocumentController();
htmlDoc.addDocumentListener(listener);
htmlDoc.setInnerHTML(branch2, "<a>link</a><b>bold</b>");
assertEquals(2, listener.getNumEvents());
checkEvent(branch2, listener.getEvent(0), DocumentEvent.EventType.INSERT, 4, 9, 0);
checkEvent(branch2, listener.getEvent(1), DocumentEvent.EventType.REMOVE, 4, 14, 8);
listener.reset();
htmlDoc.setInnerHTML(branch1, "<a>link</a><b>bold</b>");
assertEquals(2, listener.getNumEvents());
checkEvent(branch1, listener.getEvent(0), DocumentEvent.EventType.INSERT, 4, 9, 0);
checkEvent(branch1, listener.getEvent(1), DocumentEvent.EventType.REMOVE, 2, 10, 8);
}