use of org.freeplane.core.util.FixedHTMLWriter in project freeplane by freeplane.
the class MTextController method getContent.
private String[] getContent(final String text, final int pos) {
if (pos <= 0) {
return null;
}
final String[] strings = new String[2];
if (text.startsWith("<html>")) {
final HTMLEditorKit kit = new HTMLEditorKit();
final HTMLDocument doc = new HTMLDocument();
final StringReader buf = new StringReader(text);
try {
kit.read(buf, doc, 0);
final char[] firstText = doc.getText(0, pos).toCharArray();
int firstStart = 0;
int firstLen = pos;
while ((firstStart < firstLen) && (firstText[firstStart] <= ' ')) {
firstStart++;
}
while ((firstStart < firstLen) && (firstText[firstLen - 1] <= ' ')) {
firstLen--;
}
int secondStart = 0;
int secondLen = doc.getLength() - pos;
if (secondLen <= 0)
return null;
final char[] secondText = doc.getText(pos, secondLen).toCharArray();
while ((secondStart < secondLen) && (secondText[secondStart] <= ' ')) {
secondStart++;
}
while ((secondStart < secondLen) && (secondText[secondLen - 1] <= ' ')) {
secondLen--;
}
if (firstStart == firstLen || secondStart == secondLen) {
return null;
}
StringWriter out = new StringWriter();
new FixedHTMLWriter(out, doc, firstStart, firstLen - firstStart).write();
strings[0] = out.toString();
out = new StringWriter();
new FixedHTMLWriter(out, doc, pos + secondStart, secondLen - secondStart).write();
strings[1] = out.toString();
return strings;
} catch (final IOException e) {
LogUtils.severe(e);
} catch (final BadLocationException e) {
LogUtils.severe(e);
}
} else {
if (pos >= text.length()) {
return null;
}
strings[0] = text.substring(0, pos);
strings[1] = text.substring(pos);
}
return strings;
}
use of org.freeplane.core.util.FixedHTMLWriter in project freeplane by freeplane.
the class SplitNode method getFragment.
private String getFragment(final HTMLDocument doc, int start, final int end) throws BadLocationException, IOException {
final String paragraphText = doc.getText(start, end - start).trim();
if (paragraphText.length() > 0) {
final StringWriter out = new StringWriter();
new FixedHTMLWriter(out, doc, start, end - start).write();
final String fragment = out.toString();
if (!fragment.equals("")) {
return fragment;
}
}
return null;
}
Aggregations