Example usage for org.dom4j Element indexOf

List of usage examples for org.dom4j Element indexOf

Introduction

In this page you can find the example usage for org.dom4j Element indexOf.

Prototype

int indexOf(Node node);

Source Link

Document

Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.

Usage

From source file:com.globalsight.everest.tm.util.ttx.TtxClean.java

License:Apache License

/**
 * Removes a element by pulling up its children into the parent node.
 *///from   w  w w.  j  a  v a 2 s  .com
private void removeElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <ut>'s content
    // instead of the <ut>.

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.appendContent(p_element);
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.util.ttx.TtxClean.java

License:Apache License

/**
 * Removes a TU element by pulling up the content of the TUV in
 * the given locale into the parent node.
 *//*from www .jav  a 2 s  .  c om*/
private void removeTuElement(Element p_element, String p_locale) {
    // The source or target language TUV to replace the TU with.
    Element tuv = (Element) p_element.selectSingleNode("//Tuv[@Lang='" + p_locale + "']");

    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the tuv content.

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.appendContent(tuv);
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.terminology.EntryUtils.java

License:Apache License

static private void mergeDescripGrp(Element p_one, Element p_two, Element p_descripGrp, NodeComparator p_comp) {
    Element p_descrip = p_descripGrp.element("descrip");

    if (p_descrip == null || !p_descrip.hasContent()) {
        return;/*from  w  w  w.j  a  v a2 s.  c  o m*/
    }

    String type = p_descrip.attributeValue("type");

    // some descrips can occur only once per entry.
    boolean occursOnce = fieldOccursOnce(type);

    // Find nodes that match the descrip.
    List matches = p_one.selectNodes("descripGrp[descrip/@type='" + type + "']");

    if (matches == null || matches.size() == 0) {
        // descripGrp does not exist in entry 1, add.
        int index = findDescripInsertionPoint(p_one, type);
        p_one.content().add(index, p_descripGrp);

        return;
    }

    // Check if one of the matches contains the same descrip
    for (int i = 0, max = matches.size(); i < max; i++) {
        Element descripGrp = (Element) matches.get(i);
        Element descrip = descripGrp.element("descrip");

        if (fieldEquals(descrip, p_descrip, p_comp)) {
            // could be a case/formatting-insensitive match
            descrip.detach();
            descripGrp.content().add(0, p_descrip);

            mergeInnerGroups(descripGrp, p_descripGrp, p_comp);

            return;
        }
    }

    // DescripGrp was not found, add new descripGrp to old.
    if (occursOnce) {
        // DescripGrp can occur only once, merge by overwriting.
        // (Single descrips also contain just text, no HTML.)
        Element descGrp = (Element) matches.get(0);
        Element desc = descGrp.element("descrip");

        desc.setText(getInnerText(p_descrip));

        mergeInnerGroups(descGrp, p_descripGrp, p_comp);
    } else {
        // Multiple descrips may exist (for e.g., definition),
        // so add the new one after the last.
        Element last = (Element) matches.get(matches.size() - 1);

        p_one.content().add(p_one.indexOf(last) + 1, p_descripGrp);
    }
}

From source file:com.globalsight.terminology.importer.MtfReaderThread.java

License:Apache License

private void convertToNoteGrp(Element p_elem) {
    Element noteGrp = p_elem.createCopy("noteGrp");

    // noteGrps contain no other fields, remove all child
    // nodes, remembering the <descrip type="note"> itself
    for (ListIterator lit = noteGrp.elements().listIterator(); lit.hasNext();) {
        Element child = (Element) lit.next();

        if (child.getName().equals("descrip")) {
            Element note = child.createCopy("note");
            note.remove(note.attribute("type"));

            lit.set(note);/* w  w w.j a v  a 2s. c  o m*/
        } else {
            lit.remove();
        }
    }

    Element parent = p_elem.getParent();
    parent.content().set(parent.indexOf(p_elem), noteGrp);
}

From source file:com.globalsight.terminology.importer.MtfReaderThread.java

License:Apache License

private void convertToSourceGrp(Element p_elem) {
    Element sourceGrp = p_elem.createCopy("sourceGrp");

    // sourceGrp contains noteGrp, remove all non-noteGrp
    // children, remembering the <descrip type="source"> itself
    for (ListIterator lit = sourceGrp.elements().listIterator(); lit.hasNext();) {
        Element child = (Element) lit.next();

        if (child.getName().equals("descrip")) {
            Element source = child.createCopy("source");
            source.remove(source.attribute("type"));

            lit.set(source);//from  ww  w  .j  a  v  a2s  .  co  m
        } else if (!child.getName().equals("noteGrp")) {
            lit.remove();
        }
    }

    Element parent = p_elem.getParent();
    parent.content().set(parent.indexOf(p_elem), sourceGrp);
}

From source file:nl.tue.gale.ae.processor.xmlmodule.ForModule.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element traverse(Element element, Resource resource) throws ProcessorException {
    try {//from  w  w w.j a  va 2 s.com
        GaleContext gale = GaleContext.of(resource);
        String expr = element.attributeValue("expr");
        String var = element.attributeValue("var");
        List<Object> alist = new LinkedList<Object>();
        Object list = gale.eval(expr);
        if (list.getClass().isArray())
            for (Object o : (Object[]) list)
                alist.add(o);
        else
            for (Object o : (Iterable<Object>) list)
                alist.add(o);
        if (alist.size() == 0) {
            element.getParent().remove(element);
            return null;
        }

        // optionally sort the array
        String sort = element.attributeValue("sort");
        if (sort != null && !"".equals(sort)) {
            final boolean ascending = ("false".equals(element.attributeValue("ascending")) ? false : true);
            List<Object[]> slist = new ArrayList<Object[]>();
            for (Object o : alist) {
                Object result = null;
                if (o instanceof Concept) {
                    CacheSession<EntityValue> session = gale.openUmSession();
                    session.setBaseUri(((Concept) o).getUri());
                    result = gale.cm().evaluate(gale.cr(), sort,
                            Argument.of("gale", "nl.tue.gale.ae.GaleContext", gale, "session",
                                    "nl.tue.gale.common.cache.CacheSession", session, "value",
                                    "nl.tue.gale.dm.data.Concept", o));
                } else {
                    CacheSession<EntityValue> session = gale.openUmSession();
                    result = gale.cm().evaluate(gale.cr(), sort,
                            Argument.of("gale", "nl.tue.gale.ae.GaleContext", gale, "session",
                                    "nl.tue.gale.common.cache.CacheSession", session, "value",
                                    o.getClass().getName(), o));
                }
                slist.add(new Object[] { result, o });
            }
            Collections.sort(slist, new Comparator<Object[]>() {
                public int compare(Object[] arg0, Object[] arg1) {
                    Object o1 = arg0[0];
                    Object o2 = arg1[0];
                    if (!ascending) {
                        Object temp = o1;
                        o1 = o2;
                        o2 = temp;
                    }
                    if (o1 == null)
                        return (o2 == null ? 0 : -1);
                    if (o2 == null)
                        return 1;
                    if (o1 instanceof Number)
                        return (new Double(((Number) o1).doubleValue()))
                                .compareTo(new Double(((Number) o2).doubleValue()));
                    return o1.toString().compareTo(o2.toString());
                }
            });
            alist.clear();
            for (Object[] o : slist)
                alist.add(o[1]);
        }

        // process for-loop
        String guid = GaleUtil.newGUID();
        resource.put(guid, alist.toArray());

        Element parent = element.getParent();
        int index = parent.indexOf(element);
        Pattern p = Pattern.compile("\\Q%" + var + "\\E\\W");
        for (int i = 0; i < alist.size(); i++) {
            Element clone = element.createCopy();
            Object object = ((Object[]) resource.get(guid))[i];
            String type = object.getClass().getName();
            if (type.indexOf("_$$_") >= 0)
                type = type.substring(0, type.indexOf("_$$_"));
            if (object instanceof Concept) {
                replace(clone, p, ((Concept) object).getUri().toString());
            } else if (object instanceof String) {
                replace(clone, p, (String) object);
            } else if (object instanceof Number || object instanceof Boolean) {
                replace(clone, p, object.toString());
            } else {
                replace(clone, p,
                        "((" + type + ")((Object[])gale.getResource().get(\"" + guid + "\"))[" + i + "])");
            }
            processor.traverseChildren(clone, resource);
            for (Node n : (List<Node>) clone.content()) {
                parent.content().add(index, n);
                index++;
            }
        }
        element.detach();
    } catch (Exception e) {
        e.printStackTrace();
        return (Element) GaleUtil.replaceNode(element, GaleUtil.createErrorElement("[" + e.getMessage() + "]"));
    }
    return null;
}

From source file:org.collectionspace.chain.util.xtmpl.XTmplDocument.java

License:Educational Community License

@SuppressWarnings("unchecked")
public void setTexts(String key, String[] texts) {
    Node basis = document.selectSingleNode(attach.get(key));
    Element parent = basis.getParent();
    int pos = parent.indexOf(basis);
    List<Node> nodes = (List<Node>) parent.content();
    List<Node> after = new ArrayList(nodes.subList(pos + 1, nodes.size()));
    basis.detach();/*from  w ww .  j av  a2s .  com*/
    if (texts.length > 0) {
        for (Node n : after)
            n.detach();
        for (String text : texts) {
            Node renewed = (Node) basis.clone();
            renewed.setText(text);
            parent.add(renewed);
        }
        for (Node n : after)
            parent.add(n);
    }
}

From source file:org.olat.ims.qti.container.ItemContext.java

License:Apache License

/**
 * Method shuffle. shuffle clones the current item (since the whole qti tree is readonly) and shuffles it
 * //from w  w  w  . j ava  2 s.c o  m
 * @param item
 * @return Element
 */
private Element shuffle(final Element item) {
    // get the render_choice
    final XPath choice = DocumentHelper.createXPath(".//render_choice[@shuffle=\"Yes\"]");
    final Element tel_rendchoice = (Element) choice.selectSingleNode(item);
    // if shuffle is disable, just return the item
    if (tel_rendchoice == null) {
        return item;
    }
    // else: we have to shuffle
    // assume: all response_label have same parent: either render_choice or a
    // flow_label
    final Element shuffleItem = item.createCopy();
    // clone the whole item
    final Element el_rendchoice = (Element) choice.selectSingleNode(shuffleItem);
    // <!ELEMENT render_choice ((material | material_ref | response_label |
    // flow_label)* ,response_na?)>
    // <!ATTLIST response_label rshuffle (Yes | No ) 'Yes' .....
    final List el_labels = el_rendchoice.selectNodes(".//response_label[@rshuffle=\"Yes\"]");
    final int shusize = el_labels.size();

    // set up a list of children with their parents and the position of the
    // child (in case several children have the same parent
    final List respList = new ArrayList(shusize);
    final List parentList = new ArrayList(shusize);
    final int[] posList = new int[shusize];
    int j = 0;

    for (final Iterator responses = el_labels.iterator(); responses.hasNext();) {
        final Element response = (Element) responses.next();
        final Element parent = response.getParent();
        final int pos = parent.indexOf(response);
        posList[j++] = pos;
        respList.add(response.clone()); // need to use clones so they are not
        // attached anymore
        parentList.add(parent);
    }
    Collections.shuffle(respList);
    // put the children back to the parents
    for (int i = 0; i < parentList.size(); i++) {
        final Element parent = (Element) parentList.get(i);
        final int pos = posList[i];
        final Element child = (Element) respList.get(i);
        parent.elements().set(pos, child);
    }
    return shuffleItem;
}

From source file:org.opencms.ade.contenteditor.CmsContentService.java

License:Open Source License

/**
 * Returns the path elements for the given content value.<p>
 *
 * @param content the XML content/* w w w .  j  a  v  a2s  . co m*/
 * @param value the content value
 *
 * @return the path elements
 */
private String[] getPathElements(CmsXmlContent content, I_CmsXmlContentValue value) {

    List<String> pathElements = new ArrayList<String>();
    String[] paths = value.getPath().split("/");
    String path = "";
    for (int i = 0; i < paths.length; i++) {
        path += paths[i];
        I_CmsXmlContentValue ancestor = content.getValue(path, value.getLocale());
        int valueIndex = ancestor.getXmlIndex();
        if (ancestor.isChoiceOption()) {
            Element parent = ancestor.getElement().getParent();
            valueIndex = parent.indexOf(ancestor.getElement());
        }
        String pathElement = getAttributeName(ancestor.getName(), getTypeUri(ancestor.getContentDefinition()));
        pathElements.add(pathElement + "[" + valueIndex + "]");
        path += "/";
    }
    return pathElements.toArray(new String[pathElements.size()]);
}

From source file:org.opencms.setup.xml.v8.CmsXmlAddADESearch.java

License:Open Source License

/**
 * Initializes the map of XML update actions.<p>
 *///from  w w  w . j a  v a 2  s.  com
private void initActions() {

    m_actions = new LinkedHashMap<String, CmsXmlUpdateAction>();
    StringBuffer xp;
    CmsXmlUpdateAction action0 = new CmsXmlUpdateAction() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean executeUpdate(Document doc, String xpath, boolean forReal) {

            Node node = doc.selectSingleNode(xpath);
            org.dom4j.Element parent = node.getParent();
            int position = parent.indexOf(node);
            parent.remove(node);
            try {
                parent.elements().add(position, createElementFromXml("      <documenttypes>     \n"
                        + "            <documenttype>\n" + "                <name>generic</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentGeneric</class>\n"
                        + "                <mimetypes/>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>*</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype> \n"
                        + "            <documenttype>\n" + "                <name>html</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentHtml</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>text/html</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>\n"
                        + "            <documenttype>\n" + "                <name>image</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentGeneric</class>\n"
                        + "                <mimetypes/>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>image</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>     \n"
                        + "            <documenttype>\n" + "                <name>jsp</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentPlainText</class>\n"
                        + "                <mimetypes/>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>jsp</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>     \n"
                        + "            <documenttype>\n" + "                <name>pdf</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentPdf</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>application/pdf</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>binary</resourcetype>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>\n"
                        + "            <documenttype>\n" + "                <name>rtf</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentRtf</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>text/rtf</mimetype>\n"
                        + "                    <mimetype>application/rtf</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>binary</resourcetype>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>     \n"
                        + "            <documenttype>\n" + "                <name>text</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentPlainText</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>text/html</mimetype>\n"
                        + "                    <mimetype>text/plain</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype> \n"
                        + "            <documenttype>\n" + "                <name>xmlcontent</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentXmlContent</class>\n"
                        + "                <mimetypes/>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>*</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>\n"
                        + "            <documenttype>\n" + "                <name>containerpage</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentContainerPage</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>text/html</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>containerpage</resourcetype>\n"
                        + "                </resourcetypes>\n"
                        + "            </documenttype>                 \n" + "            <documenttype>\n"
                        + "                <name>xmlpage</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentXmlPage</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>text/html</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>xmlpage</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>\n"
                        + "            <documenttype>\n" + "                <name>xmlcontent-galleries</name>\n"
                        + "                <class>org.opencms.search.galleries.CmsGalleryDocumentXmlContent</class>\n"
                        + "                <mimetypes/>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>xmlcontent-galleries</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype> \n"
                        + "            <documenttype>\n" + "                <name>xmlpage-galleries</name>\n"
                        + "                <class>org.opencms.search.galleries.CmsGalleryDocumentXmlPage</class>\n"
                        + "                <mimetypes />\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>xmlpage-galleries</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>     \n"
                        + "            <documenttype>\n" + "                <name>msoffice-ole2</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentMsOfficeOLE2</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>application/vnd.ms-powerpoint</mimetype>\n"
                        + "                    <mimetype>application/msword</mimetype>     \n"
                        + "                    <mimetype>application/vnd.ms-excel</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>binary</resourcetype>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n"
                        + "            </documenttype>                 \n" + "            <documenttype>\n"
                        + "                <name>msoffice-ooxml</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentMsOfficeOOXML</class>\n"
                        + "                <mimetypes>             \n"
                        + "                    <mimetype>application/vnd.openxmlformats-officedocument.wordprocessingml.document</mimetype>\n"
                        + "                    <mimetype>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mimetype>\n"
                        + "                    <mimetype>application/vnd.openxmlformats-officedocument.presentationml.presentation</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>binary</resourcetype>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n"
                        + "            </documenttype>                 \n" + "            <documenttype>\n"
                        + "                <name>openoffice</name>\n"
                        + "                <class>org.opencms.search.documents.CmsDocumentOpenOffice</class>\n"
                        + "                <mimetypes>\n"
                        + "                    <mimetype>application/vnd.oasis.opendocument.text</mimetype>\n"
                        + "                    <mimetype>application/vnd.oasis.opendocument.spreadsheet</mimetype>\n"
                        + "                </mimetypes>\n" + "                <resourcetypes>\n"
                        + "                    <resourcetype>binary</resourcetype>\n"
                        + "                    <resourcetype>plain</resourcetype>\n"
                        + "                </resourcetypes>\n" + "            </documenttype>\n"
                        + "        </documenttypes>\n"));
            } catch (DocumentException e) {
                System.out.println("failed to update document types.");
            }
            return true;

        }
    };
    m_actions.put(buildXpathForDoctypes(), action0);
    //
    //=============================================================================================================
    //
    CmsXmlUpdateAction action1 = new CmsXmlUpdateAction() {

        @SuppressWarnings("synthetic-access")
        @Override
        public boolean executeUpdate(Document doc, String xpath, boolean forReal) {

            Node node = doc.selectSingleNode(xpath);
            if (node == null) {
                createAnalyzer(doc, xpath, CmsGallerySearchAnalyzer.class, "all");
                return true;
            }
            return false;
        }
    };
    xp = new StringBuffer(256);
    xp.append(getCommonPath());
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_ANALYZERS);
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_ANALYZER);
    xp.append("[");
    xp.append(CmsSearchConfiguration.N_CLASS);
    xp.append("='").append(CmsGallerySearchAnalyzer.class.getName()).append("']");
    m_actions.put(xp.toString(), action1);
    //
    //=============================================================================================================
    //
    CmsXmlUpdateAction action2 = new CmsXmlUpdateAction() {

        @SuppressWarnings("synthetic-access")
        @Override
        public boolean executeUpdate(Document doc, String xpath, boolean forReal) {

            Node node = doc.selectSingleNode(xpath);
            if (node != null) {
                node.detach();
            }
            createIndex(doc, xpath, CmsGallerySearchIndex.class, CmsGallerySearchIndex.GALLERY_INDEX_NAME,
                    "offline", "Offline", "all", "gallery_fields",
                    new String[] { "gallery_source", "gallery_modules_source" });
            return true;
        }
    };
    xp = new StringBuffer(256);
    xp.append(getCommonPath());
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_INDEXES);
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_INDEX);
    xp.append("[");
    xp.append(I_CmsXmlConfiguration.N_NAME);
    xp.append("='").append(CmsGallerySearchIndex.GALLERY_INDEX_NAME).append("']");
    m_actions.put(xp.toString(), action2);
    //
    //=============================================================================================================
    //
    CmsXmlUpdateAction action3 = new CmsXmlUpdateAction() {

        @SuppressWarnings("synthetic-access")
        @Override
        public boolean executeUpdate(Document doc, String xpath, boolean forReal) {

            Node node = doc.selectSingleNode(xpath);
            if (node != null) {
                return false;
            }
            // create doc type
            createIndexSource(doc, xpath, "gallery_source", CmsVfsIndexer.class,
                    new String[] { "/sites/", "/shared/", "/system/galleries/" },
                    new String[] { "xmlpage-galleries", "xmlcontent-galleries", "jsp", "text", "pdf", "rtf",
                            "html", "image", "generic", "openoffice", "msoffice-ole2", "msoffice-ooxml" });
            return true;

        }
    };
    xp = new StringBuffer(256);
    xp.append(getCommonPath());
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_INDEXSOURCES);
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_INDEXSOURCE);
    xp.append("[");
    xp.append(I_CmsXmlConfiguration.N_NAME);
    xp.append("='gallery_source']");
    m_actions.put(xp.toString(), action3);
    //
    //=============================================================================================================
    //
    CmsXmlUpdateAction action4 = new CmsXmlUpdateAction() {

        @Override
        public boolean executeUpdate(Document document, String xpath, boolean forReal) {

            Node node = document.selectSingleNode(xpath);

            if (node != null) {
                node.detach();
            }
            // create field config
            CmsSearchFieldConfiguration fieldConf = new CmsSearchFieldConfiguration();
            fieldConf.setName("gallery_fields");
            fieldConf.setDescription("The standard OpenCms search index field configuration.");
            CmsSearchField field = new CmsSearchField();
            // <field name="content" store="compress" index="true" excerpt="true">
            field.setName("content");
            field.setStored("compress");
            field.setIndexed("true");
            field.setInExcerpt("true");
            field.setDisplayNameForConfiguration("%(key.field.content)");
            // <mapping type="content" />
            CmsSearchFieldMapping mapping = new CmsSearchFieldMapping();
            mapping.setType("content");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="title-key" store="true" index="untokenized" boost="0.0">
            field = new CmsSearchField();
            field.setName("title-key");
            field.setStored("true");
            field.setIndexed("untokenized");
            field.setBoost("0.0");
            // <mapping type="property">Title</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("property");
            mapping.setParam("Title");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="title" store="false" index="true">
            field = new CmsSearchField();
            field.setName("title");
            field.setStored("false");
            field.setIndexed("true");
            field.setDisplayNameForConfiguration("%(key.field.title)");
            // <mapping type="property">Title</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("property");
            mapping.setParam("Title");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="description" store="true" index="true">
            field = new CmsSearchField();
            field.setName("description");
            field.setStored("true");
            field.setIndexed("true");
            field.setDisplayNameForConfiguration("%(key.field.description)");
            // <mapping type="property">Description</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("property");
            mapping.setParam("Description");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="meta" store="false" index="true">
            field = new CmsSearchField();
            field.setName("meta");
            field.setStored("false");
            field.setIndexed("true");
            // <mapping type="property">Title</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("property");
            mapping.setParam("Title");
            field.addMapping(mapping);
            // <mapping type="property">Description</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("property");
            mapping.setParam("Description");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_dateExpired" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_dateExpired");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">dateExpired</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("dateExpired");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_dateReleased" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_dateReleased");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">dateReleased</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("dateReleased");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_length" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_length");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">length</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("length");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_state" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_state");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">state</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("state");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_structureId" store="true" index="false">
            field = new CmsSearchField();
            field.setName("res_structureId");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">structureId</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("structureId");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_userCreated" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_userCreated");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">userCreated</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("userCreated");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_userLastModified" store="true" index="untokenized">
            field = new CmsSearchField();
            field.setName("res_userLastModified");
            field.setStored("true");
            field.setIndexed("untokenized");
            // <mapping type="attribute">userLastModified</mapping>
            mapping = new CmsSearchFieldMapping();
            mapping.setType("attribute");
            mapping.setParam("userLastModified");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="res_locales" store="true" index="true" analyzer="WhitespaceAnalyzer">
            field = new CmsSearchField();
            field.setName("res_locales");
            field.setStored("true");
            field.setIndexed("true");
            try {
                field.setAnalyzer("WhitespaceAnalyzer");
            } catch (Exception e) {
                // ignore
                e.printStackTrace();
            }
            // <mapping type="dynamic" class="org.opencms.search.galleries.CmsGallerySearchFieldMapping">res_locales</mapping>
            mapping = new CmsGallerySearchFieldMapping();
            mapping.setType("dynamic");
            mapping.setParam("res_locales");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="additional_info" store="true" index="false">
            field = new CmsSearchField();
            field.setName("additional_info");
            field.setStored("true");
            field.setIndexed("false");
            // <mapping type="dynamic" class="org.opencms.search.galleries.CmsGallerySearchFieldMapping">additional_info</mapping>
            mapping = new CmsGallerySearchFieldMapping();
            mapping.setType("dynamic");
            mapping.setParam("additional_info");
            field.addMapping(mapping);
            fieldConf.addField(field);
            // <field name="container_types" store="true" index="true" analyzer="WhitespaceAnalyzer">
            field = new CmsSearchField();
            field.setName("container_types");
            field.setStored("true");
            field.setIndexed("true");
            try {
                field.setAnalyzer("WhitespaceAnalyzer");
            } catch (Exception e) {
                // ignore
                e.printStackTrace();
            }
            // <mapping type="dynamic" class="org.opencms.search.galleries.CmsGallerySearchFieldMapping">container_types</mapping>
            mapping = new CmsGallerySearchFieldMapping();
            mapping.setType("dynamic");
            mapping.setParam("container_types");
            field.addMapping(mapping);
            fieldConf.addField(field);
            createFieldConfig(document, xpath, fieldConf, CmsGallerySearchFieldConfiguration.class);
            return true;
        }
    };

    xp = new StringBuffer(256);
    xp.append(getCommonPath());
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_FIELDCONFIGURATIONS);
    xp.append("/");
    xp.append(CmsSearchConfiguration.N_FIELDCONFIGURATION);
    xp.append("[");
    xp.append(I_CmsXmlConfiguration.N_NAME);
    xp.append("='gallery_fields']");
    m_actions.put(xp.toString(), action4);
    //
    //=============================================================================================================
    //

    m_actions.put("/opencms/search/indexsources", new CmsIndexSourceTypeUpdateAction());

    // use dummy check [1=1] to make the xpaths unique 
    m_actions.put("/opencms/search/indexsources[1=1]", new CmsAddGalleryModuleIndexSourceAction());
    m_actions.put(buildXpathForIndexedDocumentType("source1", "containerpage"),
            createIndexedTypeAction("containerpage"));

    //=============================================================================================================

    String analyzerEnPath = "/opencms/search/analyzers/analyzer[class='org.apache.lucene.analysis.standard.StandardAnalyzer'][locale='en']";
    m_actions.put(analyzerEnPath,
            new ElementReplaceAction(analyzerEnPath,
                    "<analyzer>\n"
                            + "                <class>org.apache.lucene.analysis.en.EnglishAnalyzer</class>\n"
                            + "                <locale>en</locale>\n" + "            </analyzer>"));

    String analyzerItPath = "/opencms/search/analyzers/analyzer[class='org.apache.lucene.analysis.snowball.SnowballAnalyzer'][stemmer='Italian']";
    m_actions.put(analyzerItPath,
            new ElementReplaceAction(analyzerItPath,
                    "<analyzer>\n"
                            + "                <class>org.apache.lucene.analysis.it.ItalianAnalyzer</class>\n"
                            + "                <locale>it</locale>\n" + "            </analyzer>"));

    m_actions.put(
            "/opencms/search/indexsources/indexsource[name='gallery_source']/resources['systemgalleries'='systemgalleries']",
            new CmsAddIndexSourceResourceAction());
}