List of usage examples for org.dom4j QName get
public static QName get(String name)
From source file:com.zimbra.common.soap.Element.java
License:Open Source License
public QName getQName() { String uri = getNamespaceURI(mPrefix); return uri == null ? QName.get(mName) : QName.get(getQualifiedName(), uri); }
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 www.ja v a 2 s .c o 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:org.orbeon.oxf.xforms.InstanceData.java
License:Open Source License
public static QName getType(NodeInfo nodeInfo) { // Try schema or bind type final InstanceData existingInstanceData = getLocalInstanceData(nodeInfo, false); if (existingInstanceData != null) { final QName schemaOrBindType = existingInstanceData.getSchemaOrBindType(); if (schemaOrBindType != null) return schemaOrBindType; }//from w w w . j ava 2s .c o m // No type was assigned by schema or MIP, try xsi:type if (nodeInfo.getNodeKind() == org.w3c.dom.Node.ELEMENT_NODE) { // Check for xsi:type attribute // NOTE: Saxon 9 has new code to resolve such QNames final String typeQName = nodeInfo.getAttributeValue(StandardNames.XSI_TYPE); if (typeQName != null) { try { final NameChecker checker = nodeInfo.getConfiguration().getNameChecker(); final String[] parts = checker.getQNameParts(typeQName); // No prefix if (parts[0].equals("")) { return QName.get(parts[1]); } // There is a prefix, resolve it final SequenceIterator namespaceNodes = nodeInfo.iterateAxis(Axis.NAMESPACE); while (true) { final NodeInfo currentNamespaceNode = (NodeInfo) namespaceNodes.next(); if (currentNamespaceNode == null) { break; } final String prefix = currentNamespaceNode.getLocalPart(); if (prefix.equals(parts[0])) { return QName.get(parts[1], "", currentNamespaceNode.getStringValue()); } } } catch (Exception e) { throw new OXFException(e); } } } return null; }