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

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

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

HTMLEditorKit.read介绍

暂无

代码示例

代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core

  1. @Override
  2. public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
  3. //read the reader into a String
  4. StringBuffer buffer = new StringBuffer();
  5. int length;
  6. char[] data = new char[1024];
  7. while ((length = in.read(data)) != -1) {
  8. buffer.append(data, 0, length);
  9. }
  10. //TODO is this regex right?
  11. StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
  12. super.read(reader, doc, pos);
  13. }
  14. }

代码示例来源:origin: org.swinglabs.swingx/swingx-all

  1. @Override
  2. public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
  3. //read the reader into a String
  4. StringBuffer buffer = new StringBuffer();
  5. int length;
  6. char[] data = new char[1024];
  7. while ((length = in.read(data)) != -1) {
  8. buffer.append(data, 0, length);
  9. }
  10. //TODO is this regex right?
  11. StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
  12. super.read(reader, doc, pos);
  13. }
  14. }

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

  1. @Override
  2. public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
  3. //read the reader into a String
  4. StringBuffer buffer = new StringBuffer();
  5. int length;
  6. char[] data = new char[1024];
  7. while ((length = in.read(data)) != -1) {
  8. buffer.append(data, 0, length);
  9. }
  10. //TODO is this regex right?
  11. StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
  12. super.read(reader, doc, pos);
  13. }
  14. }

代码示例来源:origin: com.haulmont.thirdparty/swingx-core

  1. @Override
  2. public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
  3. //read the reader into a String
  4. StringBuffer buffer = new StringBuffer();
  5. int length;
  6. char[] data = new char[1024];
  7. while ((length = in.read(data)) != -1) {
  8. buffer.append(data, 0, length);
  9. }
  10. //TODO is this regex right?
  11. StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
  12. super.read(reader, doc, pos);
  13. }
  14. }

代码示例来源:origin: org.swinglabs.swingx/swingx-core

  1. @Override
  2. public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
  3. //read the reader into a String
  4. StringBuffer buffer = new StringBuffer();
  5. int length;
  6. char[] data = new char[1024];
  7. while ((length = in.read(data)) != -1) {
  8. buffer.append(data, 0, length);
  9. }
  10. //TODO is this regex right?
  11. StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
  12. super.read(reader, doc, pos);
  13. }
  14. }

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

  1. private synchronized void updateHtmlEditor(final HTMLEditorKit editorkit, final StringReader reader)
  2. {
  3. Runnable runnable = new Runnable()
  4. {
  5. public void run() {
  6. try {
  7. editorkit.read(reader, htmlViewEditor.getDocument(), htmlViewEditor.getDocument().getLength());
  8. } catch (IOException ex) {
  9. Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex);
  10. } catch (BadLocationException ex) {
  11. Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex);
  12. }
  13. }
  14. };
  15. SwingUtilities.invokeLater(runnable);
  16. }

代码示例来源: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: eu.mihosoft.vrl/vrl

  1. /**
  2. * Inserts a string to the current html document of the specified editor.
  3. * Main usage is to add strings to the current log message.
  4. *
  5. * @param editor message field
  6. * @param html html string to add
  7. * @param location document location where the specified string shall be
  8. * added
  9. */
  10. private void insertHTML(JEditorPane editor, String html, int location) {
  11. //assumes editor is already set to "text/html" type
  12. HTMLEditorKit kit
  13. = (HTMLEditorKit) editor.getEditorKit();
  14. Document doc = editor.getDocument();
  15. StringReader reader = new StringReader(html);
  16. try {
  17. kit.read(reader, doc, location);
  18. } catch (BadLocationException ex) {
  19. Logger.getLogger(MessageBox.class.getName()).log(
  20. Level.SEVERE, null, ex);
  21. } catch (IOException ex) {
  22. Logger.getLogger(MessageBox.class.getName()).log(
  23. Level.SEVERE, null, ex);
  24. }
  25. }

代码示例来源: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: stackoverflow.com

  1. Files.newBufferedReader(file, StandardCharsets.ISO_8859_1)) {
  2. htmlKit.read(reader, htmlDoc, 0);
  3. Files.newBufferedReader(file, Charset.forName(charset))) {
  4. htmlKit.read(reader, htmlDoc, 0);

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

  1. private TextFragment[] split(final String text) {
  2. final LinkedList<TextFragment> htmlFragments = new LinkedList<TextFragment>();
  3. final HTMLEditorKit kit = new HTMLEditorKit();
  4. final HTMLDocument doc = new HTMLDocument();
  5. final StringReader buf = new StringReader(text);
  6. try {
  7. kit.read(buf, doc, 0);
  8. final Element parent = getParentElement(doc);
  9. split(doc, parent, htmlFragments, 0);
  10. }
  11. catch (final IOException e) {
  12. LogUtils.severe(e);
  13. }
  14. catch (final BadLocationException e) {
  15. LogUtils.severe(e);
  16. }
  17. return htmlFragments.toArray(new TextFragment[htmlFragments.size()]);
  18. }
  19. }

代码示例来源: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: es.gob.afirma/afirma-core-firmaweb

  1. BrowserDialog(final String html, final Frame parent) {
  2. super(parent, WebSignMessages.getString("BrowserDialog.13"), true); //$NON-NLS-1$
  3. this.getAccessibleContext().setAccessibleParent(parent);
  4. final JEditorPane ep = new JEditorPane();
  5. ep.setEditable(false);
  6. ep.setEnabled(false);
  7. ep.addHyperlinkListener(this.linkListener);
  8. getContentPane().add(new JScrollPane(ep), BorderLayout.CENTER);
  9. setSize(600, 600);
  10. final JPanel sur = new JPanel();
  11. sur.add(new JButton(this.afirmar), BorderLayout.WEST);
  12. sur.add(new JButton(this.anoFirmar), BorderLayout.EAST);
  13. getContentPane().add(sur, BorderLayout.SOUTH);
  14. ep.setEditorKit(this.kit);
  15. try {
  16. final Document doc = ep.getDocument();
  17. this.kit.read(new StringReader(html), doc, 0);
  18. disableContent(ep);
  19. }
  20. catch (final Exception e) {
  21. LOGGER.severe(WebSignMessages.getString("BrowserDialog.14") + e); //$NON-NLS-1$
  22. }
  23. }

代码示例来源: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());

相关文章