Example usage for org.dom4j DocumentHelper createXPath

List of usage examples for org.dom4j DocumentHelper createXPath

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createXPath.

Prototype

public static XPath createXPath(String xpathExpression) throws InvalidXPathException 

Source Link

Document

createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton DocumentFactory .

Usage

From source file:org.tsp.bws.BWSDocument.java

License:Open Source License

/** 
 * Get and rewrite all calls to a specific BWS occuring in the document.
 *
 * @param attributeValue the id of the script that is searched for.
 *///from w w  w  .  j  av a2  s  .  co m
public void getAttributeElement(String attributeValue) {
    XPath xpathSelector = DocumentHelper.createXPath("//@*");

    List results = xpathSelector.selectNodes(xmlDocument);
    List elementAttributes;

    Attribute curAttribute;

    for (Iterator attributeIterator = results.iterator(); attributeIterator.hasNext();) {
        curAttribute = (Attribute) attributeIterator.next();
        if (debug > 0) {
            System.out.println(attributeValue + "-" + curAttribute.getValue() + "-"
                    + curAttribute.getValue().equals("#:" + attributeValue));
        }
        if ((curAttribute.getValue().startsWith("bws:") || curAttribute.getValue().startsWith("#:"))
                && curAttribute.getValue().indexOf(attributeValue) > 0) {
            //curAttribute.setValue("document.getElementById('BWSApplet').executeScript('" + attributeValue + "',this)");
            //System.out.println("#:"  + curAttribute.getValue().indexOf(":"));
            curAttribute.setValue("document.getElementById('BWSApplet').executeScript('"
                    + curAttribute.getValue().substring(curAttribute.getValue().indexOf(":") + 1) + "',this)");
            //curAttribute.setValue("javascript:bwsexec(" + attributeValue + ")");
        }
    }

}

From source file:org.tsp.bws.BWSDocument.java

License:Open Source License

/** 
 * Inserts the <tt>applet</tt> tag 
 *///from  w  ww  .  ja v a2  s.c  om
public void appendApplet() {
    XPath xpathSelector = DocumentHelper.createXPath("/html/body");
    List results = xpathSelector.selectNodes(xmlDocument);

    // body should only occur once per document!
    if (results.size() > 1) {
        System.err.println("[BWSDocument.appendApplet] Warning! More than one <body> found, using the first!");
    }
    // use the first element returned
    Element bodyElement = (Element) results.get(0);
    bodyElement.addElement("applet").addAttribute("code", "org.tsp.bws.BWSApplet")
            .addAttribute("id", "BWSApplet").addAttribute("width", "0").addAttribute("height", "0")
            .addAttribute("mayscript", "true");

}

From source file:pm.inout.PM_SequencesInoutXML.java

License:Open Source License

