本文整理汇总了Java中net.htmlparser.jericho.Source类的典型用法代码示例。如果您正苦于以下问题:Java Source类的具体用法?Java Source怎么用?Java Source使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Source类属于net.htmlparser.jericho包,在下文中一共展示了Source类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: realWrite
import net.htmlparser.jericho.Source; //导入依赖的package包/类
public void realWrite(boolean printHeadBodyTags) throws IOException {
flush();
ByteArrayOutputStream stream = (ByteArrayOutputStream) this.out;
this.out = outputStream;
if (!printHeadBodyTags) {
stream.writeTo(outputStream);
return;
}
println("<html>");
println("<head>");
println("<style>");
for (Style style : styles)
println(style);
println("</style>");
println("</head>");
String htmlText = new String(stream.toByteArray(), "UTF-8");
Source source = new Source(htmlText);
source.fullSequentialParse();
List<StartTag> startTags = source.getAllStartTags("body");
if (startTags.size() == 0) {
println("<body>");
println(htmlText);
println("</body>");
} else {
println(new StringBuffer(startTags.get(0).getElement()));
}
println("</html>");
}
示例2: setHTMLText
import net.htmlparser.jericho.Source; //导入依赖的package包/类
public void setHTMLText(String htmlText) {
try {
this.text = htmlText;
if (formatt) {
Source segment = new Source(text);
segment.fullSequentialParse();
SourceFormatter formatter = new SourceFormatter(
segment);
htmlText = formatter.toString();
}
editorPane.read(new StringReader(htmlText), null);
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: actionPerformed
import net.htmlparser.jericho.Source; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
if (formatt == ((Boolean) getValue(SELECTED_KEY)))
return;
formatt = (Boolean) getValue(SELECTED_KEY);
putValue(SELECTED_KEY, formatt);
try {
String text = HTMLView.this.text;
if (formatt) {
SourceFormatter formatter = new SourceFormatter(new Source(
text));
text = formatter.toString();
}
editorPane.read(new StringReader(text), null);
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例4: processPage
import net.htmlparser.jericho.Source; //导入依赖的package包/类
protected String processPage( PathOrigin baseDir, String pagePath ) throws IOException {
long start = System.currentTimeMillis();
InputStream file = null;
try {
file = baseDir.getReader( getRepo() ).getFileInputStream( pagePath );
Source html = new Source( file );
OutputDocument outDoc = new OutputDocument( html );
// transform
modifyDocument( html, baseDir, outDoc );
return outDoc.toString();
} finally {
IOUtils.closeQuietly( file );
if ( log.isDebugEnabled() ) {
log.debug( String.format( "processPage for %s took %dms", pagePath, System.currentTimeMillis() - start ) );
}
}
}
示例5: getContent
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getContent(String eventResource) {
String reference = getReferenceFromEventResource(eventResource);
EntityProviderManager entityProviderManager = ComponentManager.get(EntityProviderManager.class);
EntityReference er= new EntityReference("/sam_item/"+reference);
ItemEntityProviderImpl qhp= (ItemEntityProviderImpl)entityProviderManager.getProviderByPrefix(er.getPrefix());
try {
ItemFacade item = (ItemFacade)qhp.getEntity(er);
String content = qhp.content(item);
//We will filter the HTML here just before send to the index
Source parseContent = new Source(content);
return parseContent.getTextExtractor().toString();
} catch (Exception e) {
throw new RuntimeException(" Failed to get item content ", e);
}
}
示例6: getContent
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getContent(String eventResource) {
String reference = getReferenceFromEventResource(eventResource);
EntityProviderManager entityProviderManager = ComponentManager.get(EntityProviderManager.class);
EntityReference er= new EntityReference("/sam_publisheditem/"+reference);
PublishedItemEntityProviderImpl qhp= (PublishedItemEntityProviderImpl)entityProviderManager.getProviderByPrefix(er.getPrefix());
try {
PublishedItemFacade item = (PublishedItemFacade)qhp.getEntity(er);
String content = qhp.content(item);
//We will filter the HTML here just before send to the index
Source parseContent = new Source(content);
return parseContent.getTextExtractor().toString();
} catch (Exception e) {
throw new RuntimeException(" Failed to get item content ", e);
}
}
示例7: strip
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* Retira tags indesejadas
*
* @param html
* @return
*/
public String strip(String html) {
if (html == null)
return "";
Source source = new Source(html);
source.fullSequentialParse();
OutputDocument output = new OutputDocument(source);
List<Tag> tags = source.getAllTags();
for (Tag tag : tags) {
if (processTag(tag, output)) {
tag.setUserData(VALID_MARKER);
} else {
output.remove(tag);
}
// reencodeTextSegment(source, output, pos, tag.getBegin());
}
// reencodeTextSegment(source, output, pos, source.getEnd());
return output.toString();
}
示例8: strip
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* Retira tags indesejadas
*
* @param html
* @return
*/
public String strip(String html) {
if (html == null)
return "";
Source source = new Source(html);
source.fullSequentialParse();
OutputDocument output = new OutputDocument(source);
List<Tag> tags = source.getAllTags();
int pos = 0;
for (Tag tag : tags) {
if (processTag(tag, output)) {
tag.setUserData(VALID_MARKER);
} else {
output.remove(tag);
}
reencodeTextSegment(source, output, pos, tag.getBegin());
pos = tag.getEnd();
}
reencodeTextSegment(source, output, pos, source.getEnd());
return output.toString();
}
示例9: doInBackground
import net.htmlparser.jericho.Source; //导入依赖的package包/类
@Override
protected List<String> doInBackground(Void... params) {
Source source = new Source(mText);
String plainText = source.getRenderer().toString();
Map<String, String> postParams = new HashMap<String, String>(2);
postParams.put("mod", requestMod);
postParams.put("text", plainText);
HttpResponse response = RemoteMessageController.sendPostRequest(postParams);
if (response != null) {
String result = RemoteMessageController.responseToString(response);
if (result != null) {
return RemoteMessageController.responseStringToArray(result);
}
}
return null;
}
示例10: tidyHtml
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* Tidy the HTML source by reformatting the entire HTML. This is
* particularly useful when the application needs to emit HTML.
*
* @param htmlSource
* the unformatted HTML source
*
* @return the formatted HTML source.
*
*/
public static String tidyHtml(String htmlSource) {
if(htmlSource == null) {
return htmlSource;
}
try {
Source source = new Source(htmlSource) ;
StringWriter writer = new StringWriter();
new SourceFormatter(source).setIndentString(" ").setTidyTags(true).writeTo(writer);
writer.close();
return writer.toString();
} catch(Exception e) {
e.printStackTrace();
}
return htmlSource;
}
示例11: ProcessTextDocument
import net.htmlparser.jericho.Source; //导入依赖的package包/类
/**
* Processes the text document, extracts the title, and strip the HTML tags
* @return boolean
*/
public boolean ProcessTextDocument() {
// The content should be in plain HTML, prefered not to be stripped
String withoutHTML = this.StripHTML(doc.getRawTextContent());
withoutHTML = StringEscapeUtils.escapeXml(withoutHTML);
doc.setStrippedTextContent(withoutHTML);
String title = ""; //doc.TitleProperty;
MicrosoftTagTypes.register();
PHPTagTypes.register();
PHPTagTypes.PHP_SHORT.deregister(); // remove PHP short tags for this example otherwise they override processing instructions
MasonTagTypes.register();
Source source = new Source(doc.getRawTextContent());
source.fullSequentialParse();
title = getTitle(source);
if (title != null) {
title = StringEscapeUtils.escapeXml(title);
doc.setTitle(title);
}
return true;
}
示例12: convert
import net.htmlparser.jericho.Source; //导入依赖的package包/类
public String convert() {
Source source = new Source(code);
source.fullSequentialParse();
int from = 0;
StringBuffer result = new StringBuffer();
for (StartTag tag : source.getAllStartTags()) {
if (tag.getName().startsWith("%")) {
addLines(result, source, from, tag.getBegin());
from = tag.getEnd();
String script = tag.toString();
if (script.length() > 4) {
if (script.charAt(2) == '=') {
result.append("doc.print(");
result.append(script.substring(3, script.length() - 2));
result.append(");");
} else {
result.append(script.substring(2, script.length() - 2));
}
}
}
}
addLines(result, source, from, source.getEnd());
return result.toString();
}
示例13: addLines
import net.htmlparser.jericho.Source; //导入依赖的package包/类
private void addLines(StringBuffer result, Source source, int from, int to) {
CharSequence toAdd = source.subSequence(from, to);
int length = toAdd.length();
result.append("doc.print(\"");
for (int i = 0; i < length; i++) {
char c = toAdd.charAt(i);
if (c != '\r') {
if (c == '\n') {
result.append("\\n\");\n");
if (i == length - 1)
return;
result.append("doc.print(\"");
} else {
if ((c == '\\') || (c == '\"') || (c == '\'')) {
result.append('\\');
result.append(c);
} else {
if (c == '\t') {
result.append("\\t");
} else
result.append(c);
}
}
}
}
result.append("\");");
}
示例14: getReport
import net.htmlparser.jericho.Source; //导入依赖的package包/类
public Source getReport(String name, Query query) {
Element element = engine.getElement(name, ReportPlugin
.getReportsQualifier(engine).getId());
if (element == null)
throw new DataException("Error.reportNotFound", "Report " + name
+ " not found", name);
HashMap<String, Object> map = new HashMap<String, Object>();
if (query != null)
map.put("query", query);
String htmlReport = reportQuery.getHTMLReport(element, map);
Source source = new Source(htmlReport);
source.fullSequentialParse();
return source;
}
示例15: printHTMLPage
import net.htmlparser.jericho.Source; //导入依赖的package包/类
public void printHTMLPage(HTMLPage page) throws IOException {
byte[] data = page.getData();
if (data == null)
return;
Source source = new Source(new ByteArrayInputStream(data));
source.fullSequentialParse();
printHTMLPage(source);
}