Example usage for org.dom4j Element remove

List of usage examples for org.dom4j Element remove

Introduction

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

Prototype

boolean remove(Text text);

Source Link

Document

Removes the given Text if the node is an immediate child of this element.

Usage

From source file:org.openadaptor.auxil.convertor.map.Dom4JDocumentMapFacade.java

License:Open Source License

private Object replace(Element oldElement, Element newElement) {
    Element parent = oldElement.getParent();
    parent.remove(oldElement);
    parent.add(newElement);/*from   w  w w.ja v a  2 s. c  o  m*/
    return oldElement;
}

From source file:org.opencms.importexport.CmsExport.java

License:Open Source License

/**
 * Export the data.<p>/*  www.  j a v a 2  s.c om*/
 * 
 * @param parameters the export parameters
 * 
 * @throws CmsImportExportException if something goes wrong 
 */
public void exportData(CmsExportParameters parameters) throws CmsImportExportException {

    m_parameters = parameters;
    m_exportCount = 0;

    // clear all caches
    getReport().println(Messages.get().container(Messages.RPT_CLEARCACHE_0), I_CmsReport.FORMAT_NOTE);
    OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_CLEAR_CACHES, new HashMap<String, Object>(0)));

    try {
        Element exportNode = openExportFile();

        if (m_parameters.getModuleInfo() != null) {
            // add the module element
            exportNode.add(m_parameters.getModuleInfo());
            // write the XML
            digestElement(exportNode, m_parameters.getModuleInfo());
        }

        // export account data only if selected
        if (m_parameters.isExportAccountData()) {
            Element accountsElement = exportNode.addElement(CmsImportVersion7.N_ACCOUNTS);
            getSaxWriter().writeOpen(accountsElement);

            exportOrgUnits(accountsElement);

            getSaxWriter().writeClose(accountsElement);
            exportNode.remove(accountsElement);
        }

        // export resource data only if selected
        if (m_parameters.isExportResourceData()) {
            exportAllResources(exportNode, m_parameters.getResources());
        }

        // export project data only if selected
        if (m_parameters.isExportProjectData()) {
            Element projectsElement = exportNode.addElement(CmsImportVersion7.N_PROJECTS);
            getSaxWriter().writeOpen(projectsElement);

            exportProjects(projectsElement);

            getSaxWriter().writeClose(projectsElement);
            exportNode.remove(projectsElement);
        }

        closeExportFile(exportNode);
    } catch (SAXException se) {
        getReport().println(se);

        CmsMessageContainer message = Messages.get()
                .container(Messages.ERR_IMPORTEXPORT_ERROR_EXPORTING_TO_FILE_1, getExportFileName());
        if (LOG.isDebugEnabled()) {
            LOG.debug(message.key(), se);
        }

        throw new CmsImportExportException(message, se);
    } catch (IOException ioe) {
        getReport().println(ioe);

        CmsMessageContainer message = Messages.get()
                .container(Messages.ERR_IMPORTEXPORT_ERROR_EXPORTING_TO_FILE_1, getExportFileName());
        if (LOG.isDebugEnabled()) {
            LOG.debug(message.key(), ioe);
        }

        throw new CmsImportExportException(message, ioe);
    }
}

From source file:org.opencms.importexport.CmsExport.java

License:Open Source License

/**
 * Writes the output element to the XML output writer and detaches it 
 * from it's parent element.<p> //from w w  w. ja  v a2 s.  c o  m
 * 
 * @param parent the parent element
 * @param output the output element 
 * 
 * @throws SAXException if something goes wrong processing the manifest.xml
 */
protected void digestElement(Element parent, Element output) throws SAXException {

    m_saxWriter.write(output);
    parent.remove(output);
}

From source file:org.opencms.importexport.CmsExport.java

License:Open Source License

/**
 * Exports all resources and possible sub-folders form the provided list of resources.
 * //www  .  j a v a 2s  .  c  om
 * @param parent the parent node to add the resources to
 * @param resourcesToExport the list of resources to export
 * 
 * @throws CmsImportExportException if something goes wrong
 * @throws SAXException if something goes wrong processing the manifest.xml
 * @throws IOException if not all resources could be appended to the ZIP archive
 */
