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:com.xebia.mojo.dashboard.util.HtmlUtil.java

License:Apache License

/**
 * Removes an {@link Attribute} specified by the attribute name from an {@link Element}.
 *
 * @param element   The {@link Element} from which to remove the {@link Attribute}.
 * @param attribute The name of the {@link Attribute} that is to be removed.
 *///from www .j av a 2s . c  o  m
public static final void removeAttribute(Element element, String attribute) {
    Attribute attr = element.attribute(attribute);

    if (attr != null) {
        element.remove(attr);
    }
}

From source file:condorclient.utilities.XMLHandler.java

public void removeJob(String clusterId) {

    SAXReader saxReader = new SAXReader();
    Document document = null;//from w ww. j a  v a 2s.co m
    try {
        document = saxReader.read(new File("niInfo.xml"));

    } catch (DocumentException ex) {
        Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex);
    }

    List list = document.selectNodes("/root/info/job");//?job
    Iterator iter = list.iterator();
    Element root = document.getRootElement();
    Element info = root.element("info");
    while (iter.hasNext()) {
        Element job = (Element) iter.next();
        String id = job.attributeValue("id");
        if (id.equals(clusterId)) {

            info.remove(job);
        }

    }
    XMLWriter writer = null;
    try {
        writer = new XMLWriter(new FileWriter(new File("niInfo.xml")));
        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:condorclient.utilities.XMLHandler.java

public void removeJobs(int[] delClusterIds, int delsum) {

    SAXReader saxReader = new SAXReader();
    Document document = null;/*from   www  .j  a  va2s . c om*/
    try {
        document = saxReader.read(new File("niInfo.xml"));

    } catch (DocumentException ex) {
        Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex);
    }

    List list = document.selectNodes("/root/info/job");//?job
    Iterator iter = list.iterator();
    Element root = document.getRootElement();
    Element info = root.element("info");
    try {
        while (iter.hasNext()) {
            Element job = (Element) iter.next();
            String id = job.attributeValue("id");
            for (int i = 0; i < delsum; i++) {
                if (id.equals("" + delClusterIds[i])) {

                    info.remove(job);
                }
            }

        }
    } catch (Exception e) {

        System.out.println("???");
    }

    XMLWriter writer = null;
    try {
        writer = new XMLWriter(new FileWriter(new File("niInfo.xml")));
        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:controller.setup.Setup.java

private void updateHibernateCfgFile(String bd, String bdHost, String bdPort, String bdName, String bdUser,
        String bdUserMdp) {/*from   ww  w . java  2  s. co  m*/

    System.out.println(
            "------------------------------ Creation hibernate config file -----------------------------");

    try {

        URL resource = Thread.currentThread().getContextClassLoader().getResource("hibernate.cfg.xml");
        File f = new File(resource.toURI());

        SAXReader xmlReader = new SAXReader();
        Document doc = xmlReader.read(f);
        Element sessionFactory = (Element) doc.getRootElement().elements().get(0);

        if (sessionFactory.elements().size() != 0)
            for (Iterator elt = sessionFactory.elements().iterator(); elt.hasNext();)
                sessionFactory.remove((Element) elt.next());

        if (bd.equals("mysql")) {
            sessionFactory.addElement("property").addAttribute("name", "dialect")
                    .addText("org.hibernate.dialect.MySQLDialect");
            sessionFactory.addElement("property").addAttribute("name", "connection.url")
                    .addText("jdbc:mysql://" + bdHost + ":" + bdPort + "/" + bdName);
            sessionFactory.addElement("property").addAttribute("name", "connection.driver_class")
                    .addText("com.mysql.jdbc.Driver");
        } else if (bd.equals("pgsql")) {
            sessionFactory.addElement("property").addAttribute("name", "dialect")
                    .addText("org.hibernate.dialect.PostgreSQLDialect");
            sessionFactory.addElement("property").addAttribute("name", "connection.url")
                    .addText("jdbc:postgresql://" + bdHost + ":" + bdPort + "/" + bdName);
            sessionFactory.addElement("property").addAttribute("name", "connection.driver_class")
                    .addText("org.postgresql.Driver");
        } else if (bd.equals("oracle")) {
            sessionFactory.addElement("property").addAttribute("name", "dialect")
                    .addText("org.hibernate.dialect.OracleDialect");
            sessionFactory.addElement("property").addAttribute("name", "connection.url")
                    .addText("jdbc:oracle:thin:@" + bdHost + ":" + bdPort + ":" + bdName);
            sessionFactory.addElement("property").addAttribute("name", "connection.driver_class")
                    .addText("oracle.jdbc.OracleDriver");
        } else if (bd.equals("mssqlserver")) {
            sessionFactory.addElement("property").addAttribute("name", "dialect")
                    .addText("org.hibernate.dialect.SQLServerDialect");
            sessionFactory.addElement("property").addAttribute("name", "connection.url")
                    .addText("jdbc:sqlserver://" + bdHost + ":" + bdPort + ";databaseName=" + bdName + ";");
            sessionFactory.addElement("property").addAttribute("name", "connection.driver_class")
                    .addText("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        }

        sessionFactory.addElement("property").addAttribute("name", "connection.username").addText(bdUser);
        sessionFactory.addElement("property").addAttribute("name", "connection.password").addText(bdUserMdp);
        sessionFactory.addElement("property").addAttribute("name", "hbm2ddl.auto").addText("update");

        XMLWriter writer = new XMLWriter(new FileWriter(f));
        writer.write(doc);
        writer.close();

        System.out.println(
                "------------------------------ Creation hibernate config file over -----------------------------");

    }

    catch (URISyntaxException e) {
        e.printStackTrace();
    }

    catch (DocumentException e) {
        e.printStackTrace();
    }

    catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java

License:Open Source License

private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) {
    Element dcRootEl = dcDoc.getRootElement();
    Attribute schemaLoc = dcRootEl.attribute("schemaLocation");
    dcRootEl.remove(schemaLoc);
    Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI);
    dcRootEl.add(xsi);//from   w ww  .jav a  2s.  c  o m
    dcRootEl.addAttribute(new QName("schemaLocation", xsi),
            "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier");
    List<? extends Node> nodes = typeXpath.selectNodes(dcDoc);
    for (Node node : nodes) {
        node.detach();
    }
    Element idUuid = dcRootEl.addElement("dc:identifier");
    idUuid.addText(pid);

    for (Node node : nodes) {
        if (node.getText() != null && !"".equals(node.getText().trim())
                && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) {
            Element temp = dcRootEl.addElement("dc:identifier");
            temp.addText(node.getText());
        }
    }

    if (signature != null) {
        Element idSignature = dcRootEl.addElement("dc:identifier");
        idSignature.addText("signature:" + signature);
    }
    if (sysno != null) {
        Element idSysno = dcRootEl.addElement("dc:identifier");
        idSysno.addText("sysno:" + sysno);
    }
    removeDcTypeElements(dcDoc);
    Element typeEl = dcRootEl.addElement("dc:type");
    typeEl.addText("model:" + model.toString());
    Element rightsEl = dcRootEl.addElement("dc:rights");
    rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase());
    updateDcLanguages(dcDoc);
}

From source file:cz.fi.muni.xkremser.editor.server.newObject.PeriodicalBuilder.java

License:Open Source License

private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) {
    Element dcRootEl = dcDoc.getRootElement();
    Attribute schemaLoc = dcRootEl.attribute("schemaLocation");
    dcRootEl.remove(schemaLoc);
    Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI);
    dcRootEl.add(xsi);/* w  w w .ja  va2s.com*/
    dcRootEl.addAttribute(new QName("schemaLocation", xsi),
            "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier");
    List<? extends Node> nodes = typeXpath.selectNodes(dcDoc);
    for (Node node : nodes) {
        node.detach();
    }
    Element idUuid = dcRootEl.addElement("dc:identifier");
    idUuid.addText(pid);

    for (Node node : nodes) {
        if (node.getText() != null && !"".equals(node.getText().trim())
                && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) {
            Element temp = dcRootEl.addElement("dc:identifier");
            temp.addText(node.getText());
        }
    }

    if (signature != null) {
        Element idSignature = dcRootEl.addElement("dc:identifier");
        idSignature.addText("signature:" + signature);
    }
    if (sysno != null) {
        Element idSysno = dcRootEl.addElement("dc:identifier");
        idSysno.addText("sysno:" + sysno);
    }
    removeDcTypeElements(dcDoc);
    Element typeEl = dcRootEl.addElement("dc:type");
    typeEl.addText("model:" + model.getValue());
    Element rightsEl = dcRootEl.addElement("dc:rights");
    rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase());
    updateDcLanguages(dcDoc);
}

