List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.processpuzzle.address.artifact.SettlementDataLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w ww. j av a2 s. co m public void loadData() { super.loadData(); countryFactory = applicationContext.getEntityFactory(CountryFactory.class); countryRepository = applicationContext.getRepository(CountryRepository.class); settlementFactory = applicationContext.getEntityFactory(SettlementFactory.class); settlementDataSheetFactory = applicationContext.getEntityFactory(SettlementDataSheetFactory.class); settlementDataSheetRepository = applicationContext.getRepository(SettlementDataSheetRepository.class); zipCodeFactory = applicationContext.getEntityFactory(ZipCodeFactory.class); Document doc = getDocument(); Element root = doc.getRootElement(); for (Iterator<Element> i = root.elementIterator(ROOT_ELEMENT); i.hasNext();) { Element countryElement = i.next(); Attribute countryNameAttribute = countryElement.attribute(COUNTRY_NAME_ATTRIBUTE); String countryName = countryNameAttribute.getValue(); if (countryName != null && !"".equals(countryName)) { Country country = createAndSaveCountry(countryName); for (Iterator<Element> j = countryElement.elementIterator(SETTLEMENT_ELEMENT); j.hasNext();) { Element settlementElement = j.next(); String settlementName = settlementElement.attribute(SETTLEMENT_NAME_ATTRIBUTE).getValue(); if (settlementName != null && !"".equals(settlementName)) { DefaultUnitOfWork work = new DefaultUnitOfWork(true); SettlementDataSheet settlementDataSheet = null; try { settlementDataSheet = createAndSaveSettlement(work, settlementName, country); savedSettlements.add(settlementDataSheet.getSettlement()); for (Iterator<Element> k = settlementElement.elementIterator(DISTRICT_ELEMENT); k .hasNext();) { Element districtElement = k.next(); String districtName = districtElement.attribute(DISTRICT_NAME_ATTRIBUTE).getValue(); District district = settlementFactory.createDistrict(districtName, settlementDataSheet.getSettlement()); // process ZipCodes for (Iterator<Element> l = districtElement.elementIterator(ZIPCODE_ELEMENT); l .hasNext();) { Element zipCodeElement = l.next(); String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue(); ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), district); } } // process ZipCodes for (Iterator<Element> l = settlementElement.elementIterator(ZIPCODE_ELEMENT); l .hasNext();) { Element zipCodeElement = l.next(); String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue(); ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), settlementDataSheet.getSettlement()); } } catch (Exception e) { logError(e, settlementName); } finally { work.finish(); logSuccess(settlementDataSheet.getSettlement()); } } } } } }
From source file:com.processpuzzle.address.artifact.SettlementDataLoader.java
License:Open Source License
private void processZipCode(Element element, Settlement settlement) { for (Iterator<Element> l = element.elementIterator(ZIPCODE_ELEMENT); l.hasNext();) { Element zipCodeElement = l.next(); String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue(); ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), settlement); }/*from www.j a v a 2s .co m*/ }
From source file:com.processpuzzle.internalization.domain.LocaleLoader.java
License:Open Source License
private void loadCurrencyElements(Element root, ProcessPuzzleLocale locale) { if (root == null) return;/*from w ww .j a v a 2 s . c o m*/ Attribute nameAttr = root.attribute("name"); Attribute symbolAttr = root.attribute("symbol"); if (nameAttr != null && symbolAttr != null) { Unit u = measurementContext.findUnitBySymbol(symbolAttr.getValue()); if (u != null) locale.setLegalTender((Currency) u); } else return; }
From source file:com.processpuzzle.internalization.domain.LocaleLoader.java
License:Open Source License
private void loadQuantityFormatElements(Element root, ProcessPuzzleLocale locale) { if (root == null) return;/*from w w w .j a v a 2 s .c o m*/ Attribute decimalSeparatorAttribute = root.attribute("decimalSeparator"); if (decimalSeparatorAttribute != null) locale.getQuantityFormat().setDecimalSeparator(decimalSeparatorAttribute.getText().charAt(0)); Attribute groupingSeparatorAttribute = root.attribute("groupingSeparator"); if (groupingSeparatorAttribute != null) locale.getQuantityFormat().setGroupingSeparator(groupingSeparatorAttribute.getText().charAt(0)); if (groupingSeparatorAttribute != null && decimalSeparatorAttribute != null) { if (groupingSeparatorAttribute.getText().charAt(0) == decimalSeparatorAttribute.getText().charAt(0)) { throw new ProcessPuzzleParseException( Character.toString(groupingSeparatorAttribute.getText().charAt(0)) + Character.toString(decimalSeparatorAttribute.getText().charAt(0)), "Same Separators!", null); } } try { Element maxIntElement = root.element("maxIntDigits"); if (maxIntElement != null) locale.getQuantityFormat().setMaximumIntegerDigits(Integer.parseInt(maxIntElement.getText())); Element minIntElement = root.element("minIntDigits"); if (minIntElement != null) locale.getQuantityFormat().setMinimumIntegerDigits(Integer.parseInt(minIntElement.getText())); Element maxFractElement = root.element("maxFractDigits"); if (maxFractElement != null) locale.getQuantityFormat().setMaximumFractionDigits(Integer.parseInt(maxFractElement.getText())); Element minFractElement = root.element("minFractDigits"); if (minFractElement != null) locale.getQuantityFormat().setMinimumFractionDigits(Integer.parseInt(minFractElement.getText())); } catch (NumberFormatException e) { throw new XmlDataLoaderException(this, "Non-Integer values!", e); } }
From source file:com.qagen.osfe.common.utils.DomReader.java
License:Apache License
public static String getValue(Element element, String attributeName) { final Attribute attribute = element.attribute(attributeName); if (attribute == null) { return null; }//from w w w . j a v a 2 s .c o m return attribute.getValue(); }
From source file:com.qagen.osfe.programData.ConfigFileLoader.java
License:Apache License
@SuppressWarnings("unchecked") private void loadColumnInfo(final Element root) { final List<Element> elements = root.element(ELEMENT.table.name()).element(ELEMENT.columns.name()) .elements();/*from www.j a v a 2s .c om*/ columnInfoMap = new HashMap<String, ColumnInfo>(); for (Element element : elements) { final String name = element.attribute(ATTRIBUTE.name.name()).getValue(); final Boolean isString = Boolean.parseBoolean(element.attribute(ATTRIBUTE.isString.name()).getValue()); final ColumnInfo info = new ColumnInfo(name, isString); columnInfoMap.put(name, info); } }
From source file:com.sammyun.util.SettingUtils.java
License:Open Source License
/** * // www.j a va 2 s. co m * * @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.sharksharding.sql.SQLTemplate.java
License:Apache License
/** * dom4j?xml// w ww. j a va 2s . com * * @author gaoxianglong * * @param in * ? * * @exception XmlResolveException * * @return void */ @SuppressWarnings("unchecked") private void resolveXml(InputStream in) { if (null == in) return; Document document = null; SAXReader saxReader = new SAXReader(); try { document = saxReader.read(in); } catch (DocumentException e) { throw new XmlResolveException("xml resolve fail"); } Element root = document.getRootElement(); List<Element> elements = root.selectNodes(xpathExpression); if (!elements.isEmpty()) { for (Element element : elements) { final String sql = element.attribute(name).getValue(); sqlMap.put(sql, element.getText()); } } else { throw new XmlResolveException("element <sql/> not found"); } }
From source file:com.smartwork.im.utils.XMLWriter.java
License:Open Source License
/** * Determines if element is a special case of XML elements * where it contains an xml:space attribute of "preserve". * If it does, then retain whitespace.//from www. j av a 2 s .co m */ protected final boolean isElementSpacePreserved(Element element) { final Attribute attr = (Attribute) element.attribute("space"); boolean preserveFound = preserve; //default to global state if (attr != null) { if ("xml".equals(attr.getNamespacePrefix()) && "preserve".equals(attr.getText())) { preserveFound = true; } else { preserveFound = false; } } return preserveFound; }
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)); }