本文整理匯總了Java中org.w3c.tidy.Tidy.setMessageListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Tidy.setMessageListener方法的具體用法?Java Tidy.setMessageListener怎麽用?Java Tidy.setMessageListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.tidy.Tidy
的用法示例。
在下文中一共展示了Tidy.setMessageListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newTidy
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
/**
* Configures a new JTidy instance.
*/
private static Tidy newTidy() {
Tidy tidy = new Tidy();
tidy.setMessageListener(new TidyMessageListener() {
@Override
public void messageReceived(TidyMessage msg) {
logger.warn(String.format("HTML warning at %s:%s: %s", msg.getLine(), msg.getColumn(), msg.getMessage()));
}
});
tidy.setDropEmptyParas(false);
tidy.setDropFontTags(false);
tidy.setDropProprietaryAttributes(false);
tidy.setTrimEmptyElements(false);
tidy.setXHTML(true);
tidy.setIndentAttributes(false);
tidy.setIndentCdata(false);
tidy.setIndentContent(false);
tidy.setQuiet(true);
tidy.setShowWarnings(!Options.isQuietEnabled());
tidy.setShowErrors(0);
tidy.setEncloseBlockText(false);
tidy.setEscapeCdata(false);
tidy.setDocType("omit");
tidy.setInputEncoding("UTF-8");
tidy.setRawOut(true);
tidy.setOutputEncoding("UTF-8");
tidy.setFixUri(false);
Properties prop = new Properties();
prop.put("new-blocklevel-tags", "canvas");
tidy.getConfiguration().addProps(prop);
return tidy;
}
示例2: convert
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
@Override
public Object convert(Class type, Object value) {
String htmlText = (String) value;
if (htmlText == null || htmlText.length() == 0) {
return null;
}
ByteArrayInputStream inStream = new ByteArrayInputStream(htmlText.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
Tidy tidy = createTidyParser();
TidyErrorsListener errorListener = new TidyErrorsListener();
tidy.setMessageListener(errorListener);
Document document = tidy.parseDOM(inStream, null);
if (errorListener.isBogus()) {
throw new ConversionException("renderers.converter.safe.invalid");
}
parseDocument(outStream, tidy, document);
try {
return filterOutput(new String(outStream.toByteArray(), ENCODING));
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
throw new ConversionException("tidy.converter.ending.notSupported.critical");
}
}
示例3: execute
import org.w3c.tidy.Tidy; //導入方法依賴的package包/類
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
try{
Tidy tidy = new Tidy();
final StringBuilder errors = new StringBuilder(32);
tidy.setMessageListener( new TidyMessageListener(){
public void messageReceived(TidyMessage mess) {
errors.append( "Line: " + mess.getLine() + "." + mess.getColumn() + "; " + mess.getMessage() + "\r\n" );
}
});
tidy.setSmartIndent( false );
tidy.setSpaces( 2 );
tidy.setTabsize( 2 );
tidy.setWraplen( 0 );
tidy.setLogicalEmphasis( true );
tidy.setMakeClean( true );
tidy.setQuiet( true );
tidy.setDropEmptyParas( true );
tidy.setXHTML( true );
tidy.setXmlSpace( true );
tidy.setTrimEmptyElements( true );
tidy.setBreakBeforeBR( false );
tidy.setUpperCaseTags( false );
tidy.setUpperCaseAttrs( false );
tidy.setWord2000( true );
tidy.setFixUri(false);
tidy.setFixBackslash( false );
tidy.setIndentAttributes( false );
tidy.setShowWarnings( false );
tidy.setShowErrors( 1 );
tidy.setOnlyErrors( false );
tidy.setPrintBodyOnly( false );
tidy.setJoinClasses( true );
tidy.setJoinStyles( true );
String inHtml = getNamedStringParam(argStruct,"string","");
StringReader reader = new StringReader( inHtml );
StringWriter writer = new StringWriter();
tidy.parse( reader, writer );
if ( errors.length() != 0 ){
throwException( _session, errors.toString() );
return null;
}else{
String outHtml = writer.toString();
int c1 = outHtml.indexOf("<body>");
if ( c1 >= 0 ){
outHtml = outHtml.substring( c1 + 6 );
c1 = outHtml.lastIndexOf("</body>");
if ( c1 >= 0 ){
outHtml = outHtml.substring( 0, c1 );
}
}
return new cfStringData( outHtml );
}
}catch( Exception e ){
throwException( _session, e.getMessage() );
return null;
}
}