From source file:cz.mzk.editor.server.newObject.MonographBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) {
    Element dcRootEl = dcDoc.getRootElement();
    Attribute schemaLoc = dcRootEl.attribute("schemaLocation");
    dcRootEl.remove(schemaLoc);
    Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI);
    dcRootEl.add(xsi);//from  ww  w .j  a  v  a 2s  .c  o  m
    dcRootEl.addAttribute(new QName("schemaLocation", xsi),
            "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier");
    List<? extends Node> nodes = typeXpath.selectNodes(dcDoc);
    for (Node node : nodes) {
        node.detach();
    }
    Element idUuid = dcRootEl.addElement("dc:identifier");
    idUuid.addText(pid);

    for (Node node : nodes) {
        if (node.getText() != null && !"".equals(node.getText().trim())
                && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) {
            Element temp = dcRootEl.addElement("dc:identifier");
            temp.addText(node.getText());
        }
    }

    if (signature != null) {
        Element idSignature = dcRootEl.addElement("dc:identifier");
        idSignature.addText("signature:" + signature);
    }
    if (sysno != null) {
        Element idSysno = dcRootEl.addElement("dc:identifier");
        idSysno.addText("sysno:" + sysno);
    }
    removeDcTypeElements(dcDoc);
    Element typeEl = dcRootEl.addElement("dc:type");
    typeEl.addText("model:" + model.getValue());
    Element rightsEl = dcRootEl.addElement("dc:rights");
    rightsEl.addText("policy:" + getPolicy().toString().toLowerCase());
    updateDcLanguages(dcDoc);
}