protected void exportAllResources(Element parent, List<String> resourcesToExport)
        throws CmsImportExportException, IOException, SAXException {

    // export all the resources
    String resourceNodeName = getResourceNodeName();
    m_resourceNode = parent.addElement(resourceNodeName);
    getSaxWriter().writeOpen(m_resourceNode);

    if (m_parameters.isRecursive()) {
        // remove the possible redundancies in the list of resources
        resourcesToExport = CmsFileUtil.removeRedundancies(resourcesToExport);
    }

    // distinguish folder and file names   
    List<String> folderNames = new ArrayList<String>();
    List<String> fileNames = new ArrayList<String>();
    Iterator<String> it = resourcesToExport.iterator();
    while (it.hasNext()) {
        String resource = it.next();
        if (CmsResource.isFolder(resource)) {
            folderNames.add(resource);
        } else {
            fileNames.add(resource);
        }
    }

    m_exportedResources = new HashSet<CmsUUID>();

    // export the folders
    for (int i = 0; i < folderNames.size(); i++) {
        String path = folderNames.get(i);
        if (m_parameters.isRecursive()) {
            // first add super folders to the xml-config file
            addParentFolders(path);
            addChildResources(path);
        } else {
            CmsFolder folder;
            try {
                folder = getCms().readFolder(path, CmsResourceFilter.IGNORE_EXPIRATION);
            } catch (CmsException e) {
                CmsMessageContainer message = Messages.get()
                        .container(Messages.ERR_IMPORTEXPORT_ERROR_ADDING_PARENT_FOLDERS_1, path);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), e);
                }
                throw new CmsImportExportException(message, e);
            }
            CmsResourceState state = folder.getState();
            long age = folder.getDateLastModified() < folder.getDateCreated() ? folder.getDateCreated()
                    : folder.getDateLastModified();

            if (getCms().getRequestContext().getCurrentProject().isOnlineProject()
                    || (m_parameters.isIncludeUnchangedResources()) || state.isNew() || state.isChanged()) {
                if (!state.isDeleted() && (age >= m_parameters.getContentAge())) {
                    // check if this is a system-folder and if it should be included.
                    String export = getCms().getSitePath(folder);
                    if (checkExportResource(export)) {
                        appendResourceToManifest(folder, false);
                    }
                }
            }
        }
    }
    // export the files
    addFiles(fileNames);

    // write the XML
    getSaxWriter().writeClose(m_resourceNode);
    parent.remove(m_resourceNode);
    m_resourceNode = null;
}

From source file:org.opencms.relations.CmsLinkUpdateUtil.java

License:Open Source License

/**
 * Updates the given xml element attribute with the given value.<p> 
 * //from  w  w  w. ja  v a  2  s.  co m
 * @param parent the element to set the attribute for
 * @param attrName the attribute name
 * @param value the value to set, or <code>null</code> to remove
 */
private static void updateAttribute(Element parent, String attrName, String value) {

    if (parent != null) {
        Attribute attribute = parent.attribute(attrName);
        if (value != null) {
            if (attribute == null) {
                parent.addAttribute(attrName, value);
            } else {
                attribute.setValue(value);
            }
        } else {
            // remove only if exists
            if (attribute != null) {
                parent.remove(attribute);
            }
        }
    }
}

From source file:org.opencms.relations.CmsLinkUpdateUtil.java

License:Open Source License

/**
 * Updates the given xml node with the given value.<p>
 * /*  w ww .ja va 2  s.c  om*/
 * @param parent the parent node
 * @param nodeName the node to update
 * @param value the value to use to update the given node, can be <code>null</code>
 * @param cdata if the value should be in a CDATA section or not
 */
private static void updateNode(Element parent, String nodeName, String value, boolean cdata) {

    // get current node element
    Element nodeElement = parent.element(nodeName);
    if (value != null) {
        if (nodeElement == null) {
            // element wasn't there before, add element and set value
            nodeElement = parent.addElement(nodeName);
        }
        // element is there, update element value
        nodeElement.clearContent();
        if (cdata) {
            nodeElement.addCDATA(value);
        } else {
            nodeElement.addText(value);
        }
    } else {
        // remove only if element exists
        if (nodeElement != null) {
            // remove element
            parent.remove(nodeElement);
        }
    }
}

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

License:Open Source License

