List of usage examples for org.dom4j XPath selectSingleNode
Node selectSingleNode(Object context);
selectSingleNode
evaluates this XPath expression on the given Node or List of Node s and returns the result as a single Node
instance. From source file:bio2rdf.datahub_get_stats_0_1.datahub_get_stats.java
License:Apache License
public void tHttpRequest_1Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String iterateId = ""; int iterateLoop = 0; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {/* w w w. j av a 2 s. c o m*/ String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row6Struct row6 = new row6Struct(); row7Struct row7 = new row7Struct(); row8Struct row8 = new row8Struct(); row9Struct row9 = new row9Struct(); row10Struct row10 = new row10Struct(); row10Struct row5 = row10; /** * [tBufferOutput_1 begin ] start */ ok_Hash.put("tBufferOutput_1", false); start_Hash.put("tBufferOutput_1", System.currentTimeMillis()); currentComponent = "tBufferOutput_1"; int tos_count_tBufferOutput_1 = 0; /** * [tBufferOutput_1 begin ] stop */ /** * [tLogRow_2 begin ] start */ ok_Hash.put("tLogRow_2", false); start_Hash.put("tLogRow_2", System.currentTimeMillis()); currentComponent = "tLogRow_2"; int tos_count_tLogRow_2 = 0; /** * [tLogRow_2 begin ] stop */ /** * [tFilterRow_1 begin ] start */ ok_Hash.put("tFilterRow_1", false); start_Hash.put("tFilterRow_1", System.currentTimeMillis()); currentComponent = "tFilterRow_1"; int tos_count_tFilterRow_1 = 0; int nb_line_tFilterRow_1 = 0; int nb_line_ok_tFilterRow_1 = 0; int nb_line_reject_tFilterRow_1 = 0; class Operator_tFilterRow_1 { private String sErrorMsg = ""; private boolean bMatchFlag = true; private String sUnionFlag = "&&"; public Operator_tFilterRow_1(String unionFlag) { sUnionFlag = unionFlag; bMatchFlag = "||".equals(unionFlag) ? false : true; } public String getErrorMsg() { if (sErrorMsg != null && sErrorMsg.length() > 1) return sErrorMsg.substring(1); else return null; } public boolean getMatchFlag() { return bMatchFlag; } public void matches(boolean partMatched, String reason) { // no need to care about the next judgement if ("||".equals(sUnionFlag) && bMatchFlag) { return; } if (!partMatched) { sErrorMsg += "|" + reason; } if ("||".equals(sUnionFlag)) bMatchFlag = bMatchFlag || partMatched; else bMatchFlag = bMatchFlag && partMatched; } } /** * [tFilterRow_1 begin ] stop */ /** * [tJavaRow_2 begin ] start */ ok_Hash.put("tJavaRow_2", false); start_Hash.put("tJavaRow_2", System.currentTimeMillis()); currentComponent = "tJavaRow_2"; int tos_count_tJavaRow_2 = 0; int nb_line_tJavaRow_2 = 0; /** * [tJavaRow_2 begin ] stop */ /** * [tExtractRegexFields_1 begin ] start */ ok_Hash.put("tExtractRegexFields_1", false); start_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); currentComponent = "tExtractRegexFields_1"; int tos_count_tExtractRegexFields_1 = 0; java.util.regex.Pattern pattern_tExtractRegexFields_1 = java.util.regex.Pattern .compile("http:\\/\\/bio2rdf.org\\/(.*)_vocabulary:Resource"); /** * [tExtractRegexFields_1 begin ] stop */ /** * [tExtractJSONFields_1 begin ] start */ ok_Hash.put("tExtractJSONFields_1", false); start_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); currentComponent = "tExtractJSONFields_1"; int tos_count_tExtractJSONFields_1 = 0; int nb_line_tExtractJSONFields_1 = 0; class ConvertJSONString_tExtractJSONFields_1 { final static int Brace = 0; // { final static int Bracket = 1; // [ private int barceType = -1; private String originalJsonString = ""; private String originalLoopString = ""; private String jsonString4XML = null; private String loopString4XML = null; private String additionRoot = null; public void barceType() { for (int c = 0; c < originalJsonString.length(); ++c) { if (originalJsonString.charAt(c) == '{') { barceType = Brace; break; } else if (originalJsonString.charAt(c) == '[') { barceType = Bracket; break; } } } public void setJsonString(String originalJsonString) { this.originalJsonString = originalJsonString; } public void setLoopString(String originalLoopString) { this.originalLoopString = originalLoopString; } public String getJsonString4XML() { return jsonString4XML; } public String getLoopString4XML() { if (loopString4XML.length() > 1 && loopString4XML.endsWith("/")) { loopString4XML = loopString4XML.substring(0, loopString4XML.length() - 1); } return loopString4XML; } public void setAdditionRoot(String additionRoot) { this.additionRoot = additionRoot; } public String getAdditionRoot() { return additionRoot; } public void generate() { barceType(); jsonString4XML = originalJsonString; loopString4XML = originalLoopString; if (Brace == barceType) { if (isNeedAddRoot(originalJsonString)) { jsonString4XML = "{ \"root\": " + originalJsonString + " }"; loopString4XML = "root" + originalLoopString; setAdditionRoot("root"); } } else if (Bracket == barceType) { jsonString4XML = "{ \"root\" : { \"object\": " + originalJsonString + " } }"; loopString4XML = "root/object" + originalLoopString; setAdditionRoot("object"); } } public boolean isNeedAddRoot(String originalJsonString) { boolean isNeedAddRoot = false; net.sf.json.JSONObject jso = net.sf.json.JSONObject.fromObject(originalJsonString); String jsonKey = ""; Object firstObject = null; if (jso.names().size() == 1) { jsonKey = jso.names().get(0).toString(); firstObject = jso.get(jsonKey); } if (jso.size() > 1 || (firstObject != null && firstObject instanceof net.sf.json.JSONArray && ((net.sf.json.JSONArray) firstObject).size() > 1)) { isNeedAddRoot = true; } return isNeedAddRoot; } } ConvertJSONString_tExtractJSONFields_1 cjs_tExtractJSONFields_1 = new ConvertJSONString_tExtractJSONFields_1(); de.odysseus.staxon.json.JsonXMLConfig config_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLConfigBuilder() .multiplePI(false).build(); de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLInputFactory( config_tExtractJSONFields_1); javax.xml.stream.XMLOutputFactory xmlOutputFactory_tExtractJSONFields_1 = javax.xml.stream.XMLOutputFactory .newInstance(); boolean isGetWholeJson_tExtractJSONFields_1 = false; class OriginalJSONString_tExtractJSONFields_1 { } OriginalJSONString_tExtractJSONFields_1 originalJSONString_tExtractJSONFields_1 = new OriginalJSONString_tExtractJSONFields_1(); class XML_API_tExtractJSONFields_1 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } String jsonStr_tExtractJSONFields_1 = ""; String xmlStr_tExtractJSONFields_1 = ""; XML_API_tExtractJSONFields_1 xml_api_tExtractJSONFields_1 = new XML_API_tExtractJSONFields_1(); /** * [tExtractJSONFields_1 begin ] stop */ /** * [tHttpRequest_1 begin ] start */ ok_Hash.put("tHttpRequest_1", false); start_Hash.put("tHttpRequest_1", System.currentTimeMillis()); currentComponent = "tHttpRequest_1"; int tos_count_tHttpRequest_1 = 0; /** * [tHttpRequest_1 begin ] stop */ /** * [tHttpRequest_1 main ] start */ currentComponent = "tHttpRequest_1"; java.net.URL url_tHttpRequest_1 = new java.net.URL("http://" + context.endpoint_namespace + ".bio2rdf.org/sparql?default-graph-uri=&query=PREFIX+void%3A+%3Chttp%3A%2F%2Frdfs.org%2Fns%2Fvoid%23%3E%0D%0APREFIX+ds%3A+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset_vocabulary%3A%3E%0D%0A%0D%0ASELECT+*%0D%0A+%7B+%5B%5D+void%3Asubset+%5B%0D%0A+++++++a+ds%3ADataset-Type-Count%3B%0D%0A+++++++void%3Aclass+%3Flink%3B%0D%0A+++++++void%3AdistinctEntities+%3FdistinctCount%3B%0D%0A+++%5D%0D%0A+++FILTER+regex%28str%28%3Flink%29%2C+%27.*bio2rdf.org%5C%5C%2F.*_vocabulary%3AResource%27%2C+%27i%27%29%0D%0A+%7D&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on"); java.net.HttpURLConnection urlConn_tHttpRequest_1 = (java.net.HttpURLConnection) url_tHttpRequest_1 .openConnection(); urlConn_tHttpRequest_1.setRequestMethod("GET"); urlConn_tHttpRequest_1.setDoOutput(true); urlConn_tHttpRequest_1.setDoInput(true); urlConn_tHttpRequest_1.setUseCaches(false); urlConn_tHttpRequest_1.connect(); byte[] buffer_tHttpRequest_1 = new byte[1024]; int bos_buffer_tHttpRequest_1 = 0; StringBuilder sb_tHttpRequest_1 = new StringBuilder(); if (java.net.HttpURLConnection.HTTP_OK == (urlConn_tHttpRequest_1.getResponseCode())) { java.io.InputStream bis_tHttpRequest_1 = new java.io.BufferedInputStream( urlConn_tHttpRequest_1.getInputStream()); while ((bos_buffer_tHttpRequest_1 = bis_tHttpRequest_1.read(buffer_tHttpRequest_1)) != -1) { sb_tHttpRequest_1.append(new String(buffer_tHttpRequest_1, 0, bos_buffer_tHttpRequest_1)); } bis_tHttpRequest_1.close(); } else { System.err.println(urlConn_tHttpRequest_1.getResponseCode() + " " + urlConn_tHttpRequest_1.getResponseMessage()); } row6.ResponseContent = sb_tHttpRequest_1.toString(); urlConn_tHttpRequest_1.disconnect(); tos_count_tHttpRequest_1++; /** * [tHttpRequest_1 main ] stop */ /** * [tExtractJSONFields_1 main ] start */ currentComponent = "tExtractJSONFields_1"; if (row6.ResponseContent != null) {// C_01 jsonStr_tExtractJSONFields_1 = row6.ResponseContent.toString(); row7 = null; org.dom4j.io.SAXReader reader_tExtractJSONFields_1 = new org.dom4j.io.SAXReader(); org.dom4j.Document doc_tExtractJSONFields_1 = null; java.util.HashMap xmlNameSpaceMap_tExtractJSONFields_1 = new java.util.HashMap<String, String>(); org.dom4j.XPath x_tExtractJSONFields_1 = null; java.util.List<org.dom4j.tree.AbstractNode> nodeList_tExtractJSONFields_1 = null; boolean isStructError_tExtractJSONFields_1 = true; String loopQuery_tExtractJSONFields_1 = "/results/bindings"; String oraginalJsonStr_tExtractJSONFields_1 = jsonStr_tExtractJSONFields_1; cjs_tExtractJSONFields_1.setJsonString(jsonStr_tExtractJSONFields_1); cjs_tExtractJSONFields_1.setLoopString(loopQuery_tExtractJSONFields_1); java.io.ByteArrayInputStream bais_tExtractJSONFields_1 = null; java.io.ByteArrayOutputStream baos_tExtractJSONFields_1 = new java.io.ByteArrayOutputStream(); try { cjs_tExtractJSONFields_1.generate(); jsonStr_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getJsonString4XML(); loopQuery_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getLoopString4XML(); bais_tExtractJSONFields_1 = new ByteArrayInputStream( jsonStr_tExtractJSONFields_1.getBytes("UTF-8")); javax.xml.stream.XMLEventReader xmlEventReader_tExtractJSONFields_1 = jsonXMLInputFactory_tExtractJSONFields_1 .createXMLEventReader(bais_tExtractJSONFields_1); javax.xml.stream.XMLEventWriter xmLEventWriter_tExtractJSONFields_1 = xmlOutputFactory_tExtractJSONFields_1 .createXMLEventWriter(baos_tExtractJSONFields_1, "UTF-8"); xmLEventWriter_tExtractJSONFields_1.add(xmlEventReader_tExtractJSONFields_1); // convert json string to xml xmlStr_tExtractJSONFields_1 = baos_tExtractJSONFields_1.toString(); xmLEventWriter_tExtractJSONFields_1.close(); xmlEventReader_tExtractJSONFields_1.close(); doc_tExtractJSONFields_1 = reader_tExtractJSONFields_1 .read(new java.io.StringReader(xmlStr_tExtractJSONFields_1)); x_tExtractJSONFields_1 = doc_tExtractJSONFields_1 .createXPath(loopQuery_tExtractJSONFields_1); x_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); nodeList_tExtractJSONFields_1 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tExtractJSONFields_1 .selectNodes(doc_tExtractJSONFields_1); isStructError_tExtractJSONFields_1 = false; } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); } finally { baos_tExtractJSONFields_1.close(); if (bais_tExtractJSONFields_1 != null) { bais_tExtractJSONFields_1.close(); } } org.dom4j.Node node_tExtractJSONFields_1 = null; String str_tExtractJSONFields_1 = ""; for (int i_tExtractJSONFields_1 = 0; isStructError_tExtractJSONFields_1 || (nodeList_tExtractJSONFields_1 != null && i_tExtractJSONFields_1 < nodeList_tExtractJSONFields_1 .size()); i_tExtractJSONFields_1++) { if (!isStructError_tExtractJSONFields_1) { row7 = null; row7 = new row7Struct(); org.dom4j.tree.AbstractNode temp_tExtractJSONFields_1 = nodeList_tExtractJSONFields_1 .get(i_tExtractJSONFields_1); nb_line_tExtractJSONFields_1++; try { org.dom4j.XPath xTmp0_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("link/value"); xTmp0_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj0_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj0_tExtractJSONFields_1 instanceof String || obj0_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj0_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.link = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.link = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.link = null; } else { row7.link = str_tExtractJSONFields_1; } org.dom4j.XPath xTmp1_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("distinctCount/value"); xTmp1_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj1_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj1_tExtractJSONFields_1 instanceof String || obj1_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj1_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.count = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.count = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.count = null; } else { row7.count = str_tExtractJSONFields_1; } } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); row7 = null; } } isStructError_tExtractJSONFields_1 = false; tos_count_tExtractJSONFields_1++; /** * [tExtractJSONFields_1 main ] stop */ // Start of branch "row7" if (row7 != null) { /** * [tExtractRegexFields_1 main ] start */ currentComponent = "tExtractRegexFields_1"; row8 = null; if (row7.link != null) {// C_01 java.util.regex.Matcher matcher_tExtractRegexFields_1 = pattern_tExtractRegexFields_1 .matcher(row7.link); int groupCount_tExtractRegexFields_1 = matcher_tExtractRegexFields_1.groupCount(); while (matcher_tExtractRegexFields_1.find()) { try { row8 = new row8Struct(); row8.count = row7.count; String temp_tExtractRegexFields_1 = null; row8.linkNamespace = groupCount_tExtractRegexFields_1 <= 0 ? "" : matcher_tExtractRegexFields_1.group(1); } catch (java.lang.Exception ex_tExtractRegexFields_1) { throw (ex_tExtractRegexFields_1); } tos_count_tExtractRegexFields_1++; /** * [tExtractRegexFields_1 main ] stop */ // Start of branch "row8" if (row8 != null) { /** * [tJavaRow_2 main ] start */ currentComponent = "tJavaRow_2"; // Code gnr selon le schmas d'entre // et de sortie row9.link = row8.linkNamespace; row9.stat = row8.count; nb_line_tJavaRow_2++; tos_count_tJavaRow_2++; /** * [tJavaRow_2 main ] stop */ /** * [tFilterRow_1 main ] start */ currentComponent = "tFilterRow_1"; row10 = null; Operator_tFilterRow_1 ope_tFilterRow_1 = new Operator_tFilterRow_1("&&"); ope_tFilterRow_1.matches((// code sample : use // row9 to define // the condition. // row9.columnName1.equals("foo") // ||!(row9.columnName2.equals("bar")) // replace the following // expression by your // own filter condition !row9.link.contains(".") && !row9.link.contains(" ") && !row9.link.equals(context.endpoint_namespace)), "advanced condition failed"); if (ope_tFilterRow_1.getMatchFlag()) { if (row10 == null) { row10 = new row10Struct(); } row10.link = row9.link; row10.stat = row9.stat; nb_line_ok_tFilterRow_1++; } else { nb_line_reject_tFilterRow_1++; } nb_line_tFilterRow_1++; tos_count_tFilterRow_1++; /** * [tFilterRow_1 main ] stop */ // Start of branch "row10" if (row10 != null) { /** * [tLogRow_2 main ] start */ currentComponent = "tLogRow_2"; row5 = row10; tos_count_tLogRow_2++; /** * [tLogRow_2 main ] stop */ /** * [tBufferOutput_1 main ] start */ currentComponent = "tBufferOutput_1"; String[] row_tBufferOutput_1 = new String[] { "", "", }; if (row5.link != null) { row_tBufferOutput_1[0] = row5.link; } else { row_tBufferOutput_1[0] = null; } if (row5.stat != null) { row_tBufferOutput_1[1] = row5.stat; } else { row_tBufferOutput_1[1] = null; } globalBuffer.add(row_tBufferOutput_1); tos_count_tBufferOutput_1++; /** * [tBufferOutput_1 main ] stop */ } // End of branch "row10" } // End of branch "row8" // end for } } // C_01 } // End of branch "row7" // end for } } // C_01 /** * [tHttpRequest_1 end ] start */ currentComponent = "tHttpRequest_1"; ok_Hash.put("tHttpRequest_1", true); end_Hash.put("tHttpRequest_1", System.currentTimeMillis()); /** * [tHttpRequest_1 end ] stop */ /** * [tExtractJSONFields_1 end ] start */ currentComponent = "tExtractJSONFields_1"; globalMap.put("tExtractJSONFields_1_NB_LINE", nb_line_tExtractJSONFields_1); ok_Hash.put("tExtractJSONFields_1", true); end_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); /** * [tExtractJSONFields_1 end ] stop */ /** * [tExtractRegexFields_1 end ] start */ currentComponent = "tExtractRegexFields_1"; ok_Hash.put("tExtractRegexFields_1", true); end_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); /** * [tExtractRegexFields_1 end ] stop */ /** * [tJavaRow_2 end ] start */ currentComponent = "tJavaRow_2"; globalMap.put("tJavaRow_2_NB_LINE", nb_line_tJavaRow_2); ok_Hash.put("tJavaRow_2", true); end_Hash.put("tJavaRow_2", System.currentTimeMillis()); /** * [tJavaRow_2 end ] stop */ /** * [tFilterRow_1 end ] start */ currentComponent = "tFilterRow_1"; globalMap.put("tFilterRow_1_NB_LINE", nb_line_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_OK", nb_line_ok_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_REJECT", nb_line_reject_tFilterRow_1); ok_Hash.put("tFilterRow_1", true); end_Hash.put("tFilterRow_1", System.currentTimeMillis()); /** * [tFilterRow_1 end ] stop */ /** * [tLogRow_2 end ] start */ currentComponent = "tLogRow_2"; ok_Hash.put("tLogRow_2", true); end_Hash.put("tLogRow_2", System.currentTimeMillis()); /** * [tLogRow_2 end ] stop */ /** * [tBufferOutput_1 end ] start */ currentComponent = "tBufferOutput_1"; ok_Hash.put("tBufferOutput_1", true); end_Hash.put("tBufferOutput_1", System.currentTimeMillis()); /** * [tBufferOutput_1 end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tHttpRequest_1 finally ] start */ currentComponent = "tHttpRequest_1"; /** * [tHttpRequest_1 finally ] stop */ /** * [tExtractJSONFields_1 finally ] start */ currentComponent = "tExtractJSONFields_1"; /** * [tExtractJSONFields_1 finally ] stop */ /** * [tExtractRegexFields_1 finally ] start */ currentComponent = "tExtractRegexFields_1"; /** * [tExtractRegexFields_1 finally ] stop */ /** * [tJavaRow_2 finally ] start */ currentComponent = "tJavaRow_2"; /** * [tJavaRow_2 finally ] stop */ /** * [tFilterRow_1 finally ] start */ currentComponent = "tFilterRow_1"; /** * [tFilterRow_1 finally ] stop */ /** * [tLogRow_2 finally ] start */ currentComponent = "tLogRow_2"; /** * [tLogRow_2 finally ] stop */ /** * [tBufferOutput_1 finally ] start */ currentComponent = "tBufferOutput_1"; /** * [tBufferOutput_1 finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 1); }
From source file:bio2rdf.upload_all_datasets_0_1.upload_all_datasets.java
License:Apache License
public void tFileList_3Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tFileList_3_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String iterateId = ""; int iterateLoop = 0; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {// w ww . j av a 2 s . c o m String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row6Struct row6 = new row6Struct(); row4Struct row4 = new row4Struct(); row7Struct row7 = new row7Struct(); /** * [tFileList_3 begin ] start */ int NB_ITERATE_tHttpRequest_4 = 0; // for statistics ok_Hash.put("tFileList_3", false); start_Hash.put("tFileList_3", System.currentTimeMillis()); currentComponent = "tFileList_3"; int tos_count_tFileList_3 = 0; String directory_tFileList_3 = context.workspace; final java.util.List<String> maskList_tFileList_3 = new java.util.ArrayList<String>(); final java.util.List<java.util.regex.Pattern> patternList_tFileList_3 = new java.util.ArrayList<java.util.regex.Pattern>(); maskList_tFileList_3.add("datahub_import_*.json"); for (final String filemask_tFileList_3 : maskList_tFileList_3) { String filemask_compile_tFileList_3 = filemask_tFileList_3; filemask_compile_tFileList_3 = org.apache.oro.text.GlobCompiler.globToPerl5( filemask_tFileList_3.toCharArray(), org.apache.oro.text.GlobCompiler.DEFAULT_MASK); java.util.regex.Pattern fileNamePattern_tFileList_3 = java.util.regex.Pattern .compile(filemask_compile_tFileList_3); patternList_tFileList_3.add(fileNamePattern_tFileList_3); } int NB_FILEtFileList_3 = 0; final boolean case_sensitive_tFileList_3 = true; final java.util.List<java.io.File> list_tFileList_3 = new java.util.ArrayList<java.io.File>(); final java.util.List<String> filePath_tFileList_3 = new java.util.ArrayList<String>(); java.io.File file_tFileList_3 = new java.io.File(directory_tFileList_3); file_tFileList_3.listFiles(new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { java.io.File file = new java.io.File(dir, name); if (!file.isDirectory()) { String fileName_tFileList_3 = file.getName(); for (final java.util.regex.Pattern fileNamePattern_tFileList_3 : patternList_tFileList_3) { if (fileNamePattern_tFileList_3.matcher(fileName_tFileList_3).matches()) { if (!filePath_tFileList_3.contains(file.getAbsolutePath())) { list_tFileList_3.add(file); filePath_tFileList_3.add(file.getAbsolutePath()); } } } } return true; } }); java.util.Collections.sort(list_tFileList_3); for (int i_tFileList_3 = 0; i_tFileList_3 < list_tFileList_3.size(); i_tFileList_3++) { java.io.File files_tFileList_3 = list_tFileList_3.get(i_tFileList_3); String fileName_tFileList_3 = files_tFileList_3.getName(); String currentFileName_tFileList_3 = files_tFileList_3.getName(); String currentFilePath_tFileList_3 = files_tFileList_3.getAbsolutePath(); String currentFileDirectory_tFileList_3 = files_tFileList_3.getParent(); String currentFileExtension_tFileList_3 = null; if (files_tFileList_3.getName().contains(".") && files_tFileList_3.isFile()) { currentFileExtension_tFileList_3 = files_tFileList_3.getName() .substring(files_tFileList_3.getName().lastIndexOf(".") + 1); } else { currentFileExtension_tFileList_3 = ""; } NB_FILEtFileList_3++; globalMap.put("tFileList_3_CURRENT_FILE", currentFileName_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEPATH", currentFilePath_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEDIRECTORY", currentFileDirectory_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEEXTENSION", currentFileExtension_tFileList_3); globalMap.put("tFileList_3_NB_FILE", NB_FILEtFileList_3); /** * [tFileList_3 begin ] stop */ /** * [tFileList_3 main ] start */ currentComponent = "tFileList_3"; tos_count_tFileList_3++; /** * [tFileList_3 main ] stop */ NB_ITERATE_tHttpRequest_4++; iterateLoop++; /** * [tLogRow_4 begin ] start */ ok_Hash.put("tLogRow_4", false); start_Hash.put("tLogRow_4", System.currentTimeMillis()); currentComponent = "tLogRow_4"; int tos_count_tLogRow_4 = 0; // ///////////////////// final String OUTPUT_FIELD_SEPARATOR_tLogRow_4 = "|"; java.io.PrintStream consoleOut_tLogRow_4 = null; StringBuilder strBuffer_tLogRow_4 = null; int nb_line_tLogRow_4 = 0; // ///////////////////// /** * [tLogRow_4 begin ] stop */ /** * [tExtractJSONFields_3 begin ] start */ ok_Hash.put("tExtractJSONFields_3", false); start_Hash.put("tExtractJSONFields_3", System.currentTimeMillis()); currentComponent = "tExtractJSONFields_3"; int tos_count_tExtractJSONFields_3 = 0; int nb_line_tExtractJSONFields_3 = 0; class ConvertJSONString_tExtractJSONFields_3 { final static int Brace = 0; // { final static int Bracket = 1; // [ private int barceType = -1; private String originalJsonString = ""; private String originalLoopString = ""; private String jsonString4XML = null; private String loopString4XML = null; private String additionRoot = null; public void barceType() { for (int c = 0; c < originalJsonString.length(); ++c) { if (originalJsonString.charAt(c) == '{') { barceType = Brace; break; } else if (originalJsonString.charAt(c) == '[') { barceType = Bracket; break; } } } public void setJsonString(String originalJsonString) { this.originalJsonString = originalJsonString; } public void setLoopString(String originalLoopString) { this.originalLoopString = originalLoopString; } public String getJsonString4XML() { return jsonString4XML; } public String getLoopString4XML() { if (loopString4XML.length() > 1 && loopString4XML.endsWith("/")) { loopString4XML = loopString4XML.substring(0, loopString4XML.length() - 1); } return loopString4XML; } public void setAdditionRoot(String additionRoot) { this.additionRoot = additionRoot; } public String getAdditionRoot() { return additionRoot; } public void generate() { barceType(); jsonString4XML = originalJsonString; loopString4XML = originalLoopString; if (Brace == barceType) { if (isNeedAddRoot(originalJsonString)) { jsonString4XML = "{ \"root\": " + originalJsonString + " }"; loopString4XML = "root" + originalLoopString; setAdditionRoot("root"); } } else if (Bracket == barceType) { jsonString4XML = "{ \"root\" : { \"object\": " + originalJsonString + " } }"; loopString4XML = "root/object" + originalLoopString; setAdditionRoot("object"); } } public boolean isNeedAddRoot(String originalJsonString) { boolean isNeedAddRoot = false; net.sf.json.JSONObject jso = net.sf.json.JSONObject.fromObject(originalJsonString); String jsonKey = ""; Object firstObject = null; if (jso.names().size() == 1) { jsonKey = jso.names().get(0).toString(); firstObject = jso.get(jsonKey); } if (jso.size() > 1 || (firstObject != null && firstObject instanceof net.sf.json.JSONArray && ((net.sf.json.JSONArray) firstObject).size() > 1)) { isNeedAddRoot = true; } return isNeedAddRoot; } } ConvertJSONString_tExtractJSONFields_3 cjs_tExtractJSONFields_3 = new ConvertJSONString_tExtractJSONFields_3(); de.odysseus.staxon.json.JsonXMLConfig config_tExtractJSONFields_3 = new de.odysseus.staxon.json.JsonXMLConfigBuilder() .multiplePI(false).build(); de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory_tExtractJSONFields_3 = new de.odysseus.staxon.json.JsonXMLInputFactory( config_tExtractJSONFields_3); javax.xml.stream.XMLOutputFactory xmlOutputFactory_tExtractJSONFields_3 = javax.xml.stream.XMLOutputFactory .newInstance(); boolean isGetWholeJson_tExtractJSONFields_3 = false; class OriginalJSONString_tExtractJSONFields_3 { } OriginalJSONString_tExtractJSONFields_3 originalJSONString_tExtractJSONFields_3 = new OriginalJSONString_tExtractJSONFields_3(); class XML_API_tExtractJSONFields_3 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } String jsonStr_tExtractJSONFields_3 = ""; String xmlStr_tExtractJSONFields_3 = ""; XML_API_tExtractJSONFields_3 xml_api_tExtractJSONFields_3 = new XML_API_tExtractJSONFields_3(); /** * [tExtractJSONFields_3 begin ] stop */ /** * [tReplicate_1 begin ] start */ ok_Hash.put("tReplicate_1", false); start_Hash.put("tReplicate_1", System.currentTimeMillis()); currentComponent = "tReplicate_1"; int tos_count_tReplicate_1 = 0; /** * [tReplicate_1 begin ] stop */ /** * [tHttpRequest_4 begin ] start */ ok_Hash.put("tHttpRequest_4", false); start_Hash.put("tHttpRequest_4", System.currentTimeMillis()); currentComponent = "tHttpRequest_4"; int tos_count_tHttpRequest_4 = 0; /** * [tHttpRequest_4 begin ] stop */ /** * [tHttpRequest_4 main ] start */ currentComponent = "tHttpRequest_4"; java.net.URL url_tHttpRequest_4 = new java.net.URL( "http://datahub.io/api/action/package_update"); java.net.HttpURLConnection urlConn_tHttpRequest_4 = (java.net.HttpURLConnection) url_tHttpRequest_4 .openConnection(); urlConn_tHttpRequest_4.setRequestMethod("POST"); urlConn_tHttpRequest_4.setDoOutput(true); urlConn_tHttpRequest_4.setDoInput(true); urlConn_tHttpRequest_4.setUseCaches(false); urlConn_tHttpRequest_4.setRequestProperty("Authorization", context.authorizationKey); urlConn_tHttpRequest_4.connect(); byte[] buffer_tHttpRequest_4 = new byte[1024]; int bos_buffer_tHttpRequest_4 = 0; StringBuilder sb_tHttpRequest_4 = new StringBuilder(); java.io.InputStream bisParam_tHttpRequest_4 = new java.io.BufferedInputStream( new java.io.FileInputStream(((String) globalMap.get("tFileList_3_CURRENT_FILEPATH")))); java.io.OutputStream bosParam_tHttpRequest_4 = new java.io.BufferedOutputStream( urlConn_tHttpRequest_4.getOutputStream()); while ((bos_buffer_tHttpRequest_4 = bisParam_tHttpRequest_4 .read(buffer_tHttpRequest_4)) != -1) { bosParam_tHttpRequest_4.write(buffer_tHttpRequest_4, 0, bos_buffer_tHttpRequest_4); } bosParam_tHttpRequest_4.flush(); bosParam_tHttpRequest_4.close(); bisParam_tHttpRequest_4.close(); if (java.net.HttpURLConnection.HTTP_OK == (urlConn_tHttpRequest_4.getResponseCode())) { java.io.InputStream bis_tHttpRequest_4 = new java.io.BufferedInputStream( urlConn_tHttpRequest_4.getInputStream()); while ((bos_buffer_tHttpRequest_4 = bis_tHttpRequest_4.read(buffer_tHttpRequest_4)) != -1) { sb_tHttpRequest_4 .append(new String(buffer_tHttpRequest_4, 0, bos_buffer_tHttpRequest_4)); } bis_tHttpRequest_4.close(); } else { System.err.println(urlConn_tHttpRequest_4.getResponseCode() + " " + urlConn_tHttpRequest_4.getResponseMessage()); } row6.ResponseContent = sb_tHttpRequest_4.toString(); urlConn_tHttpRequest_4.disconnect(); tos_count_tHttpRequest_4++; /** * [tHttpRequest_4 main ] stop */ /** * [tReplicate_1 main ] start */ currentComponent = "tReplicate_1"; row4 = new row4Struct(); row4.ResponseContent = row6.ResponseContent; tos_count_tReplicate_1++; /** * [tReplicate_1 main ] stop */ /** * [tExtractJSONFields_3 main ] start */ currentComponent = "tExtractJSONFields_3"; if (row4.ResponseContent != null) {// C_01 jsonStr_tExtractJSONFields_3 = row4.ResponseContent.toString(); row7 = null; org.dom4j.io.SAXReader reader_tExtractJSONFields_3 = new org.dom4j.io.SAXReader(); org.dom4j.Document doc_tExtractJSONFields_3 = null; java.util.HashMap xmlNameSpaceMap_tExtractJSONFields_3 = new java.util.HashMap<String, String>(); org.dom4j.XPath x_tExtractJSONFields_3 = null; java.util.List<org.dom4j.tree.AbstractNode> nodeList_tExtractJSONFields_3 = null; boolean isStructError_tExtractJSONFields_3 = true; String loopQuery_tExtractJSONFields_3 = "/result"; String oraginalJsonStr_tExtractJSONFields_3 = jsonStr_tExtractJSONFields_3; cjs_tExtractJSONFields_3.setJsonString(jsonStr_tExtractJSONFields_3); cjs_tExtractJSONFields_3.setLoopString(loopQuery_tExtractJSONFields_3); java.io.ByteArrayInputStream bais_tExtractJSONFields_3 = null; java.io.ByteArrayOutputStream baos_tExtractJSONFields_3 = new java.io.ByteArrayOutputStream(); try { cjs_tExtractJSONFields_3.generate(); jsonStr_tExtractJSONFields_3 = cjs_tExtractJSONFields_3.getJsonString4XML(); loopQuery_tExtractJSONFields_3 = cjs_tExtractJSONFields_3.getLoopString4XML(); bais_tExtractJSONFields_3 = new ByteArrayInputStream( jsonStr_tExtractJSONFields_3.getBytes("UTF-8")); javax.xml.stream.XMLEventReader xmlEventReader_tExtractJSONFields_3 = jsonXMLInputFactory_tExtractJSONFields_3 .createXMLEventReader(bais_tExtractJSONFields_3); javax.xml.stream.XMLEventWriter xmLEventWriter_tExtractJSONFields_3 = xmlOutputFactory_tExtractJSONFields_3 .createXMLEventWriter(baos_tExtractJSONFields_3, "UTF-8"); xmLEventWriter_tExtractJSONFields_3.add(xmlEventReader_tExtractJSONFields_3); // convert json string to xml xmlStr_tExtractJSONFields_3 = baos_tExtractJSONFields_3.toString(); xmLEventWriter_tExtractJSONFields_3.close(); xmlEventReader_tExtractJSONFields_3.close(); doc_tExtractJSONFields_3 = reader_tExtractJSONFields_3 .read(new java.io.StringReader(xmlStr_tExtractJSONFields_3)); x_tExtractJSONFields_3 = doc_tExtractJSONFields_3 .createXPath(loopQuery_tExtractJSONFields_3); x_tExtractJSONFields_3.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_3); nodeList_tExtractJSONFields_3 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tExtractJSONFields_3 .selectNodes(doc_tExtractJSONFields_3); isStructError_tExtractJSONFields_3 = false; } catch (java.lang.Exception ex_tExtractJSONFields_3) { System.err.println(ex_tExtractJSONFields_3.getMessage()); } finally { baos_tExtractJSONFields_3.close(); if (bais_tExtractJSONFields_3 != null) { bais_tExtractJSONFields_3.close(); } } org.dom4j.Node node_tExtractJSONFields_3 = null; String str_tExtractJSONFields_3 = ""; for (int i_tExtractJSONFields_3 = 0; isStructError_tExtractJSONFields_3 || (nodeList_tExtractJSONFields_3 != null && i_tExtractJSONFields_3 < nodeList_tExtractJSONFields_3 .size()); i_tExtractJSONFields_3++) { if (!isStructError_tExtractJSONFields_3) { row7 = null; row7 = new row7Struct(); org.dom4j.tree.AbstractNode temp_tExtractJSONFields_3 = nodeList_tExtractJSONFields_3 .get(i_tExtractJSONFields_3); nb_line_tExtractJSONFields_3++; try { org.dom4j.XPath xTmp0_tExtractJSONFields_3 = temp_tExtractJSONFields_3 .createXPath("name"); xTmp0_tExtractJSONFields_3 .setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_3); Object obj0_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .evaluate(temp_tExtractJSONFields_3); if (obj0_tExtractJSONFields_3 instanceof String || obj0_tExtractJSONFields_3 instanceof Number) { node_tExtractJSONFields_3 = temp_tExtractJSONFields_3; str_tExtractJSONFields_3 = String.valueOf(obj0_tExtractJSONFields_3); } else { node_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .selectSingleNode(temp_tExtractJSONFields_3); str_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .valueOf(temp_tExtractJSONFields_3); } if (xml_api_tExtractJSONFields_3.isDefNull(node_tExtractJSONFields_3)) { row7.ResponseContent = null; } else if (xml_api_tExtractJSONFields_3.isEmpty(node_tExtractJSONFields_3)) { row7.ResponseContent = ""; } else if (xml_api_tExtractJSONFields_3.isMissing(node_tExtractJSONFields_3)) { row7.ResponseContent = null; } else { row7.ResponseContent = str_tExtractJSONFields_3; } } catch (java.lang.Exception ex_tExtractJSONFields_3) { System.err.println(ex_tExtractJSONFields_3.getMessage()); row7 = null; } } isStructError_tExtractJSONFields_3 = false; tos_count_tExtractJSONFields_3++; /** * [tExtractJSONFields_3 main ] stop */ // Start of branch "row7" if (row7 != null) { /** * [tLogRow_4 main ] start */ currentComponent = "tLogRow_4"; // ///////////////////// strBuffer_tLogRow_4 = new StringBuilder(); if (row7.ResponseContent != null) { // strBuffer_tLogRow_4.append(String.valueOf(row7.ResponseContent)); } // if (globalMap.get("tLogRow_CONSOLE") != null) { consoleOut_tLogRow_4 = (java.io.PrintStream) globalMap.get("tLogRow_CONSOLE"); } else { consoleOut_tLogRow_4 = new java.io.PrintStream( new java.io.BufferedOutputStream(System.out)); globalMap.put("tLogRow_CONSOLE", consoleOut_tLogRow_4); } consoleOut_tLogRow_4.println(strBuffer_tLogRow_4.toString()); consoleOut_tLogRow_4.flush(); nb_line_tLogRow_4++; // //// // //// // ///////////////////// tos_count_tLogRow_4++; /** * [tLogRow_4 main ] stop */ } // End of branch "row7" // end for } } // C_01 /** * [tHttpRequest_4 end ] start */ currentComponent = "tHttpRequest_4"; ok_Hash.put("tHttpRequest_4", true); end_Hash.put("tHttpRequest_4", System.currentTimeMillis()); /** * [tHttpRequest_4 end ] stop */ /** * [tReplicate_1 end ] start */ currentComponent = "tReplicate_1"; ok_Hash.put("tReplicate_1", true); end_Hash.put("tReplicate_1", System.currentTimeMillis()); /** * [tReplicate_1 end ] stop */ /** * [tExtractJSONFields_3 end ] start */ currentComponent = "tExtractJSONFields_3"; globalMap.put("tExtractJSONFields_1_NB_LINE", nb_line_tExtractJSONFields_3); ok_Hash.put("tExtractJSONFields_3", true); end_Hash.put("tExtractJSONFields_3", System.currentTimeMillis()); /** * [tExtractJSONFields_3 end ] stop */ /** * [tLogRow_4 end ] start */ currentComponent = "tLogRow_4"; // //// // //// globalMap.put("tLogRow_4_NB_LINE", nb_line_tLogRow_4); // ///////////////////// ok_Hash.put("tLogRow_4", true); end_Hash.put("tLogRow_4", System.currentTimeMillis()); /** * [tLogRow_4 end ] stop */ /** * [tFileList_3 end ] start */ currentComponent = "tFileList_3"; } globalMap.put("tFileList_3_NB_FILE", NB_FILEtFileList_3); ok_Hash.put("tFileList_3", true); end_Hash.put("tFileList_3", System.currentTimeMillis()); /** * [tFileList_3 end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tFileList_3 finally ] start */ currentComponent = "tFileList_3"; /** * [tFileList_3 finally ] stop */ /** * [tHttpRequest_4 finally ] start */ currentComponent = "tHttpRequest_4"; /** * [tHttpRequest_4 finally ] stop */ /** * [tReplicate_1 finally ] start */ currentComponent = "tReplicate_1"; /** * [tReplicate_1 finally ] stop */ /** * [tExtractJSONFields_3 finally ] start */ currentComponent = "tExtractJSONFields_3"; /** * [tExtractJSONFields_3 finally ] stop */ /** * [tLogRow_4 finally ] start */ currentComponent = "tLogRow_4"; /** * [tLogRow_4 finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tFileList_3_SUBPROCESS_STATE", 1); }
From source file:br.gov.jfrj.siga.wf.tag.ProcessImageTag.java
License:Open Source License
/** * Extrai os limites da caixa para que seja desenhada a marcao sua volta. * @param root/*w w w .j a v a 2 s. c o m*/ * @return */ private int[] extractBoxConstraint(Element root) { int[] result = new int[4]; String nodeName = currentToken.getNode().getName(); XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']"); Element node = (Element) xPath.selectSingleNode(root); result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue(); result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue(); result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue(); result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue(); return result; }
From source file:br.gov.jfrj.siga.wf.tag.ProcessImageTag.java
License:Open Source License
/** * Extrai os limites da caixa para que seja desenhada a marcao sua volta. * @param root//from w w w . j a v a2 s. c o m * @param token * @return */ private int[] extractBoxConstraint(Element root, Token token) { int[] result = new int[4]; String nodeName = ""; try { nodeName = new String(token.getNode().getName().getBytes("ISO-8859-1")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']"); Element node = (Element) xPath.selectSingleNode(root); result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue(); result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue(); result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue(); result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue(); return result; }
From source file:com.alibaba.intl.bcds.goldroom.remote.DoubanBookInfoFetcher.java
License:Open Source License
private String queryByXpath(String xpathExpression, Document document) { try {/*from w w w. jav a 2s. co m*/ XPath xPath = createXpath(xpathExpression); Node node = xPath.selectSingleNode(document); if (node != null) { return node.getText(); } return null; } catch (RuntimeException e) { return null; } }
From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java
License:Open Source License
/** * Extracts the value of the supplied attribute * //from ww w.ja v a 2 s . c o m * @param element * element with attribute in question * @param attributeName * name of the attribute in question * @return value of the attribute in question * @throws GenericArtifactParsingException * exception s thrown is attribute is missing */ private static String getAttributeValue(Element element, String attributeName) throws GenericArtifactParsingException { // TODO Cash constructed XPath objects? // XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" + // attributeName); XPath xpath = new DefaultXPath("@" + attributeName); xpath.setNamespaceURIs(ccfNamespaceMap); Node attributeNode = xpath.selectSingleNode(element); if (attributeNode == null) throw new GenericArtifactParsingException( "Missing attribute: " + attributeName + " in element " + element.getName()); else return attributeNode.getText(); }
From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java
License:Open Source License
/** * Extracts the value of the supplied attribute without throwing an * exception if missing/*w w w . j a v a 2 s.c o m*/ * * @param element * element with attribute in question * @param attributeName * name of the attribute in question * @return value of the attribute in question, null if attribute is missing * */ private static String getAttributeValueWithoutException(Element element, String attributeName) { // TODO Cash constructed XPath objects? // XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" + // attributeName); XPath xpath = new DefaultXPath("@" + attributeName); xpath.setNamespaceURIs(ccfNamespaceMap); Node attributeNode = xpath.selectSingleNode(element); if (attributeNode == null) return null; else return attributeNode.getText(); }
From source file:com.collabnet.ccf.core.utils.XPathUtils.java
License:Open Source License
/** * Extracts the value of the supplied attribute * /*from www . jav a2 s. c o m*/ * @param element * element with attribute in question * @param attributeName * name of the attribute in question * @param failIfNotFound * determines if exception should be thrown if attribute is not * found * @return value of the attribute in question, null if not found and * failIfNotFound is set to false * @throws GenericArtifactParsingException * exception thrown is attribute is missing and failIfNotFound * is set to true */ public static String getAttributeValue(Element element, String attributeName, boolean failIfNotFound) throws GenericArtifactParsingException { XPath xpath = new DefaultXPath("@" + attributeName); xpath.setNamespaceURIs(ccfNamespaceMap); Node attributeNode = xpath.selectSingleNode(element); if (attributeNode == null) { if (failIfNotFound) { throw new GenericArtifactParsingException( "Missing attribute: " + attributeName + " in element " + element.getName()); } else { return null; } } else { return attributeNode.getText(); } }
From source file:com.controlj.addon.weather.noaa.StationSourceFactory.java
License:Open Source License
private String findClosestWeatherStationID(Document weatherStations, float latitude, float longitude) { XPath idXpath = weatherStations.createXPath("station_id"); float minDistance = Float.MAX_VALUE; String minId = null;/*from ww w . j a va 2 s .com*/ List stations = weatherStations.selectNodes("/wx_station_index//station"); for (Object station : stations) { try { StationSourceImpl stationSource = new StationSourceImpl((Node) station); float nextDistance = stationSource.getDistanceTo(latitude, longitude, false); if (nextDistance < minDistance) { Node id = idXpath.selectSingleNode(station); if (id != null) { minId = id.getText(); minDistance = nextDistance; } } } catch (NumberFormatException e) { } // skip this one if malformed } return minId; }
From source file:com.controlj.addon.weather.noaa.StationSourceImpl.java
License:Open Source License
private Float getFloatValue(XPath xpath) { Float result = null;/*from w ww . j a v a2s. c o m*/ Node node = xpath.selectSingleNode(stationNode); if (node != null) { try { result = new Float(node.getText()); } catch (NumberFormatException e) { } // ignore and return null } return result; }