Java Code Examples for net.htmlparser.jericho.Source#fullSequentialParse()

The following examples show how to use net.htmlparser.jericho.Source#fullSequentialParse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLView.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
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();
    }
}
 
Example 2
Source File: StyleEditor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
protected void locateView ()
{
    if ( !locate )
    {
        return;
    }

    final WebSyntaxArea syntaxArea = editors.get ( editorTabs.getSelectedIndex () );
    final String xml = syntaxArea.getText ();

    final Source xmlSource = new Source ( xml );
    xmlSource.setLogger ( null );
    xmlSource.fullSequentialParse ();

    final StartTag tag = xmlSource.getPreviousStartTag ( syntaxArea.getCaretPosition (), "style" );
    if ( tag != null )
    {
        // todo Won't work with new scheme, have to go all the way up and gather all style identifiers
        final String type = tag.getAttributeValue ( ComponentStyleConverter.COMPONENT_TYPE_ATTRIBUTE );
        final String id = tag.getAttributeValue ( ComponentStyleConverter.STYLE_ID_ATTRIBUTE );
        locateView ( previewPanel, type, id );
    }
}
 
Example 3
Source File: StyleEditor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
protected void loadFirstResource ( final List<ClassResource> resources, final List<String> xmlContent, final List<String> xmlNames,
                                   final List<ClassResource> xmlFiles ) throws IOException
{
    final ClassResource rf = resources.get ( 0 );
    final Source xmlSource = new Source ( ReflectUtils.getClassSafely ( rf.getClassName () ).getResource ( rf.getPath () ) );
    xmlSource.setLogger ( null );
    xmlSource.fullSequentialParse ();

    final Element baseClassTag = xmlSource.getFirstElement ( SkinInfoConverter.CLASS_NODE );
    final String baseClass = baseClassTag != null ? baseClassTag.getContent ().toString () : null;

    for ( final Element includeTag : xmlSource.getAllElements ( SkinInfoConverter.INCLUDE_NODE ) )
    {
        final String includeClass = includeTag.getAttributeValue ( SkinInfoConverter.NEAR_CLASS_ATTRIBUTE );
        final String finalClass = includeClass != null ? includeClass : baseClass;
        final String src = includeTag.getContent ().toString ();
        resources.add ( new ClassResource ( finalClass, src ) );
    }

    xmlContent.add ( xmlSource.toString () );
    xmlNames.add ( new File ( rf.getPath () ).getName () );
    xmlFiles.add ( rf );

    resources.remove ( 0 );
}
 
Example 4
Source File: HtmlUtils.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns plain text extracted from the specified HTML.
 *
 * @param html          HTML
 * @param lineSeparator line separator
 * @return plain text
 */
@NotNull
public static String getPlainText ( @NotNull final String html, @NotNull final String lineSeparator )
{
    final String plain;
    final Source source = new Source ( html );
    final Tag[] tags = source.fullSequentialParse ();
    if ( tags.length > 0 )
    {
        final Renderer renderer = source.getRenderer ();
        renderer.setIncludeHyperlinkURLs ( false );
        renderer.setIncludeAlternateText ( false );
        renderer.setDecorateFontStyles ( false );
        renderer.setMaxLineLength ( Integer.MAX_VALUE );
        renderer.setHRLineLength ( 40 );
        renderer.setBlockIndentSize ( 4 );
        renderer.setConvertNonBreakingSpaces ( false );
        renderer.setNewLine ( lineSeparator );
        plain = renderer.toString ();
    }
    else
    {
        plain = html;
    }
    return plain;
}
 
Example 5
Source File: JSSPToJsConverter.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: Data.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: Out.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: Out.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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>");
}
 
Example 9
Source File: ScriptEditorView.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    String text = getText();
    Source segment = new Source(text);
    segment.fullSequentialParse();
    SourceFormatter formatter = new SourceFormatter(segment);
    text = formatter.toString();
    editorPane.selectAll();
    editorPane.replaceSelection(text);
}
 
Example 10
Source File: Out.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
public void realWriteWithHTMLUpdate() throws IOException {
    flush();
    ByteArrayOutputStream out = (ByteArrayOutputStream) this.out;
    Source source = new Source(new String(out.toByteArray(), "UTF-8"));
    source.fullSequentialParse();
    List<StartTag> list = source.getAllStartTags("html");
    if (list.size() == 0) {
        realWrite();
        return;
    }

    this.out = outputStream;

    OutputStreamWriter writer = new OutputStreamWriter(this.out, "UTF-8");
    OutputDocument document = new OutputDocument(source);

    StringBuffer style = new StringBuffer();
    if (this.styles.size() > 0) {
        for (Style style2 : this.styles)
            style.append(style2.toString());
    }

    List<StartTag> h = source.getAllStartTags("style");
    if (h.size() > 0) {
        document.insert(h.get(0).getElement().getEndTag().getBegin(), style);
    } else {

        style.insert(0, "\n<style>\n");
        style.append("</style>\n");

        h = source.getAllStartTags("head");
        if (h.size() > 0) {
            document.insert(h.get(0).getElement().getEndTag().getBegin(),
                    style);
        } else {
            style.insert(0, "\n<head>\n");
            style.append("</head>\n");
            document.insert(h.get(0).getElement().getEndTag().getBegin(),
                    style);
        }
    }
    document.writeTo(writer);
    writer.flush();

}