List of usage examples for org.dom4j Element getText
String getText();
From source file:com.github.autoprimer3.GetUcscBuildsAndTables.java
License:Open Source License
public void readDasGenomeXmlDocument() { if (dasGenomeXml == null) { return;/*from w ww .j ava 2s . c om*/ } Element root = dasGenomeXml.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"); Element desc = dsn.element("DESCRIPTION"); buildToMapMaster.put(build.getValue(), mapmaster.getText()); buildToDescription.put(build.getValue(), desc.getText()); } }
From source file:com.github.autoprimer3.GetUcscBuildsAndTables.java
License:Open Source License
public String retrieveSequence(String build, String chrom, Integer start, Integer end) throws DocumentException, MalformedURLException { if (buildToDescription.isEmpty()) { this.connectToUcsc(); }/*from w ww. j a v a 2s .c om*/ if (!buildToMapMaster.containsKey(build)) { return null; } else { StringBuilder dna = new StringBuilder(); URL genomeUrl = new URL( buildToMapMaster.get(build) + "/dna?segment=" + chrom + ":" + (start + 1) + "," + end); SAXReader reader = new SAXReader(); Document dasXml; dasXml = reader.read(genomeUrl); Element 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.autoprimer3.SequenceFromDasUcsc.java
License:Open Source License
SequenceFromDasUcsc() {//get build names and DAS urls try {//from w ww. j a v a 2 s.co m 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 {/* w w w. j av a 2 s . com*/ 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.glaf.core.provider.ServiceProviderConfigReader.java
License:Apache License
private String getValue(Element parentElem, String name, boolean mandatory) { final Element valueElement = parentElem.element(name); if (mandatory) { Check.isNotNull(valueElement, "Element with name " + name + " not found"); } else if (valueElement == null) { return null; }//www . j av a 2 s.c o m return valueElement.getText(); }
From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java
License:Apache License
public static Object getValue(Class<?> type, Element propertyElement) { Object value = null;//ww w . j ava2s . c om if (type == String.class) { value = propertyElement.getText(); } else if ((type == Integer.class) || (type == int.class)) { value = Integer.parseInt(propertyElement.getTextTrim()); } else if ((type == Long.class) || (type == long.class)) { value = Long.parseLong(propertyElement.getTextTrim()); } else if ((type == Float.class) || (type == float.class)) { value = new Float(propertyElement.getTextTrim()); } else if ((type == Double.class) || (type == double.class)) { value = Double.parseDouble(propertyElement.getTextTrim()); } else if ((type == Boolean.class) || (type == boolean.class)) { value = Boolean.valueOf(propertyElement.getTextTrim()); } else if ((type == Character.class) || (type == char.class)) { value = Character.valueOf(propertyElement.getTextTrim().charAt(0)); } else if ((type == Short.class) || (type == short.class)) { value = Short.valueOf(propertyElement.getTextTrim()); } else if ((type == Byte.class) || (type == byte.class)) { value = Byte.valueOf(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(java.util.Date.class)) { value = DateUtils.toDate(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(List.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Set.class)) { value = getCollectionValue(propertyElement, new LinkedHashSet<Object>()); } else if (type.isAssignableFrom(Collection.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Map.class)) { value = getMapValue(propertyElement, new LinkedHashMap<Object, Object>()); } else if (type == Element.class) { value = propertyElement; } else { try { Constructor<?> constructor = type.getConstructor(new Class[] { String.class }); if ((propertyElement.isTextOnly()) && (constructor != null)) { value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() }); } } catch (Exception ex) { logger.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'"); throw new RuntimeException(ex); } } return value; }
From source file:com.glaf.wechat.util.MessageUtils.java
License:Apache License
/** * ???XML//from w w w . j a v a2 s . c o m * * @param request * @return * @throws Exception */ @SuppressWarnings("unchecked") public static Map<String, String> parseXml(HttpServletRequest request) { // ?HashMap Map<String, String> map = new java.util.concurrent.ConcurrentHashMap<String, String>(); // request?? InputStream inputStream = null; // ?? SAXReader reader = new SAXReader(); try { inputStream = request.getInputStream(); Document document = reader.read(inputStream); // xml Element root = document.getRootElement(); // ? List<Element> elementList = root.elements(); // ??? for (Element e : elementList) { map.put(e.getName(), e.getText()); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { try { // ? if (inputStream != null) { inputStream.close(); inputStream = null; } } catch (IOException ex) { } } return map; }
From source file:com.globalsight.connector.mindtouch.util.MindTouchHelper.java
License:Apache License
/** * Parse tree xml from "getTreeXml(pageId)" method to form a tree. * //from www. j a v a 2 s. co m * @param treeXml * -- the tree information in XML format. * @return MindTouchPage */ @SuppressWarnings("rawtypes") public MindTouchPage parseTreeXml(String treeXml) throws Exception { MindTouchPage rootMtp = null; Document doc = getDocument(treeXml); String id = null; String href = null; List pageNodes = doc.selectNodes("//page"); List<MindTouchPage> allPages = new ArrayList<MindTouchPage>(); Iterator it = pageNodes.iterator(); while (it.hasNext()) { MindTouchPage mtp = new MindTouchPage(); Element pageNode = (Element) it.next(); // page id id = pageNode.attributeValue("id"); mtp.setId(Long.parseLong(id)); // href href = pageNode.attributeValue("href"); mtp.setHref(href); // parent page id String parentName = null; if (pageNode.getParent() != null) { parentName = pageNode.getParent().getName(); } if ("subpages".equals(parentName)) { String parentId = pageNode.getParent().getParent().attributeValue("id"); mtp.setParentId(Long.parseLong(parentId)); } else if ("pages".equals(parentName)) { rootMtp = mtp; } Iterator subNodeIt = pageNode.nodeIterator(); while (subNodeIt.hasNext()) { Element node = (Element) subNodeIt.next(); String name = node.getName(); String text = node.getText(); if ("uri.ui".equals(name)) { mtp.setUriUi(text); } else if ("title".equals(name)) { // title cannot have "<" and ">" text = text.replace("<", "<").replace(">", ">"); // as json does not allow "\" and "/", remove them for displaying. text = text.replace("\\", "").replace("/", ""); text = text.replace("%22", "\""); text = text.replace("%3F", "?"); text = text.replace("%23", "#"); text = text.replace("%3D", "="); text = text.replace("%26", "&"); text = text.replace("%25", "%"); mtp.setTitle(text); } else if ("path".equals(name)) { mtp.setPath(text); } else if ("date.created".equals(name)) { mtp.setDateCreated(text); } } allPages.add(mtp); } HashMap<Long, MindTouchPage> map = new HashMap<Long, MindTouchPage>(); for (MindTouchPage mtp : allPages) { map.put(mtp.getId(), mtp); } for (MindTouchPage mtp : allPages) { long parentId = mtp.getParentId(); MindTouchPage parent = map.get(parentId); if (parent != null) { parent.addSubPage(mtp); } } return rootMtp; }
From source file:com.globalsight.connector.mindtouch.util.MindTouchHelper.java
License:Apache License
/** * Parse page info xml from "getPageInfo()" method. * //from w ww . j av a2s . c o m * @param pageInfoXml * @return MindTouchPage * @throws DocumentException */ @SuppressWarnings("rawtypes") public MindTouchPage parsePageInfoXml(String pageInfoXml) throws DocumentException { MindTouchPage mtp = new MindTouchPage(); Document doc = getDocument(pageInfoXml); String id = null; String href = null; List pageNodes = doc.selectNodes("//page"); if (pageNodes != null && pageNodes.size() > 0) { Element pageNode = (Element) pageNodes.get(0); // page id id = pageNode.attributeValue("id"); mtp.setId(Long.parseLong(id)); // href href = pageNode.attributeValue("href"); mtp.setHref(href); String name = null; String text = null; Iterator subNodeIt = pageNode.nodeIterator(); while (subNodeIt.hasNext()) { Element node = (Element) subNodeIt.next(); name = node.getName(); text = node.getText(); if ("uri.ui".equals(name)) { mtp.setUriUi(text); } else if ("title".equals(name)) { mtp.setTitle(text); } else if ("path".equals(name)) { mtp.setPath(text); } else if ("date.created".equals(name)) { mtp.setDateCreated(text); } } } return mtp; }
From source file:com.globalsight.everest.aligner.AlignerPackageOptions.java
License:Apache License
/** * Initializes this object from an XML string. *//*from ww w. java 2s . c o m*/ public void init(String p_options) throws Exception { XmlParser parser = null; Document dom = null; Element elem; List nodes; clearFilePairs(); clearExtensions(); try { parser = XmlParser.hire(); dom = parser.parseXml(p_options); Element root = dom.getRootElement(); m_packageName = root.elementText("packageName"); elem = (Element) root.selectSingleNode("//extractionOptions"); m_extractionOptions.m_formatType = elem.elementText("formatType"); m_extractionOptions.m_rules = elem.elementText("rules"); m_extractionOptions.m_sourceEncoding = elem.elementText("sourceEncoding"); m_extractionOptions.m_targetEncoding = elem.elementText("targetEncoding"); m_extractionOptions.m_sourceLocale = elem.elementText("sourceLocale"); m_extractionOptions.m_targetLocale = elem.elementText("targetLocale"); nodes = root.selectNodes("//extractionOptions//extension"); for (int i = 0, max = nodes.size(); i < max; i++) { elem = (Element) nodes.get(i); String ext = elem.getText(); addExtension(ext); } nodes = root.selectNodes("//filePair"); for (int i = 0, max = nodes.size(); i < max; i++) { elem = (Element) nodes.get(i); FilePair pair = new FilePair(elem.elementText("source"), elem.elementText("target")); addFilePair(pair); } elem = (Element) root.selectSingleNode("//alignerOptions"); m_alignerOptions.m_ignoreFormatting = elem.elementText("ignoreFormatting"); } finally { XmlParser.fire(parser); } }