本文整理汇总了Java中javax.swing.text.html.HTMLEditorKit.ParserCallback类的典型用法代码示例。如果您正苦于以下问题:Java ParserCallback类的具体用法?Java ParserCallback怎么用?Java ParserCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserCallback类属于javax.swing.text.html.HTMLEditorKit包,在下文中一共展示了ParserCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
/**
* Parses the HTML document, calling methods of the provided
* callback. This method must be multithread - safe.
* @param reader The reader to read the HTML document from
* @param a_callback The callback that is notifyed about the presence
* of HTML elements in the document.
* @param ignoreCharSet If thrue, any charset changes during parsing
* are ignored.
* @throws java.io.IOException
*/
public void parse(Reader reader, HTMLEditorKit.ParserCallback a_callback,
boolean ignoreCharSet
)
throws IOException
{
callBack = a_callback;
if (gnu == null || !dtd.equals(gnu.getDTD()))
{
gnu = new gnuParser(dtd);
}
gnu.parse(reader);
callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
try
{
callBack.flush();
}
catch (BadLocationException ex)
{
// Convert this into the supported type of exception.
throw new IOException(ex.getMessage());
}
}
示例2: parse
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
/**
* Parses the HTML document, calling methods of the provided callback. This
* method must be multithread - safe.
*
* @param reader The reader to read the HTML document from
* @param a_callback The callback that is notifyed about the presence of HTML
* elements in the document.
* @param ignoreCharSet If thrue, any charset changes during parsing are
* ignored.
* @throws java.io.IOException
*/
public void parse(Reader reader,
HTMLEditorKit.ParserCallback a_callback,
boolean ignoreCharSet) throws IOException
{
callBack = a_callback;
gnu.parse(reader);
callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
try
{
callBack.flush();
}
catch (BadLocationException ex)
{
// Convert this into the supported type of exception.
throw new IOException(ex.getMessage());
}
}
示例3: parse
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
/**
* Parses the HTML document, calling methods of the provided callback. This
* method must be multithread - safe.
*
* @param reader The reader to read the HTML document from
* @param a_callback The callback that is notifyed about the presence of HTML
* elements in the document.
* @param ignoreCharSet If thrue, any charset changes during parsing are
* ignored.
* @throws java.io.IOException
*/
public void parse(Reader reader,
HTMLEditorKit.ParserCallback a_callback,
boolean ignoreCharSet) throws IOException
{
callBack = a_callback;
gnu.parse(reader);
callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
try
{
callBack.flush();
}
catch (BadLocationException ex)
{
// Convert this into the supported type of exception.
throw new IOException(ex.getMessage());
}
}
示例4: testSpecialStart_Calls
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public void testSpecialStart_Calls() {
final Marker specialMarker = new Marker();
doc = new HTMLDocument() {
public ParserCallback getReader(int pos) {
return new HTMLReader(0) {
protected void addSpecialElement(final Tag tag, final MutableAttributeSet attr) {
specialMarker.setOccurred();
ArrayList callInfo = new ArrayList();
callInfo.add(tag);
callInfo.add(attr);
specialMarker.setAuxiliary(callInfo);
}
};
}
};
reader = (HTMLReader)doc.getReader(0);
String text = "precontent";
Tag tag = Tag.HTML;
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute("aaaa", "bbbb");
reader.addSpecialElement(tag, attr);
assertTrue(specialMarker.isOccurred());
ArrayList callInfo = (ArrayList)specialMarker.getAuxiliary();
assertEquals(tag, callInfo.get(0));
assertEquals(attr, callInfo.get(1));
}
示例5: testHTMLReaderIntIntIntTag_PushPopParameter_BlockParagraph
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public void testHTMLReaderIntIntIntTag_PushPopParameter_BlockParagraph() throws Exception {
// trailing specs cutting for block and paragraph tags
if (!isHarmony()) {
return;
}
final String str = "<P>link</P>";
init();
editable = false;
ParserCallback reader = doc.getReader(0, 2, 3, Tag.P);
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute(StyleConstants.NameAttribute, Tag.S.toString());
doc.insertString(0, "0000", attr);
assertFalse(insertMarker.isOccurred());
parse(str, reader);
reader.flush();
assertTrue(insertMarker.isOccurred());
ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
String specsDescr = "cpeoeosnsnsnsoco";
assertEquals(specsDescr.length()/2, specs.length);
insertMarker.reset();
for (int i = 0; i < specs.length; i++) {
checkSpecType(specsDescr, i, (ElementSpec)specs[i]);
}
}
示例6: testBlockOpen_ImpliedAttribute
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public void testBlockOpen_ImpliedAttribute() {
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute("aaaa", "bbbb");
attr.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED, Boolean.TRUE);
reader.blockOpen(Tag.B, attr);
assertEquals(0, reader.charAttr.getAttributeCount());
assertEquals(1, reader.parseBuffer.size());
final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
final AttributeSet specAttr = spec.getAttributes();
assertEquals(2, specAttr.getAttributeCount());
checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.B);
checkAttributes(specAttr, "aaaa", "bbbb");
assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
assertNotSame(attr, specAttr);
assertEquals(2, attr.getAttributeCount());
checkAttributes(attr, StyleConstants.NameAttribute, Tag.B);
checkAttributes(attr, "aaaa", "bbbb");
}
示例7: testPreContent_Calls
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public void testPreContent_Calls() {
final Marker contentMarker = new Marker();
doc = new HTMLDocument() {
public ParserCallback getReader(int pos) {
return new HTMLReader(0) {
protected void addContent(char[] data, int offs, int length) {
contentMarker.setOccurred();
ArrayList callInfo = new ArrayList();
callInfo.add(data);
callInfo.add(new Integer(offs));
callInfo.add(new Integer(length));
contentMarker.setAuxiliary(callInfo);
};
};
}
};
reader = (HTMLReader)doc.getReader(0);
String text = "precontent";
reader.preContent(text.toCharArray());
assertTrue(contentMarker.isOccurred());
ArrayList callInfo = (ArrayList)contentMarker.getAuxiliary();
assertEquals(text, new String((char[])callInfo.get(0)));
assertEquals(new Integer(0), callInfo.get(1));
assertEquals(text.length(), ((Integer)callInfo.get(2)).intValue());
}
示例8: checkConstructorTagParameter
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
private void checkConstructorTagParameter(final Tag tag, final String str, final int numSpecs) throws Exception {
init();
editable = false;
ParserCallback reader = doc.getReader(0, 0, 0, tag);
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute(StyleConstants.NameAttribute, Tag.B.toString());
doc.insertString(0, "0000", attr);
assertFalse("no inserts", insertMarker.isOccurred());
parse(str, reader);
reader.flush();
if (numSpecs == 0 && isHarmony()) {
assertFalse("inserted", insertMarker.isOccurred());
} else {
assertTrue("inserted", insertMarker.isOccurred());
ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
assertEquals("number of specs inserted", numSpecs, specs.length);
insertMarker.reset();
}
}
示例9: checkConstructorPopPushParameter
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
private void checkConstructorPopPushParameter(final Tag tag, final String str, final int pop, final int push, final String specsDescr) throws Exception {
init();
editable = false;
ParserCallback reader = doc.getReader(0, pop, push, tag);
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute(StyleConstants.NameAttribute, Tag.S.toString());
doc.insertString(0, "0000", attr);
assertFalse(insertMarker.isOccurred());
parse(str, reader);
reader.flush();
assertTrue(insertMarker.isOccurred());
ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
assertEquals(specsDescr.length()/2, specs.length);
insertMarker.reset();
for (int i = 0; i < specs.length; i++) {
checkSpecType(specsDescr, i, (ElementSpec)specs[i]);
}
}
示例10: checkConstructorOffsetPopPushParameter
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
private void checkConstructorOffsetPopPushParameter(final Tag tag, final String str, final int offset, final int pop, final int push, final String specsDescr) throws Exception {
init();
ParserCallback reader = doc.getReader(offset, pop, push, tag);
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute(StyleConstants.NameAttribute, Tag.S.toString());
editable = false;
insertMarker.reset();
parse(str, reader);
reader.flush();
assertTrue(insertMarker.isOccurred());
ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
assertEquals(specsDescr.length()/2, specs.length);
insertMarker.reset();
for (int i = 0; i < specs.length; i++) {
checkSpecType(specsDescr, i, (ElementSpec)specs[i]);
}
}
示例11: createContentMarkersInstrumentedReader
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
private void createContentMarkersInstrumentedReader(final Marker addContentMarker, final Marker preContentMarker, final Marker textAreaMarker) {
doc = new HTMLDocument() {
public ParserCallback getReader(int pos) {
return new HTMLReader(pos) {
protected void addContent(char[] data, int offset, int length, boolean createImpliedPIfNecessary) {
addContentMarker.setOccurred();
super.addContent(data, offset, length, createImpliedPIfNecessary);
};
protected void preContent(char[] data) {
preContentMarker.setOccurred();
super.preContent(data);
}
protected void textAreaContent(char[] data) {
textAreaMarker.setOccurred();
super.textAreaContent(data);
}
};
}
};
reader = (HTMLReader)doc.getReader(0);
}
示例12: verify
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public String verify(String html, String trace)
throws Exception
{
out.setLength(0);
HTMLEditorKit.ParserCallback callback = this;
ParserDelegator delegator = new ParserDelegator();
delegator.parse(new StringReader(html), callback, true);
String ou = out.toString();
if (trace != null)
{
if (!ou.equals(trace))
{
System.err.println("Unable to parse '" + html + "':");
System.err.println(" expected: '" + trace + "',");
System.out.println(" returned: '" + ou + "'.");
throw new Exception("'" + html + "' -> '" + ou + "' expected '" +
trace + "'"
);
}
}
return ou;
}
示例13: handleStartTag
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
protected final void handleStartTag(TagElement tag)
{
SimpleAttributeSet attributes = gnu.getAttributes();
if (tag.fictional())
attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
callBack.handleStartTag(tag.getHTMLTag(), attributes,
hTag.where.startPosition
);
}
示例14: testPreStartEnd_PreContentCalls
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
public void testPreStartEnd_PreContentCalls() {
final Marker preContentMarker = new Marker();
doc = new HTMLDocument() {
public ParserCallback getReader(int pos) {
return new HTMLReader(0) {
protected void preContent(char[] data) {
preContentMarker.setOccurred();
preContentMarker.setAuxiliary(data);
super.preContent(data);
}
};
}
};
reader = (HTMLReader)doc.getReader(0);
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute("aaaa", "bbbb");
action = reader.new PreAction();
action.start(Tag.PRE, attr);
String text = "data";
assertFalse(preContentMarker.isOccurred());
reader.handleText(text.toCharArray(), 0);
assertTrue(preContentMarker.isOccurred());
assertEquals(text, new String((char [])preContentMarker.getAuxiliary()));
action.end(Tag.PRE);
preContentMarker.reset();
reader.handleText(text.toCharArray(), 0);
assertFalse(preContentMarker.isOccurred());
}
示例15: checkConstructorOffsetParameter
import javax.swing.text.html.HTMLEditorKit.ParserCallback; //导入依赖的package包/类
private void checkConstructorOffsetParameter(final Tag tag, final String str, final int offset) throws Exception {
insertMarker.reset();
doc = new HTMLDocument() {
protected void insert(int offset, ElementSpec[] data) throws BadLocationException {
insertMarker.setOccurred();
insertMarker.setAuxiliary(new Integer(offset));
}
};
ParserCallback reader = doc.getReader(offset, 0, 0, tag);
parse(str, reader);
reader.flush();
assertTrue(insertMarker.isOccurred());
assertEquals(new Integer(offset), insertMarker.getAuxiliary());
}