本文整理了Java中javax.swing.text.html.HTMLEditorKit.createDefaultDocument()
方法的一些代码示例,展示了HTMLEditorKit.createDefaultDocument()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit.createDefaultDocument()
方法的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit
方法名:createDefaultDocument
暂无
代码示例来源:origin: Multibit-Legacy/multibit-hd
@Override
public Document createDefaultDocument() {
return super.createDefaultDocument();
}
代码示例来源:origin: net.sf.gluebooster.java.booster/gb-basic
/**
* Create a new document.
*
* @return the created document
*/
public static HTMLDocument createDocument(){
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
return doc;
}
代码示例来源:origin: Chatanga/Girinoscope
@Override
public Document createDefaultDocument() {
HTMLDocument document = (HTMLDocument) super.createDefaultDocument();
document.setBase(Icon.class.getResource("/org/hihan/girinoscope/ui/"));
return document;
}
};
代码示例来源:origin: freeplane/freeplane
public HtmlProcessor(final String input){
final HTMLEditorKit kit = new HTMLEditorKit();
doc = kit.createDefaultDocument();
try {
final int defaultDocumentLength = doc.getLength();
kit.read(new StringReader(input), doc, defaultDocumentLength);
} catch (Exception e) {
}
}
public String htmlSubstring(int pos, int length){
代码示例来源:origin: stackoverflow.com
{
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
Reader HTMLReader = new InputStreamReader(testURL.openConnection().getInputStream());
kit.read(HTMLReader, doc, 0);
String title = (String) doc.getProperty(Document.TitleProperty);
System.out.println(title);
}
代码示例来源:origin: stackoverflow.com
HTMLEditorKit kit = new HTMLEditorKit();
StyledDocument doc2 = (StyledDocument)kit.createDefaultDocument();
kit.read(new FileInputStream(file), doc2, 0);
pane = new JTextPane();
pane.setEditorKit(kit);//set EditorKit of JTextPane as kit.
pane.setDocument(doc2);
代码示例来源:origin: stackoverflow.com
Reader stringReader = new StringReader(string);
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
htmlKit.read(stringReader, htmlDoc, 0);
代码示例来源:origin: stackoverflow.com
public static void main(String args[]) throws Exception {
String webUrl = "http://ramp.sdr.co.za/cache/1402NYFW/GoRedForWomen/";
URL url = new URL(webUrl);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
htmlKit.read(br, htmlDoc, 0);
for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator.next()) {
AttributeSet attributes = iterator.getAttributes();
String imgSrc = (String) attributes.getAttribute(HTML.Attribute.HREF);
System.out.println(imgSrc);
if (imgSrc != null && (imgSrc.toLowerCase().endsWith(".jpg") || (imgSrc.endsWith(".png")) || (imgSrc.endsWith(".jpeg")) || (imgSrc.endsWith(".bmp")) || (imgSrc.endsWith(".ico")))) {
try {
downloadImage(webUrl, imgSrc);
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
代码示例来源:origin: stackoverflow.com
HTMLEditorKit tmp = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) tmp.createDefaultDocument();
StringWriter writer = new StringWriter();
tmp.write(writer, doc, 0, doc.getLength());
String s = writer.toString();
console.log(s);
代码示例来源:origin: stefanhaustein/nativehtml
@Override
public javax.swing.text.Document createDefaultDocument() {
HTMLDocument result = (HTMLDocument) super.createDefaultDocument();
try {
result.setBase(document.getUrl().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
result.putProperty("imageCache", imageCache);
return result;
}
});
代码示例来源:origin: stackoverflow.com
String htmlString = "<body><h1>Karaoke Beyonce song</h1><p><span class="highlight">Hello</span>world</p></body>";
JEditorPane pane = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
pane.setEditable(false);
pane.setEditorKit(kit);
StyleSheet sh = editorKit.getStyleSheet();
sh.addRule("span.highlight {background-color:yellow}");
Document doc = kit.createDefaultDocument();
pane.setDocument(doc);
pane.setText(htmlString);
代码示例来源:origin: stackoverflow.com
Reader stringReader = new StringReader(string);
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
HTMLEditorKit.Parser parser = new ParserDelegator();
parser.parse(stringReader, htmlDoc.getReader(0), true);
代码示例来源:origin: DSpace/DSpace
/**
* @param currentItem item
* @param source source input stream
* @param verbose verbose mode
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception {
// try and read the document - set to ignore character set directive,
// assuming that the input stream is already set properly (I hope)
HTMLEditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(source, doc, 0);
String extractedText = doc.getText(0, doc.getLength());
// generate an input stream with the extracted text
byte[] textBytes = extractedText.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(textBytes);
return bais; // will this work? or will the byte array be out of scope?
}
}
代码示例来源:origin: stackoverflow.com
private static String convertToRTF(String htmlStr) {
OutputStream os = new ByteArrayOutputStream();
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
RTFEditorKit rtfEditorKit = new RTFEditorKit();
String rtfStr = null;
htmlStr = htmlStr.replaceAll("<br.*?>","#NEW_LINE#");
htmlStr = htmlStr.replaceAll("</p>","#NEW_LINE#");
htmlStr = htmlStr.replaceAll("<p.*?>","");
InputStream is = new ByteArrayInputStream(htmlStr.getBytes());
try {
Document doc = htmlEditorKit.createDefaultDocument();
htmlEditorKit.read(is, doc, 0);
rtfEditorKit .write(os, doc, 0, doc.getLength());
rtfStr = os.toString();
rtfStr = rtfStr.replaceAll("#NEW_LINE#","\\\\par ");
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
return rtfStr;
}
代码示例来源:origin: org.seleniumhq.selenium.server/selenium-server-coreless
public HTMLSuiteResult(String originalSuite) {
//this.originalSuite = originalSuite;
StringReader s = new StringReader(originalSuite);
HTMLEditorKit k = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) k.createDefaultDocument();
Parser parser = doc.getParser();
HrefConverter p = new HrefConverter(originalSuite);
doc.setAsynchronousLoadPriority(-1);
try {
parser.parse(s, p, true);
} catch (IOException e) {
// DGF aw, this won't really happen! (will it?)
throw new RuntimeException(e);
}
hrefs = p.hrefList;
StringBuilder sb = new StringBuilder();
int previousPosition = originalSuite.length();
for (int i = p.tagPositions.size()-1; i >= 0; i--) {
int pos = p.tagPositions.get(i);
String href = p.hrefList.get(i);
String snippet = originalSuite.substring(pos, previousPosition);
String replaceSnippet = snippet.replaceFirst ("\\Q" + href + "\\E", "#testresult" + i);
sb.insert(0, replaceSnippet);
previousPosition = pos;
}
String snippet = originalSuite.substring(0, previousPosition);
sb.insert(0, snippet);
updatedSuite = sb.toString();
}
代码示例来源:origin: org.testatoo.openqa/selenium-server
public HTMLSuiteResult(String originalSuite) {
//this.originalSuite = originalSuite;
StringReader s = new StringReader(originalSuite);
HTMLEditorKit k = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) k.createDefaultDocument();
Parser parser = doc.getParser();
HrefConverter p = new HrefConverter(originalSuite);
doc.setAsynchronousLoadPriority(-1);
try {
parser.parse(s, p, true);
} catch (IOException e) {
// DGF aw, this won't really happen! (will it?)
throw new RuntimeException(e);
}
hrefs = p.hrefList;
StringBuilder sb = new StringBuilder();
int previousPosition = originalSuite.length();
for (int i = p.tagPositions.size()-1; i >= 0; i--) {
int pos = p.tagPositions.get(i);
String href = p.hrefList.get(i);
String snippet = originalSuite.substring(pos, previousPosition);
String replaceSnippet = snippet.replaceFirst ("\\Q" + href + "\\E", "#testresult" + i);
sb.insert(0, replaceSnippet);
previousPosition = pos;
}
String snippet = originalSuite.substring(0, previousPosition);
sb.insert(0, snippet);
updatedSuite = sb.toString();
}
代码示例来源:origin: stackoverflow.com
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("a:hover{color:red;}");
Document doc = kit.createDefaultDocument();
String htmlString = "<a href='stackoverflow.com'>Go to StackOverflow!</a>";
// your JEditorPane
jEditorPane.setDocument(doc);
jEditorPane.setText(htmlString);
代码示例来源:origin: freeplane/freeplane
/**
* Read HTML from the Reader, and send XHTML to the writer. Common mistakes
* in the HTML code will also be corrected. The result is pretty-printed.
*
* @param reader
* HTML source
* @param writer
* XHTML target
*/
public static void html2xhtml(final Reader reader, final Writer writer) throws IOException, BadLocationException {
final HTMLEditorKit kit = new HTMLEditorKit();
final Document doc = kit.createDefaultDocument();
kit.read(reader, doc, doc.getLength());
final XHTMLWriter xhw = new XHTMLWriter(writer, (HTMLDocument) doc);
xhw.write();
}
代码示例来源:origin: MegaMek/mekhq
public void refreshLog(String s) {
if(logText.equals(s)) {
return;
}
logText = s;
//txtLog.setText(logText); -- NO. BAD. DON'T DO THIS.
Reader stringReader = new StringReader(logText);
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument blank = (HTMLDocument) htmlKit.createDefaultDocument();
try {
htmlKit.read(stringReader, blank, 0);
} catch (Exception e) {
// Ignore
}
txtLog.setDocument(blank);
txtLog.setCaretPosition(blank.getLength());
}
代码示例来源:origin: stackoverflow.com
HTMLEditorKit kit=new HTMLEditorKit();
Document doc=kit.createDefaultDocument();
kit.read(inputStream, doc, 0);
doc.getText(0, doc.getLength());
内容来源于网络,如有侵权,请联系作者删除!