public static String getIndented(String inHTML) { String formated_html = null; try { StringWriter writer = new StringWriter(); new SourceFormatter(new Source(inHTML)).setIndentString(" ").setTidyTags(true).setCollapseWhiteSpace(true).writeTo(writer); formated_html = writer.toString(); } catch (IOException e) { LOG.log(Level.SEVERE, null, e); } return formated_html; }
private Source getPreviewSource(final String previewEncoding) throws IOException { final byte[] bytes=new byte[PREVIEW_BYTE_COUNT]; int i; for (i=0; i<PREVIEW_BYTE_COUNT; i++) { final int nextByte=inputStream.read(); if (nextByte==-1) break; bytes[i]=(byte)nextByte; } return new Source(new InputStreamReader(new ByteArrayInputStream(bytes,0,i),previewEncoding),null); }
public CFMLSource(String contents) { CFMLTags.register(); if (contents != null && contents.contains("<!---")) { fSource = new Source(contents); } else { fSource = new Source(contents); } // fSource.ignoreWhenParsing(fSource.getAllElements(CFMLTags.CFML_CONTENT)); // fSource.ignoreWhenParsing(fSource.getAllElements(CFMLTags.CFML_COMMENT)); fSource.setLogger(this); }
public static OGObject parse(String html,Set<String> unescapeHtml){ return parse(new Source(html),unescapeHtml); }
protected String removeHtml(String string) { // quick HTML detection on the initial part of the string String initial = string.substring(0, Math.min(string.length(), HTML_MAGIC_OFFSET)).toLowerCase(); if (initial.startsWith("<!doctype html") || initial.contains("<html")) { // convert using Jericho HTML Parser string = new Source(string).getRenderer() .setIncludeHyperlinkURLs(false) .setDecorateFontStyles(false) .toString(); } return string; }
public static List<String> getForms(ZestResponse response) { List<String> list = new ArrayList<String>(); Source src = new Source(response.getHeaders() + response.getBody()); List<Element> formElements = src.getAllElements(HTMLElementName.FORM); int formId = 0; while (formElements != null && formId < formElements.size()) { // TODO support form names // Element form = formElements.get(formId); list.add(Integer.toString(formId)); formId++; } return list; }
public CFMLSource(URL url) throws IOException { CFMLTags.register(); fSource = new Source(url); // fSource.ignoreWhenParsing(fSource.getAllElements(CFMLTags.CFML_CONTENT)); fSource.setLogger(this); }
public CFMLSource(URL url, ParserPreferences prefs) throws IOException { CFMLTags.register(prefs); fSource = new Source(url); // fSource.ignoreWhenParsing(fSource.getAllElements(CFMLTags.CFML_CONTENT)); fSource.setLogger(this); }
public CFMLSource(String contents, ParserPreferences prefs) { CFMLTags.register(prefs); fSource = new Source(contents); // fSource.ignoreWhenParsing(fSource.getAllElements(CFMLTags.CFML_CONTENT)); fSource.setLogger(this); }
public String stripHtml(String input) { return new Source(input).getRenderer().toString(); }
public static void htmlToPlainText(@Nonnull Reader from, @Nonnull Writer to) throws IOException { final Source source = new Source(from); source.fullSequentialParse(); final TextExtractor extractor = source.getTextExtractor().setIncludeAttributes(true); extractor.writeTo(to); }
public String filter(String key, String value) { Source source = new Source(value); OutputDocument document = new OutputDocument(source); replaceChildren(source, source, document); return document.toString(); }
public String filter(String key, String value) { Source source = new Source(value); OutputDocument document = new OutputDocument(source); replaceChildren(source, source, document); return document.toString(); }
private StreamedSource(final Reader reader, final boolean isInternallyCreatedReader, final String encoding, final String encodingSpecificationInfo, final String preliminaryEncodingInfo) throws IOException { this.reader=reader; if (isInternallyCreatedReader) internallyCreatedReaderFinalizer=new InternallyCreatedReaderFinalizer(reader); streamedText=new StreamedText(reader); streamedParseText=new StreamedParseText(streamedText); source=new Source(streamedText,streamedParseText,encoding,encodingSpecificationInfo,preliminaryEncodingInfo); }
@Override public void process(LocalDocument doc) { for (String field : fields) { String stringToRender = (String) doc.getContentField(field); if (stringToRender == null || stringToRender.isEmpty()) { continue; } else { Source source = new Source(stringToRender); String renderedString = source.getRenderer().toString(); doc.putContentField(field, renderedString); } } }
@Override public void parse(URL url, Reader reader, IHtmlCallback callback, String fileName) throws TranslatorToCAst.Error { warnings.clear(); Parser parser = new Parser(callback, fileName); Source src; try { src = new Source(reader); src.setLogger(Config.LoggerProvider.getLogger(fileName)); List<Element> childElements = src.getChildElements(); for (Element e : childElements) { parser.parse(e); } if (! warnings.isEmpty()) { throw new TranslatorToCAst.Error(warnings); } } catch (IOException e) { System.err.println("Error parsing file: " + e.getMessage()); } } /**
public HtmlContextAnalyser (HttpMessage msg) { this.msg = msg; this.htmlPage = msg.getResponseHeader().toString() + msg.getResponseBody().toString(); src = new Source(htmlPage); src.fullSequentialParse(); }
public List<TemplateNode> parse(Reader reader, String className) throws IOException { source = new Source(reader); use(source, "std", "org.teavm.flavour.components.standard"); use(source, "event", "org.teavm.flavour.components.events"); use(source, "attr", "org.teavm.flavour.components.attributes"); use(source, "html", "org.teavm.flavour.components.html"); pushVar("this", new GenericClass(className)); position = source.getBegin(); List<TemplateNode> nodes = new ArrayList<>(); parseSegment(source.getEnd(), nodes, elem -> true); popVar("this"); source = null; return nodes; }
public List<TemplateNode> parse(Reader reader, String className) throws IOException { source = new Source(reader); use(source, "std", "org.teavm.flavour.components.standard"); use(source, "event", "org.teavm.flavour.components.events"); use(source, "attr", "org.teavm.flavour.components.attributes"); use(source, "html", "org.teavm.flavour.components.html"); pushVar("this", new GenericClass(className)); position = source.getBegin(); List<TemplateNode> nodes = new ArrayList<>(); parseSegment(source.getEnd(), nodes, elem -> true); popVar("this"); source = null; return nodes; }
@Override public String assign(ZestResponse response, ZestRuntime runtime) throws ZestAssignFailException { if (response == null) { throw new ZestAssignFailException(this, "Null response"); } Source src = new Source(response.getBody()); List<Element> elementsFilteredByElementName = filterByElementNameIfConfigured(src); List<Element> elementsFilteredByAttributeValue = filterByAttributeValueIfConfigured(elementsFilteredByElementName); List<Element> elements = reverseIfConfigured(elementsFilteredByAttributeValue); Element element = findElementAtIndex(elements); if (element == null) { return null; } return getReturnValue(element); }