Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

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

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:de.fmaul.android.cmis.repo.CmisPropertyTypeDefinition.java

License:Apache License

public static CmisPropertyTypeDefinition createFromElement(Element propElement) {
    CmisPropertyTypeDefinition cpd = new CmisPropertyTypeDefinition();

    cpd.id = propElement.elementText("id");
    cpd.localName = propElement.elementText("localName");
    cpd.localNamespace = propElement.elementText("localNamespace");
    cpd.displayName = propElement.elementText("displayName");
    cpd.queryName = propElement.elementText("queryName");
    cpd.description = propElement.elementText("description");
    cpd.propertyType = propElement.elementText("propertyType");
    cpd.cardinality = propElement.elementText("cardinality");
    cpd.updatability = propElement.elementText("updatability");
    cpd.inherited = Boolean.parseBoolean(propElement.elementText("inherited"));
    cpd.required = Boolean.parseBoolean(propElement.elementText("required"));
    cpd.queryable = Boolean.parseBoolean(propElement.elementText("queryable"));
    cpd.orderable = Boolean.parseBoolean(propElement.elementText("orderable"));
    cpd.openChoice = Boolean.parseBoolean(propElement.elementText("openChoice"));

    return cpd;//  w ww  .j av  a  2  s  . c  o m
}

From source file:de.fmaul.android.cmis.utils.FeedUtils.java

License:Apache License

public static String getCollectionUrlFromRepoFeed(String type, Element workspace) {
    if (workspace != null) {

        List<Element> collections = workspace.elements("collection");

        for (Element collection : collections) {
            String currentType = collection.elementText(CMISRA_COLLECTION_TYPE);
            if (type.equals(currentType.toLowerCase())) {
                return collection.attributeValue("href");
            }//from  w  ww.  j  a va  2 s .c  o  m
        }
    }
    return "";
}

From source file:de.fmaul.android.cmis.utils.FeedUtils.java

License:Apache License

public static String getUriTemplateFromRepoFeed(String type, Element workspace) {

    List<Element> templates = workspace.elements(CMISRA_URI_TEMPLATE);

    for (Element template : templates) {
        String currentType = template.elementText(CMISRA_TYPE);
        if (type.equals(currentType.toLowerCase())) {
            return template.elementText(CMISRA_TEMPLATE);
        }//from  www .ja  va2 s.  c  om
    }
    return null;
}

From source file:de.fmaul.android.cmis.utils.FeedUtils.java

License:Apache License

public static Map<String, CmisProperty> getCmisPropertiesForEntry(Element feedEntry) {
    Map<String, CmisProperty> props = new HashMap<String, CmisProperty>();

    Element objectElement = feedEntry.element(CMISRA_OBJECT);
    if (objectElement != null) {
        Element properitesElement = objectElement.element(CMIS_PROPERTIES);
        if (properitesElement != null) {
            List<Element> properties = properitesElement.elements();

            for (Element property : properties) {
                final String id = property.attributeValue("propertyDefinitionId");

                props.put(id, new CmisProperty(property.getName(), id, property.attributeValue("localName"),
                        property.attributeValue("displayName"), property.elementText(CMIS_VALUE)));
            }//from  w w w  .ja v  a2s  .  co m
        }
    }
    return props;
}

From source file:de.innovationgate.wga.common.beans.csconfig.v1.CSConfig.java

License:Apache License

/**
 * Tries to determine the minimum WGA version of the given csconfig.xml data.
 * Fails silently if something goes wrong.
 * @param in The data of the csconfig.xml
 * @return A string describing the target version of the csconfig.xml
 *//*  w w  w. j a va 2s .  com*/
public static String determineMinimumWGAVersion(InputStream in) {
    String version = "(unknown)";
    try {
        Document doc = (new SAXReader()).read(in);
        Element wgaVersionElement = (Element) doc.selectSingleNode("//minimumWGAVersion");
        version = wgaVersionElement.elementText("majorVersion") + "."
                + wgaVersionElement.elementText("minorVersion") + "."
                + wgaVersionElement.elementText("maintenanceVersion");
    } catch (Exception ee) {
    }
    return version;
}

From source file:de.innovationgate.wga.config.WGAConfigurationMigrator.java

License:Apache License