protected void readAllSequences() {

    listNew = new ArrayList<PM_Sequence>();
    listBase = new ArrayList<PM_Sequence>();
    listExtended = new ArrayList<PM_Sequence>();
    listAlbum = new ArrayList<PM_Sequence>();

    PM_MetadataContainer metadatenContainer = PM_MetadataContainer.getInstance();
    XPath xpathSelector = null;/*from  w  w w .  j  a  v a2s  .  co m*/
    List<Element> result = null;

    // Wenn <alle-tocs> nicht vorhanden, dann anlegen
    xpathSelector = DocumentHelper.createXPath("//" + TAG_ALLE_TOCS);
    result = xpathSelector.selectNodes(document);
    if (result.size() == 0) {
        // not found
        Element rootElement = document.getRootElement();
        List<Element> l = rootElement.elements();
        Element neuesElement = new org.dom4j.tree.DefaultElement(TAG_ALLE_TOCS);
        l.add(neuesElement);
        return;
    }

    // read max-a and max-bx (max album number and max base/extended - sequence number)

    Element root = result.get(0);
    maxSequNumber = PM_XML_Utils.getAttributeInt(root, TAG_ALLE_ATTR_MAX_SEQUENCE_NUMBER);
    maxSequAlbumNumber = PM_XML_Utils.getAttributeInt(root, TAG_ALLE_ATTR_MAX_ALBUM_SEQUENCE_NUMBER);
    // read all sequences elements
    // ( <toc type="einfach" name="b503" inhalt="hamburg"/> )
    xpathSelector = DocumentHelper.createXPath("//" + TAG_TOC);

    result = xpathSelector.selectNodes(document);
    for (Iterator<Element> it = result.iterator(); it.hasNext();) {

        Element toc = it.next();

        String xmlType = PM_XML_Utils.getAttribute(toc, TOC_ATTR_TYPE);
        String sequName = PM_XML_Utils.getAttribute(toc, TOC_ATTR_NAME);
        String sgName = PM_XML_Utils.getAttribute(toc, TOC_ATTR_SG_NAME);
        String von = PM_XML_Utils.getAttribute(toc, TOC_ATTR_VON);
        String bis = PM_XML_Utils.getAttribute(toc, TOC_ATTR_BIS);
        String inhalt = PM_XML_Utils.getAttribute(toc, TOC_ATTR_INHALT);
        String index = PM_XML_Utils.getAttribute(toc, TOC_ATTR_INDEX);
        String qual = PM_XML_Utils.getAttribute(toc, TOC_ATTR_QS);
        String ort = PM_XML_Utils.getAttribute(toc, TOC_ATTR_ORT);

        // Anzahl Bilder holen
        int numberPictures = 0;
        if (metadatenContainer.getInitSequences().containsKey(sequName)) {
            numberPictures = metadatenContainer.getInitSequences().get(sequName);
        }

        if (sequName.startsWith(SEQ_CHARACTER_BASE)) {
            // ----------------------------------------------------------------------------
            //  Base:
            //       <toc type="einfach" name="b206" inhalt="1998.venedig" />
            // -----------------------------------------------------------------------------
            PM_SequenceBase sequence;
            if (sequName.equals(SEQ_CHARACTER_BASE)) {
                sequence = new PM_SequenceBase(inhalt, sequName);
                sequence.setStringLeaf(true);
                listBase.add(sequence);
                continue;
            }
            if (!inInitDicAllSequences(sequName)) {
                continue;
            }
            sequence = new PM_SequenceBase(inhalt, sequName);
            sequence.setAnzahlBilder(numberPictures);
            listBase.add(sequence);
            continue;

        } else if (sequName.startsWith(SEQ_CHARACTER_EXTENDED)) {
            // ----------------------------------------------------------------------------
            //  Extended:
            //       <toc type="einfach" name="s169" inhalt="s.haus-vom-see" />
            // -----------------------------------------------------------------------------
            PM_SequenceExtended sequence;
            if (sequName.equals(SEQ_CHARACTER_EXTENDED)) {
                sequence = new PM_SequenceExtended(inhalt, sequName);
                sequence.setStringLeaf(true);
                listExtended.add(sequence);
                continue;
            }
            if (!inInitDicAllSequences(sequName)) {
                continue;
            }
            sequence = new PM_SequenceExtended(inhalt, sequName);
            sequence.setAnzahlBilder(numberPictures);
            listExtended.add(sequence);
            continue;
        } else if (sequName.startsWith(SEQ_CHARACTER_NEW)) {
            // ----------------------------------------------------------------------------
            //  New:
            //       <toc type="neu" name="n475" inhalt="1249670506839"/>
            // -----------------------------------------------------------------------------
            if (!inInitDicAllSequences(sequName)) {
                continue;
            }
            PM_SequenceNew sequence = new PM_SequenceNew(inhalt, sequName);
            sequence.setAnzahlBilder(numberPictures);
            listNew.add(sequence);
            continue;
        } else if (xmlType.equals("komplex")) {
            // ----------------------------------------------------------------------------
            //  Album: 
            //    <toc type="komplex" name="v481" von="1998.03.01" bis="2000.02.01" 
            //         inhalt="test.ich.harz" index="  kal2008  kal2009kuechealle" 
            //         qs="13" ort="  bad_sooden towcqnq" sg-name="b17" markieren="n"/>
            // -----------------------------------------------------------------------------
            PM_SequenceAlbum sequence;
            if (sequName.equals(SEQ_CHARACTER_ALBUM)) {
                sequence = new PM_SequenceAlbum(inhalt, sequName);
                sequence.setStringLeaf(true);
                listAlbum.add(sequence);
                continue;
            }
            sequence = new PM_SequenceAlbum(inhalt, sequName);
            sequence.setAnzahlBilder(numberPictures);
            sequence.setVon(von);
            sequence.setBis(bis);
            sequence.setIndex(index);
            sequence.setQual(qual);
            sequence.setOrt(ort);
            sequence.setSeqClosedName(sgName);
            listAlbum.add(sequence);
            continue;
        }
    } // for

    // -----------------------------------------------------------
    // Version auf 1
    // -----------------------------------------------------------
    setVersionWrite(1);

}