From source file:de.innovationgate.utils.WGUtils.java

License:Apache License

/**
 * Sorts the child elements of an element based on their indiviual XPath
 * result. This utility method should be used instead of direct sorting of
 * the elements()-list of a parent element, since this will fail with
 * exception on most occasions.//  w w  w . ja va 2 s . c om
 * 
 * @param parent
 *            The parent element
 * @param xpath
 *            The xpath that is evaluated on each child element
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void sortChildElements(Element parent, String xpath) {

    // Create a copy of the elements list and sort it
    List list = new ArrayList(parent.elements());
    DocumentHelper.sort(list, xpath);

    // Iterate over sorted list. Remove and add all in order
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Element element = (Element) it.next();
        parent.remove(element);
        parent.add(element);
    }

}

From source file:de.innovationgate.wga.common.WGAXML.java

License:Apache License

/**
 * Performs normalization on the wga.xml by creating mandatory elements and attributes and doing some
 * additional validations, like converting obsolete structures, defining yet undefined domains etc.
 * @param doc The wga.xml//from  w w w  .  j  av  a  2s. co  m
 */
public static void normalize(Document doc) {

    // Remove obsolete namespace
    String ns = "urn:de.innovationgate.webgate.api.query.domino.WGDatabaseImpl";
    Iterator nodes = doc.selectNodes("//*[namespace-uri(.)='" + ns + "']").iterator();
    Element element;
    while (nodes.hasNext()) {
        element = (Element) nodes.next();
        element.setQName(QName.get(element.getName()));
    }

    // Build necessary elements
    Element wga = (Element) doc.selectSingleNode("wga");

    // Licenses
    Element licenses = WGUtils.getOrCreateElement(wga, "licenses");
    Iterator licenseTags = licenses.elements("authorlicense").iterator();
    while (licenseTags.hasNext()) {
        Element licenseTag = (Element) licenseTags.next();
        //WGUtils.getOrCreateAttribute(licenseTag, "type", "WGA.Client");
        // B0000486E
        licenseTag.addAttribute("type", "WGA.Client");
    }

    // administrators
    WGUtils.getOrCreateElement(wga, "administrators");

    // configuration
    Element configuration = WGUtils.getOrCreateElement(wga, "configuration");
    Element defaultdb = WGUtils.getOrCreateElement(configuration, "defaultdb");
    WGUtils.getOrCreateAttribute(defaultdb, "key", "");
    WGUtils.getOrCreateAttribute(defaultdb, "favicon", "");
    WGUtils.getOrCreateAttribute(defaultdb, "datacache", "10000");
    WGUtils.getOrCreateAttribute(defaultdb, "staticexpiration", "10");

    Element features = WGUtils.getOrCreateElement(configuration, "features");
    WGUtils.getOrCreateAttribute(features, "bi", "true");
    WGUtils.getOrCreateAttribute(features, "adminpage", "true");
    WGUtils.getOrCreateAttribute(features, "manager", "true");
    WGUtils.getOrCreateAttribute(features, "startpage", "true");
    WGUtils.getOrCreateAttribute(features, "webdav", "true");
    WGUtils.getOrCreateAttribute(features, "webservice", "true");
    WGUtils.getOrCreateAttribute(features, "adminport", "");
    WGUtils.getOrCreateAttribute(features, "authoringport", "");
    WGUtils.getOrCreateAttribute(features, "clusterport", "");

    Element warnings = WGUtils.getOrCreateElement(configuration, "warnings");
    WGUtils.getOrCreateAttribute(warnings, "enabled", "true");
    WGUtils.getOrCreateAttribute(warnings, "consoleOutput", "false");
    WGUtils.getOrCreateAttribute(warnings, "pageOutput", "true");

    Element tml = WGUtils.getOrCreateElement(configuration, "tml");
    WGUtils.getOrCreateAttribute(tml, "characterEncoding", "");
    WGUtils.getOrCreateAttribute(tml, "linkEncoding", "UTF-8");
    Element tmlheader = WGUtils.getOrCreateElement(tml, "tmlheader");
    WGUtils.getOrCreateAttribute(tmlheader, "buffer", "8kb");

    Element authoringconfig = WGUtils.getOrCreateElement(configuration, "authoringconfig");
    WGUtils.getOrCreateAttribute(authoringconfig, "dbfile", "");

    Element applog = WGUtils.getOrCreateElement(configuration, "applog");
    WGUtils.getOrCreateAttribute(applog, "level", "INFO");
    WGUtils.getOrCreateAttribute(applog, "logserver", "false");

    Element compression = WGUtils.getOrCreateElement(configuration, "compression");
    WGUtils.getOrCreateAttribute(compression, "enabled", "false");

    Element listeners = WGUtils.getOrCreateElement(configuration, "listeners");

    Element lucene = WGUtils.getOrCreateElement(configuration, "lucene");
    WGUtils.getOrCreateAttribute(lucene, "dir", "");
    WGUtils.getOrCreateAttribute(lucene, "enabled", "false");
    WGUtils.getOrCreateAttribute(lucene, "booleanQueryMaxClauseCount", "1024");
    WGUtils.getOrCreateAttribute(lucene, "maxDocsPerDBSession", "50");

    // read old lucene enabled dbs
    Attribute dbs = WGUtils.getOrCreateAttribute(lucene, "dbs", "");
    List oldLuceneEnabledDBKeys = WGUtils.deserializeCollection(dbs.getText(), ",");
    // remove old attribute for lucene enabled dbs
    lucene.remove(dbs);

    Element persoconfig = WGUtils.getOrCreateElement(configuration, "personalisation");

    // Element for TestCore - config
    Element testcore = WGUtils.getOrCreateElement(configuration, "testcore");
    WGUtils.getOrCreateAttribute(testcore, "dir", "");
    WGUtils.getOrCreateAttribute(testcore, "enabled", "false");

    Element design = WGUtils.getOrCreateElement(configuration, "designsync");
    WGUtils.getOrCreateAttribute(design, "fileEncoding", "");
    WGUtils.getOrCreateAttribute(design, "interval", "1");
    WGUtils.getOrCreateAttribute(design, "throttling", "false");
    WGUtils.getOrCreateAttribute(design, "throttlingactivation", "10");

    Element jdbcDrivers = WGUtils.getOrCreateElement(configuration, "jdbcdrivers");

    WGUtils.getOrCreateElement(configuration, "defaultdboptions");
    WGUtils.getOrCreateElement(configuration, "defaultpublisheroptions");

    Element mailConfig = WGUtils.getOrCreateElement(configuration, "mailconfig");
    WGUtils.getOrCreateAttribute(mailConfig, "mailHost", "");
    WGUtils.getOrCreateAttribute(mailConfig, "mailUser", "");
    WGUtils.getOrCreateAttribute(mailConfig, "mailPassword", "");
    WGUtils.getOrCreateAttribute(mailConfig, "mailFrom", "");
    WGUtils.getOrCreateAttribute(mailConfig, "mailTo", "");
    WGUtils.getOrCreateAttribute(mailConfig, "mailWGARootURL", "");
    WGUtils.getOrCreateAttribute(mailConfig, "useAsDefaultForWF", "false");
    WGUtils.getOrCreateAttribute(mailConfig, "enableAdminNotifications", "true");

    // Mappings
    Element mappings = WGUtils.getOrCreateElement(wga, "mappings");
    Attribute mappingLibraries = WGUtils.getOrCreateAttribute(mappings, "libraries", "");

    Element elementmappings = WGUtils.getOrCreateElement(mappings, "elementmappings");
    if (elementmappings.attribute("libraries") != null && mappingLibraries.getText().equals("")) {
        mappingLibraries.setText(elementmappings.attributeValue("libraries", ""));
        elementmappings.remove(elementmappings.attribute("libraries"));
    }

    List elementsToRemove = new ArrayList();
    Iterator elementmappingTags = elementmappings.selectNodes("elementmapping").iterator();
    while (elementmappingTags.hasNext()) {
        Element elementmapping = (Element) elementmappingTags.next();
        if (elementmapping.attribute("binary") != null) {
            elementmapping.remove(elementmapping.attribute("binary"));
        }
        // remove old FOP implementation reference (F000040EE)
        String implClass = elementmapping.attributeValue("class", null);
        if (implClass != null && implClass.equals("de.innovationgate.wgpublisher.webtml.elements.FOP")) {
            elementsToRemove.add(elementmapping);
        }
    }
    Iterator toRemove = elementsToRemove.iterator();
    while (toRemove.hasNext()) {
        Element elementmapping = (Element) toRemove.next();
        elementmappings.remove(elementmapping);
    }

    Element mediamappings = WGUtils.getOrCreateElement(mappings, "mediamappings");
    Iterator mediamappingTags = mediamappings.selectNodes("mediamapping").iterator();
    while (mediamappingTags.hasNext()) {
        Element mediamapping = (Element) mediamappingTags.next();
        WGUtils.getOrCreateAttribute(mediamapping, "binary", "false");
        WGUtils.getOrCreateAttribute(mediamapping, "httplogin", "false");
    }

    WGUtils.getOrCreateElement(mappings, "encodermappings");
    WGUtils.getOrCreateElement(mappings, "syncmappings");

    Element analyzermappings = WGUtils.getOrCreateElement(mappings, "analyzermappings");
    WGUtils.getOrCreateAttribute(analyzermappings, "defaultAnalyzerClass",
            "de.innovationgate.wgpublisher.lucene.analysis.StandardAnalyzer");

    removeDefaultFileHandlerMappings(WGUtils.getOrCreateElement(mappings, "filehandlermappings"));

    WGUtils.getOrCreateElement(mappings, "filtermappings");

    Element scheduler = WGUtils.getOrCreateElement(wga, "scheduler");
    WGUtils.getOrCreateAttribute(scheduler, "loggingdir", "");

    // Domains
    Element domains = WGUtils.getOrCreateElement(wga, "domains");
    Iterator domainsIt = domains.elementIterator("domain");
    while (domainsIt.hasNext()) {
        Element domain = (Element) domainsIt.next();
        WGUtils.getOrCreateAttribute(domain, "name", "");
        WGUtils.getOrCreateAttribute(domain, "loginattempts", "5");
        WGUtils.getOrCreateAttribute(domain, "defaultmanager", "");
        Element login = WGUtils.getOrCreateElement(domain, "login");
        WGUtils.getOrCreateAttribute(login, "mode", "user");
        WGUtils.getOrCreateAttribute(login, "username", "");
        WGUtils.getOrCreateAttribute(login, "password", "");
        Element errorpage = WGUtils.getOrCreateElement(domain, "errorpage");
        WGUtils.getOrCreateAttribute(errorpage, "enabled", "false");
        WGUtils.getOrCreateElement(domain, "defaultdboptions");
        WGUtils.getOrCreateElement(domain, "defaultpublisheroptions");
    }

    // content dbs
    Element contentdbs = WGUtils.getOrCreateElement(wga, "contentdbs");
    Iterator contentdbTags = contentdbs.selectNodes("contentdb").iterator();
    Set usedDomains = new HashSet();
    while (contentdbTags.hasNext()) {
        Element contentdb = (Element) contentdbTags.next();
        WGUtils.getOrCreateAttribute(contentdb, "enabled", "true");
        WGUtils.getOrCreateAttribute(contentdb, "lazyconnect", "false");

        Element type = WGUtils.getOrCreateElement(contentdb, "type");
        String typeName = type.getStringValue();
        if (typeName.equals("de.innovationgate.webgate.api.domino.local.WGDatabaseImpl")) {
            type.setText("de.innovationgate.webgate.api.domino.WGDatabaseImpl");
        }

        boolean isFullContentStore = false;
        DbType dbType = DbType.getByImplClass(DbType.GENTYPE_CONTENT, typeName);
        if (dbType != null) {
            isFullContentStore = dbType.isFullContentStore();
        }

        //lowercase dbkey
        Element dbkey = WGUtils.getOrCreateElement(contentdb, "dbkey");
        dbkey.setText(dbkey.getText().trim().toLowerCase());

        WGUtils.getOrCreateElement(contentdb, "title");
        Element domain = WGUtils.getOrCreateElement(contentdb, "domain");
        String domainStr = domain.getTextTrim();
        if (domainStr.equals("")) {
            domainStr = "masterloginonly";
            domain.setText("masterloginonly");
        }
        usedDomains.add(domainStr);
        WGUtils.getOrCreateElement(contentdb, "login");

        Element dboptions = WGUtils.getOrCreateElement(contentdb, "dboptions");
        Iterator options = dboptions.selectNodes("option").iterator();
        Element option;
        String optionName;
        while (options.hasNext()) {
            option = (Element) options.next();
            optionName = option.attributeValue("name");
            if (optionName.indexOf(":") != -1) {
                option.addAttribute("name", optionName.substring(optionName.indexOf(":") + 1));
            }
        }

        WGUtils.getOrCreateElement(contentdb, "publisheroptions");
        WGUtils.getOrCreateElement(contentdb, "storedqueries");
        WGUtils.getOrCreateElement(contentdb, "fieldmappings");

        if (isFullContentStore) {
            WGUtils.getOrCreateElement(contentdb, "shares");
        } else {
            if (contentdb.element("shares") != null) {
                contentdb.remove(contentdb.element("shares"));
            }
        }

        Element cache = WGUtils.getOrCreateElement(contentdb, "cache");
        WGUtils.getOrCreateAttribute(cache, "type", "de.innovationgate.wgpublisher.cache.WGACacheHSQLDB");
        WGUtils.getOrCreateAttribute(cache, "path", "");
        WGUtils.getOrCreateAttribute(cache, "maxpages", "5000");

        // Design - Migrate old designsync element
        Element designsync = contentdb.element("designsync");
        design = contentdb.element("design");
        if (designsync != null && design == null) {
            design = contentdb.addElement("design");
            if (designsync.attributeValue("enabled", "false").equals("true")) {
                design.addAttribute("provider", "sync");
            } else {
                design.addAttribute("provider", "none");
            }
            design.addAttribute("mode", designsync.attributeValue("mode", ""));
            design.addAttribute("key", designsync.attributeValue("key", ""));
            design.setText(designsync.getText());
        } else {
            design = WGUtils.getOrCreateElement(contentdb, "design");
            WGUtils.getOrCreateAttribute(design, "provider", "none");
            WGUtils.getOrCreateAttribute(design, "mode", "");
            WGUtils.getOrCreateAttribute(design, "key", "");
        }

        // create default lucene config for old enabled dbs
        if (oldLuceneEnabledDBKeys.contains(dbkey.getText().toLowerCase())) {
            Element luceneDBConfig = WGUtils.getOrCreateElement(contentdb, "lucene");
            WGUtils.getOrCreateAttribute(luceneDBConfig, "enabled", "true");
            WGUtils.getOrCreateElement(luceneDBConfig, "itemrules");
            // create defaultrule
            LuceneIndexItemRule.addDefaultRule(luceneDBConfig);
        }

        //lucene config per db
        Element luceneDBConfig = WGUtils.getOrCreateElement(contentdb, "lucene");
        WGUtils.getOrCreateAttribute(luceneDBConfig, "enabled", "false");
        WGUtils.getOrCreateElement(luceneDBConfig, "itemrules");
        //check for default rule
        ArrayList rules = (ArrayList) LuceneIndexItemRule.getRules(luceneDBConfig);
        if (rules.size() > 0) {
            //check if last rule is defaultrule
            LuceneIndexItemRule checkDefaultRule = (LuceneIndexItemRule) rules.get(rules.size() - 1);
            if (!checkDefaultRule.getItemExpression().equals(LuceneIndexItemRule.EXPRESSION_WILDCARD)) {
                //last rule is no defaultRule, create defaultRule
                LuceneIndexItemRule.addDefaultRule(luceneDBConfig);
            }
        } else {
            //no rules present, create defaultRule
            LuceneIndexItemRule.addDefaultRule(luceneDBConfig);
        }
        // lucene file rules
        WGUtils.getOrCreateElement(luceneDBConfig, "filerules");
        //check for default filerule
        rules = (ArrayList) LuceneIndexFileRule.getRules(luceneDBConfig);
        if (rules.size() > 0) {
            //check if last rule is defaultrule
            LuceneIndexFileRule checkDefaultRule = (LuceneIndexFileRule) rules.get(rules.size() - 1);
            if (!checkDefaultRule.isDefaultRule()) {
                //last rule is no defaultRule, create defaultRule
                LuceneIndexFileRule.addDefaultRule(luceneDBConfig);
            }
        } else {
            //no rules present, create defaultRule
            LuceneIndexFileRule.addDefaultRule(luceneDBConfig);
        }

        // client restrictions
        Element clientRestrictions = WGUtils.getOrCreateElement(contentdb, "clientrestrictions");
        WGUtils.getOrCreateAttribute(clientRestrictions, "enabled", "false");
        WGUtils.getOrCreateElement(clientRestrictions, "restrictions");
    }

    // Personalisation dbs
    Element persodbs = WGUtils.getOrCreateElement(wga, "personalisationdbs");
    Iterator persodbTags = persodbs.selectNodes("personalisationdb").iterator();
    while (persodbTags.hasNext()) {
        Element persodb = (Element) persodbTags.next();
        WGUtils.getOrCreateAttribute(persodb, "enabled", "true");
        WGUtils.getOrCreateAttribute(persodb, "lazyconnect", "false");

        Element type = WGUtils.getOrCreateElement(persodb, "type");
        if (type.getStringValue().equals("de.innovationgate.webgate.api.domino.local.WGDatabaseImpl")) {
            type.setText("de.innovationgate.webgate.api.domino.WGDatabaseImpl");
        }

        Element domain = WGUtils.getOrCreateElement(persodb, "domain");
        String domainStr = domain.getTextTrim();
        if (domainStr.equals("")) {
            domainStr = "masterloginonly";
            domain.setText("masterloginonly");
        }
        usedDomains.add(domainStr);
        WGUtils.getOrCreateElement(persodb, "login");

        Element persConfig = WGUtils.getOrCreateElement(persodb, "persconfig");
        WGUtils.getOrCreateAttribute(persConfig, "mode", "auto");
        WGUtils.getOrCreateAttribute(persConfig, "statistics", "off");

        Element dboptions = WGUtils.getOrCreateElement(persodb, "dboptions");
        Iterator options = dboptions.selectNodes("option").iterator();
        Element option;
        String optionName;
        while (options.hasNext()) {
            option = (Element) options.next();
            optionName = option.attributeValue("name");
            if (optionName.indexOf(":") != -1) {
                option.addAttribute("name", optionName.substring(optionName.indexOf(":") + 1));
            }
        }

        WGUtils.getOrCreateElement(persodb, "publisheroptions");
    }

    //  **** Post-Processings **** 

    // Turn stored queries into CDATA-Sections
    List queries = doc.selectNodes("/wga/contentdbs/contentdb/storedqueries/storedquery/query");
    for (Iterator iter = queries.iterator(); iter.hasNext();) {
        Element query = (Element) iter.next();
        Node text = query.selectSingleNode("text()");
        if (text != null && text instanceof Text) {
            query.addCDATA(text.getText());
            query.remove(text);
        }
    }

    // Create domains from database definitions
    Iterator usedDomainsIt = usedDomains.iterator();
    String usedDomain;
    while (usedDomainsIt.hasNext()) {
        usedDomain = (String) usedDomainsIt.next();
        Element domain = (Element) domains.selectSingleNode("domain[@name='" + usedDomain + "']");
        if (domain == null) {
            domain = domains.addElement("domain");
            domain.addAttribute("name", usedDomain);
            Element login = domain.addElement("login");
            if (usedDomain.equals("masterloginonly")) {
                login.addAttribute("mode", "master");
            } else {
                login.addAttribute("mode", "user");
            }
            login.addAttribute("username", "");
            login.addAttribute("password", "");
            Element errorPage = domain.addElement("errorpage");
            errorPage.addAttribute("enabled", "false");
            Element defDBOptions = domain.addElement("defaultdboptions");
            Element defPublisherOptions = domain.addElement("defaultpublisheroptions");
        }
    }

    // Reorder content dbs, so design providers are first
    pullupDesignProviders(doc);
}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.IQ.java

License:Open Source License

/**
 * Deletes the first element whose element name and namespace matches the specified
 * element name and namespace in this packet's child element. If the
 * IQ packet does not have a child element then this method does nothing and returns
 * <tt>false</tt>.<p>//ww w.jav  a2 s. c  om
 *
 * Notice that this method may remove any child element that matches the specified
 * element name and namespace even if that element was not added to the Packet using a
 * {@link PacketExtension}.<p>
 *
 * Note: packet extensions on IQ packets are only for use in specialized situations.
 * In most cases, you should only need to set the child element of the IQ.
 *
 * @param name the child element name.
 * @param namespace the child element namespace.
 * @return true if a child element was removed.
 */
@SuppressWarnings("unchecked")
public boolean deleteExtension(String name, String namespace) {
    Element childElement = getChildElement();
    if (childElement == null) {
        return false;
    }
    // Delete extensions in the child element
    List<Element> extensions = childElement.elements(QName.get(name, namespace));
    if (!extensions.isEmpty()) {
        childElement.remove(extensions.get(0));
        return true;
    }
    return false;
}