本文整理匯總了Java中org.w3c.tidy.Tidy.setOutputEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java Tidy.setOutputEncoding方法的具體用法?Java Tidy.setOutputEncoding怎麽用?Java Tidy.setOutputEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.tidy.Tidy
的用法示例。
在下文中一共展示了Tidy.setOutputEncoding方法的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: 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;
}
示例4: 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();
}
}
}
示例5: 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();
}
示例6: 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();
}
示例7: 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");
}
示例8: formatXml
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
public static String formatXml(@NotNull String xml) throws TransformerException {
StringReader stringReader = new StringReader(xml);
Tidy tidy = new Tidy();
tidy.setXmlOut(true);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setTidyMark(false);
tidy.setForceOutput(true);
tidy.setSmartIndent(true);
tidy.setShowWarnings(false);
tidy.setQuiet(true);
StringWriter stringWriter = new StringWriter();
tidy.parse(stringReader, stringWriter);
return stringWriter.toString();
}
示例9: formatHtml
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
public static String formatHtml(String html) {
StringReader stringReader = new StringReader(html);
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setTidyMark(false);
tidy.setSmartIndent(true);
tidy.setForceOutput(true);
tidy.setShowWarnings(false);
tidy.setQuiet(true);
StringWriter stringWriter = new StringWriter();
tidy.parse(stringReader, stringWriter);
return stringWriter.toString();
}
示例10: makeTidyParser
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* Create a Tidy parser with the specified settings.
*
* @param quiet - set the Tidy quiet flag?
* @param showWarnings - show Tidy warnings?
* @param isXml - treat the content as XML?
* @param stringWriter - if non-null, use this for Tidy errorOutput
* @return the Tidy parser
*/
public static Tidy makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter) {
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF8");
tidy.setOutputEncoding("UTF8");
tidy.setQuiet(quiet);
tidy.setShowWarnings(showWarnings);
tidy.setMakeClean(true);
tidy.setXmlTags(isXml);
if (stringWriter != null) {
tidy.setErrout(new PrintWriter(stringWriter));
}
return tidy;
}
示例11: getTidyParser
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* Returns <code>tidy</code> as HTML parser.
*
* @return a <code>tidy</code> HTML parser
*/
private static Tidy getTidyParser(String encoding) {
log.debug("Start : getParser");
Tidy tidy = new Tidy();
tidy.setInputEncoding(encoding);
tidy.setOutputEncoding("UTF8");
tidy.setQuiet(true);
tidy.setShowWarnings(false);
if (log.isDebugEnabled()) {
log.debug("getParser : tidy parser created - " + tidy);
}
log.debug("End : getParser");
return tidy;
}
示例12: htmlOutputStreamViaTidy
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* To Output html Stream via Tidy.
*
* @param pathOfHOCRFile String
* @param outputFilePath String
* @throws IOException
*/
public static void htmlOutputStreamViaTidy(final String pathOfHOCRFile, final String outputFilePath) throws IOException {
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setDocType(DOC_TYPE_OMIT);
tidy.setInputEncoding(UTF_ENCODING);
tidy.setOutputEncoding(UTF_ENCODING);
tidy.setForceOutput(true);
tidy.setWraplen(0);
FileInputStream inputStream = null;
OutputStream fout = null;
OutputStream bout = null;
OutputStreamWriter out = null;
try {
/*
* Fix for UTF-8 encoding to support special characters in turkish and czech language. UTF-8 encoding supports major
* characters in all the languages
*/
fout = new FileOutputStream(outputFilePath);
bout = new BufferedOutputStream(fout);
out = new OutputStreamWriter(bout, UTF_ENCODING);
inputStream = new FileInputStream(pathOfHOCRFile);
tidy.parse(inputStream, out);
} finally {
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(bout);
IOUtils.closeQuietly(fout);
}
}
示例13: beautyHTML
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
private String beautyHTML(String html) throws UnsupportedEncodingException {
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setWraplen(Integer.MAX_VALUE);
tidy.setXmlOut(true);
tidy.setXmlTags(true);
tidy.setSmartIndent(true);
ByteArrayInputStream inputStream = new ByteArrayInputStream(html.getBytes("UTF-8"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Document doc = tidy.parseDOM(inputStream, null);
tidy.pprint(doc, outputStream);
return outputStream.toString("UTF-8");
}
示例14: URIContext
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* Constructor.
*
* @param scanDir Scan directory.
* @param sockFactory Socket factory.
*/
public URIContext(URL scanDir, SSLSocketFactory sockFactory) {
this.scanDir = scanDir;
this.sockFactory = sockFactory;
tidy = new Tidy();
tidy.setQuiet(true);
tidy.setOnlyErrors(true);
tidy.setShowWarnings(false);
tidy.setInputEncoding("UTF8");
tidy.setOutputEncoding("UTF8");
}
示例15: initializeTidyBuilder
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* Initializes the tidy document builder.
*/
private void initializeTidyBuilder() {
tidyBuilder = new Tidy();
tidyBuilder.setInputEncoding("UTF-8");
tidyBuilder.setOutputEncoding("UTF-8");
tidyBuilder.setXmlOut(true);
tidyBuilder.setShowWarnings(false);
tidyBuilder.setQuiet(true);
tidyBuilder.setDropEmptyParas(false);
tidyBuilder.setTidyMark(false);
tidyBuilder.setFixComments(false);
tidyBuilder.setTrimEmptyElements(false);
tidyBuilder.setJoinStyles(false);
tidyBuilder.setXmlTags(true); // important, otherwise jtidy manipulates the markup
}