List of usage examples for org.dom4j Attribute setValue
void setValue(String value);
UnsupportedOperationException
if it is read-only. From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void invertFileFilter(String pipelineName) { List<Element> materials = materialsForPipeline(pipelineName); for (Element material : materials) { Attribute invertFile = material.attribute("invertFilter"); if (invertFile == null) { material.add(new DefaultAttribute("invertFilter", "true")); } else {/* w w w . j av a 2 s . c o m*/ invertFile.setValue("true"); } } }
From source file:com.thoughtworks.go.server.JUnitReportGenerator.java
License:Apache License
private static void setAttr(int i, Element test, final String attr) { Attribute classname = test.attribute(attr); classname.setValue(classname.getValue() + i); }
From source file:com.wabacus.config.database.datasource.ProxoolDataSource.java
License:Open Source License
private void changePassword(String configfile, boolean actiontype) { if (!configfile.toLowerCase().endsWith(".xml")) { throw new WabacusConfigLoadingException("?" + configfile + "???wabacus??.xml?proxool??"); }//w ww . j av a 2s . c o m Document doc = XmlAssistant.getInstance().loadXmlDocument(configfile); Element root = doc.getRootElement(); Element eleDriverProp = root.element("driver-properties"); if (eleDriverProp == null) return; List lstProps = eleDriverProp.elements("property"); if (lstProps == null || lstProps.size() == 0) { return; } Element elePasswordProp = null; for (int i = 0; i < lstProps.size(); i++) { if ("password".equalsIgnoreCase(((Element) lstProps.get(i)).attributeValue("name").trim())) { elePasswordProp = (Element) lstProps.get(i); } } if (elePasswordProp == null) return; String password = elePasswordProp.attributeValue("value"); password = password == null ? "" : password.trim(); if (password.equals("")) return; boolean shouldsave = false; if (actiontype) { if (DesEncryptTools.KEY_OBJ == null) return;//wabacus.cfg.xml? if (password.startsWith("{3DES}")) { if (DesEncryptTools.IS_NEWKEY) { throw new WabacusConfigLoadingException("??" + configfile + "????"); } } else if (!password.equals("")) { password = "{3DES}" + DesEncryptTools.encrypt(password); shouldsave = true; } } else { if (password.startsWith("{3DES}")) { if (DesEncryptTools.IS_NEWKEY) { throw new WabacusConfigLoadingException("??" + configfile + "????"); } if (DesEncryptTools.KEY_OBJ == null) { throw new WabacusConfigLoadingException("wabacus.cfg.xml," + configfile + "?"); } password = DesEncryptTools.decrypt(password.substring("{3DES}".length())); shouldsave = true; } } if (shouldsave) { Attribute attrPass = elePasswordProp.attribute("value"); attrPass.setValue(password); try { XmlAssistant.getInstance().saveDocumentToXmlFile(configfile, doc); } catch (IOException e) { log.warn(configfile + "????", e); } } }
From source file:com.wedian.site.common.utils.SettingUtils.java
License:Open Source License
/** * /*from ww w. java2 s . c o m*/ * * @param setting * */ public static void set(Setting setting) { try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SITE_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/site/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(shopxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.lmf.transform.XMLToDBTransformer.java
License:Apache License
@Override public void onStart(ElementPath epath) { Element el = epath.getCurrent(); String n = el.getName();/* ww w.ja va 2s . c om*/ // Remove empty attributes and invalid characters. Iterator<?> attrIter = el.attributeIterator(); while (attrIter.hasNext()) { Attribute attr = (Attribute) attrIter.next(); if ("NULL".equals(attr.getStringValue())) { attrIter.remove(); } else { attr.setValue(StringUtils.replaceNonUtf8(attr.getValue())); } } if ("LexicalResource".equals(n)) { // If no lexical resource exists yet, create a new one. if (lexicalResource == null) { lexicalResource = new LexicalResource(); lexicalResource.setName(el.attributeValue("name")); lexicalResource.setDtdVersion(el.attributeValue("dtdVersion")); session.save(lexicalResource); } else { externalLexicalResource = true; } } else if ("Lexicon".equals(n)) { // Create a new, empty lexicon. lexicon = new Lexicon(); lexicon.setId(el.attributeValue("id")); lexicon.setName(el.attributeValue("name")); lexicon.setLanguageIdentifier(el.attributeValue("languageIdentifier")); lexicalResource.addLexicon(lexicon); saveCascade(lexicon, lexicalResource); } // Save some global information if we're using a new lexical resource. else if ("GlobalInformation".equals(n) && !externalLexicalResource) { GlobalInformation glInformation = new GlobalInformation(); glInformation.setLabel(el.attributeValue("label")); lexicalResource.setGlobalInformation(glInformation); saveCascade(glInformation, lexicalResource); commit(); lexicalResource.setGlobalInformation(null); } }
From source file:gov.guilin.util.SettingUtils.java
License:Open Source License
/** * //from ww w . j a va2 s. c o m * * @param setting * */ public static void set(Setting setting) { try { File guilinXmlFile = new ClassPathResource(CommonAttributes.XML_PATH).getFile(); Document document = new SAXReader().read(guilinXmlFile); List<Element> elements = document.selectNodes("/guilin/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(guilinXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void changeImgUrl(Element autoTileElement) { List<Element> selectNodes = autoTileElement.selectNodes(".//img"); for (Element bagroundImage : selectNodes) { Attribute srcImg = bagroundImage.attribute("src"); if (!srcImg.getValue().contains(domain)) srcImg.setValue(domain + "/" + srcImg.getValue()); }/*from www .j a va 2 s .com*/ // Element bagroundImage = (Element) autoTileElement.selectSingleNode("img[1]"); }
From source file:net.groupbuy.util.SettingUtils.java
License:Open Source License
/** * /* w w w . j av a2 s . c o m*/ * * @param setting * */ public static void set(Setting setting) { try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/groupbuy/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(shopxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.osxx.util.SettingUtils.java
License:Open Source License
/** * /*from w ww .jav a 2s .c o m*/ * * @param setting * */ public static void set(Setting setting) { try { File osxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile(); Document document = new SAXReader().read(osxxXmlFile); List<Element> elements = document.selectNodes("/osxx/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(osxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
private void insertPermissionsAndInheritance(Element principalElement, RolePrincipal ppal) { Element permsRefElement = principalElement.addElement(PERMISSIONS_REF); Set perms = ppal.getPermissions(); for (Object orphanedPerm : perms) { Permission perm = (Permission) orphanedPerm; Element permRef = permsRefElement.addElement(PERMISSION_REF); //add the name attribute Attribute idAttribute = new UserDataAttribute(new QName(ID)); idAttribute.setValue("" + perm.getId()); permRef.add(idAttribute);// w w w . java2 s . c om } //role inheritance is only supported by RolePrincipal if (ppal.getDescendants().size() > 0) { Element descendants = principalElement.addElement(DESCENDANTS); //add the descendants of this role for (RolePrincipal o : ppal.getDescendants()) { Element principalRef = descendants.addElement(PRINCIPAL_REF); Attribute idAttribute = new UserDataAttribute(new QName(ID)); idAttribute.setValue("" + o.getId()); principalRef.add(idAttribute); } } }