private static void addPersonalisationDB(WGAConfiguration config, Element persDBElement, DatabaseServer server,
        MigrationResult migrationResult, String dbPath) {
    // default props for all content dbs (full cs && custom)
    String type = persDBElement.elementText("type");
    String domain = persDBElement.elementText("domain");
    boolean enabled = Boolean.parseBoolean(persDBElement.attributeValue("enabled"));
    boolean lazy = Boolean.parseBoolean(persDBElement.attributeValue("lazyconnect"));
    if (dbPath == null) {
        dbPath = persDBElement.elementText("dbpath");
        // create relative path if dbserver defines one
        String serverPath = server.getOptions().get(DatabaseServer.OPTION_PATH);
        if (serverPath != null) {
            int relativeDbPathStart = dbPath.indexOf(serverPath);
            if (relativeDbPathStart != -1) {
                relativeDbPathStart += serverPath.length();
                dbPath = dbPath.substring(relativeDbPathStart + 1);
            }//from w  ww. ja v a 2  s . co  m
        }
    }
    PersonalisationDatabase persDB = new PersonalisationDatabase(server.getUid(), type);
    persDB.getDatabaseOptions().put(Database.OPTION_PATH, dbPath);
    migrateOptions(persDB, persDBElement, migrationResult);

    // lookup domain by title since domain has a uid
    Domain domainConfig = null;
    Iterator<Domain> domains = config.getDomains().iterator();
    while (domains.hasNext()) {
        Domain tempDomainConfig = domains.next();
        if (tempDomainConfig.getName() != null && tempDomainConfig.getName().equalsIgnoreCase(domain)) {
            domainConfig = tempDomainConfig;
            break;
        }
    }
    if (domainConfig != null) {
        domainConfig.setPersonalisation(persDB);
    } else {
        migrationResult.logError(
                "Unable to migrate personalisation db for domain '" + domain + "' bc. domain does not exist.");
    }
}

From source file:de.innovationgate.wga.config.WGAConfigurationMigrator.java

License:Apache License

private static String determineUser(Element contentDBElement) {
    Element login = contentDBElement.element("login");
    String user = null;/*from   www.j a  v  a2 s  . c o m*/

    // first try retrieve user from db
    if (login != null) {
        String value = login.attributeValue("username");
        if (value != null && !value.trim().equalsIgnoreCase("")) {
            user = value;
        }
    }

    // second try retrieve user from domain
    if (user == null) {
        String domain = contentDBElement.elementText("domain");
        if (domain != null) {
            Element domainsElement = contentDBElement.getParent().getParent().element("domains");
            List domainElements = domainsElement.selectNodes("domain[@name='" + domain + "']");
            if (domainElements.size() > 0) {
                Element domainElement = (Element) domainElements.get(0);
                login = domainElement.element("login");
                if (login != null) {
                    String value = login.attributeValue("username");
                    if (value != null && !value.trim().equalsIgnoreCase("")) {
                        user = value;
                    }
                }

            }
        }
    }

    return user;
}

From source file:de.innovationgate.wga.config.WGAConfigurationMigrator.java

License:Apache License

private static String determinePassword(Element contentDBElement) {
    Element login = contentDBElement.element("login");
    String password = null;// w ww .  jav  a2s  .c  om

    // first try retrieve user from db
    if (login != null) {
        String value = login.attributeValue("password");
        if (value != null && !value.trim().equalsIgnoreCase("")) {
            password = value;
        }
    }

    // second try retrieve user from domain
    if (password == null) {
        String domain = contentDBElement.elementText("domain");
        if (domain != null) {
            Element domainsElement = contentDBElement.getParent().getParent().element("domains");
            List domainElements = domainsElement.selectNodes("domain[@name='" + domain + "']");
            if (domainElements.size() > 0) {
                Element domainElement = (Element) domainElements.get(0);
                login = domainElement.element("login");
                if (login != null) {
                    String value = login.attributeValue("password");
                    if (value != null && !value.trim().equalsIgnoreCase("")) {
                        password = value;
                    }
                }

            }
        }
    }

    return password;
}

From source file:de.innovationgate.wga.config.WGAConfigurationMigrator.java

License:Apache License

