List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator(QName qName);
From source file:edu.ku.brc.specify.datamodel.WorkbenchTemplate.java
License:Open Source License
/** * @param schema/*from ww w.ja v a 2s . c om*/ * * Applies applicable remappings for the fields mapped by the Template. */ public void checkMappings(final DBTableIdMgr schema) { Element remapDom = XMLHelper.readDOMFromConfigDir("specify_workbench_remappings.xml"); if (remapDom == null) { return; } HashMap<String, Pair<String, String>> remaps = new HashMap<String, Pair<String, String>>(); for (Iterator<?> i = remapDom.elementIterator("remapping"); i.hasNext();) { Element remap = (Element) i.next(); String from = remap.attributeValue("table") + "." + remap.attributeValue("field"); Pair<String, String> to = new Pair<String, String>(remap.attributeValue("newtable"), remap.attributeValue("newfield")); remaps.put(from, to); } for (WorkbenchTemplateMappingItem item : getWorkbenchTemplateMappingItems()) { String key = item.getTableName() + "." + item.getFieldName(); Pair<String, String> remap = remaps.get(key); if (remap != null) { item.setTableName(remap.getFirst()); item.setFieldName(remap.getSecond()); DBTableInfo tblInfo = schema.getInfoByTableName(remap.getFirst()); item.setFieldInfo(tblInfo.getFieldByName(remap.getSecond())); item.setSrcTableId(tblInfo.getTableId()); } } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.WorkbenchUploadMapper.java
License:Open Source License
/** * @return Map of defs for 'special' import fields. */// www . j a v a 2 s . com protected Map<String, DefInfo> buildDefs() { Element xmlDef = getXMLDef(); if (xmlDef != null) { Map<String, DefInfo> result = new HashMap<String, DefInfo>(); for (Iterator<?> i = xmlDef.elementIterator("field"); i.hasNext();) { Element fld = (Element) i.next(); try { result.put(fld.attributeValue("table").toLowerCase() + "." + fld.attributeValue("name").toLowerCase(), new DefInfo(fld)); } catch (java.lang.NumberFormatException numEx) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(WorkbenchUploadMapper.class, numEx); log.error("Bad number format in workbench upload def file: " + DatamodelHelper.getDatamodelFilePath()); return null; } } return result; } log.error(getClass().getName() + ": unable to build defs"); return null; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
License:Open Source License
/** * @param path//from w w w . ja v a 2 s . c o m * @param plugins */ private void readRegistry(final String path, final HashMap<String, WBPluginInfo> plugins) { File file = new File(path); if (file.exists()) { try { Element root = XMLHelper.readFileToDOM4J(file); if (root != null) { for (Iterator<?> i = root.elementIterator("plugin"); i.hasNext();) //$NON-NLS-1$ { Element node = (Element) i.next(); String pluginName = node.attributeValue("name"); //$NON-NLS-1$ String className = node.attributeValue("class"); //$NON-NLS-1$ String iconName = node.attributeValue("icon"); //$NON-NLS-1$ String toolTip = node.attributeValue("tooltip"); //$NON-NLS-1$ String prefName = node.attributeValue("pref"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(pluginName) && StringUtils.isNotEmpty(className) && StringUtils.isNotEmpty(iconName)) { WBPluginInfo wbp = new WBPluginInfo(pluginName, className, iconName, toolTip, prefName); plugins.put(pluginName, wbp); } else { log.error("WBPlugin in error: One of the fields (name, class, icon) is null or empty."); } } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
License:Open Source License
/** * Gets column name./* w w w . j a v a 2 s .co m*/ * @param element the element * @return the name of the column */ public String getColumnName(final Element element) { String columnName = null; for (Iterator<?> i2 = element.elementIterator("column"); i2.hasNext();) { Element element1 = (Element) i2.next(); columnName = element1.attributeValue("name"); } return columnName; }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
License:Open Source License
/** * Reads in file that provides listing of tables with their respective Id's and default views. * @return boolean true if reading of tableId file was successful. *//* www . j a va 2 s .co m*/ private boolean readTableMetadataFromFile(final String tableIdListingFilePath) { Hashtable<String, Boolean> abbrvHashLocal = new Hashtable<String, Boolean>(); log.info("Preparing to read in Table and TableID listing from file: " + tableIdListingFilePath); try { File tableIdFile = new File(tableIdListingFilePath); FileInputStream fileInputStream = new FileInputStream(tableIdFile); SAXReader reader = new SAXReader(); reader.setValidation(false); org.dom4j.Document doc = reader.read(fileInputStream); Element root = doc.getRootElement(); Element dbNode = (Element) root.selectSingleNode("database"); if (dbNode != null) { for (Iterator<?> i = dbNode.elementIterator("table"); i.hasNext();) { Element element = (Element) i.next(); String tablename = element.attributeValue("name"); String defaultView = element.attributeValue("view"); String id = element.attributeValue("id"); String abbrv = XMLHelper.getAttr(element, "abbrev", null); boolean isSearchable = XMLHelper.getAttr(element, "searchable", false); if (StringUtils.isNotEmpty(abbrv)) { if (abbrvHashLocal.get(abbrv) == null) { abbrvHashLocal.put(abbrv, true); } else { throw new RuntimeException( "`abbrev` [" + abbrv + "] or table[" + tablename + "] ids already in use."); } } else { throw new RuntimeException("`abbrev` is missing or empty for table[" + tablename + "]"); } String busRule = ""; Element brElement = (Element) element.selectSingleNode("businessrule"); if (brElement != null) { busRule = brElement.getTextTrim(); } //log.debug("Creating TableMetaData and putting in tblMetaDataHashtable for name: " + tablename + " id: " + id + " defaultview: " + defaultView); TableMetaData tblMetaData = new TableMetaData(id, defaultView, createDisplay(element), createFieldAliases(element), isSearchable, busRule, abbrv); tblMetaDataHash.put(tablename, tblMetaData); for (Iterator<?> ir = element.elementIterator("relationship"); ir.hasNext();) { Element relElement = (Element) ir.next(); String relName = relElement.attributeValue("relationshipname"); boolean isLike = XMLHelper.getAttr(relElement, "likemanytoone", false); tblMetaData.setIsLikeManyToOne(relName, isLike); } } } else { log.debug("Ill-formatted file for reading in Table and TableID listing. Filename:" + tableIdFile.getAbsolutePath()); } fileInputStream.close(); return true; } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatamodelGenerator.class, ex); ex.printStackTrace(); log.fatal(ex); } return false; }
From source file:edu.ku.brc.specify.ui.DBObjDialogFactory.java
License:Open Source License
/** * *//*from w w w . j av a 2 s . c om*/ protected void init() { try { Element root = AppContextMgr.getInstance().getResourceAsDOM("DialogDefs"); if (root != null) { for (Iterator<?> i = root.elementIterator("dialog"); i.hasNext();) { Element fileElement = (Element) i.next(); String type = getAttr(fileElement, "type", "display"); String name = getAttr(fileElement, "name", null); boolean isDisplay = type.equals("display"); DialogInfo di = new DialogInfo(isDisplay ? null : getAttr(fileElement, "viewset", null), getAttr(fileElement, "view", null), name, getAttr(fileElement, "class", null), getAttr(fileElement, "idfield", null), getAttr(fileElement, "helpcontext", "")); if (isDisplay) { dialogs.put(name, di); } else { searchDialogs.put(name, di); } } } else { String msg = "The root element for the document was null!"; log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBObjDialogFactory.class, ex); log.error(ex); ex.printStackTrace(); throw new RuntimeException("Couldn't load DialogDefs"); } }
From source file:edu.ku.brc.util.WebStoreAttachmentMgr.java
License:Open Source License
/** * @param webAssetFile//from www.j a va 2 s . c o m * @return */ private boolean getURLSFromStr(final String data) { try { Element root = XMLHelper.readStrToDOM4J(data); if (root != null) { for (Iterator<?> i = root.elementIterator("url"); i.hasNext();) //$NON-NLS-1$ { Element urlNode = (Element) i.next(); String type = urlNode.attributeValue("type"); //$NON-NLS-1$ String urlStr = urlNode.getTextTrim(); if (type.equals("read")) { readURLStr = urlStr; } else if (type.equals("write")) { writeURLStr = urlStr; } else if (type.equals("delete")) { delURLStr = urlStr; } else if (type.equals("fileget")) { fileGetURLStr = urlStr; } else if (type.equals("getmetadata")) { fileGetMetaDataURLStr = urlStr; } else if (type.equals("testkey")) { testKeyURLStr = urlStr; } } } return StringUtils.isNotEmpty(readURLStr) && StringUtils.isNotEmpty(writeURLStr) && StringUtils.isNotEmpty(delURLStr); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.PlannedActivityXmlSerializer.java
License:BSD License
protected void addAdditionalNodeAttributes(final Element element, PlanTreeNode<?> node) { ((PlannedActivity) node).setDetails(element.attributeValue(DETAILS)); ((PlannedActivity) node).setDay(new Integer(element.attributeValue(DAY))); ((PlannedActivity) node).setCondition(element.attributeValue(CONDITION)); if (element.attributeValue(WEIGHT) != null) { ((PlannedActivity) node).setWeight(new Integer(element.attributeValue(WEIGHT))); }/*from w ww. j a v a2 s . c o m*/ String populationAbbreviation = element.attributeValue(POPULATION); if (populationAbbreviation != null) { Population population = new Population(); population.setAbbreviation(populationAbbreviation); ((PlannedActivity) node).setPopulation(population); } if (XsdElement.PLANNED_ACTIVITY_LABEL.xmlName() != null) { Iterator iterator = element.elementIterator(XsdElement.PLANNED_ACTIVITY_LABEL.xmlName()); if (iterator != null) { while (iterator.hasNext()) { PlannedActivityLabel label = plannedActivityLabelXmlSerializer .readElement((Element) iterator.next()); ((PlannedActivity) node).addPlannedActivityLabel(label); } } } Activity activity = null; if (element.element(XsdElement.ACTIVITY.xmlName()) != null) { activity = activityXmlSerializer.readElement(element.element(XsdElement.ACTIVITY.xmlName())); } else if (element.element(XsdElement.ACTIVITY_REFERENCE.xmlName()) != null) { activity = activityReferenceXmlSerializer .readElement(element.element(XsdElement.ACTIVITY_REFERENCE.xmlName())); } ((PlannedActivity) node).setActivity(activity); }
From source file:edu.pitt.sis.FetchNE.java
/** * @param args/*from w w w . j a v a 2s .c om*/ */ public static void getNameEntity(long col_id) { //public static void main(String args[]){ //long col_id = 19; try { URL url = new URL("http://api.opencalais.com/enlighten/rest/"); String license = "t32k95r9k8n9ftdp256e8esw"; String paramsXML = "<c:params xmlns:c=\"http://s.opencalais.com/1/pred/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" + "<c:processingDirectives c:contentType=\"text/txt\" c:enableMetadataType=\"GenericRelations\" c:outputFormat=\"text/simple\">" + "</c:processingDirectives>" + "<c:userDirectives c:allowDistribution=\"true\" c:allowSearch=\"true\" c:externalID=\"17cabs901\" c:submitter=\"jahn\">" + "</c:userDirectives>" + "<c:externalMetadata>" + "</c:externalMetadata>" + "</c:params>"; try { String sql = "SELECT c.col_id,c.title,s.name,h.host,c.location,c.detail " + "FROM colloquium c,speaker s,host h " + "WHERE c.speaker_id = s.speaker_id AND " + "c.host_id = h.host_id AND " + "c.col_id = " + col_id; connectDB conn = new connectDB(); ResultSet rs = conn.getResultSet(sql); try { if (rs.next()) { col_id = rs.getLong("col_id"); String content = rs.getString("title") + "\n" + rs.getString("name") + "\n" + rs.getString("host") + "\n" + rs.getString("location") + "\n" + rs.getString("detail"); if (content.length() > 100000) { content = content.substring(0, 99999); } String query = "licenseID=" + URLEncoder.encode(license, "UTF-8") + "&" + "content=" + URLEncoder.encode(content, "UTF-8") + "&" + "paramsXML=" + URLEncoder.encode(paramsXML, "UTF-8"); //make connection URLConnection urlc = url.openConnection(); //use post mode urlc.setDoOutput(true); urlc.setAllowUserInteraction(false); //send query PrintStream ps = new PrintStream(urlc.getOutputStream()); ps.print(query); ps.close(); //get result BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String line = null; String result = ""; while ((line = br.readLine()) != null) { System.out.println(line); result += line; } br.close(); //save opencalais response sql = "INSERT INTO opencalais (col_id,content,output,_date) VALUES (?,?,?,NOW())"; PreparedStatement pstmt = conn.conn.prepareStatement(sql); pstmt.setLong(1, col_id); pstmt.setString(2, content); pstmt.setString(3, result); pstmt.executeUpdate(); try { Document document = DocumentHelper.parseText(result); Element root = document.getRootElement(); //topics and topic tables were merged into entities and entity tables //sql = "DELETE FROM topics WHERE col_id = " + col_id; //conn.executeUpdate(sql); sql = "DELETE FROM entities WHERE col_id = " + col_id; conn.executeUpdate(sql); // iterate through child elements of root with element name "CalaisSimpleOutputFormat" for (Iterator i = root.elementIterator("CalaisSimpleOutputFormat"); i.hasNext();) { Element element = (Element) i.next(); for (Iterator j = element.elementIterator(); j.hasNext();) { Element e = (Element) j.next(); System.out.println(e.getName() + " : " + e.getText()); if (e.getName().trim().equalsIgnoreCase("topics")) {//Insert topics => entities for (Iterator l = e.elementIterator(); l.hasNext();) { Element ee = (Element) l.next(); System.out.println(ee.getName() + " : " + ee.getText()); sql = "SELECT entity_id FROM entity WHERE entity = ?"; pstmt = conn.conn.prepareStatement(sql); pstmt.setString(1, ee.getText().replaceAll("_", " ")); ResultSet rst = pstmt.executeQuery(); long entity_id = -1; if (rst.next()) { entity_id = rst.getLong("entity_id"); } else { sql = "INSERT INTO entity (entity,_type,_date) VALUES (?,'Topic',NOW())"; pstmt = conn.conn.prepareStatement(sql); pstmt.setString(1, ee.getText()); pstmt.executeUpdate(); sql = "SELECT LAST_INSERT_ID()"; ResultSet rsst = conn.getResultSet(sql); if (rsst.next()) { entity_id = rsst.getLong(1); } } sql = "INSERT INTO entities (entity_id,col_id) VALUES (?,?)"; pstmt = conn.conn.prepareStatement(sql); pstmt.setLong(1, entity_id); pstmt.setLong(2, col_id); pstmt.executeUpdate(); //for(Iterator m = e.attributeIterator();m.hasNext();){ // Attribute aa = (Attribute)m.next(); // System.out.println(aa.getName() + " : " + aa.getText()); //} } } else { String entity = e.getText(); String _type = e.getName(); String normalized = ""; String other = ""; int count = -1; double relevance = 0.0; for (Iterator k = e.attributeIterator(); k.hasNext();) { Attribute a = (Attribute) k.next(); System.out.println(a.getName() + " : " + a.getText()); if (a.getName().equalsIgnoreCase("count")) { count = Integer.parseInt(a.getText()); } else if (a.getName().equalsIgnoreCase("relevance")) { relevance = Double.parseDouble(a.getText()); } else if (a.getName().equalsIgnoreCase("normalized")) { normalized = a.getText(); } else { other += a.getText(); } } //Find an entity in db sql = "SELECT entity_id FROM entity WHERE entity = ?"; pstmt = conn.conn.prepareStatement(sql); pstmt.setString(1, entity); ResultSet rsEntity = pstmt.executeQuery(); long entity_id = -1; if (rsEntity.next()) { entity_id = rsEntity.getLong("entity_id"); } else { sql = "INSERT INTO entity (entity,_type,normalized,other,_date) VALUES (?,?,?,?,NOW())"; pstmt = conn.conn.prepareStatement(sql); pstmt.setString(1, entity); pstmt.setString(2, _type); pstmt.setString(3, normalized); pstmt.setString(4, other); pstmt.executeUpdate(); sql = "SELECT LAST_INSERT_ID()"; rsEntity = conn.getResultSet(sql); if (rsEntity.next()) { entity_id = rsEntity.getLong(1); } } sql = "INSERT INTO entities (entity_id,relevance,occur,col_id) VALUES (?,?,?,?)"; pstmt = conn.conn.prepareStatement(sql); pstmt.setLong(1, entity_id); pstmt.setDouble(2, relevance); pstmt.setInt(3, count); pstmt.setLong(4, col_id); pstmt.executeUpdate(); } } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } conn.conn.close(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { conn = null; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } //return 1; }
From source file:edu.umd.cs.marmoset.codeCoverage.CodeCoverageResults.java
License:Apache License
private static CodeCoverageResults parseDocument(Document document) throws DocumentException { CodeCoverageResults cloverXMLOutput = new CodeCoverageResults(); Element root = document.getRootElement(); for (Iterator<?> ii = root.elementIterator(CodeCoverageConstants.PROJECT); ii.hasNext();) { Element projectElement = (Element) ii.next(); for (Iterator<?> jj = projectElement.elementIterator(CodeCoverageConstants.PACKAGE); jj.hasNext();) { Element packageElement = (Element) jj.next(); for (Iterator<?> kk = packageElement.elementIterator(CodeCoverageConstants.FILE); kk.hasNext();) { Element fileElement = (Element) kk.next(); String sourceFileName = fileElement.attributeValue(CodeCoverageConstants.NAME); // Create a new source file that stores coverage // information. FileWithCoverage fileWithCoverage = new FileWithCoverage(sourceFileName); // System.out.println("attributes: " // +fileElement.attributeCount()); for (Iterator<?> ll = fileElement.elementIterator(CodeCoverageConstants.LINE); ll.hasNext();) { Element lineElement = (Element) ll.next(); // System.out.println("Name: " +node.getName()); // Process the coverage information from this line node. fileWithCoverage.processLineNode(lineElement); }/* w ww. ja v a2s. com*/ // add the file with its coverage information cloverXMLOutput.addFileWithCoverage(fileWithCoverage); } } } return cloverXMLOutput; }