From source file:pm.inout.PM_XML_File_Session.java

License:Open Source License

public void setAllPictureDirectoryIDs() {
    PM_MetadataContainer metadatenContainer = PM_MetadataContainer.getInstance();

    HashMap<String, File> alleFiles = new HashMap<String, File>();
    for (PM_PictureDirectory pd : metadatenContainer.getPictureDirectories()) {
        File xmlFile = pd.getPmIndexFile();
        alleFiles.put(xmlFile.getPath(), xmlFile);
    }/*from  w w w.j  a v  a2  s.  c  o m*/

    XPath xpathSelector = DocumentHelper.createXPath("//" + TAG_INDEX_FILE);
    List<Element> result = xpathSelector.selectNodes(document);
    for (Iterator it = result.iterator(); it.hasNext();) {
        Element element = (Element) it.next();
        int id = PM_XML_Utils.getAttributeInt(element, ATR_INDEX_FILE_ID);
        String lg = PM_XML_Utils.getAttribute(element, ATR_INDEX_FILE_LG);
        String name = PM_XML_Utils.getAttribute(element, ATR_INDEX_FILE_NAME);
    }
}

From source file:pm.inout.PM_XML_File_Session.java

License:Open Source License

public boolean indexFilesGeaendert() {

    PM_MetadataContainer metadatenContainer = PM_MetadataContainer.getInstance();

    HashMap<String, File> alleFiles = new HashMap<String, File>();
    for (PM_PictureDirectory pd : metadatenContainer.getPictureDirectories()) {
        File xmlFile = pd.getPmIndexFile();
        alleFiles.put(xmlFile.getPath(), xmlFile);
    }/*from w w w  .  j  a va  2  s.c om*/

    // Holen alle Files aus pm_session.xml
    XPath xpathSelector = DocumentHelper.createXPath("//" + TAG_INDEX_FILE);
    List<Element> result = xpathSelector.selectNodes(document);
    for (Iterator it = result.iterator(); it.hasNext();) {
        Element element = (Element) it.next();
        int id = PM_XML_Utils.getAttributeInt(element, ATR_INDEX_FILE_ID);
        String lg = PM_XML_Utils.getAttribute(element, ATR_INDEX_FILE_LG);
        String name = PM_XML_Utils.getAttribute(element, ATR_INDEX_FILE_NAME);
        if (!alleFiles.containsKey(name)) {
            return true;
        }
        File fInMap = (File) alleFiles.get(name);
        long lLong = fInMap.length();
        long lll = PM_Utils.stringToLong(lg);
        if (lLong != lll) {
            return true;
        }
        alleFiles.remove(name); // Eintrag loeschen
    }
    // Jetzt muss das hashMap leer sein, da gefundene gelscht wurden
    if (!alleFiles.isEmpty()) {
        return true;
    }
    return false;

}

From source file:pm.utilities.PM_XML_Utils.java

License:Open Source License

static public java.util.List getElementListe(Node element, String xpathSelectorString) {
    XPath xpathSelector = null;/*w w  w. j ava2 s .c o m*/
    try {
        xpathSelector = DocumentHelper.createXPath(xpathSelectorString);
    } catch (InvalidXPathException e) {
        //     System.out.println(" InvalidXPathException vom >" + xpathSelectorString + "<  " + e);
        return new java.util.ArrayList();
    }

    return xpathSelector.selectNodes(element);
}

From source file:se.kb.xml.XPathWrapper.java

License:Apache License

private XPath createXPath(String xpathExpression) {
    XPath xpath = DocumentHelper.createXPath(xpathExpression);
    xpath.setNamespaceURIs(this.namespaces);
    return xpath;
}