use of org.apache.xerces.dom.CoreDocumentImpl in project translationstudio8 by heartsome.
the class MessageParser method htmlToText.
/**
* 将 html 格式的文本过滤掉标签.
* @param html
* html 格式的字符串
* @return String
* 过滤掉 html 标签后的文本。如果 html 为空,返回空串""
*/
private String htmlToText(String html) {
if (html == null) {
return "";
}
DOMFragmentParser parser = new DOMFragmentParser();
CoreDocumentImpl codeDoc = new CoreDocumentImpl();
InputSource inSource = new InputSource(new ByteArrayInputStream(html.getBytes()));
inSource.setEncoding(textCharset);
DocumentFragment doc = codeDoc.createDocumentFragment();
try {
parser.parse(inSource, doc);
} catch (Exception e) {
return "";
}
textBuffer = new StringBuffer();
processNode(doc);
return textBuffer.toString();
}
use of org.apache.xerces.dom.CoreDocumentImpl in project gocd by gocd.
the class XmlEntityReference method init.
protected void init(ThreadContext context, IRubyObject[] args) {
if (args.length < 2) {
throw getRuntime().newArgumentError(args.length, 2);
}
IRubyObject doc = args[0];
IRubyObject name = args[1];
Document document = ((XmlNode) doc).getOwnerDocument();
// FIXME: disable error checking as a workaround for #719. this depends on the internals of Xerces.
CoreDocumentImpl internalDocument = (CoreDocumentImpl) document;
boolean oldErrorChecking = internalDocument.getErrorChecking();
internalDocument.setErrorChecking(false);
Node node = document.createEntityReference(rubyStringToString(name));
internalDocument.setErrorChecking(oldErrorChecking);
setNode(context, node);
}
use of org.apache.xerces.dom.CoreDocumentImpl in project gocd by gocd.
the class XmlNode method fixUserData.
/**
* This is a hack to fix #839. We should submit a patch to Xerces.
* It looks like CoreDocumentImpl.adoptNode() doesn't copy
* the user data associated with child nodes (recursively).
*/
private void fixUserData(Document previous, Node ret) {
String key = NokogiriHelpers.ENCODED_STRING;
for (Node child = ret.getFirstChild(); child != null; child = child.getNextSibling()) {
CoreDocumentImpl previousDocument = (CoreDocumentImpl) previous;
child.setUserData(key, previousDocument.getUserData(child, key), null);
fixUserData(previous, child);
}
}
use of org.apache.xerces.dom.CoreDocumentImpl in project nokogiri by sparklemotion.
the class XmlEntityReference method init.
protected void init(ThreadContext context, IRubyObject[] args) {
if (args.length < 2) {
throw getRuntime().newArgumentError(args.length, 2);
}
IRubyObject doc = args[0];
IRubyObject name = args[1];
Document document = ((XmlNode) doc).getOwnerDocument();
// FIXME: disable error checking as a workaround for #719. this depends on the internals of Xerces.
CoreDocumentImpl internalDocument = (CoreDocumentImpl) document;
boolean oldErrorChecking = internalDocument.getErrorChecking();
internalDocument.setErrorChecking(false);
Node node = document.createEntityReference(rubyStringToString(name));
internalDocument.setErrorChecking(oldErrorChecking);
setNode(context, node);
}
use of org.apache.xerces.dom.CoreDocumentImpl in project nokogiri by sparklemotion.
the class XmlNode method fixUserData.
/**
* This is a hack to fix #839. We should submit a patch to Xerces.
* It looks like CoreDocumentImpl.adoptNode() doesn't copy
* the user data associated with child nodes (recursively).
*/
private void fixUserData(Document previous, Node ret) {
String key = NokogiriHelpers.ENCODED_STRING;
for (Node child = ret.getFirstChild(); child != null; child = child.getNextSibling()) {
CoreDocumentImpl previousDocument = (CoreDocumentImpl) previous;
child.setUserData(key, previousDocument.getUserData(child, key), null);
fixUserData(previous, child);
}
}
Aggregations