/**
 * Initializes the map of XML update actions.<p>
 *///  w w  w.ja  v a 2s . c  o m
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());
}

From source file:org.opencms.xml.content.CmsXmlContentPropertyHelper.java

License:Open Source License

/**
 * Saves the given properties to the given xml element.<p>
 * /*from   ww w  .  j av a2s.c  om*/
 * @param cms the current CMS context
 * @param parentElement the parent xml element
 * @param properties the properties to save, if there is a list of resources, every entry can be a site path or a UUID
 * @param resource the resource to get the property configuration from
 * @param propertiesConf the configuration of the properties 
 */
public static void saveProperties(CmsObject cms, Element parentElement, Map<String, String> properties,
        CmsResource resource, Map<String, CmsXmlContentProperty> propertiesConf) {

    // remove old entries
    for (Object propElement : parentElement.elements(CmsXmlContentProperty.XmlNode.Properties.name())) {
        parentElement.remove((Element) propElement);
    }

    // create new entries
    for (Map.Entry<String, String> property : properties.entrySet()) {
        String propName = property.getKey();
        String propValue = property.getValue();
        boolean isSpecial = isSpecialProperty(propName);
        if (!isSpecial && (!propertiesConf.containsKey(propName) || (propValue == null))) {
            continue;
        }
        // only if the property is configured in the schema we will save it
        Element propElement = parentElement.addElement(CmsXmlContentProperty.XmlNode.Properties.name());

        // the property name
        propElement.addElement(CmsXmlContentProperty.XmlNode.Name.name()).addCDATA(propName);
        Element valueElement = propElement.addElement(CmsXmlContentProperty.XmlNode.Value.name());
        String baseName = isSpecial ? propName.substring(1) : propName;
        boolean isVfs = false;
        CmsXmlContentProperty propDef = propertiesConf.get(baseName);
        if (propDef != null) {
            isVfs = CmsXmlContentProperty.PropType.isVfsList(propDef.getType());
        }
        if (!isVfs) {
            // string value
            valueElement.addElement(CmsXmlContentProperty.XmlNode.String.name()).addCDATA(propValue);
        } else {
            addFileListPropertyValue(cms, valueElement, propValue);
        }
    }
}

From source file:org.opencms.xml.page.CmsXmlPage.java

License:Open Source License

/**
 * Sets the enabled flag of an already existing element.<p>
 * //from  w w  w  .  j  a va  2  s .com
 * Note: if isEnabled is set to true, the attribute is removed
 * since true is the default
 * 
 * @param name name name of the element
 * @param locale locale of the element
 * @param isEnabled enabled flag for the element
 */
public void setEnabled(String name, Locale locale, boolean isEnabled) {

    CmsXmlHtmlValue value = (CmsXmlHtmlValue) getValue(name, locale);
    Element element = value.getElement();
    Attribute enabled = element.attribute(ATTRIBUTE_ENABLED);

    if (enabled == null) {
        if (!isEnabled) {
            element.addAttribute(ATTRIBUTE_ENABLED, Boolean.toString(isEnabled));
        }
    } else if (isEnabled) {
        element.remove(enabled);
    } else {
        enabled.setValue(Boolean.toString(isEnabled));
    }
}

From source file:org.openkoala.koala.deploy.curd.module.util.CURDConfigUpdate.java

License:Open Source License

private static void jpaDBUpdate(List<String> entitys, String config) {
    Document jpaDocument = DocumentUtil.readDocument(config);
    String parent = "/xmlns:persistence/xmlns:persistence-unit";
    Element parentElement = XPathQueryUtil.querySingle(JPA_XMLS, parent, jpaDocument);
    for (String entity : entitys) {
        String entityQueryString = "/xmlns:persistence/xmlns:persistence-unit[xmlns:class='" + entity + "']";
        Element entityElement = XPathQueryUtil.querySingle(JPA_XMLS, entityQueryString, jpaDocument);

        if (entityElement == null) {
            entityElement = parentElement.addElement("class", JPA_XMLS);
            entityElement.setText(entity);
            Element add = entityElement;
            parentElement.remove(entityElement);
            parentElement.content().add(0, add);
        }/*from  w  ww .ja  va2s  .c o m*/
    }
    DocumentUtil.document2Xml(config, jpaDocument);
}