本文整理匯總了Java中org.w3c.tidy.Tidy類的典型用法代碼示例。如果您正苦於以下問題:Java Tidy類的具體用法?Java Tidy怎麽用?Java Tidy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Tidy類屬於org.w3c.tidy包,在下文中一共展示了Tidy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cleanNfo
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* Try to clean the NFO(XML) content with JTidy.
*
* @param sourceNfoContent
* the XML content to be cleaned
* @return the cleaned XML content (or the source, if any Exceptions occur)
*/
public static String cleanNfo(String sourceNfoContent) {
try {
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setWraplen(Integer.MAX_VALUE);
tidy.setXmlOut(true);
tidy.setSmartIndent(true);
tidy.setXmlTags(true);
tidy.setMakeClean(true);
tidy.setForceOutput(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
StringReader in = new StringReader(sourceNfoContent);
StringWriter out = new StringWriter();
tidy.parse(in, out);
return out.toString();
}
catch (Exception e) {
}
return sourceNfoContent;
}
示例2: tidy_init
import org.w3c.tidy.Tidy; //導入依賴的package包/類
public void tidy_init() {
long bgn = System_.Ticks();
wtr = new ByteArrayOutputStream();
System.setProperty("line.separator", "\n");
tidy = new Tidy(); // obtain a new Tidy instance
tidy.setInputEncoding("utf-8"); // -utf8
tidy.setOutputEncoding("utf-8"); // -utf8
tidy.setDocType("\"\""); // --doctype \"\"; set to empty else some wikis will show paragraph text with little vertical gap; PAGE:tr.b:
tidy.setForceOutput(true); // --force-output y
tidy.setQuiet(true); // --quiet y
tidy.setTidyMark(false); // --tidy-mark n
tidy.setWraplen(0); // --wrap 0
tidy.setIndentContent(true); // --indent y; NOTE: true indents all content in edit box
tidy.setQuoteNbsp(true); // --quote-nbsp y
tidy.setLiteralAttribs(true); // --literal-attributes y
tidy.setWrapAttVals(false); // --wrap-attributes n
tidy.setFixUri(false); // --fix-url n
tidy.setFixBackslash(false); // --fix-backslash n
tidy.setEncloseBlockText(true); // --enclose-block-text y; NOTE: true creates extra <p>; very noticeable in sidebar
tidy.setNumEntities(false); // NOTE: true will convert all UTF-8 chars to &#val; which ruins readability
tidy.setTrimEmptyElements(true); // NOTE: tidy always trims (not even an option)
tidy.setShowWarnings(false); // NOTE: otherwise warnings printed to output window
tidy.setShowErrors(0); // NOTE: otherwise errors printed to output window; EX: Error: <time> is not recognized!
app.Usr_dlg().Log_many("", "", "jtidy.init; elapsed=~{0}", System_.Ticks__elapsed_in_frac(bgn));
}
示例3: getHtmlDocument
import org.w3c.tidy.Tidy; //導入依賴的package包/類
private Document getHtmlDocument(String htmlContent) {
StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append("<head><style language='text/css'>");
sb.append("@page{ margin: 0; }");
sb.append("body{ margin:0;}");
sb.append("</style></head>");
sb.append("<body>");
sb.append(htmlContent);
sb.append("</body>");
sb.append("</html>");
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
return tidy.parseDOM(new ByteArrayInputStream(sb.toString().getBytes()), null);
}
示例4: tidyDoc
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* Create a document using Tidy
*
* @param stream - input
* @param quiet - set Tidy quiet?
* @param showWarnings - show Tidy warnings?
* @param report_errors - log errors and throw TidyException?
* @param isXML - treat document as XML?
* @param out OutputStream, null if no output required
* @return the document
*
* @throws TidyException if a ParseError is detected and report_errors is true
*/
private static Document tidyDoc(InputStream stream, boolean quiet, boolean showWarnings, boolean report_errors,
boolean isXML, OutputStream out) throws TidyException {
StringWriter sw = new StringWriter();
Tidy tidy = makeTidyParser(quiet, showWarnings, isXML, sw);
Document doc = tidy.parseDOM(stream, out);
doc.normalize();
if (tidy.getParseErrors() > 0) {
if (report_errors) {
log.error("TidyException: " + sw.toString());
throw new TidyException(tidy.getParseErrors(),tidy.getParseWarnings());
}
log.warn("Tidy errors: " + sw.toString());
}
return doc;
}
示例5: getParser
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* Returns <code>tidy</code> as HTML parser.
*
* @return a <code>tidy</code> HTML parser
*/
public static Tidy getParser() {
log.debug("Start : getParser1");
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF8");
tidy.setOutputEncoding("UTF8");
tidy.setQuiet(true);
tidy.setShowWarnings(false);
if (log.isDebugEnabled()) {
log.debug("getParser1 : tidy parser created - " + tidy);
}
log.debug("End : getParser1");
return tidy;
}
示例6: htmlOutputStreamForISOEncoding
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* To Output html Stream for ISO Encoding.
*
* @param pathOfHOCRFile String
* @param outputFilePath String
* @return FileWriter
* @throws IOException
*/
public static void htmlOutputStreamForISOEncoding(final String pathOfHOCRFile, final String outputFilePath) throws IOException {
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setDocType(DOC_TYPE_OMIT);
tidy.setInputEncoding(ISO_ENCODING);
tidy.setOutputEncoding(ISO_ENCODING);
tidy.setHideEndTags(false);
FileInputStream inputStream = null;
FileWriter outputStream = null;
try {
inputStream = new FileInputStream(pathOfHOCRFile);
outputStream = new FileWriter(outputFilePath);
tidy.parse(inputStream, outputStream);
} finally {
if (null != inputStream) {
inputStream.close();
}
if (null != outputStream) {
outputStream.flush();
outputStream.close();
}
}
}
示例7: getDocument
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* Permet de retourner un objet de type Document construit autour de sText.
*
* @param sText
* Le texte original.
* @param errout
* Flux o� sera affich� les erreurs de syntaxe html. Si � null,
* alors par d�faut,
* @param showWarnings
* Permet de sp�cifier si on veut que les warnings soient
* affich�s ou pas dans errout.
* @return Un objet de type Document.
* @throws IOException
* Lev�e si une erreur se produit.
*/
private static Document getDocument(String sText, PrintWriter errout,
boolean showWarnings) throws IOException {
File temp = File.createTempFile("TwikiToHtml", ".tmp");
temp.deleteOnExit();
PrintWriter msg = new PrintWriter(new FileWriter(temp));
msg.print(sText);
msg.close();
// new StringReader(sText);
Tidy tidy = new Tidy();
tidy.setShowWarnings(showWarnings);
tidy.setMakeClean(true);
tidy.setXHTML(true);
if (errout != null) {
tidy.setErrout(errout);
}
return tidy.parseDOM(new FileInputStream(temp), null);
}
示例8: run
import org.w3c.tidy.Tidy; //導入依賴的package包/類
/**
* start the tidification
*/
@Override
public void run() {
URL url;
BufferedInputStream in;
FileOutputStream out;
Tidy tidy = new Tidy();
tidy.setXmlOut(xmlOut);
try {
tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName), true));
url = new URL(strUrl);
in = new BufferedInputStream(url.openStream());
out = new FileOutputStream(outFileName);
tidy.parse(in, out);
}
catch ( IOException e ) {
log.warn( this.toString() + e.toString() );
}
}
示例9: JTidyBookProcessor
import org.w3c.tidy.Tidy; //導入依賴的package包/類
public JTidyBookProcessor()
{
tidy = new Tidy();
// tidy.setConfigurationFromFile(JTidyBookProcessor.class.getResource("/jtidy.properties").getFile());
tidy.setSpaces(2);
tidy.setIndentContent(true);
tidy.setSmartIndent(true);
tidy.setXHTML(true);
tidy.setQuoteMarks(false);
tidy.setQuoteAmpersand(true);
tidy.setDropEmptyParas(false);
tidy.setTidyMark(false);
tidy.setJoinClasses(true);
tidy.setJoinStyles(true);
tidy.setWraplen(0);
tidy.setDropProprietaryAttributes(true);
tidy.setEscapeCdata(true);
Properties props = new Properties();
props.put("new-blocklevel-tags", "svg image altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform circle clipPath color-profile cursor defs desc ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject g glyph glyphRef hkern image line linearGradient marker mask metadata missing-glyph mpath path pattern polygon polyline radialGradient rect script set stop style svg switch symbol text textPath title tref tspan use view vkern");
tidy.getConfiguration().addProps(props);
}
示例10: cleanupHtml
import org.w3c.tidy.Tidy; //導入依賴的package包/類
private String cleanupHtml(String story) {
Tidy tidy = new Tidy();
tidy.setInputEncoding(ENCODING);
tidy.setOutputEncoding(ENCODING);
tidy.setPrintBodyOnly(true);
tidy.setXmlOut(true);
tidy.setSmartIndent(false);
tidy.setBreakBeforeBR(false);
tidy.setMakeBare(true);
tidy.setMakeClean(true);
tidy.setNumEntities(true);
tidy.setWraplen(0);
StringWriter writer = new StringWriter();
StringReader reader = new StringReader(story);
tidy.parse(reader, writer);
return writer.toString();
}
示例11: getXHTML
import org.w3c.tidy.Tidy; //導入依賴的package包/類
public static String getXHTML(String html){
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setMakeClean(true);
tidy.setShowWarnings(false);
tidy.setShowErrors(0);
tidy.setQuiet(true);
tidy.setPrintBodyOnly(true);
tidy.setOutputEncoding("ISO-8859-1");
StringWriter stringWriter = new StringWriter();
tidy.parse(new StringReader(html), stringWriter);
return stringWriter.toString();
}
示例12: cleanXMLData
import org.w3c.tidy.Tidy; //導入依賴的package包/類
public static String cleanXMLData(String data) throws UnsupportedEncodingException {
// data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+data;
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setWraplen(Integer.MAX_VALUE);
// tidy.setPrintBodyOnly(true);
tidy.setXmlOut(true);
tidy.setXmlTags(true);
tidy.setSmartIndent(true);
tidy.setMakeClean(true);
tidy.setForceOutput(true);
ByteArrayInputStream inputStream = new ByteArrayInputStream(data.getBytes("UTF-8"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tidy.parseDOM(inputStream, outputStream);
return outputStream.toString("UTF-8");
}
示例13: parseSmile
import org.w3c.tidy.Tidy; //導入依賴的package包/類
private void parseSmile(Tidy tidy, Element element, String indent) {
String source = element.getAttribute("src");
if (source == null) {
return;
}
if (!source.matches(".*?smiley-[^.]+\\.gif")) { // TODO: check this
// convention
return;
}
int indexStart = source.lastIndexOf("smiley-") + "smiley-".length();
int indexEnd = source.lastIndexOf(".");
String smiley = source.substring(indexStart, indexEnd);
String emoticon = emoticons.get(smiley);
if (emoticon != null) {
addText(emoticon, indent);
}
}
示例14: convert
import org.w3c.tidy.Tidy; //導入依賴的package包/類
public void convert() {
URL u;
BufferedInputStream in;
FileOutputStream out;
Tidy tidy = new Tidy();
tidy.setXmlOut(true);
try {
tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName),true));
u = new URL(url);
in = new BufferedInputStream(u.openStream());
out = new FileOutputStream(outFileName);
tidy.parse(in, out);
in.close();
out.close();
} catch (IOException e) {
System.out.println(this.toString() + e.toString());
}
}
示例15: getParser
import org.w3c.tidy.Tidy; //導入依賴的package包/類
private static Tidy getParser( URL url ) {
Tidy tidy = new Tidy();
tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
tidy.setQuiet( true );
tidy.setShowWarnings( HTMLParserFactory.isParserWarningsEnabled() );
if (!HTMLParserFactory.getHTMLParserListeners().isEmpty()) {
tidy.setErrout( new JTidyPrintWriter( url ) );
}
return tidy;
}