javax.swing.text.html.HTMLEditorKit.createDefaultDocument()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中javax.swing.text.html.HTMLEditorKit.createDefaultDocument()方法的一些代码示例,展示了HTMLEditorKit.createDefaultDocument()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit.createDefaultDocument()方法的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit
方法名:createDefaultDocument

HTMLEditorKit.createDefaultDocument介绍

暂无

代码示例

代码示例来源:origin: Multibit-Legacy/multibit-hd

  1. @Override
  2. public Document createDefaultDocument() {
  3. return super.createDefaultDocument();
  4. }

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-basic

  1. /**
  2. * Create a new document.
  3. *
  4. * @return the created document
  5. */
  6. public static HTMLDocument createDocument(){
  7. HTMLEditorKit kit = new HTMLEditorKit();
  8. HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
  9. return doc;
  10. }

代码示例来源:origin: Chatanga/Girinoscope

  1. @Override
  2. public Document createDefaultDocument() {
  3. HTMLDocument document = (HTMLDocument) super.createDefaultDocument();
  4. document.setBase(Icon.class.getResource("/org/hihan/girinoscope/ui/"));
  5. return document;
  6. }
  7. };

代码示例来源:origin: freeplane/freeplane

  1. public HtmlProcessor(final String input){
  2. final HTMLEditorKit kit = new HTMLEditorKit();
  3. doc = kit.createDefaultDocument();
  4. try {
  5. final int defaultDocumentLength = doc.getLength();
  6. kit.read(new StringReader(input), doc, defaultDocumentLength);
  7. } catch (Exception e) {
  8. }
  9. }
  10. public String htmlSubstring(int pos, int length){

代码示例来源:origin: stackoverflow.com

  1. {
  2. HTMLEditorKit kit = new HTMLEditorKit();
  3. HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
  4. doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
  5. Reader HTMLReader = new InputStreamReader(testURL.openConnection().getInputStream());
  6. kit.read(HTMLReader, doc, 0);
  7. String title = (String) doc.getProperty(Document.TitleProperty);
  8. System.out.println(title);
  9. }

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit kit = new HTMLEditorKit();
  2. StyledDocument doc2 = (StyledDocument)kit.createDefaultDocument();
  3. kit.read(new FileInputStream(file), doc2, 0);
  4. pane = new JTextPane();
  5. pane.setEditorKit(kit);//set EditorKit of JTextPane as kit.
  6. pane.setDocument(doc2);

代码示例来源:origin: stackoverflow.com

  1. Reader stringReader = new StringReader(string);
  2. HTMLEditorKit htmlKit = new HTMLEditorKit();
  3. HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  4. htmlKit.read(stringReader, htmlDoc, 0);

代码示例来源:origin: stackoverflow.com

  1. public static void main(String args[]) throws Exception {
  2. String webUrl = "http://ramp.sdr.co.za/cache/1402NYFW/GoRedForWomen/";
  3. URL url = new URL(webUrl);
  4. URLConnection connection = url.openConnection();
  5. InputStream is = connection.getInputStream();
  6. InputStreamReader isr = new InputStreamReader(is);
  7. BufferedReader br = new BufferedReader(isr);
  8. HTMLEditorKit htmlKit = new HTMLEditorKit();
  9. HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  10. htmlKit.read(br, htmlDoc, 0);
  11. for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator.next()) {
  12. AttributeSet attributes = iterator.getAttributes();
  13. String imgSrc = (String) attributes.getAttribute(HTML.Attribute.HREF);
  14. System.out.println(imgSrc);
  15. if (imgSrc != null && (imgSrc.toLowerCase().endsWith(".jpg") || (imgSrc.endsWith(".png")) || (imgSrc.endsWith(".jpeg")) || (imgSrc.endsWith(".bmp")) || (imgSrc.endsWith(".ico")))) {
  16. try {
  17. downloadImage(webUrl, imgSrc);
  18. } catch (IOException ex) {
  19. System.out.println(ex.getMessage());
  20. }
  21. }
  22. }

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit tmp = new HTMLEditorKit();
  2. HTMLDocument doc = (HTMLDocument) tmp.createDefaultDocument();
  3. StringWriter writer = new StringWriter();
  4. tmp.write(writer, doc, 0, doc.getLength());
  5. String s = writer.toString();
  6. console.log(s);

代码示例来源:origin: stefanhaustein/nativehtml

  1. @Override
  2. public javax.swing.text.Document createDefaultDocument() {
  3. HTMLDocument result = (HTMLDocument) super.createDefaultDocument();
  4. try {
  5. result.setBase(document.getUrl().toURL());
  6. } catch (MalformedURLException e) {
  7. e.printStackTrace();
  8. }
  9. result.putProperty("imageCache", imageCache);
  10. return result;
  11. }
  12. });

