List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:org.hibernate.console.ConfigurationXMLFactory.java
License:Open Source License
public Document createXML() { Document res = DocumentFactory.getInstance().createDocument(); Element root = createRoot(); res.setRootElement(root); return res; }
From source file:org.hibernate.console.ConfigurationXMLFactory.java
License:Open Source License
public Element createRoot() { if (prefs == null) { return null; }//from w w w . j a v a 2 s . com @SuppressWarnings("unused") Properties properties = prefs.getProperties(); String rootName = "undef"; //$NON-NLS-1$ Boolean jdbcConfig = Boolean.valueOf(additional.getProperty(ConfigurationXMLStrings.ISREVENG, "false")); //$NON-NLS-1$ if (jdbcConfig) { rootName = ConfigurationXMLStrings.JDBCCONFIGURATION; } else if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) { rootName = ConfigurationXMLStrings.ANNOTATIONCONFIGURATION; } else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) { rootName = ConfigurationXMLStrings.JPACONFIGURATION; } else if (prefs.getConfigurationMode().equals(ConfigurationMode.CORE)) { rootName = ConfigurationXMLStrings.CONFIGURATION; } Element root = DocumentFactory.getInstance().createElement(rootName); final ConsoleConfiguration cc2ExtractConfigXMLFile = new ConsoleConfiguration(prefs); final File configXMLFile = cc2ExtractConfigXMLFile.getConfigXMLFile(); String tmp = file2Str(configXMLFile); tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath); updateAttr(root, tmp, ConfigurationXMLStrings.CONFIGURATIONFILE); tmp = file2Str(prefs.getPropertyFile()); tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath); updateAttr(root, tmp, ConfigurationXMLStrings.PROPERTYFILE); updateAttr(root, prefs.getEntityResolverName(), ConfigurationXMLStrings.ENTITYRESOLVER); updateAttr(root, prefs.getNamingStrategy(), ConfigurationXMLStrings.NAMINGSTRATEGY); updateAttr(root, prefs.getPersistenceUnitName(), ConfigurationXMLStrings.PERSISTENCEUNIT); // very specific property, for more information -> JBIDE-6997 //updateAttr(root, additional, ConfigurationXMLStrings.PREFERBASICCOMPOSITEIDS); updateAttr(root, additional, ConfigurationXMLStrings.DETECTMANYTOMANY); updateAttr(root, additional, ConfigurationXMLStrings.DETECTONTTOONE); updateAttr(root, additional, ConfigurationXMLStrings.DETECTOPTIMISTICLOCK); updateAttr(root, additional, ConfigurationXMLStrings.PACKAGENAME); updateAttr(root, additional, ConfigurationXMLStrings.REVENGFILE); updateAttr(root, additional, ConfigurationXMLStrings.REVERSESTRATEGY); // includeMappings File[] mappingFiles = prefs.getMappingFiles(); if (mappingFiles.length > 0) { Element fileset = root.addElement("fileset"); //$NON-NLS-1$ fileset.addAttribute("dir", "."); //$NON-NLS-1$ //$NON-NLS-2$ fileset.addAttribute("id", "id"); //$NON-NLS-1$ //$NON-NLS-2$ for (int i = 0; i < mappingFiles.length; i++) { Element include = fileset.addElement("include"); //$NON-NLS-1$ tmp = mappingFiles[i].getAbsolutePath(); tmp = new Path(tmp).toString(); tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath); include.addAttribute("name", tmp); //$NON-NLS-1$ } } return root; }
From source file:org.hibernate.eclipse.launch.CodeGenXMLFactory.java
License:Open Source License
@SuppressWarnings("unchecked") protected Element createRoot() { ExporterAttributes attributes = null; try {/*from www .j a v a 2 s . com*/ attributes = new ExporterAttributes(lc); } catch (CoreException e) { // ignore } if (attributes == null) { return null; } Properties props = new Properties(); if (attributes.isReverseEngineer()) { props.setProperty(ConfigurationXMLStrings.ISREVENG, Boolean.toString(attributes.isReverseEngineer())); props.setProperty(ConfigurationXMLStrings.PACKAGENAME, attributes.getPackageName()); props.setProperty(ConfigurationXMLStrings.PREFERBASICCOMPOSITEIDS, Boolean.toString(attributes.isPreferBasicCompositeIds())); props.setProperty(ConfigurationXMLStrings.DETECTMANYTOMANY, Boolean.toString(attributes.detectManyToMany())); props.setProperty(ConfigurationXMLStrings.DETECTONTTOONE, Boolean.toString(attributes.detectOneToOne())); props.setProperty(ConfigurationXMLStrings.DETECTOPTIMISTICLOCK, Boolean.toString(attributes.detectOptimisticLock())); props.setProperty(ConfigurationXMLStrings.REVERSESTRATEGY, attributes.getRevengStrategy()); String revEngFile = getResLocation(attributes.getRevengSettings()); props.setProperty(ConfigurationXMLStrings.REVENGFILE, revEngFile); } // final IPath pathPlace2Generate = isEmpty(place2Generate) ? null : new Path(getResLocation(place2Generate)); final IPath pathWorkspacePath = isEmpty(workspacePath) ? null : new Path(getResLocation(workspacePath)); // String consoleConfigName = attributes.getConsoleConfigurationName(); ConsoleConfigurationPreferences consoleConfigPrefs = getConsoleConfigPreferences(consoleConfigName); final ConfigurationXMLFactory configurationXMLFactory = new ConfigurationXMLFactory(consoleConfigPrefs, props); configurationXMLFactory.setPlace2Generate(pathPlace2Generate); configurationXMLFactory.setWorkspacePath(pathWorkspacePath); Element rootConsoleConfig = configurationXMLFactory.createRoot(); // String defaultTargetName = "hibernateAntCodeGeneration"; //$NON-NLS-1$ Element el, root = DocumentFactory.getInstance().createElement(CodeGenerationStrings.PROJECT); root.addAttribute(CodeGenerationStrings.NAME, "CodeGen"); //$NON-NLS-1$ root.addAttribute(CodeGenerationStrings.DEFAULT, defaultTargetName); // if (!isEmpty(place2Generate)) { el = root.addElement(CodeGenerationStrings.PROPERTY); el.addAttribute(CodeGenerationStrings.NAME, varCurrentDir); el.addAttribute(CodeGenerationStrings.LOCATION, getPlace2GenerateUID()); } if (!isEmpty(workspacePath)) { el = root.addElement(CodeGenerationStrings.PROPERTY); el.addAttribute(CodeGenerationStrings.NAME, varWorkspaceDir); el.addAttribute(CodeGenerationStrings.LOCATION, getWorkspacePathUID()); } // String location = getResLocation(attributes.getOutputPath()); location = ConfigurationXMLFactory.makePathRelative(location, pathPlace2Generate, pathWorkspacePath); el = root.addElement(CodeGenerationStrings.PROPERTY); el.addAttribute(CodeGenerationStrings.NAME, varBuildDir); el.addAttribute(CodeGenerationStrings.LOCATION, location); // String hibernatePropFile = null; String generateHibernatePropeties = null; String connProfileName = consoleConfigPrefs == null ? null : consoleConfigPrefs.getConnectionProfileName(); IConnectionProfile profile = getConnectionProfile(connProfileName); boolean bPropFile = profile != null; // update property with fake tm Properties propsTmp = null; String hibernateVersion = consoleConfigPrefs == null ? "3.5" : consoleConfigPrefs.getHibernateVersion(); IService service = ServiceLookup.findService(hibernateVersion); IEnvironment environment = service.getEnvironment(); if (consoleConfigPrefs != null && consoleConfigPrefs.getPropertyFile() != null) { propsTmp = consoleConfigPrefs.getProperties(); String tmStrategy = propsTmp.getProperty(environment.getTransactionManagerStrategy()); if (tmStrategy != null && StringHelper.isEmpty(tmStrategy)) { propsTmp.setProperty(environment.getTransactionManagerStrategy(), ConfigurationFactory.FAKE_TM_LOOKUP); bPropFile = true; } } if (bPropFile) { Set<String> specialProps = new TreeSet<String>(); specialProps.add(environment.getDriver()); specialProps.add(environment.getURL()); specialProps.add(environment.getUser()); specialProps.add(environment.getPass()); specialProps.add(environment.getDialect()); // if (propsTmp == null) { propsTmp = new Properties(); } StringBuilder propFileContent = new StringBuilder(); String driverClass = getDriverClass(connProfileName); if (profile != null) { final Properties cpProperties = profile.getProperties(profile.getProviderId()); // String url = cpProperties.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID); // String user = cpProperties.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); // String pass = cpProperties.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID); // String dialectName = consoleConfigPrefs.getDialectName(); // propsTmp.setProperty(environment.getDriver(), driverClass); propsTmp.setProperty(environment.getURL(), url); propsTmp.setProperty(environment.getUser(), user); propsTmp.setProperty(environment.getPass(), pass); if (StringHelper.isNotEmpty(dialectName)) { propsTmp.setProperty(environment.getDialect(), dialectName); } } // output keys in sort order Object[] keys = propsTmp.keySet().toArray(); Arrays.sort(keys); // if (externalPropFile) { for (Object obj : keys) { addIntoPropFileContent(propFileContent, obj.toString(), propsTmp.getProperty(obj.toString())); } } else { for (Object obj : keys) { if (specialProps.contains(obj)) { el = root.addElement(CodeGenerationStrings.PROPERTY); el.addAttribute(CodeGenerationStrings.NAME, obj.toString()); el.addAttribute(CodeGenerationStrings.VALUE, propsTmp.getProperty(obj.toString())); addIntoPropFileContent(propFileContent, obj.toString()); } else { addIntoPropFileContent(propFileContent, obj.toString(), propsTmp.getProperty(obj.toString())); } } } if (externalPropFile) { hibernatePropFile = externalPropFileName; } else { hibernatePropFile = "hibernatePropFile"; //$NON-NLS-1$ el = root.addElement(CodeGenerationStrings.PROPERTY); el.addAttribute(CodeGenerationStrings.NAME, hibernatePropFile); el.addAttribute(CodeGenerationStrings.VALUE, "${java.io.tmpdir}${ant.project.name}-hibernate.properties"); //$NON-NLS-1$ // generateHibernatePropeties = "generateHibernatePropeties"; //$NON-NLS-1$ Element target = root.addElement(CodeGenerationStrings.TARGET); target.addAttribute(CodeGenerationStrings.NAME, generateHibernatePropeties); // hibernatePropFile = getVar(hibernatePropFile); Element echo = target.addElement(CodeGenerationStrings.ECHO); echo.addAttribute(CodeGenerationStrings.FILE, hibernatePropFile); echo.addText(getPropFileContentStubUID()); } propFileContentPreSave = propFileContent.toString().trim(); } // all jars from libraries should be here String toolslibID = "toolslib"; //$NON-NLS-1$ Element toolslib = root.addElement(CodeGenerationStrings.PATH); toolslib.addAttribute(CodeGenerationStrings.ID, toolslibID); final URL[] customClassPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfigPrefs); for (int i = 0; i < customClassPathURLs.length; i++) { if (customClassPathURLs[i] == null) { continue; } // what is right here: CodeGenerationStrings.PATH or CodeGenerationStrings.PATHELEMENT? // http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/hibernatetools/html/ant.html // use CodeGenerationStrings.PATH - so may be error in documentation? Element pathItem = toolslib.addElement(CodeGenerationStrings.PATH); //Element pathItem = toolslib.addElement(CodeGenerationStrings.PATHELEMENT); String strPathItem = customClassPathURLs[i].getPath(); try { strPathItem = (new java.io.File(customClassPathURLs[i].toURI())).getPath(); } catch (URISyntaxException e) { // ignore } strPathItem = new Path(strPathItem).toString(); strPathItem = ConfigurationXMLFactory.makePathRelative(strPathItem, pathPlace2Generate, pathWorkspacePath); pathItem.addAttribute(CodeGenerationStrings.LOCATION, strPathItem); } // Element target = root.addElement(CodeGenerationStrings.TARGET); target.addAttribute(CodeGenerationStrings.NAME, defaultTargetName); if (!isEmpty(generateHibernatePropeties)) { target.addAttribute(CodeGenerationStrings.DEPENDS, generateHibernatePropeties); } // Element taskdef = target.addElement(CodeGenerationStrings.TASKDEF); taskdef.addAttribute(CodeGenerationStrings.NAME, CodeGenerationStrings.HIBERNATETOOL); taskdef.addAttribute(CodeGenerationStrings.CLASSNAME, "org.hibernate.tool.ant.HibernateToolTask"); //$NON-NLS-1$ taskdef.addAttribute(CodeGenerationStrings.CLASSPATHREF, toolslibID); // Element hibernatetool = target.addElement(CodeGenerationStrings.HIBERNATETOOL); hibernatetool.addAttribute(CodeGenerationStrings.DESTDIR, getVar(varBuildDir)); if (attributes.isUseOwnTemplates()) { String templatePath = getResLocation(attributes.getTemplatePath()); hibernatetool.addAttribute(CodeGenerationStrings.TEMPLATEPATH, templatePath); } if (rootConsoleConfig != null) { if (StringHelper.isNotEmpty(hibernatePropFile)) { rootConsoleConfig.addAttribute(ConfigurationXMLStrings.PROPERTYFILE, hibernatePropFile); } // add hibernate console configuration hibernatetool.content().add(rootConsoleConfig); } // // the path there are user classes Element classpath = hibernatetool.addElement(CodeGenerationStrings.CLASSPATH); Element path = classpath.addElement(CodeGenerationStrings.PATH); path.addAttribute(CodeGenerationStrings.LOCATION, getVar(varBuildDir)); // Map<String, Map<String, AttributeDescription>> exportersDescr = ExportersXMLAttributeDescription .getExportersDescription(); Map<String, Set<String>> exportersSetSubTags = ExportersXMLAttributeDescription.getExportersSetSubTags(); // Properties globalProps = new Properties(); // obligatory global properties globalProps.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$ globalProps.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$ List<ExporterFactory> exporterFactories = attributes.getExporterFactories(); for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) { ExporterFactory ef = iter.next(); if (!ef.isEnabled(lc)) { continue; } //Map<String, ExporterProperty> defExpProps = ef.getDefaultExporterProperties(); //String expId = ef.getId(); String expDefId = ef.getExporterDefinitionId(); String expName = ef.getExporterTag(); // mapping: guiName -> AttributeDescription Map<String, AttributeDescription> attributesDescrGui = exportersDescr.get(expName); if (attributesDescrGui == null) { attributesDescrGui = new TreeMap<String, AttributeDescription>(); } // mapping: guiName -> set of sub tags Set<String> setSubTags = exportersSetSubTags.get(expName); if (setSubTags == null) { setSubTags = new TreeSet<String>(); } // construct new mapping: name -> AttributeDescription Map<String, AttributeDescription> attributesDescrAnt = new TreeMap<String, AttributeDescription>(); for (AttributeDescription ad : attributesDescrGui.values()) { attributesDescrAnt.put(ad.name, ad); } // Element exporter = hibernatetool.addElement(expName); Properties expProps = new Properties(); expProps.putAll(globalProps); expProps.putAll(ef.getProperties()); // Properties extractGUISpecial = new Properties(); try { ExporterFactory.extractExporterProperties(expDefId, expProps, extractGUISpecial); } catch (CoreException e) { // ignore } // convert gui special properties names into Ant names for (Map.Entry<Object, Object> propEntry : extractGUISpecial.entrySet()) { Object key = propEntry.getKey(); Object val = propEntry.getValue(); AttributeDescription ad = attributesDescrGui.get(key); if (ad == null) { expProps.put(key, val); continue; } expProps.put(ad.name, val); } // to add attributes and properties in alphabetic order Map<String, Object> expPropsSorted = new TreeMap<String, Object>(); for (Map.Entry<Object, Object> propEntry : expProps.entrySet()) { Object key = propEntry.getKey(); Object val = propEntry.getValue(); expPropsSorted.put(key.toString(), val); } // list2Remove - list to collect properties which put into attributes, // all other properties be ordinal property definition List<Object> list2Remove = new ArrayList<Object>(); for (Map.Entry<String, Object> propEntry : expPropsSorted.entrySet()) { Object key = propEntry.getKey(); Object val = propEntry.getValue(); AttributeDescription ad = attributesDescrAnt.get(key); if (ad == null) { continue; } list2Remove.add(key); if (val == null || 0 == val.toString().compareTo(ad.defaultValue)) { continue; } String processedVal = processPropertyValue(val); if (setSubTags.contains(ad.guiName)) { Element subTag = exporter.addElement(ad.name); subTag.addText(processedVal); } else { exporter.addAttribute(ad.name, processedVal); } } for (Object obj : list2Remove) { expProps.remove(obj); expPropsSorted.remove(obj); } for (Map.Entry<String, Object> propEntry : expPropsSorted.entrySet()) { Object key = propEntry.getKey(); Object val = propEntry.getValue(); String processedVal = processPropertyValue(val); Element property = exporter.addElement(CodeGenerationStrings.PROPERTY); property.addAttribute(CodeGenerationStrings.KEY, key.toString()); property.addAttribute(CodeGenerationStrings.VALUE, processedVal); } } return root; }
From source file:org.hibernate.internal.util.xml.XMLHelper.java
License:LGPL
public static DocumentFactory getDocumentFactory() { ClassLoader cl = ClassLoaderHelper.getContextClassLoader(); DocumentFactory factory;/*from ww w . j a v a 2s .c o m*/ try { Thread.currentThread().setContextClassLoader(XMLHelper.class.getClassLoader()); factory = DocumentFactory.getInstance(); } finally { Thread.currentThread().setContextClassLoader(cl); } return factory; }
From source file:org.itracker.web.util.ImportExportUtilities.java
License:Open Source License
private static DocumentFactory getDocumentFactory() { return DocumentFactory.getInstance(); }
From source file:org.jivesoftware.admin.AdminConsole.java
License:Open Source License
/** * Rebuilds the generated model./*from ww w .ja v a 2s . c o m*/ */ private static synchronized void rebuildModel() { Document doc = DocumentFactory.getInstance().createDocument(); generatedModel = coreModel.createCopy(); doc.add(generatedModel); // Add in all overrides. for (Element element : overrideModels.values()) { // See if global settings are overriden. Element appName = (Element) element.selectSingleNode("//adminconsole/global/appname"); if (appName != null) { Element existingAppName = (Element) generatedModel .selectSingleNode("//adminconsole/global/appname"); existingAppName.setText(appName.getText()); if (appName.attributeValue("plugin") != null) { existingAppName.addAttribute("plugin", appName.attributeValue("plugin")); } } Element appLogoImage = (Element) element.selectSingleNode("//adminconsole/global/logo-image"); if (appLogoImage != null) { Element existingLogoImage = (Element) generatedModel .selectSingleNode("//adminconsole/global/logo-image"); existingLogoImage.setText(appLogoImage.getText()); if (appLogoImage.attributeValue("plugin") != null) { existingLogoImage.addAttribute("plugin", appLogoImage.attributeValue("plugin")); } } Element appLoginImage = (Element) element.selectSingleNode("//adminconsole/global/login-image"); if (appLoginImage != null) { Element existingLoginImage = (Element) generatedModel .selectSingleNode("//adminconsole/global/login-image"); existingLoginImage.setText(appLoginImage.getText()); if (appLoginImage.attributeValue("plugin") != null) { existingLoginImage.addAttribute("plugin", appLoginImage.attributeValue("plugin")); } } Element appVersion = (Element) element.selectSingleNode("//adminconsole/global/version"); if (appVersion != null) { Element existingVersion = (Element) generatedModel .selectSingleNode("//adminconsole/global/version"); if (existingVersion != null) { existingVersion.setText(appVersion.getText()); if (appVersion.attributeValue("plugin") != null) { existingVersion.addAttribute("plugin", appVersion.attributeValue("plugin")); } } else { ((Element) generatedModel.selectSingleNode("//adminconsole/global")) .add(appVersion.createCopy()); } } // Tabs for (Object o : element.selectNodes("//tab")) { Element tab = (Element) o; String id = tab.attributeValue("id"); Element existingTab = getElemnetByID(id); // Simple case, there is no existing tab with the same id. if (existingTab == null) { // Make sure that the URL on the tab is set. If not, default to the // url of the first item. if (tab.attributeValue("url") == null) { Element firstItem = (Element) tab.selectSingleNode("//item[@url]"); if (firstItem != null) { tab.addAttribute("url", firstItem.attributeValue("url")); } } generatedModel.add(tab.createCopy()); } // More complex case -- a tab with the same id already exists. // In this case, we have to overrite only the difference between // the two elements. else { overrideTab(existingTab, tab); } } } // Special case: show a link to Clearspace admin console if it is integrated with // Openfire. if (ClearspaceManager.isEnabled()) { Element clearspace = generatedModel.addElement("tab"); clearspace.addAttribute("id", "tab-clearspace"); clearspace.addAttribute("name", LocaleUtils.getLocalizedString("tab.tab-clearspace")); clearspace.addAttribute("url", "clearspace-status.jsp"); clearspace.addAttribute("description", LocaleUtils.getLocalizedString("tab.tab-clearspace.descr")); Element sidebar = clearspace.addElement("sidebar"); sidebar.addAttribute("id", "sidebar-clearspace"); sidebar.addAttribute("name", LocaleUtils.getLocalizedString("sidebar.sidebar-clearspace")); Element statusItem = sidebar.addElement("item"); statusItem.addAttribute("id", "clearspace-status"); statusItem.addAttribute("name", LocaleUtils.getLocalizedString("sidebar.clearspace-status")); statusItem.addAttribute("url", "clearspace-status.jsp"); statusItem.addAttribute("description", LocaleUtils.getLocalizedString("sidebar.clearspace-status.descr")); Element adminItem = sidebar.addElement("item"); adminItem.addAttribute("id", "clearspace-admin"); adminItem.addAttribute("name", LocaleUtils.getLocalizedString("sidebar.clearspace-admin")); adminItem.addAttribute("url", "clearspace-admin.jsp"); adminItem.addAttribute("description", LocaleUtils.getLocalizedString("sidebar.clearspace-admin.descr")); } }
From source file:org.jivesoftware.openfire.archive.ArchiveIndexer.java
License:Open Source License
/** * Loads a property manager for search properties if it isn't already * loaded. If an XML file for the search properties isn't already * created, it will attempt to make a file with default values. *///w w w. ja v a 2s. com private void loadPropertiesFile(File searchDir) throws IOException { File indexPropertiesFile = new File(searchDir, "indexprops.xml"); // Make sure the file actually exists. If it doesn't, a new file // will be created. // If it doesn't exists we have to create it. if (!indexPropertiesFile.exists()) { org.dom4j.Document doc = DocumentFactory.getInstance() .createDocument(DocumentFactory.getInstance().createElement("search")); // Now, write out to the file. Writer out = null; try { // Use JDOM's XMLOutputter to do the writing and formatting. out = new FileWriter(indexPropertiesFile); XMLWriter outputter = new XMLWriter(out, OutputFormat.createPrettyPrint()); outputter.write(doc); outputter.flush(); } catch (Exception e) { Log.error(e.getMessage(), e); } finally { try { if (out != null) { out.close(); } } catch (Exception e) { // Ignore. } } } indexProperties = new XMLProperties(indexPropertiesFile); }
From source file:org.jivesoftware.openfire.handler.IQBlockingHandler.java
License:Open Source License
/** * Adds a collection of JIDs to the blocklist of the provided user. * * This method adds the JIDs to the default privacy list, creating a new privacy list (and setting it as default) * if the user does not have a default privacy list. * * The newly added JIDs are push on the front end of the list. The order of pre-existing list items is modified. * * @param user The owner of the blocklist to which JIDs are to be added (cannot be null). * @param toBlocks The JIDs to be added (can be null, which results in a noop). *//*w w w. j a va2 s.c o m*/ protected void addToBlockList(User user, List<JID> toBlocks) { if (toBlocks == null || toBlocks.isEmpty()) { return; } Log.debug("Obtain or create a the default privacy list for '{}'", user.getUsername()); PrivacyList defaultPrivacyList = PrivacyListManager.getInstance().getDefaultPrivacyList(user.getUsername()); if (defaultPrivacyList == null) { final Element listElement = DocumentFactory.getInstance().createDocument().addElement("list", "jabber:iq:privacy"); listElement.addAttribute("name", "blocklist"); defaultPrivacyList = PrivacyListManager.getInstance().createPrivacyList(user.getUsername(), "blocklist", listElement); PrivacyListManager.getInstance().changeDefaultList(user.getUsername(), defaultPrivacyList, null); } Log.debug("Adding {} JIDs as blocked items to the beginning of list '{}' (belonging to '{}')", toBlocks.size(), defaultPrivacyList.getName(), user.getUsername()); final Element listElement = defaultPrivacyList.asElement(); for (int i = 0; i < toBlocks.size(); i++) { final Element element = DocumentHelper.createElement("item").addAttribute("type", "jid") .addAttribute("value", toBlocks.get(i).toString()).addAttribute("action", "deny") .addAttribute("order", Integer.toString(i)); listElement.elements().add(i, element); } Log.debug( "Iterating over all items of list '{}' (belonging to '{}'), to ensure that their 'order' value is unique.", defaultPrivacyList.getName(), user.getUsername()); final List<Element> elements = listElement.elements(); for (int i = 0; i < elements.size(); i++) { elements.get(i).attribute("order").setValue(Integer.toString(i)); } defaultPrivacyList.updateList(listElement); PrivacyListProvider.getInstance().updatePrivacyList(user.getUsername(), defaultPrivacyList); }
From source file:org.mule.intents.AppBuilder.java
License:Open Source License
protected Document createMuleConfig() { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement(new QName("mule", muleNS)); root.addAttribute("version", app.getPlatformVersion()); return DocumentFactory.getInstance().createDocument(root); }
From source file:org.nuxeo.automation.scripting.blockly.converter.XMLSerializer.java
License:Open Source License
public static Element createRoot() { return DocumentFactory.getInstance().createElement(xmlTag); }