List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.github.autoprimer3.SequenceFromDasUcsc.java
License:Open Source License
SequenceFromDasUcsc() {//get build names and DAS urls try {//from w w w . j a v a 2s. com SAXReader reader = new SAXReader(); URL url = new URL("http://genome.ucsc.edu/cgi-bin/das/dsn");//usa //URL url = new URL("http://genome-euro.ucsc.edu/cgi-bin/das/dsn"); Document dasXml; dasXml = reader.read(url); Element root = dasXml.getRootElement(); for (Iterator i = root.elementIterator("DSN"); i.hasNext();) { Element dsn = (Element) i.next(); Element source = dsn.element("SOURCE"); Attribute build = source.attribute("id"); Element mapmaster = dsn.element("MAPMASTER"); buildToMapMaster.put(build.getValue(), mapmaster.getText()); } } catch (DocumentException | MalformedURLException ex) { //TO DO - handle (throw) this error properly ex.printStackTrace(); } }
From source file:com.github.autoprimer3.SequenceFromDasUcsc.java
License:Open Source License
public String retrieveSequence(String build, String chrom, Integer start, Integer end) throws DocumentException, MalformedURLException { if (!buildToMapMaster.containsKey(build)) { return null; } else {/*from w ww .j a va 2s.c o m*/ String chromNumber = chrom.replaceFirst("chr", ""); int length = 0; URL entryPointUrl = new URL(buildToMapMaster.get(build) + "/entry_points"); Document dasXml; SAXReader reader = new SAXReader(); dasXml = reader.read(entryPointUrl); Element root = dasXml.getRootElement(); for (Iterator i = root.elementIterator("ENTRY_POINTS"); i.hasNext();) { Element dsn = (Element) i.next(); for (Iterator j = dsn.elementIterator("SEGMENT"); j.hasNext();) { Element seg = (Element) j.next(); String id = seg.attributeValue("id"); if (id != null && id.equals(chromNumber)) { String stop = seg.attributeValue("stop"); length = Integer.valueOf(stop); break; } } } if (length > 0) { end = end <= length ? end : length; } StringBuilder dna = new StringBuilder(); URL genomeUrl = new URL( buildToMapMaster.get(build) + "/dna?segment=" + chrom + ":" + (start + 1) + "," + end); dasXml = reader.read(genomeUrl); root = dasXml.getRootElement(); for (Iterator i = root.elementIterator("SEQUENCE"); i.hasNext();) { Element dsn = (Element) i.next(); Element seq = dsn.element("DNA"); String text = seq.getText().replaceAll("\n", ""); dna.append(text); //dna.append(seq.getText()); } return dna.toString(); } }
From source file:com.github.ipaas.ifw.util.XmlUtil.java
License:Apache License
/** * xml??map/* w w w. j ava2 s . c o m*/ * * @param in * -- xml? * @return -- map */ public static Map toMap(InputStream in) { try { SAXReader reader = new SAXReader(); Document doc = reader.read(in); return toMap(doc.getRootElement()); } catch (Exception ex) { throw new RuntimeException("?xml?map", ex); } }
From source file:com.github.megatronking.svg.applet.graphics.VdTree.java
License:Apache License
void parse(Document doc) { Element rootNode = doc.getRootElement(); if (SHAPE_VECTOR.equals(rootNode.getName())) { parseRootNode(rootNode);/*ww w . j a v a 2 s. c o m*/ parseTree(rootNode, mRootGroup); } else { throw new RuntimeException("The root node is not vector!"); } }
From source file:com.glaf.activiti.extension.xml.ExtensionReader.java
License:Apache License
public List<ExtensionEntity> readTasks(java.io.InputStream inputStream) { List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>(); SAXReader xmlReader = new SAXReader(); try {//from w w w .j a v a 2s. c om Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> rows = root.elements("taskmgr"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); ExtensionEntity extension = new ExtensionEntity(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setType(x_type); if (element.elementTextTrim("taskMgmtType") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("taskMgmtType"); extensionField.setValue(element.elementTextTrim("taskMgmtType")); extension.addField(extensionField); } Element propertiesE = element.element("properties"); if (propertiesE != null) { List<?> properties = propertiesE.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("key"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } } if (element.elementText("handlers") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.activiti.extension.xml.ExtensionReader.java
License:Apache License
public List<ExtensionEntity> readActions(java.io.InputStream inputStream) { List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>(); SAXReader xmlReader = new SAXReader(); try {/*from w w w . jav a2s. c o m*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> actions = root.elements("action"); Iterator<?> iter = actions.iterator(); while (iter.hasNext()) { Element element = (Element) iter.next(); ExtensionEntity extension = new ExtensionEntity(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setName(element.attributeValue("name")); extension.setType(x_type); extension.setDescription(element.elementTextTrim("description")); Iterator<?> it99 = element.elementIterator(); while (it99.hasNext()) { Element elem = (Element) it99.next(); String propertyName = elem.getName(); String propertyValue = elem.getTextTrim(); if (StringUtils.isNotEmpty(propertyValue)) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } if (element.elementText("sql") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("sql"); extensionField.setValue(element.elementTextTrim("sql")); extension.addField(extensionField); } if (element.elementText("handlers") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } Element parametersE = element.element("parameters"); if (parametersE != null) { List<?> parameters = parametersE.elements("parameter"); Iterator<?> it = parameters.iterator(); while (it.hasNext()) { Element elem = (Element) it.next(); String propertyName = elem.attributeValue("name"); String type = elem.attributeValue("type"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionParamEntity extensionParam = new ExtensionParamEntity(); extensionParam.setName(propertyName.trim()); extensionParam.setValue(propertyValue.trim()); extensionParam.setType(type); extension.addParam(extensionParam); } } } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.activiti.spring.SpringProcessEngineConfigurationBean.java
License:Apache License
@Override protected void initSqlSessionFactory() { logger.info("-------------------------------------------"); logger.info("-------------initSqlSessionFactory()-------"); logger.info("sqlSessionFactory:" + sqlSessionFactory); logger.info("transactionFactory:" + transactionFactory); if (sqlSessionFactory == null) { InputStream inputStream = null; try {//from www . j a v a 2 s . c om if (configLocation != null) { logger.info("mybatis config:" + this.configLocation.getFile().getAbsolutePath()); inputStream = this.configLocation.getInputStream(); } else { Resource resource = new ClassPathResource("com/glaf/activiti/activiti.mybatis.conf.xml"); inputStream = resource.getInputStream(); } if (!ObjectUtils.isEmpty(this.mapperLocations)) { SAXReader xmlReader = new SAXReader(); EntityResolver entityResolver = new XMLMapperEntityResolver(); xmlReader.setEntityResolver(entityResolver); Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element mappers = root.element("mappers"); if (mappers != null) { java.util.List<?> list = mappers.elements(); Collection<String> files = new HashSet<String>(); if (list != null && !list.isEmpty()) { Iterator<?> iterator = list.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); if (elem.attributeValue("resource") != null) { String file = elem.attributeValue("resource"); files.add(file); } else if (elem.attributeValue("url") != null) { String file = elem.attributeValue("url"); files.add(file); } } } for (Resource mapperLocation : this.mapperLocations) { if (mapperLocation == null) { continue; } String url = mapperLocation.getURL().toString(); // logger.debug("find mapper:" + url); if (!files.contains(url)) { Element element = mappers.addElement("mapper"); element.addAttribute("url", url); } } } IOUtils.closeStream(inputStream); byte[] bytes = Dom4jUtils.getBytesFromPrettyDocument(doc); inputStream = new ByteArrayInputStream(bytes); } // update the jdbc parameters to the configured ones... Environment environment = new Environment("default", transactionFactory, dataSource); Reader reader = new InputStreamReader(inputStream); Properties properties = new Properties(); properties.put("prefix", databaseTablePrefix); if (databaseType != null) { properties.put("limitBefore", DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType)); properties.put("limitAfter", DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType)); properties.put("limitBetween", DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType)); properties.put("orderBy", DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType)); } XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties); Configuration configuration = parser.getConfiguration(); configuration.setEnvironment(environment); configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR, new IbatisVariableTypeHandler()); configuration = parser.parse(); sqlSessionFactory = new DefaultSqlSessionFactory(configuration); } catch (Exception e) { throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e); } finally { IoUtil.closeSilently(inputStream); } } }
From source file:com.glaf.activiti.xml.BpmnXmlReader.java
License:Apache License
public Element getRootElement(InputStream inputStream) { SAXReader xmlReader = new SAXReader(); Document doc = null; try {//from w w w . j a v a 2 s . c om doc = xmlReader.read(inputStream); } catch (DocumentException ex) { throw new RuntimeException(ex); } Element root = doc.getRootElement(); return root; }
From source file:com.glaf.core.provider.ServiceProviderConfigReader.java
License:Apache License
void process(String prefix, Document doc) { checkName(doc.getRootElement(), "provider"); for (final Object o : doc.getRootElement().elements()) { final Element elem = (Element) o; checkName(elem, "bean"); // now check for three children: final String name = getValue(elem, "name", true); final String clzName = getValue(elem, "class", true); Class<?> clz = null; try {/* w w w .j a v a2 s . c om*/ clz = BaseClassLoader.getInstance().loadClass(clzName); } catch (final ClassNotFoundException e) { // catch ClassNotFoundException log.warn("Class " + clzName + " can not be loaded. This can happen " + "when rebuilding after installing new modules. " + "The system needs to be restarted to find " + "new services"); continue; } if (ServiceModulePrefixRequired.class.isAssignableFrom(clz) && prefix != null && prefix.trim().length() > 0) { ServiceProvider.getInstance().register(prefix + "." + name, clz, true); } else { ServiceProvider.getInstance().register(name, clz, true); } } }
From source file:com.glaf.core.todo.util.TodoXmlReader.java
License:Apache License
public List<Todo> read(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); SAXReader xmlReader = new SAXReader(); int sortNo = 1; try {//from w ww.j a v a2s. co m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); List<?> rows = root.elements(); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String id = element.attributeValue("id"); Map<String, Object> rowMap = new java.util.HashMap<String, Object>(); rowMap.put("id", id); List<?> properties = element.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("name"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { rowMap.put(propertyName, propertyValue); } } Todo model = new Todo(); model.setSortNo(sortNo++); Tools.populate(model, rowMap); todos.add(model); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex.getMessage()); } return todos; }