Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:Data.Storage.java

License:Apache License

/**
 * helper for adding xml/*from   w  w w  .j a va  2 s  .c  o  m*/
 * @param path where the xml will be added
 * @param xmlData the data as an xml Element
 */
private void addXmlWithPath(ArrayList<String> path, Element xmlData) {
    boolean isXml = xmlData.elements().size() > 0;

    //set the key
    String[] thePath = new String[path.size()];
    path.toArray(thePath);

    //put either the value or an imbeded object
    if (isXml && !has(thePath)) {
        put(thePath, new Storage());
    } else {
        put(thePath, xmlData.getStringValue());
    }
    for (int i = 0; i < xmlData.attributeCount(); ++i) {
        //get attribute data
        Attribute attr = xmlData.attribute(i);

        //save attribute
        putAttribute(thePath, attr.getName(), attr.getValue());
    }

    //if it is xml need to see all children
    if (isXml) {
        recurseOverElements(path, xmlData);
    }
}

From source file:de.bps.onyx.plugin.course.nodes.iq.IQEditController.java

License:Apache License

/**
 * Update the module configuration from the qti file: read min/max/cut values
 * /*from   w w w .  ja v a2  s .c  o m*/
 * @param res
 */
public void updateModuleConfigFromQTIFile(final OLATResource res) {
    final FileResourceManager frm = FileResourceManager.getInstance();
    final File unzippedRoot = frm.unzipFileResource(res);
    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    final VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
    final VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    if (vfsQTI == null) {
        throw new AssertException("qti file did not exist even it should be guaranteed by repositor check-in "
                + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
    }
    // ensures that InputStream is closed in every case.
    final Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    if (doc == null) {
        // error reading qti file (existence check was made before)
        throw new AssertException(
                "qti file could not be read " + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
    }
    // Extract min, max and cut value
    Float minValue = null, maxValue = null, cutValue = null;
    final Element decvar = (Element) doc
            .selectSingleNode("questestinterop/assessment/outcomes_processing/outcomes/decvar");
    if (decvar != null) {
        final Attribute minval = decvar.attribute("minvalue");
        if (minval != null) {
            final String mv = minval.getValue();
            try {
                minValue = new Float(Float.parseFloat(mv));
            } catch (final NumberFormatException e1) {
                // if not correct in qti file -> ignore
            }
        }
        final Attribute maxval = decvar.attribute("maxvalue");
        if (maxval != null) {
            final String mv = maxval.getValue();
            try {
                maxValue = new Float(Float.parseFloat(mv));
            } catch (final NumberFormatException e1) {
                // if not correct in qti file -> ignore
            }
        }
        final Attribute cutval = decvar.attribute("cutvalue");
        if (cutval != null) {
            final String cv = cutval.getValue();
            try {
                cutValue = new Float(Float.parseFloat(cv));
            } catch (final NumberFormatException e1) {
                // if not correct in qti file -> ignore
            }
        }
    }
    // Put values to module configuration
    moduleConfiguration.set(CONFIG_KEY_MINSCORE, minValue);
    moduleConfiguration.set(CONFIG_KEY_MAXSCORE, maxValue);
    moduleConfiguration.set(CONFIG_KEY_CUTVALUE, cutValue);
}

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

License:Apache License

private void parseEntry(Element entry) {
    title = entry.element("title").getText();
    id = entry.element("id").getText();
    downLink = "";
    contentUrl = "";
    mimeType = "";
    author = getAuthorName(entry);//  ww w  .j  av  a  2s . c  o m
    modificationDate = getModificationDate(entry);

    Element contentElement = entry.element("content");
    if (contentElement != null) {
        contentUrl = contentElement.attributeValue("src");
        mimeType = contentElement.attributeValue("type");
        if (mimeType == null) {
            mimeType = "";
        }
    }

    for (Element link : (List<Element>) entry.elements("link")) {
        if (CmisModel.ITEM_LINK_DOWN.equals(link.attribute("rel").getText())) {
            if (link.attribute("type").getText().startsWith("application/atom+xml")) {
                downLink = link.attribute("href").getText();
            }
        } else if (CmisModel.ITEM_LINK_SELF.equals(link.attribute("rel").getText())) {
            selfUrl = link.attribute("href").getText();
        } else if (CmisModel.ITEM_LINK_UP.equals(link.attribute("rel").getText())) {
            parentUrl = link.attribute("href").getText();
        }
    }

    properties = FeedUtils.getCmisPropertiesForEntry(entry);

    if (properties.get(CmisProperty.CONTENT_STREAMLENGTH) != null) {
        size = properties.get(CmisProperty.CONTENT_STREAMLENGTH).getValue();
    } else {
        size = null;
    }
    if (properties.get(CmisProperty.FOLDER_PATH) != null) {
        path = properties.get(CmisProperty.FOLDER_PATH).getValue();
    }

    if (properties.get(CmisProperty.OBJECT_BASETYPEID) != null) {
        baseType = properties.get(CmisProperty.OBJECT_BASETYPEID).getValue();
    }

}

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

License:Apache License

/**
 * Retrieves a DOM attribute with a given name. The attribute is created if it does not yet exist
 * @param element The element containing the attribute
 * @param name The name of the attribute
 * @param defaultValue The default value of the attribute, used when it must be created
 * @return The attribute/*from  w w w  . j a  va2  s  . co  m*/
 */
public static Attribute getOrCreateAttribute(Element element, String name, String defaultValue) {

    Attribute att = element.attribute(name);
    if (att == null) {
        element.addAttribute(name, defaultValue);
        att = element.attribute(name);
    }
    return att;

}

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  ww. java 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.jwic.base.JWicRuntime.java

License:Apache License

/**
 * Read the setup document.//from  w  w  w. jav  a  2s  .com
 * @param document
 */
private void readDocument(Document document) {

    Element root = document.getRootElement();

    for (Iterator<?> it = root.elementIterator(); it.hasNext();) {
        Element node = (Element) it.next();

        String nodeName = node.getName();
        // setup a velocity-engine
        if (nodeName.equals("velocity-engine")) {

            String veId = node.attribute("id").getValue();
            Properties prop = null;
            for (Iterator<?> pi = node.elementIterator(); pi.hasNext();) {
                Element node2 = (Element) pi.next();
                if (node2.getName().equals("properties")) {
                    prop = XMLTool.getProperties(node2);
                }
            }
            // replace ${rootPath} with real path
            ConfigurationTool.insertRootPath(prop);
            VelocityEngine engine = new VelocityEngine();
            try {
                engine.init(prop);
            } catch (Exception e) {
                String msg = "Can not instanciate velocity engine '" + veId + "'";
                log.error(msg, e);
                throw new RuntimeException(msg + e, e);
            }
            velocityEngines.put(veId, engine);

        } else if (nodeName.equals("session-swap-time")) {
            sessionStoreTime = Integer.parseInt(node.getText());

        } else if (nodeName.equals("session-storage-path")) {
            setSavePath(ConfigurationTool.insertRootPath(node.getText()));

        } else if (nodeName.equals("renderer")) {
            String id = node.attribute("id").getValue();
            String type = node.attribute("type").getValue();
            String classname = node.attribute("classname").getValue();

            IControlRenderer renderer;
            try {
                renderer = (IControlRenderer) Class.forName(classname).newInstance();
            } catch (Exception e) {
                String msg = "Can not instanciate renderer '" + id + "'";
                log.error(msg, e);
                throw new RuntimeException(msg + e, e);
            }

            if (type.equals("velocity")) {
                Element nEngine = node.element("engine");
                if (nEngine != null) {
                    String engineId = nEngine.getText();
                    if (renderer instanceof BaseVelocityRenderer) {
                        BaseVelocityRenderer vr = (BaseVelocityRenderer) renderer;
                        VelocityEngine engine = velocityEngines.get(engineId);
                        if (engine == null) {
                            throw new RuntimeException("Specified velocity engine not found: " + engineId);
                        }
                        vr.setVelocityEngine(engine);
                    } else {
                        throw new RuntimeException("renderer " + id
                                + " is specified as type 'velocity' but is not instance of BaseVelocityRenderer");
                    }
                }
            }
            renderers.put(id, renderer);

        }
    }

}

From source file:de.jwic.base.XmlApplicationSetup.java

License:Apache License

/**
 * Read the document content./*  ww  w .  jav a  2  s . c  o m*/
 * @param document
 */
private void readDocument(Document document) {

    Element root = document.getRootElement();
    for (Iterator<?> it = root.elementIterator(); it.hasNext();) {
        Element node = (Element) it.next();
        String nodeName = node.getName();
        if (nodeName.equals(NODE_NAME)) {
            name = node.getText();
        } else if (nodeName.equals(NODE_CLASS)) {
            appClassName = node.getText();
        } else if (nodeName.equals(NODE_ROOTCONTROL)) {
            rootControlName = node.attribute(ATTR_NAME).getValue();
            rootControlClass = node.attribute(ATTR_CLASSNAME).getValue();
        } else if (nodeName.equals(NODE_SERIALIZABLE)) {
            String s = node.getText();
            serializable = "true".equals(s) | "1".equals(s) | "on".equals(s);
        } else if (nodeName.equals(NODE_SINGLESESSION)) {
            String s = node.getText();
            singleSession = "true".equals(s) | "1".equals(s) | "on".equals(s);
        } else if (nodeName.equals(NODE_REQUIREAUTH)) {
            String s = node.getText();
            requireAuth = "true".equals(s) | "1".equals(s) | "on".equals(s);
        } else if (nodeName.equals(NODE_USEAJAX)) {
            String s = node.getText();
            useAjaxRendering = "true".equals(s) | "1".equals(s) | "on".equals(s);
        } else if (nodeName.equals(NODE_PROPERTY)) {
            if (properties == null) {
                properties = new HashMap<String, String>();
            }
            properties.put(node.attribute(ATTR_NAME).getValue(), node.getText());
        }
    }

}

From source file:de.mwolff.command.chainbuilder.XMLChainBuilder.java

License:Open Source License

private static Map<String, String> getAttributeOfElement(final Element element) {
    final Map<String, String> attributeMap = new HashMap<>();
    for (int i = 0; i < element.attributeCount(); i++) {
        attributeMap.put(element.attribute(i).getName(), element.attribute(i).getValue());
    }/*from  w  w  w . j a v  a 2  s  .  co m*/
    return attributeMap;
}

From source file:de.r2soft.empires.framework.util.MapParser.java

License:Open Source License

public void readXML(Element root) {
    HashSet<Planet> planetary = new HashSet<Planet>();
    map = new GalaxyMap();
    Element solarSystems = root.element("SolarSystems");

    for (Iterator<Element> s = solarSystems.elementIterator(); s.hasNext();) {
        Element solarSystem = s.next();

        SolarSystem temp = new SolarSystem(null);

        Element position = solarSystem.element("Position");

        temp.setPosition(new GalaxyPosition(Integer.parseInt(position.attribute("PosX").getText()),
                Integer.parseInt(position.attribute("PosY").getText())));

        temp.setClaim(new Player(solarSystem.attribute("Owner").getText()));

        Element planets = solarSystem.element("Planets");

        for (Iterator<Element> p = planets.elementIterator(); p.hasNext();) {
            Element planet = p.next();
            planetary.add(new Planet(Float.parseFloat(planet.attribute("Distance").getValue()),
                    Float.parseFloat(planet.attribute("Size").getValue())));

        }//from  w ww  .java 2 s  .  co  m
        temp.setPlanets(planetary);

        map.addSystem(temp);
    }

    map.setVersion(0);
    map.setSize(new IntVec2(1, 2));
}

From source file:de.tud.kom.p2psim.impl.scenario.DefaultConfigurator.java

License:Open Source License

private Object createComponent(Element elem, Set<String> consAttrs) {
    if (elem.attribute(CLASS_TAG) == null)
        return null;

    Object component;//from w ww  . ja  va 2 s  . c om
    String className = getAttributeValue(elem.attribute(CLASS_TAG));
    log.debug("Create component " + className + " with element " + elem.getName());
    component = createInstance(className, getAttributeValue(elem.attribute(STATIC_CREATION_METHOD_TAG)),
            consAttrs, elem);
    if (component instanceof Configurable)
        register(elem.getName(), (Configurable) component);
    // composable can use other components
    if (component instanceof Composable) {
        log.debug("Compose composable " + component);
        ((Composable) component).compose(this);
    }
    return component;
}