org.apache.xerces.dom.CoreDocumentImpl Java Examples

The following examples show how to use org.apache.xerces.dom.CoreDocumentImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageParser.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 将 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();
}
 
Example #2
Source File: MessageParser.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 将 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();
}
 
Example #3
Source File: DomParser.java    From caja with Apache License 2.0 5 votes vote down vote up
public static Document makeDocument(
    Function<DOMImplementation, DocumentType> doctypeMaker, String features,
    DOMImplementation domImpl) {
  if (features != null) { throw new SomethingWidgyHappenedError(); }
  if (domImpl == null) {
    domImpl = new CoreDocumentImpl().getImplementation();
  }

  DocumentType doctype = doctypeMaker != null
      ? doctypeMaker.apply(domImpl) : null;
  return domImpl.createDocument(null, null, doctype);
}