Example usage for org.dom4j Attribute setValue

List of usage examples for org.dom4j Attribute setValue

Introduction

In this page you can find the example usage for org.dom4j Attribute setValue.

Prototype

void setValue(String value);

Source Link

Document

Sets the value of this attribute or this method will throw an UnsupportedOperationException if it is read-only.

Usage

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ?//  w w w  . ja v  a  2  s  .co m
 *
 * @param document
 *            
 * @param attributeName
 *            ??????//??/@???
 *            //article/@levelarticlelevel
 * @param attributeValue
 *            
 */
public void setAttrValues(Document document, String attributeName, String attributeValue) {
    List<?> list = document.selectNodes(attributeName);
    Iterator<?> iter = list.iterator();
    while (iter.hasNext()) {
        Attribute attribute = (Attribute) iter.next();
        attribute.setValue(attributeValue);
    }
}

From source file:com.iterzp.momo.utils.SettingUtils.java

License:Open Source License

/**
 * /* www. j a  va 2s. c  om*/
 * 
 * @param setting
 *            
 */
public static void set(Setting setting) {
    try {
        File shopxxXmlFile = new ClassPathResource(CommonAttributes.MOMO_XML_PATH).getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<Element> elements = document.selectNodes("/momo/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:com.lingxiang2014.util.SettingUtils.java

License:Open Source License

public static void set(Setting setting) {
    try {/*from  w w  w .j  a v a  2  s. co  m*/
        File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<Element> elements = document.selectNodes("/shopxx/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:com.sammyun.util.SettingUtils.java

License:Open Source License

/**
 * //  ww  w .  ja v  a  2s.c  om
 * 
 * @param setting 
 */
public static void set(Setting setting) {
    try {
        File preschoolEduXmlFile = new ClassPathResource(CommonAttributes.PRESCHOOLEDU_XML_PATH).getFile();
        Document document = new SAXReader().read(preschoolEduXmlFile);
        List<Element> elements = document.selectNodes("/preschoolEdu/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();
                logger.error(e.getMessage());
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                logger.error(e.getMessage());
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
                logger.error(e.getMessage());
            }
        }

        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(preschoolEduXmlFile);
            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();
        logger.error(e.getMessage());
    }
}

From source file:com.sofrecom.MybatisGenXmlHandler.java

private void modifyJavaClientElement(Document document) {
    final Element javaClientElement = (Element) document.getRootElement()
            .selectSingleNode("/generatorConfiguration/context/javaClientGenerator");
    final Attribute targetpackage = javaClientElement.attribute("targetPackage");
    final Attribute targetProjectPath = javaClientElement.attribute("targetProject");
    targetProjectPath.setValue(Configuration.getProperty(Configuration.TargetProjectPathField));
    targetpackage.setValue(Configuration.getProperty(Configuration.JavaClientTargetPathField));
}

From source file:com.sofrecom.MybatisGenXmlHandler.java

private void modifyDriverPath(Document document) {
    final Element javaClientElement = (Element) document.getRootElement()
            .selectSingleNode("/generatorConfiguration/classPathEntry");
    final Attribute locationAttribute = javaClientElement.attribute("location");
    locationAttribute.setValue(Configuration.getProperty(Configuration.JDBCDriverPathField));
}

From source file:com.sofrecom.MybatisGenXmlHandler.java

private void modifyJavaModelElement(Document document) {
    Element javaModelGeneratorElement = (Element) document.getRootElement()
            .selectSingleNode("/generatorConfiguration/context/javaModelGenerator");
    final Attribute targetpackage = javaModelGeneratorElement.attribute("targetPackage");
    final Attribute targetProjectPath = javaModelGeneratorElement.attribute("targetProject");
    targetProjectPath.setValue(Configuration.getProperty(Configuration.TargetProjectPathField));
    targetpackage.setValue(Configuration.getProperty(Configuration.JavaModelTargetPathField));
}

From source file:com.sofrecom.MybatisGenXmlHandler.java

private void modifyJDBCElement(Document document) {
    Element javaModelGeneratorElement = (Element) document.getRootElement()
            .selectSingleNode("/generatorConfiguration/context/jdbcConnection");
    final Attribute driverClass = javaModelGeneratorElement.attribute("driverClass");
    final Attribute connectionURL = javaModelGeneratorElement.attribute("connectionURL");
    final Attribute userId = javaModelGeneratorElement.attribute("userId");
    final Attribute password = javaModelGeneratorElement.attribute("password");
    driverClass.setValue(Configuration.getProperty(Configuration.JdbcDriver));
    connectionURL.setValue(Configuration.getProperty(Configuration.DataBaseCnxUrl));
    userId.setValue(Configuration.getProperty(Configuration.DBUser));
    password.setValue(Configuration.getProperty(Configuration.DBPassword));

}

From source file:com.sofrecom.MybatisGenXmlHandler.java

private void modifyTableElement(Document document) {
    Element tableElement = (Element) document.getRootElement()
            .selectSingleNode("/generatorConfiguration/context/table");
    final Attribute tableNameAttribute = tableElement.attribute("tableName");
    tableNameAttribute.setValue(tableName);

}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Add the element to the parent branch. The min number of times to add it is determined by the element's minOccurs
 * value and the max no. of times to add it is determined by the minimum of the max repeating elements option
 * and the element's maxOccurs value/*from w  ww. ja  v  a2s .c o  m*/
 * <p/>
 * Note: the element may again be added multiple times based on its container minOccurs and maxOccurs values
 *
 * @param branch
 * @param elemToAdd
 * @param schElemOfElemToAdd
 */

private void addElement(Branch branch, Element elemToAdd, XmlSchemaElement schElemOfElemToAdd) {

    long minCount = schElemOfElemToAdd.getMinOccurs();
    long maxCount = schElemOfElemToAdd.getMaxOccurs();

    //determine how many times to add this element to the parent
    if (branch != null) {

        if (maxCount > 0) {
            long maxEls = getMaxElementsToGenerate(minCount, maxCount);

            for (long i = 1; i <= maxEls; i++) {
                if (i > minCount) { //anything > the min count but < max is optional
                    if (options.isGenCommentsForParticles()) {
                        branch.add(factory.createComment("optional"));
                    }
                }
                logger.trace("Adding dom4j element: {} to branch: {}", elemToAdd.getName(), branch.getName());
                branch.add(elemToAdd);

                elemToAdd = elemToAdd.createCopy(); //cannot add same element again, so create a copy

                //if id attr is present need to set a new value for it in the copied el
                Attribute idAttr = elemToAdd.attribute("id"); //NON-NLS
                if (idAttr != null) {
                    idAttr.setValue(SampleValueProvider.get(Constants.XSD_ID));
                }
            }
        }
    }

}