Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.flaptor.util.parser.HtmlParser.java

License:Apache License

/**
 * Parse the given html document./* www.  j a  va 2 s.  c  o m*/
 * 
 * @param content the html document to parse.
 * @return the parsed string.
 */
public ParseOutput parse(String url, byte[] bytes) throws Exception {
    // <html xmlns=...>  ==>   <html>

    // Parser keeps state, synchronize in case its used in a multi-threaded setting.
    ParseOutput out = new ParseOutput(url);

    Document htmlDoc = getHtmlDocument(url, bytes);

    removeNamespace((Element) htmlDoc.selectSingleNode("HTML|Html|html"));

    ignoreXpath(htmlDoc);

    // this 2 must be before the ignoreXPath, else an ignoreXPath that
    // includes the //TITLE will imply that the title is not indexed
    // extract the links
    extractLinks(htmlDoc, out);

    // extact the title
    extractTitle(htmlDoc, out);

    replaceSeparatorTags(htmlDoc);

    // extract the text from the html tags
    extractAllText(htmlDoc.getRootElement(), out, ParseOutput.CONTENT);

    // extract special fields
    extractFields(htmlDoc, out);

    // eliminate any namespace, it breaks xpath
    out.close();
    return out;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgAdHocSubProcessComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;//w w  w  .  j  av  a 2 s  .  c o m
    try {
        int loopx = 260;
        int loopy = 281;
        SvgSubProcessTo signavio = (SvgSubProcessTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();

        String loopStd = none;
        String loopPar = none;
        String loopSeq = none;

        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(signavio.getX() - 2));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(signavio.getY() - 2));
        str = FlowSvgUtil.replaceAll(str, id, signavio.getId());
        str = FlowSvgUtil.replaceAll(str, text, signavio.getLabel());
        str = FlowSvgUtil.replaceAll(str, text_x, StringUtil.getString(signavio.getWidth() / 2));
        str = FlowSvgUtil.replaceAll(str, text_y, StringUtil.getString(signavio.getHeight() / 2));
        str = FlowSvgUtil.replaceAll(str, width, StringUtil.getString(signavio.getWidth()));
        str = FlowSvgUtil.replaceAll(str, hight, StringUtil.getString(signavio.getHeight()));
        str = FlowSvgUtil.replaceAll(str, loop_x, StringUtil.getString(signavio.getWidth() / 2 - loopx));
        str = FlowSvgUtil.replaceAll(str, loop_y, StringUtil.getString(signavio.getHeight() - 7 - loopy));
        str = FlowSvgUtil.replaceAll(str, adhoc, "");
        str = FlowSvgUtil.replaceAll(str, callActivity, none);

        if (signavio.getLoopType().equals(LoopType.StandardLoop)) {
            loopStd = "";
        } else if (signavio.getLoopType().equals(LoopType.MultiInstanceLoopParallel)) {
            loopPar = "";
        } else if (signavio.getLoopType().equals(LoopType.MultiInstanceLoopSequential)) {
            loopSeq = "";
        }

        str = FlowSvgUtil.replaceAll(str, loop_std, loopStd);
        str = FlowSvgUtil.replaceAll(str, loop_par, loopPar);
        str = FlowSvgUtil.replaceAll(str, loop_seq, loopSeq);

        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }

    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgAnnotationComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/*from   ww  w .  j a  v a  2  s  . c o m*/
    try {
        SvgAnnotationTo annoTo = (SvgAnnotationTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(annoTo.getX()));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(annoTo.getY()));
        str = FlowSvgUtil.replaceAll(str, id, annoTo.getId());
        str = FlowSvgUtil.replaceAll(str, text, annoTo.getLabel());
        StringBuffer sb = new StringBuffer();
        sb.append(" M19 0  L0 0  L0 ");
        sb.append(annoTo.getHeight());
        sb.append("  L19 ");
        sb.append(annoTo.getHeight());
        str = FlowSvgUtil.replaceAll(str, path, sb.toString());
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }

    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgAssocationComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/*  ww  w . j  a v  a2s.  c o m*/
    try {
        SvgAssocationTo assoTo = (SvgAssocationTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, id, assoTo.getId());
        str = FlowSvgUtil.replaceAll(str, text, assoTo.getLabel());
        List<SvgPoint> pointList = assoTo.getSvgPointList();
        StringBuffer pointPath = new StringBuffer();
        String textx = null;
        String texty = null;

        int size = pointList.size();
        for (int i = 0; i < size; i++) {
            if (i == 0) {
                pointPath.append("M");
            } else {
                pointPath.append("L");
            }
            SvgPoint point = pointList.get(i);
            pointPath.append(point.getX());
            pointPath.append(" ");
            pointPath.append(point.getY());
        }

        if (size != 0 && size % 2 == 0) {
            SvgPoint leftPoint = pointList.get(size / 2 - 1);
            SvgPoint rightPoint = pointList.get(size / 2);
            textx = String.valueOf((leftPoint.getX() + rightPoint.getX()) / 2);
            texty = String.valueOf((leftPoint.getY() + rightPoint.getY()) / 2);
        } else {
            int position = size / 2;
            SvgPoint middlePoint = pointList.get(position);
            textx = String.valueOf(middlePoint.getX());
            texty = String.valueOf(middlePoint.getY());
        }

        str = FlowSvgUtil.replaceAll(str, path, pointPath.toString());
        str = FlowSvgUtil.replaceAll(str, text_x, textx);
        str = FlowSvgUtil.replaceAll(str, text_y, texty);

        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }

    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgCallActivityComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/*from  ww w.  ja v a 2  s  .c o  m*/
    try {
        int loopx = 260;
        int loopy = 281;
        SvgCallActivityTo signavio = (SvgCallActivityTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();

        String loopStd = none;
        String loopPar = none;
        String loopSeq = none;

        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(signavio.getX() - 2));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(signavio.getY() - 2));
        str = FlowSvgUtil.replaceAll(str, id, signavio.getId());
        str = FlowSvgUtil.replaceAll(str, text, signavio.getLabel());
        str = FlowSvgUtil.replaceAll(str, text_x, StringUtil.getString(signavio.getWidth() / 2));
        str = FlowSvgUtil.replaceAll(str, text_y, StringUtil.getString(signavio.getHeight() / 2));
        str = FlowSvgUtil.replaceAll(str, width, StringUtil.getString(signavio.getWidth()));
        str = FlowSvgUtil.replaceAll(str, hight, StringUtil.getString(signavio.getHeight()));
        str = FlowSvgUtil.replaceAll(str, loop_x, StringUtil.getString(signavio.getWidth() / 2 - loopx));
        str = FlowSvgUtil.replaceAll(str, loop_y, StringUtil.getString(signavio.getHeight() - 7 - loopy));
        str = FlowSvgUtil.replaceAll(str, adhoc, none);
        str = FlowSvgUtil.replaceAll(str, callActivity, "");

        if (signavio.getLoopType().equals(LoopType.StandardLoop)) {
            loopStd = "";
        } else if (signavio.getLoopType().equals(LoopType.MultiInstanceLoopParallel)) {
            loopPar = "";
        } else if (signavio.getLoopType().equals(LoopType.MultiInstanceLoopSequential)) {
            loopSeq = "";
        }

        str = FlowSvgUtil.replaceAll(str, loop_std, loopStd);
        str = FlowSvgUtil.replaceAll(str, loop_par, loopPar);
        str = FlowSvgUtil.replaceAll(str, loop_seq, loopSeq);

        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }

    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgComplexGatewayComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/*from ww  w. ja  va 2 s.co m*/
    try {
        SvgComplexGatewayTo cGateTo = (SvgComplexGatewayTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(cGateTo.getX() + 2));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(cGateTo.getY() + 2));
        str = FlowSvgUtil.replaceAll(str, id, cGateTo.getId());
        str = FlowSvgUtil.replaceAll(str, text, cGateTo.getLabel());
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }
    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgDataInputComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/* w w w. j  a  v a2 s  . c o  m*/
    try {
        SvgDataInputTo stevent = (SvgDataInputTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(stevent.getX()));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(stevent.getY()));
        str = FlowSvgUtil.replaceAll(str, id, stevent.getId());
        str = FlowSvgUtil.replaceAll(str, text, stevent.getLabel());
        str = FlowSvgUtil.replaceAll(str, input, "");
        str = FlowSvgUtil.replaceAll(str, output, none);
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }
    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgDataObjectComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;//w w  w.  ja  v a  2s  .co  m
    try {
        SvgDataObjectTo stevent = (SvgDataObjectTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(stevent.getX()));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(stevent.getY()));
        str = FlowSvgUtil.replaceAll(str, id, stevent.getId());
        str = FlowSvgUtil.replaceAll(str, text, stevent.getLabel());
        str = FlowSvgUtil.replaceAll(str, input, none);
        str = FlowSvgUtil.replaceAll(str, output, none);
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }
    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgDataObjectReferenceComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;//from ww  w. jav  a2 s .  c  o m
    try {
        SvgDataObjectReferenceTo stevent = (SvgDataObjectReferenceTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(stevent.getX()));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(stevent.getY()));
        str = FlowSvgUtil.replaceAll(str, id, stevent.getId());
        str = FlowSvgUtil.replaceAll(str, text, stevent.getLabel());
        str = FlowSvgUtil.replaceAll(str, input, none);
        str = FlowSvgUtil.replaceAll(str, output, none);
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }
    return result;
}

From source file:com.founder.fix.fixflow.core.impl.flowgraphics.svg.component.SvgDataOutputComponent.java

License:Apache License

public String createComponent(SvgBaseTo svgTo) {
    String result = null;/* w ww  . j  a  v  a 2 s. c o  m*/
    try {
        SvgDataOutputTo stevent = (SvgDataOutputTo) svgTo;
        InputStream in = SvgBench.class.getResourceAsStream(comPath);
        Document doc = XmlUtil.read(in);
        String str = doc.getRootElement().asXML();
        str = FlowSvgUtil.replaceAll(str, local_x, StringUtil.getString(stevent.getX()));
        str = FlowSvgUtil.replaceAll(str, local_y, StringUtil.getString(stevent.getY()));
        str = FlowSvgUtil.replaceAll(str, id, stevent.getId());
        str = FlowSvgUtil.replaceAll(str, text, stevent.getLabel());
        str = FlowSvgUtil.replaceAll(str, input, none);
        str = FlowSvgUtil.replaceAll(str, output, "");
        result = str;
    } catch (DocumentException e) {
        throw new FixFlowException("", e);
    }
    return result;
}