private static void addContentDB(WGAConfiguration config, Element contentDBElement, DatabaseServer server,
        MigrationResult migrationResult, String configPath, DesignSource fsDesignSource, String dbPath) {
    // default props for all content dbs (full cs && custom)
    String type = contentDBElement.elementText("type");
    String dbkey = contentDBElement.elementText("dbkey");
    String sDomain = contentDBElement.elementText("domain");

    // find domain by old key (title)
    Domain domain = null;//  w w  w. j  a v a2s.co m
    Iterator<Domain> domains = config.getDomains().iterator();
    while (domains.hasNext()) {
        domain = domains.next();
        if (domain.getName() != null && domain.getName().equalsIgnoreCase(sDomain)) {
            break;
        } else {
            domain = null;
        }
    }
    if (domain == null) {
        migrationResult.logWarning("Domain '" + sDomain + "' not found. Adding content database '" + dbkey
                + "' to default domain.");
        domain = config.getDefaultDomain();
    }

    String title = contentDBElement.elementText("title");
    boolean enabled = Boolean.parseBoolean(contentDBElement.attributeValue("enabled"));
    boolean lazy = Boolean.parseBoolean(contentDBElement.attributeValue("lazyconnect"));

    if (FULL_CONTENT_STORE_IMPLEMENTATIONS.contains(type)) {
        // migrate full cs

        // determine default language - fallback to current system locale
        String defaultLang = Locale.getDefault().getLanguage();
        List defaultLangOptions = contentDBElement.element("dboptions")
                .selectNodes("option[@name='DefaultLanguage']");
        if (defaultLangOptions.size() > 0) {
            defaultLang = ((Element) defaultLangOptions.get(0)).attributeValue("value");
        } else {
            migrationResult.logWarning("DefaultLanguage was not defined on db '" + dbkey
                    + "' using current system locale '" + defaultLang + "' as default language.");
        }

        ContentStore cs = new ContentStore(server.getUid(), domain.getUid(), type, dbkey, defaultLang);
        cs.setTitle(title);
        cs.setEnabled(enabled);
        cs.setLazyConnecting(lazy);
        cs.getDatabaseOptions().put(Database.OPTION_PATH, dbPath);

        // determine design
        migrateDesign(contentDBElement, cs, config, configPath, fsDesignSource, migrationResult);

        // options
        migrateOptions(cs, contentDBElement, migrationResult);

        migrateClientRestrictions(cs, contentDBElement);

        // stored queries are not supported anymore - log warnings
        Iterator storedQueries = contentDBElement.element("storedqueries").elementIterator();
        if (storedQueries.hasNext()) {
            migrationResult.logWarning("Database '" + dbkey
                    + "' defines stored queries. This feature is not supported anymore and will not be migrated.");
        }

        // migrate item & meta mappings
        Iterator itemMappings = contentDBElement.element("fieldmappings").elementIterator();
        while (itemMappings.hasNext()) {
            Element mapping = (Element) itemMappings.next();
            String mappingType = null;
            if (mapping.getName().equals("itemmapping")) {
                mappingType = FieldMapping.TYPE_ITEM;
            } else {
                mappingType = FieldMapping.TYPE_META;
            }
            FieldMapping fieldMapping = new FieldMapping(mappingType, mapping.attributeValue("name"),
                    mapping.attributeValue("expression"));
            cs.getFieldMappings().add(fieldMapping);
        }

        // migrate lucene config
        Element lucene = contentDBElement.element("lucene");
        LuceneIndexConfiguration luceneConfig = cs.getLuceneIndexConfiguration();
        luceneConfig.setEnabled(Boolean.parseBoolean(lucene.attributeValue("enabled", "false")));
        Iterator itemRules = lucene.element("itemrules").elementIterator("itemrule");
        while (itemRules.hasNext()) {
            Element itemRuleElement = (Element) itemRules.next();
            String ruleExpression = itemRuleElement.getTextTrim();
            if (!ruleExpression.equals(LuceneIndexItemRule.DEFAULT_RULE.getItemExpression())) {
                LuceneIndexItemRule rule = new LuceneIndexItemRule(ruleExpression,
                        itemRuleElement.attributeValue("indextype"),
                        itemRuleElement.attributeValue("contenttype"));
                rule.setSortable(Boolean.parseBoolean(itemRuleElement.attributeValue("sortable")));
                rule.setBoost(Float.parseFloat(itemRuleElement.attributeValue("boost", "1.0")));
                luceneConfig.getItemRules().add(rule);
            }
        }
        Iterator fileRules = lucene.element("filerules").elementIterator("filerule");
        while (fileRules.hasNext()) {
            Element fileRuleElement = (Element) fileRules.next();
            String ruleExpression = fileRuleElement.getTextTrim();
            if (!ruleExpression.equals(LuceneIndexFileRule.DEFAULT_RULE.getFilePattern())) {
                LuceneIndexFileRule rule = new LuceneIndexFileRule(ruleExpression);
                rule.setFileSizeLimit(Integer.parseInt(fileRuleElement.attributeValue("filesizelimit")));
                rule.setIncludedInAllContent(
                        Boolean.parseBoolean(fileRuleElement.attributeValue("includedinallcontent")));
                rule.setBoost(Float.parseFloat(fileRuleElement.attributeValue("boost", "1.0")));
                luceneConfig.getFileRules().add(rule);
            }
        }

        // Migrate WebDAV shares
        Element sharesRoot = contentDBElement.element("shares");
        if (sharesRoot != null) {
            Iterator shares = sharesRoot.elementIterator("share");
            while (shares.hasNext()) {
                Element share = (Element) shares.next();
                String name = share.attributeValue("name");
                if (!WGUtils.isEmpty(name)) {
                    name = cs.getKey() + "-" + name;
                } else {
                    name = cs.getKey();
                }

                Share newShare = new Share();
                newShare.setName(name);
                newShare.setImplClassName(
                        "de.innovationgate.enterprise.modules.contentshares.WebDAVContentShareModuleDefinition");
                newShare.getOptions().put("Database", cs.getKey());
                newShare.getOptions().put("RootType", share.attributeValue("parenttype"));
                newShare.getOptions().put("RootName", share.attributeValue("parentname"));

                String unknownCtTreatment;
                int oldCtTreatment = Integer.parseInt(share.attributeValue("unknownctmode"));
                if (oldCtTreatment == 0) {
                    unknownCtTreatment = "ignore";
                } else if (oldCtTreatment == 1) {
                    unknownCtTreatment = "folder";
                } else {
                    unknownCtTreatment = "fileorfolder";
                }
                newShare.getOptions().put("UnknownCtTreatment", unknownCtTreatment);

                newShare.getOptions().put("FolderContentType", share.attributeValue("folderct"));
                newShare.getOptions().put("FolderOperations", share.attributeValue("folderactions"));
                newShare.getOptions().put("FileContentType", share.attributeValue("filect"));
                newShare.getOptions().put("FileOperations", share.attributeValue("fileactions"));

                List options = WGUtils.deserializeCollection(share.attributeValue("options"), ",");
                if (options.contains("versioning")) {
                    newShare.getOptions().put("Versioning", "true");
                }

                config.getShares().add(newShare);
            }
        }

        config.add(cs);
    } else {

        // Transform custom types to new special types for database server
        if (type.equals(ENHANCED_JDBC_DB_CLASS)) {
            if (server.getImplClassName().equals(MYSQL_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.mysql.MySqlEnhancedQuerySource";
            } else if (server.getImplClassName().equals(HSQL_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.hsql.HsqlEnhancedQuerySource";
            } else if (server.getImplClassName().equals(ORACLE_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.oracle.OracleEnhancedQuerySource";
            }
        } else if (type.equals(QUERY_JDBC_DB_CLASS)) {
            if (server.getImplClassName().equals(MYSQL_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.mysql.MySqlQuerySource";
            } else if (server.getImplClassName().equals(HSQL_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.hsql.HsqlQuerySource";
            } else if (server.getImplClassName().equals(ORACLE_SERVER_CLASS)) {
                type = "de.innovationgate.webgate.api.oracle.OracleQuerySource";
            }
        }

        // migrate custom db
        ContentDatabase contentDB = new ContentDatabase(server.getUid(), domain.getUid(), type, dbkey);
        contentDB.setTitle(title);
        contentDB.setEnabled(enabled);
        contentDB.setLazyConnecting(lazy);
        contentDB.getDatabaseOptions().put(Database.OPTION_PATH, dbPath);
        migrateOptions(contentDB, contentDBElement, migrationResult);
        migrateClientRestrictions(contentDB, contentDBElement);
        config.add(contentDB);
    }
}

From source file:de.matzefratze123.heavyspleef.core.extension.SignExtension.java

License:Open Source License

@Override
public void unmarshal(Element element) {
    Element locationElement = element.element("location");

    World world = Bukkit.getWorld(locationElement.elementText("world"));
    int x = Integer.parseInt(locationElement.elementText("x"));
    int y = Integer.parseInt(locationElement.elementText("y"));
    int z = Integer.parseInt(locationElement.elementText("z"));
    location = new Location(world, x, y, z);
}