代码示例来源:origin: stackoverflow.com

  1. String htmlString = "<body><h1>Karaoke Beyonce song</h1><p><span class="highlight">Hello</span>world</p></body>";
  2. JEditorPane pane = new JEditorPane();
  3. HTMLEditorKit kit = new HTMLEditorKit();
  4. pane.setEditable(false);
  5. pane.setEditorKit(kit);
  6. StyleSheet sh = editorKit.getStyleSheet();
  7. sh.addRule("span.highlight {background-color:yellow}");
  8. Document doc = kit.createDefaultDocument();
  9. pane.setDocument(doc);
  10. pane.setText(htmlString);

代码示例来源:origin: stackoverflow.com

  1. Reader stringReader = new StringReader(string);
  2. HTMLEditorKit htmlKit = new HTMLEditorKit();
  3. HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  4. HTMLEditorKit.Parser parser = new ParserDelegator();
  5. parser.parse(stringReader, htmlDoc.getReader(0), true);

代码示例来源:origin: DSpace/DSpace

  1. /**
  2. * @param currentItem item
  3. * @param source source input stream
  4. * @param verbose verbose mode
  5. * @return InputStream the resulting input stream
  6. * @throws Exception if error
  7. */
  8. @Override
  9. public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
  10. throws Exception {
  11. // try and read the document - set to ignore character set directive,
  12. // assuming that the input stream is already set properly (I hope)
  13. HTMLEditorKit kit = new HTMLEditorKit();
  14. Document doc = kit.createDefaultDocument();
  15. doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
  16. kit.read(source, doc, 0);
  17. String extractedText = doc.getText(0, doc.getLength());
  18. // generate an input stream with the extracted text
  19. byte[] textBytes = extractedText.getBytes();
  20. ByteArrayInputStream bais = new ByteArrayInputStream(textBytes);
  21. return bais; // will this work? or will the byte array be out of scope?
  22. }
  23. }

代码示例来源:origin: stackoverflow.com

  1. private static String convertToRTF(String htmlStr) {
  2. OutputStream os = new ByteArrayOutputStream();
  3. HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
  4. RTFEditorKit rtfEditorKit = new RTFEditorKit();
  5. String rtfStr = null;
  6. htmlStr = htmlStr.replaceAll("<br.*?>","#NEW_LINE#");
  7. htmlStr = htmlStr.replaceAll("</p>","#NEW_LINE#");
  8. htmlStr = htmlStr.replaceAll("<p.*?>","");
  9. InputStream is = new ByteArrayInputStream(htmlStr.getBytes());
  10. try {
  11. Document doc = htmlEditorKit.createDefaultDocument();
  12. htmlEditorKit.read(is, doc, 0);
  13. rtfEditorKit .write(os, doc, 0, doc.getLength());
  14. rtfStr = os.toString();
  15. rtfStr = rtfStr.replaceAll("#NEW_LINE#","\\\\par ");
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. } catch (BadLocationException e) {
  19. e.printStackTrace();
  20. }
  21. return rtfStr;
  22. }

代码示例来源:origin: org.seleniumhq.selenium.server/selenium-server-coreless

  1. public HTMLSuiteResult(String originalSuite) {
  2. //this.originalSuite = originalSuite;
  3. StringReader s = new StringReader(originalSuite);
  4. HTMLEditorKit k = new HTMLEditorKit();
  5. HTMLDocument doc = (HTMLDocument) k.createDefaultDocument();
  6. Parser parser = doc.getParser();
  7. HrefConverter p = new HrefConverter(originalSuite);
  8. doc.setAsynchronousLoadPriority(-1);
  9. try {
  10. parser.parse(s, p, true);
  11. } catch (IOException e) {
  12. // DGF aw, this won't really happen! (will it?)
  13. throw new RuntimeException(e);
  14. }
  15. hrefs = p.hrefList;
  16. StringBuilder sb = new StringBuilder();
  17. int previousPosition = originalSuite.length();
  18. for (int i = p.tagPositions.size()-1; i >= 0; i--) {
  19. int pos = p.tagPositions.get(i);
  20. String href = p.hrefList.get(i);
  21. String snippet = originalSuite.substring(pos, previousPosition);
  22. String replaceSnippet = snippet.replaceFirst ("\\Q" + href + "\\E", "#testresult" + i);
  23. sb.insert(0, replaceSnippet);
  24. previousPosition = pos;
  25. }
  26. String snippet = originalSuite.substring(0, previousPosition);
  27. sb.insert(0, snippet);
  28. updatedSuite = sb.toString();
  29. }

