List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:musite.taxonomy.TaxonomyXMLReader.java
License:Open Source License
public TaxonomyTree read(InputStream is) throws IOException { if (is == null) { throw new IllegalArgumentException(); }// w w w . ja v a 2s .c o m TaxonomyTree tree = new TaxonomyTree(); SAXReader saxReader = new SAXReader(); //BufferedInputStream bis = new BufferedInputStream(is); //Document document = saxReader.read(new File("c:/catalog/catalog.xml")); try { Document document = saxReader .read(new File("D:/Yao/NetBeansProjects/musite/testData/taxonomy-ancestor_51967.rdf")); List list = document.selectNodes("//rdf:RDF"); Iterator iter = list.iterator(); while (iter.hasNext()) { String TaxonomyID = null; String Type = null; String Rank = null; String ScientificName = null; ArrayList<String> OtherNames = new ArrayList<String>(); boolean partOfLineage = false; Element element = (Element) iter.next(); Attribute attribute = element.attribute("rdf:about"); TaxonomyID = attribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, ""); Iterator typeIterator = element.elementIterator("rdf:type"); while (typeIterator.hasNext()) { Element typeElement = (Element) typeIterator.next(); Attribute typeAttribute = typeElement.attribute("rdf:resource"); Type = typeAttribute.getValue().replaceAll(UniprotTaxonomySettings.TYPE_ADDRESS, ""); } Iterator rankIterator = element.elementIterator("rank"); while (rankIterator.hasNext()) { Element rankElement = (Element) rankIterator.next(); Attribute rankAttribute = rankElement.attribute("rdf:resource"); Rank = rankAttribute.getValue().replaceAll(UniprotTaxonomySettings.RANK_ADDRESS, ""); } Iterator scientificnameIterator = element.elementIterator("scientificName"); while (scientificnameIterator.hasNext()) { Element scientificnameElement = (Element) scientificnameIterator.next(); ScientificName = scientificnameElement.getText(); } Iterator othernameIterator = element.elementIterator("otherName"); while (othernameIterator.hasNext()) { Element othernameElement = (Element) othernameIterator.next(); String tempname = othernameElement.getText(); OtherNames.add(tempname); } Iterator lineageIterator = element.elementIterator("partOfLineage"); while (lineageIterator.hasNext()) { Element lineageElement = (Element) lineageIterator.next(); String temptext = lineageElement.getText(); if (temptext.equals("true")) { partOfLineage = true; } else partOfLineage = false; } //create a new node TaxonomyNode node = tree.getTaxonomyNode(TaxonomyID); if (node == null) { node = new TaxonomyNode(); node.setIdentifier(TaxonomyID); tree.addtoNodelist(node); } node.setOtherNames(OtherNames); node.setRank(Rank); node.setScientificName(ScientificName); node.setType(Type); node.setPartOfLineage(partOfLineage); //add the parent node Iterator subclassIterator = element.elementIterator("rdfs:subClassOf"); while (subclassIterator.hasNext()) { Element subclassElement = (Element) subclassIterator.next(); Attribute subclassAttribute = subclassElement.attribute("rdf:resource"); String subclassID = subclassAttribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, ""); TaxonomyNode parent = tree.getTaxonomyNode(subclassID); if (parent != null) { node.addParent(parent); } else { parent = new TaxonomyNode(); parent.setIdentifier(subclassID); tree.addtoNodelist(parent); node.addParent(parent); } } } } catch (Exception e) { } return tree; }
From source file:musite.taxonomy.UniprotTaxonomyXMLReader.java
License:Open Source License
public TaxonomyTree read(InputStream is) throws IOException { if (is == null) { throw new IllegalArgumentException(); }/*from ww w . j a va2s . co m*/ final TaxonomyTree tree = new TaxonomyTree(); SAXReader saxReader = new SAXReader(); final TaxonomyNode currentNode = new TaxonomyNode(); // entry saxReader.addHandler("/RDF/Description", new ElementHandler() { public void onStart(ElementPath path) { currentNode.clearMembers(); Element element = path.getCurrent(); Attribute attribute = element.attribute("about"); String TaxonomyID = attribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, ""); currentNode.setIdentifier(TaxonomyID); } public void onEnd(ElementPath path) { // process an element //create a new node TaxonomyNode node = tree.getTaxonomyNode(currentNode.getIdentifier()); if (node == null) { node = new TaxonomyNode(); currentNode.copyMembersTo(node); tree.addtoNodelist(node); } else { currentNode.copyMembersTo(node); } //change the parent from currentNode to node ArrayList<TaxonomyNode> parentlist = node.getParents(); for (int i = 0; i < parentlist.size(); i++) { TaxonomyNode parent = parentlist.get(i); parent.getChildren().add(node); } // prune the tree Element row = path.getCurrent(); row.detach(); } }); // type saxReader.addHandler("/RDF/Description/type", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element typeElement = (Element) path.getCurrent(); Attribute typeAttribute = typeElement.attribute("resource"); String Type = typeAttribute.getValue().replaceAll(UniprotTaxonomySettings.TYPE_ADDRESS, ""); currentNode.setType(Type); } }); // rank saxReader.addHandler("/RDF/Description/rank", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element rankElement = (Element) path.getCurrent(); Attribute rankAttribute = rankElement.attribute("resource"); String Rank = rankAttribute.getValue().replaceAll(UniprotTaxonomySettings.RANK_ADDRESS, ""); currentNode.setRank(Rank); } }); // scientificName saxReader.addHandler("/RDF/Description/scientificName", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element scientificnameElement = (Element) path.getCurrent(); String ScientificName = scientificnameElement.getText(); currentNode.setScientificName(ScientificName); } }); // otherName saxReader.addHandler("/RDF/Description/otherName", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element othernameElement = (Element) path.getCurrent(); String tempname = othernameElement.getText(); currentNode.addOthernames(tempname); } }); // partOfLineage saxReader.addHandler("/RDF/Description/partOfLineage", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element lineageElement = (Element) path.getCurrent(); String temptext = lineageElement.getText(); boolean partOfLineage; if (temptext.equals("true")) { partOfLineage = true; } else partOfLineage = false; currentNode.setPartOfLineage(partOfLineage); } }); // Add parent saxReader.addHandler("/RDF/Description/subClassOf", new ElementHandler() { public void onStart(ElementPath path) { // do nothing } public void onEnd(ElementPath path) { Element subclassElement = (Element) path.getCurrent(); Attribute subclassAttribute = subclassElement.attribute("resource"); String subclassID = subclassAttribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, ""); TaxonomyNode parent = tree.getTaxonomyNode(subclassID); if (parent != null) { currentNode.addParentOnly(parent); } else { parent = new TaxonomyNode(); parent.setIdentifier(subclassID); tree.addtoNodelist(parent); currentNode.addParentOnly(parent); } } }); BufferedInputStream bis = new BufferedInputStream(is); Document doc; try { doc = saxReader.read(bis); } catch (DocumentException e) { throw new IOException(e.getMessage()); } tree.searchRoot(); return tree; }
From source file:net.emiva.crossfire.plugin.muc.HistoryRequest.java
License:Open Source License
public HistoryRequest(Element userFragment) { Element history = userFragment.element("history"); if (history != null) { if (history.attribute("maxchars") != null) { this.maxChars = Integer.parseInt(history.attributeValue("maxchars")); }//from w w w . j a v a2 s . co m if (history.attribute("maxstanzas") != null) { this.maxStanzas = Integer.parseInt(history.attributeValue("maxstanzas")); } if (history.attribute("seconds") != null) { this.seconds = Integer.parseInt(history.attributeValue("seconds")); } if (history.attribute("since") != null) { try { // parse utc into Date synchronized (formatter) { this.since = formatter.parse(history.attributeValue("since")); } } catch (ParseException pe) { Log.error("Error parsing date from history management", pe); this.since = null; } } } }
From source file:net.emiva.crossfire.plugin.muc.spi.MultiUserChatServiceImpl.java
License:Open Source License
/** * Removes an extra Disco identity from the list of identities returned for the conference service. * @param name Name of identity to remove. *///from w w w . j av a 2 s . c o m public void removeExtraIdentity(String name) { for (Element elem : extraDiscoIdentities) { if (name.equals(elem.attribute("name").getStringValue())) { extraDiscoFeatures.remove(elem); break; } } }
From source file:net.form105.rm.base.Container.java
License:GNU General Public License
/** * Building the pico container based on the nano container. To create a pico * container a configuration must be available * // w w w .j a v a 2 s. c o m * @param builder * @param parentContainer * @param scope * @return */ public void load(ContainerConfiguration configuration) { if (container.getComponents().size() > 0 || factoryContainer.getComponents().size() > 0) { System.err.println("Can't do Container.load(): Container already started. Do nothing!"); return; } this.configuration = configuration; // check for log4j config file // 1st of all - load log4j String configDir = configuration.getConfigurationDirectory(); String log4jConfigPath = configDir + "log4j.properties"; File file = new File(log4jConfigPath); if (!file.exists()) { System.err.println("Error: Log4j configuration file doesn't exit: " + log4jConfigPath); } PropertyConfigurator.configureAndWatch(configDir + File.separator + "log4j.properties"); logger = Logger.getLogger(Container.class); XMLLoader loader = new XMLLoader(configuration.getPath()); Document document = loader.parseFile(); Element rootElement = document.getRootElement(); List<Element> classElements = rootElement.elements(); for (Element element : classElements) { try { if (element.attribute("factory") == null) { String className = element.attributeValue("class"); String id = element.attributeValue("id"); logger.info("Loading class for container: " + className); Class containerClass = Class.forName(className); container.addComponent(id, containerClass); } else { String className = element.attributeValue("class"); String key = element.attributeValue("id"); logger.info("Loading class for factory container: " + className); Class containerClass = Class.forName(className); factoryContainer.addComponent(key, containerClass); } } catch (ClassNotFoundException ex) { logger.error(ex, ex); } } //container.addChildContainer(factoryContainer); //factoryContainer.addChildContainer(container); factoryContainer.start(); }
From source file:net.groupbuy.util.SettingUtils.java
License:Open Source License
/** * //from w ww .j a v a 2 s. co 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.nikr.eve.jeveasset.io.local.update.Update.java
License:Open Source License
void setVersion(final File xml, final int newVersion) throws DocumentException { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(xml); XPath xpathSelector = DocumentHelper.createXPath("/settings"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute attr = element.attribute("version"); if (attr == null) { element.add(new DefaultAttribute("version", String.valueOf(newVersion))); } else {//from w w w . ja v a 2 s. c o m attr.setText(String.valueOf(newVersion)); } } try { FileOutputStream fos = new FileOutputStream(xml); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-16"); XMLWriter writer = new XMLWriter(fos, outformat); writer.write(doc); writer.flush(); } catch (IOException ioe) { LOG.error("Failed to update the serttings.xml version number", ioe); throw new RuntimeException(ioe); } }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/filters/filter/row"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("mode"); String currentValue = attr.getText(); attr.setText(convertMode(currentValue)); }//w w w . java 2 s . c om }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertDefaultPriceModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/marketstat"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("defaultprice"); if (attr != null) { //May not exist (in early versions) String currentValue = attr.getText(); attr.setText(convertDefaultPriceMode(currentValue)); }//ww w. j a v a 2s . c o m } }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertTableSettings(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/columns/column"); List<?> results = xpathSelector.selectNodes(doc); List<String> tableColumnNames = new ArrayList<String>(); List<String> tableColumnVisible = new ArrayList<String>(); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute name = element.attribute("name"); Attribute visible = element.attribute("visible"); tableColumnNames.add(name.getText()); if (visible.getText().equals("true")) { tableColumnVisible.add(name.getText()); }/*w w w . j av a 2 s . c om*/ } String mode = convertFlag(doc); writeTableSettings(doc, mode, tableColumnNames, tableColumnVisible); }