下面列出了javax.swing.text.html.parser.ParserDelegator#parse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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");
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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;
}
private void parse(String html) throws IOException {
Reader reader = new StringReader(html);
ParserDelegator parsers = new ParserDelegator();
parsers.parse(reader, this, Boolean.TRUE);
}
void parse() throws IOException {
ParserDelegator pd = new ParserDelegator();
formParser = new FormHTMLParser();
Reader r = new StringReader(definition);
pd.parse(r, formParser, true);
}
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);
}