代码示例来源:origin: org.testatoo.openqa/selenium-server

  1. public HTMLSuiteResult(String originalSuite) {
  2. //this.originalSuite = originalSuite;
  3. StringReader s = new StringReader(originalSuite);
  4. HTMLEditorKit k = new HTMLEditorKit();
  5. HTMLDocument doc = (HTMLDocument) k.createDefaultDocument();
  6. Parser parser = doc.getParser();
  7. HrefConverter p = new HrefConverter(originalSuite);
  8. doc.setAsynchronousLoadPriority(-1);
  9. try {
  10. parser.parse(s, p, true);
  11. } catch (IOException e) {
  12. // DGF aw, this won't really happen! (will it?)
  13. throw new RuntimeException(e);
  14. }
  15. hrefs = p.hrefList;
  16. StringBuilder sb = new StringBuilder();
  17. int previousPosition = originalSuite.length();
  18. for (int i = p.tagPositions.size()-1; i >= 0; i--) {
  19. int pos = p.tagPositions.get(i);
  20. String href = p.hrefList.get(i);
  21. String snippet = originalSuite.substring(pos, previousPosition);
  22. String replaceSnippet = snippet.replaceFirst ("\\Q" + href + "\\E", "#testresult" + i);
  23. sb.insert(0, replaceSnippet);
  24. previousPosition = pos;
  25. }
  26. String snippet = originalSuite.substring(0, previousPosition);
  27. sb.insert(0, snippet);
  28. updatedSuite = sb.toString();
  29. }

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit kit = new HTMLEditorKit();
  2. StyleSheet styleSheet = kit.getStyleSheet();
  3. styleSheet.addRule("a:hover{color:red;}");
  4. Document doc = kit.createDefaultDocument();
  5. String htmlString = "<a href='stackoverflow.com'>Go to StackOverflow!</a>";
  6. // your JEditorPane
  7. jEditorPane.setDocument(doc);
  8. jEditorPane.setText(htmlString);

代码示例来源:origin: freeplane/freeplane

  1. /**
  2. * Read HTML from the Reader, and send XHTML to the writer. Common mistakes
  3. * in the HTML code will also be corrected. The result is pretty-printed.
  4. *
  5. * @param reader
  6. * HTML source
  7. * @param writer
  8. * XHTML target
  9. */
  10. public static void html2xhtml(final Reader reader, final Writer writer) throws IOException, BadLocationException {
  11. final HTMLEditorKit kit = new HTMLEditorKit();
  12. final Document doc = kit.createDefaultDocument();
  13. kit.read(reader, doc, doc.getLength());
  14. final XHTMLWriter xhw = new XHTMLWriter(writer, (HTMLDocument) doc);
  15. xhw.write();
  16. }

代码示例来源:origin: MegaMek/mekhq

  1. public void refreshLog(String s) {
  2. if(logText.equals(s)) {
  3. return;
  4. }
  5. logText = s;
  6. //txtLog.setText(logText); -- NO. BAD. DON'T DO THIS.
  7. Reader stringReader = new StringReader(logText);
  8. HTMLEditorKit htmlKit = new HTMLEditorKit();
  9. HTMLDocument blank = (HTMLDocument) htmlKit.createDefaultDocument();
  10. try {
  11. htmlKit.read(stringReader, blank, 0);
  12. } catch (Exception e) {
  13. // Ignore
  14. }
  15. txtLog.setDocument(blank);
  16. txtLog.setCaretPosition(blank.getLength());
  17. }

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit kit=new HTMLEditorKit();
  2. Document doc=kit.createDefaultDocument();
  3. kit.read(inputStream, doc, 0);
  4. doc.getText(0, doc.getLength());

相关文章