本文整理了Java中javax.swing.text.html.HTMLEditorKit.read()
方法的一些代码示例,展示了HTMLEditorKit.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit.read()
方法的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit
方法名:read
暂无
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
//read the reader into a String
StringBuffer buffer = new StringBuffer();
int length;
char[] data = new char[1024];
while ((length = in.read(data)) != -1) {
buffer.append(data, 0, length);
}
//TODO is this regex right?
StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
super.read(reader, doc, pos);
}
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
//read the reader into a String
StringBuffer buffer = new StringBuffer();
int length;
char[] data = new char[1024];
while ((length = in.read(data)) != -1) {
buffer.append(data, 0, length);
}
//TODO is this regex right?
StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
super.read(reader, doc, pos);
}
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
//read the reader into a String
StringBuffer buffer = new StringBuffer();
int length;
char[] data = new char[1024];
while ((length = in.read(data)) != -1) {
buffer.append(data, 0, length);
}
//TODO is this regex right?
StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
super.read(reader, doc, pos);
}
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
//read the reader into a String
StringBuffer buffer = new StringBuffer();
int length;
char[] data = new char[1024];
while ((length = in.read(data)) != -1) {
buffer.append(data, 0, length);
}
//TODO is this regex right?
StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
super.read(reader, doc, pos);
}
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
//read the reader into a String
StringBuffer buffer = new StringBuffer();
int length;
char[] data = new char[1024];
while ((length = in.read(data)) != -1) {
buffer.append(data, 0, length);
}
//TODO is this regex right?
StringReader reader = new StringReader(buffer.toString().replaceAll("/>", ">"));
super.read(reader, doc, pos);
}
}
代码示例来源:origin: stackoverflow.com
private synchronized void updateHtmlEditor(final HTMLEditorKit editorkit, final StringReader reader)
{
Runnable runnable = new Runnable()
{
public void run() {
try {
editorkit.read(reader, htmlViewEditor.getDocument(), htmlViewEditor.getDocument().getLength());
} catch (IOException ex) {
Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex);
} catch (BadLocationException ex) {
Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
SwingUtilities.invokeLater(runnable);
}
代码示例来源: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: eu.mihosoft.vrl/vrl
/**
* Inserts a string to the current html document of the specified editor.
* Main usage is to add strings to the current log message.
*
* @param editor message field
* @param html html string to add
* @param location document location where the specified string shall be
* added
*/
private void insertHTML(JEditorPane editor, String html, int location) {
//assumes editor is already set to "text/html" type
HTMLEditorKit kit
= (HTMLEditorKit) editor.getEditorKit();
Document doc = editor.getDocument();
StringReader reader = new StringReader(html);
try {
kit.read(reader, doc, location);
} catch (BadLocationException ex) {
Logger.getLogger(MessageBox.class.getName()).log(
Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MessageBox.class.getName()).log(
Level.SEVERE, null, ex);
}
}
代码示例来源: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: stackoverflow.com
Files.newBufferedReader(file, StandardCharsets.ISO_8859_1)) {
htmlKit.read(reader, htmlDoc, 0);
Files.newBufferedReader(file, Charset.forName(charset))) {
htmlKit.read(reader, htmlDoc, 0);
代码示例来源:origin: freeplane/freeplane
private TextFragment[] split(final String text) {
final LinkedList<TextFragment> htmlFragments = new LinkedList<TextFragment>();
final HTMLEditorKit kit = new HTMLEditorKit();
final HTMLDocument doc = new HTMLDocument();
final StringReader buf = new StringReader(text);
try {
kit.read(buf, doc, 0);
final Element parent = getParentElement(doc);
split(doc, parent, htmlFragments, 0);
}
catch (final IOException e) {
LogUtils.severe(e);
}
catch (final BadLocationException e) {
LogUtils.severe(e);
}
return htmlFragments.toArray(new TextFragment[htmlFragments.size()]);
}
}
代码示例来源: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: es.gob.afirma/afirma-core-firmaweb
BrowserDialog(final String html, final Frame parent) {
super(parent, WebSignMessages.getString("BrowserDialog.13"), true); //$NON-NLS-1$
this.getAccessibleContext().setAccessibleParent(parent);
final JEditorPane ep = new JEditorPane();
ep.setEditable(false);
ep.setEnabled(false);
ep.addHyperlinkListener(this.linkListener);
getContentPane().add(new JScrollPane(ep), BorderLayout.CENTER);
setSize(600, 600);
final JPanel sur = new JPanel();
sur.add(new JButton(this.afirmar), BorderLayout.WEST);
sur.add(new JButton(this.anoFirmar), BorderLayout.EAST);
getContentPane().add(sur, BorderLayout.SOUTH);
ep.setEditorKit(this.kit);
try {
final Document doc = ep.getDocument();
this.kit.read(new StringReader(html), doc, 0);
disableContent(ep);
}
catch (final Exception e) {
LOGGER.severe(WebSignMessages.getString("BrowserDialog.14") + e); //$NON-NLS-1$
}
}
代码示例来源: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());
内容来源于网络,如有侵权,请联系作者删除!