List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.ctvit.vdp.product.baseconfig.service.SystemConfigService.java
public ArrayList<String[]> getOrgTypes() throws Exception { String[] typeBean = null;//from ww w .j av a2s . com ArrayList<String[]> resultList = new ArrayList<String[]>(); Document doc = XMLUtil.transforXml(getSystemConfig("EnumDefines")); Element root = doc.getRootElement(); List<Element> selectedNodes = root.selectNodes("Enum"); for (Element element : selectedNodes) { if ("".equals(element.attributeValue("enumid"))) { List<Element> el = element.elements("EnumNode"); for (Element element1 : el) { typeBean = new String[2]; typeBean[0] = element1.attributeValue("label"); typeBean[1] = element1.attributeValue("value"); resultList.add(typeBean); } break; } } return resultList; }
From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java
/** * ?????XML/*from ww w . j av a 2s . com*/ **/ public Map<String, String> getXML(Map xmlRightIds, Map thirdRightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Document topDoc = DocumentHelper.createDocument(); Element baseElement = doc.getRootElement(); Element topEl = topDoc.addElement("Rights");//?XML List<Element> secMenuList = new ArrayList<Element>(); String topIdFlag = ""; Iterator elementIter = baseElement.elementIterator(); while (elementIter.hasNext()) {//?? Element element01 = (Element) elementIter.next(); Iterator elementIter01 = element01.elementIterator(); while (elementIter01.hasNext()) {//?? Element element02 = (Element) elementIter01.next(); Iterator elementIter02 = element02.elementIterator(); String idFlag = ""; if (xmlRightIds.get(element02.attributeValue("id")) != null) {//??ID?ID Element tempEl = element02.getParent();//? if (topEl.nodeCount() > 0 && !topIdFlag.equals(tempEl.attributeValue("id"))) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } if (topEl.nodeCount() == 0) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } topIdFlag = tempEl.attributeValue("id"); secMenuList.add(element02); } } } StringBuffer secXML = new StringBuffer(); secXML.append("<Rights>"); Element tempTopEl = topEl.createCopy(); // System.out.println("tempTopEl: "+tempTopEl.asXML()); Iterator secIt = tempTopEl.elementIterator();//???? String flag = ""; while (secIt.hasNext()) { Element op = (Element) secIt.next(); for (Element eo : secMenuList) {//eo?? if (eo.attributeValue("id").substring(0, 2).equals(op.attributeValue("id")) && !flag.equals(eo.attributeValue("id"))) { flag = eo.attributeValue("id"); Document secDoc = DocumentHelper.createDocument(); Element secEle = secDoc.addElement("SecMenu"); secEle.addAttribute("id", eo.attributeValue("id")); secEle.addAttribute("name", eo.attributeValue("name")); secEle.addAttribute("source", eo.attributeValue("source")); Iterator eoIter = eo.elementIterator(); while (eoIter.hasNext()) {//?? Element thirdEl = (Element) eoIter.next(); if (thirdRightIds.get(thirdEl.attributeValue("id")) != null) { Document document = DocumentHelper.createDocument(); Element tempEle = document.addElement("ThirdMenu"); tempEle.addAttribute("id", thirdEl.attributeValue("id")); tempEle.addAttribute("name", thirdEl.attributeValue("name")); tempEle.addAttribute("source", thirdEl.attributeValue("source")); secEle.add(tempEle);// } } op.add(secEle);// } //System.out.println("************ op: "+op.asXML()); } secXML.append(op.asXML()); } secXML.append("</Rights>"); Map<String, String> xmlMap = new HashMap<String, String>(); xmlMap.put("topMenu", topEl.asXML()); xmlMap.put("treeMenu", secXML.toString()); xmlMap.put("baseXML", baseElement.asXML()); // this.getElementList(baseElement,xmlRightIds); return xmlMap; }
From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java
public String getRightXML(Map rightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Element baseElement = doc.getRootElement(); Iterator elementIter = baseElement.elementIterator(); //?// w w w.j a v a 2 s.co m while (elementIter.hasNext()) {//?? Element el01 = (Element) elementIter.next(); if (rightIds.get(el01.attributeValue("id")) == null) { baseElement.remove(el01); } Iterator elIter01 = el01.elementIterator(); while (elIter01.hasNext()) {//?? Element el02 = (Element) elIter01.next(); if (rightIds.get(el02.attributeValue("id")) == null) { el01.remove(el02); } Iterator elIter02 = el02.elementIterator(); while (elIter02.hasNext()) {//??(?) Element el03 = (Element) elIter02.next(); if (rightIds.get(el03.attributeValue("id")) == null) { el02.remove(el03); } Iterator elIter03 = el03.elementIterator(); while (elIter03.hasNext()) {//??() Element el04 = (Element) elIter03.next(); if (rightIds.get(el04.attributeValue("id")) == null) { el03.remove(el04); } Iterator elIter04 = el04.elementIterator(); while (elIter04.hasNext()) {//??() Element el05 = (Element) elIter04.next(); System.out.println(el05.attributeValue("id")); if (rightIds.get(el05.attributeValue("id")) == null) { el04.remove(el05); } } } } } } return baseElement.asXML(); }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.SuiteResult.java
License:Open Source License
/** * Parses the JUnit XML file into {@link SuiteResult}s. This method returns a collection, as a single XML may have multiple <testsuite> * elements wrapped into the top-level <testsuites>. *///from w w w . ja v a 2s . c om static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException { List<SuiteResult> r = new ArrayList<SuiteResult>(); // parse into DOM SAXReader saxReader = new SAXReader(); // install EntityResolver for resolving DTDs, which are in files created by TestNG. // (see https://hudson.dev.java.net/servlets/ReadMsg?listName=users&msgNo=5530) XMLEntityResolver resolver = new XMLEntityResolver(); saxReader.setEntityResolver(resolver); Document result = saxReader.read(xmlReport); Element root = result.getRootElement(); if (root.getName().equals("testsuites")) { // multi-suite file for (Element suite : (List<Element>) root.elements("testsuite")) r.add(new SuiteResult(xmlReport, suite, keepLongStdio)); } else { // single suite file r.add(new SuiteResult(xmlReport, root, keepLongStdio)); } return r; }
From source file:com.cy.dcts.identityVerify.service.impl.IdentityVerifyServiceImpl.java
private Map<String, String> paresXml2Map(String xml) { Map<String, String> map = new HashMap<String, String>(); Document document = null; String errormesage = ""; String errormesagecol = ""; String idNumberRst = ""; String xmRst = ""; String errorMsg = ""; String errorCode = ""; try {//w w w . j a v a2 s . c om document = DocumentHelper.parseText(xml); Element rootElement = document.getRootElement();//? Attribute rootAttr = rootElement.attribute("errorcode"); if (rootAttr != null) { Node errorCodeNode = rootElement.selectSingleNode("//RESPONSE/ROWS/ROW/ErrorCode"); Node errorMsgNode = rootElement.selectSingleNode("//RESPONSE/ROWS/ROW/ErrorMsg"); if (errorCodeNode != null && errorMsgNode != null) { errorMsg = errorMsgNode.getText(); errorCode = errorCodeNode.getText(); } map.put("errorCode", errorCode); map.put("errorMsg", errorMsg); return map; } Node idNumberNode = rootElement.selectSingleNode("//ROWS/ROW/INPUT/gmsfhm"); String idNumber = idNumberNode.getText(); String name = rootElement.selectSingleNode("//ROWS/ROW/INPUT/xm").getText(); map.put("gmsfhm", idNumber); map.put("xm", name); Node sfNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/result_gmsfhm"); Node xmNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/result_xm"); if (sfNode == null || xmNode == null) { Node errorMsgNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/errormesage"); Node errorColNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/errormesagecol"); if (errorMsgNode != null && errorColNode != null) { errormesage = errorMsgNode.getText(); errormesagecol = errorColNode.getText(); } } else { idNumberRst = sfNode.getText(); xmRst = xmNode.getText(); } map.put("result_gmsfhm", idNumberRst); map.put("result_xm", xmRst); map.put("errormesage", errormesage); map.put("errormesagecol", errormesagecol); } catch (DocumentException e) { e.printStackTrace(); } return map; }
From source file:com.daoke.mobileserver.carinsurance.controller.CarInsuranceController.java
/** * // w w w .java2 s.c o m * * @param car * @return */ @ResponseBody @RequestMapping("/queryCarType") public String queryCarType(Car car) { String result = null; Document doc = null; try { String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>" + "<PackageList>" + "<Package>" + "<Header>" + "<version>2</version>" + "<ordertype>3</ordertype>" + "<username>" + car.getUsername() + "</username>" + "<password>" + car.getPassword() + "</password>" + "</Header>" + "<Request>" + "<AreaInfo>" + "<companyno>" + car.getCompanyno() + "</companyno>" + "<citycode>" + car.getCitycode() + "</citycode>" + "</AreaInfo>" + "<CarmoduleInfo>" + "<callback>" + car.getCallback() + "</callback>" + "</CarmoduleInfo>" + "<VehicleInfo>" + "<licenseno>" + car.getLicenseno() + "</licenseno>" + "<nolicenseflag>" + car.isNolicenseflag() + "</nolicenseflag>" + "<ownername>" + car.getOwnername() + "</ownername>" + "</VehicleInfo>" + "</Request>" + "</Package>" + "</PackageList>"; result = carInsuranceService.queryCarType(xml, carApi); doc = DocumentHelper.parseText(result); Element rootElement = doc.getRootElement(); Element element = rootElement.element("Package"); Element header = element.element("Header"); String statuscode = header.elementTextTrim("statuscode"); if (("0").equals(statuscode)) { Element response = element.element("Response"); Element carmoduleInfo = response.element("CarmoduleInfo"); String page = carmoduleInfo.elementTextTrim("page"); } else { String message = header.elementTextTrim("message"); } logger.info(result); } catch (Exception e) { result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, ConstantsUtil.RESULT_SERVICE_ERROR); logger.error(JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString())); } return result; }
From source file:com.daoke.mobileserver.carinsurance.controller.CarInsuranceController.java
/** * ?????/*from ww w . j av a 2 s. c o m*/ * * @param elementInsurance * @return */ @ResponseBody @RequestMapping("/getElementAndInsurance") public String getElementAndInsurance(ElementInsurance elementInsurance) { String result = null; Document doc = null; try { String type = elementInsurance.getSubType(); if (StringUtils.isNotEmpty(type)) { type = "<TagsCarSubjList>" + "<Tag>" + "<Definition name=\"type\">" + elementInsurance.getSubType() + "</ Definition>" + "<Definition name=\"key\">" + elementInsurance.getSubKey() + "</ Definition>" + "<Definition name=\"label\">" + elementInsurance.getSubLabel() + "</Definition>" + "<Definition name=\"value\"/>" + "<Definition name=\"premium\"/>" + "<Definition name=\"disable\"/>" + "<Definition name=\"data\"> <![CDATA:1;?: 0]]> </ Definition>" + "</Tag>" + "</TagsCarSubjList>" + "<TagsCarRiskList>" + "<Tag>" + "<Definition name=\"type\">" + elementInsurance.getRiskType() + "</Definition>" + "<Definition name=\"key\">" + elementInsurance.getRiskKey() + "</Definition>" + "<Definition name=\"label\">" + elementInsurance.getRiskLabel() + "</Definition>" + "<Definition name=\"value\">" + elementInsurance.getRiskValue() + "</Definition>" + "<Definition name=\"premium\">" + elementInsurance.getRiskPremium() + "</Definition>" + "<Definition name=\"disable\"/>" + "<Definition name=\"data\"><![CDATA[?:1]]></Definition>" + "</Tag>" + "</TagsCarRiskList>"; } else { type = ""; } String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>" + "<PackageList>" + "<Package>" + "<Header>" + "<version>2</version>" + "<ordertype>3</ordertype>" + "<username>" + elementInsurance.getUsername() + "</username>" + "<password>" + elementInsurance.getPassword() + "</password>" + "</Header>" + "<Request>" + "<AreaInfo>" + "<companyno>" + elementInsurance.getCompanyno() + "</companyno>" + "<citycode>" + elementInsurance.getCitycode() + "</citycode>" + "</AreaInfo>" + "<PlcInfo>" + "<plcstartdate>" + elementInsurance.getPlcstartdate() + "</plcstartdate>" + "<plcenddate>" + elementInsurance.getPlcenddate() + "</plcenddate>" + "</PlcInfo>" + "<VehicleInfo>" + "<licenseno>" + elementInsurance.getLicenseno() + "</licenseno>" + "<nolicenseflag>" + elementInsurance.isNolicenseflag() + "</nolicenseflag>" + "<ownername>" + elementInsurance.getOwnername() + "</ownername>" + "<ownercerttype>" + elementInsurance.getOwnercerttype() + "</ownercerttype>" + "<ownercertno>" + elementInsurance.getOwnercertno() + "</ownercertno>" + "</VehicleInfo>" + "<InsurInfo>" + "<name>" + elementInsurance.getName() + "</name>" + "</InsurInfo>" + type + "</Request>" + "</Package>" + "</PackageList>"; result = carInsuranceService.getElementAndInsurance(xml, carApi); doc = DocumentHelper.parseText(result); Element rootElement = doc.getRootElement(); Element element = rootElement.element("Package"); Element header = element.element("Header"); String statuscode = header.elementTextTrim("statuscode"); if (("2").equals(statuscode)) { //? } } catch (Exception e) { result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, ConstantsUtil.RESULT_SERVICE_ERROR); logger.error(JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString())); } return result; }
From source file:com.delmar.station.service.impl.WFDetailServiceImpl.java
public String updateDcmsFcrDate(EDIResponseInfo edirInfo, String trustFileCode) { String resultMessage = "success"; Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); String currentDate = sf.format(date); try {/*w ww. j ava 2 s . com*/ date = sf.parse(edirInfo.getInDate()); currentDate = sf.format(date); } catch (ParseException e1) { e1.printStackTrace(); } try { EDIResponseInfo resultEDIResponseInfo = ediResponseInfoService.getEDIRByTrustFileCode(trustFileCode); // Booking IDCargoProDcms????bookingID if (StringUtil.isNotEmpty(resultEDIResponseInfo.getCsReferenceNo())) { Map<String, String> params = new HashMap<String, String>(); params.put("id", resultEDIResponseInfo.getCsReferenceNo()); params.put("fcrDate", currentDate); params.put("remark", edirInfo.getResponseDesc()); HttpClient httpClient = null; httpClient.getParams().setAuthenticationPreemptive(true); // ? Credentials credentials = new UsernamePasswordCredentials("wsuserchina", "ws1sGreat"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); HttpMethod method = buildPostMethod( "https://www.delmarcargo.com/cms/api/bookingservice/updateBookingFcrDate", params); int statusCode = httpClient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new HttpException(method.getStatusText()); } String xmlResult = method.getResponseBodyAsString(); method.releaseConnection(); // StringReader xmlReader = new StringReader(xmlResult); // ?SAX ? InputSource ?? XML InputSource xmlSource = new InputSource(xmlReader); // SAXBuilder SAXReader builder = new SAXReader(); // ?SAXDocument Document doc = builder.read(xmlSource); // Element root = doc.getRootElement(); // BODY Element resultStatusCode = root.element("ServiceResponse").element("statusCode"); // ???? if ("200".equals(resultStatusCode.getText())) { // add edirInfo.setEdiType("DCMS_FCRDATE"); edirInfo.setEdiStatus("1"); edirInfo.setCsReferenceNo(resultEDIResponseInfo.getCsReferenceNo());// set Booking Id edirInfo.setEdiAction("NEW"); edirInfo.setEdiStatus("1"); edirInfo.setBatchNo("0"); edirInfo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); edirInfo.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); edirInfo.setBeUse(0); ediResponseInfoService.saveOrUpdate(edirInfo); ediResponseInfoService.updateTrustFileInfoFCRDate(currentDate, edirInfo.getTrustFileCode()); } else if ("405".equals(resultStatusCode.getText())) { Element resultText = root.element("ServiceResponse").element("description"); resultMessage = resultText.getText(); // add edirInfo.setEdiType("DCMS_FCRDATE"); edirInfo.setEdiStatus("11"); edirInfo.setCsReferenceNo(resultEDIResponseInfo.getCsReferenceNo());// set Booking Id edirInfo.setEdiAction("NEW"); edirInfo.setEdiStatus("1"); edirInfo.setBatchNo("0"); edirInfo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); edirInfo.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); edirInfo.setBeUse(0); ediResponseInfoService.saveOrUpdate(edirInfo); } else { Element resultText = root.element("ServiceResponse").element("description"); resultMessage = resultText.getText(); } } else { resultMessage = "Booking IDCargoProDcms?"; } } catch (Exception e) { e.printStackTrace(); resultMessage = "Modify Dcms Fcr Date have Exception"; return resultMessage; } return resultMessage; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
@Override public Survey constructSurvey(InputStream inputStream) throws DocumentException { Document document = null; document = new SAXReader().read(inputStream); Element rootElement = document.getRootElement(); if (!rootElement.getName().equals("survey")) { throw new DocumentException("The root element of the XML document should be 'survey'."); }/*from ww w . j av a2 s. c o m*/ return constructSurvey(rootElement); }
From source file:com.devoteam.srit.xmlloader.core.operations.basic.operators.PluggableParameterOperatorBinary.java
License:Open Source License
@Override public Parameter operate(Runner runner, Map<String, Parameter> operands, String name, String resultant) throws ParameterException { normalizeParameters(operands);//from w ww .j a v a 2s .c o m Parameter param_1 = assertAndGetParameter(operands, "value"); Parameter result = new Parameter(); try { int size = param_1.length(); for (int i = 0; i < size; i++) { if (name.equals(NAME_BIN_EQUALS)) { Array array1 = Array.fromHexString(param_1.get(i).toString()); Parameter param_2 = assertAndGetParameter(operands, "value2"); Array array2 = Array.fromHexString(param_2.get(i).toString()); result.add(array1.equals(array2)); } else if (name.equals(NAME_BIN_PARSE)) { result.add(Array .toHexString(new DefaultArray(Utils.parseBinaryString(param_1.get(i).toString())))); } else if (name.equals(NAME_BIN_FROMBASE64)) { result.add(Array.toHexString(Array.fromBase64String(param_1.get(i).toString()))); } else if (name.equals(NAME_BIN_TOBASE64)) { result.add(Array.toBase64String(Array.fromHexString(param_1.get(i).toString()))); } else if (name.equals(NAME_BIN_CONTAINS)) { Parameter param_2 = assertAndGetParameter(operands, "value2"); Array array1 = Array.fromHexString(param_1.get(i).toString()); Array array2 = Array.fromHexString(param_2.get(i).toString()); result.add(String.valueOf(array1.indexOf(array2) != -1)); } else if (name.equalsIgnoreCase(NAME_BIN_LENGTH)) { result.add(String.valueOf(param_1.get(i).toString().length() / 2)); } else if (name.equals(NAME_BIN_INDEXOF)) { Parameter param_2 = assertAndGetParameter(operands, "value2"); Array array_data = Array.fromHexString(param_1.get(i).toString()); Array array_searched = Array.fromHexString(param_2.get(i).toString()); int index = 0; Parameter param_3 = operands.get("value3"); if (null != param_3) { index = Integer.valueOf(param_3.get(i).toString()); } result.add(String.valueOf(array_data.indexOf(array_searched, index))); } else if (name.equals(NAME_BIN_TOSTRING)) { Parameter param1 = PluggableParameterOperatorList.assertAndGetParameter(operands, "value"); String value1 = param1.get(i).toString(); Parameter paramCharset = operands.get("value2"); String alphabet = null; if (paramCharset != null) { alphabet = paramCharset.get(i).toString(); } Array array = Array.fromHexString(value1); // for GSM SMS alphabet perform a 7bits encoding if (alphabet != null && alphabet.contains("Default alphabet")) { array = PluggableParameterOperatorBinary.decodeNumberBits(array, 7, true); } byte[] bytes = array.getBytes(); String stringResult; if (paramCharset != null) { String charset = alphabet; int posCS = charset.indexOf('{'); if (posCS >= 0) { charset = charset.substring(posCS + 1); } posCS = charset.lastIndexOf('}'); if (posCS >= 0) { charset = charset.substring(0, posCS); } stringResult = new String(bytes, charset); } else { stringResult = new String(bytes); } // for GSM SMS alphabet perform a 7bits encoding if (alphabet != null && alphabet.contains("Default alphabet")) { // remove twice the @ character int lastPos = stringResult.length() - 1; if (lastPos >= 0 && stringResult.charAt(lastPos) == '@') { stringResult = stringResult.substring(0, lastPos); } /* lastPos = stringResult.length() - 1; if (lastPos >= 0 && stringResult.charAt(lastPos) == '@') { stringResult = stringResult.substring(0, lastPos); } */ } result.add(stringResult); } else if (name.equals(NAME_BIN_SUBBINARY)) { Array arrayValue = Array.fromHexString(param_1.get(i).toString()); int offset = Integer.valueOf(assertAndGetParameter(operands, "value2").get(i).toString()) .intValue(); Parameter paramLength = operands.get("value3"); int length; if (paramLength != null) { length = Integer.valueOf(paramLength.get(i).toString()).intValue(); } else { length = arrayValue.length - offset; } result.add(Array.toHexString(arrayValue.subArray(offset, length))); } else if (name.equals(NAME_BIN_RANDOM)) { Array random = new RandomArray(new Integer(param_1.get(i).toString())); result.add(Array.toHexString(random)); } else if (name.equalsIgnoreCase(NAME_BIN_DIGEST)) { Parameter algo = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); Array data = Array.fromHexString(param_1.get(i).toString()); DigestArray array = new DigestArray(data, algo.get(i).toString()); result.add(Array.toHexString(array)); } else if (name.equalsIgnoreCase(NAME_BIN_HMAC)) { Parameter algo = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); Array data = Array.fromHexString(param_1.get(i).toString()); Array secret = Array.fromHexString(PluggableParameterOperatorList .assertAndGetParameter(operands, "value3").get(i).toString()); MacArray array = new MacArray(data, algo.get(i).toString(), secret); result.add(Array.toHexString(array)); } else if (name.equalsIgnoreCase(NAME_BIN_ENCRYPT)) { Array data = Array.fromHexString(param_1.get(i).toString()); String algo = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2").get(i) .toString(); String keyAlgo = algo.contains("/") ? algo.substring(0, algo.indexOf('/')) : algo; Array secret = Array.fromHexString(PluggableParameterOperatorList .assertAndGetParameter(operands, "value3").get(i).toString()); Array salt = Array.fromHexString(PluggableParameterOperatorList .assertAndGetParameter(operands, "value4").get(i).toString()); CipherArray array = new CipherArray(data, secret, salt, algo, keyAlgo, Cipher.ENCRYPT_MODE); result.add(Array.toHexString(array)); } else if (name.equalsIgnoreCase(NAME_BIN_DECRYPT)) { Array data = Array.fromHexString(param_1.get(i).toString()); String algo = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2").get(i) .toString(); String keyAlgo = algo.contains("/") ? algo.substring(0, algo.indexOf('/')) : algo; Array secret = Array.fromHexString(PluggableParameterOperatorList .assertAndGetParameter(operands, "value3").get(i).toString()); Array salt = Array.fromHexString(PluggableParameterOperatorList .assertAndGetParameter(operands, "value4").get(i).toString()); CipherArray array = new CipherArray(data, secret, salt, algo, keyAlgo, Cipher.DECRYPT_MODE); result.add(Array.toHexString(array)); } else if (name.equalsIgnoreCase(NAME_BIN_STATMAX)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); byte res = Byte.MIN_VALUE; for (int j = 0; j < data.length; j++) { if (data[j] > res) { res = data[j]; } } byte[] tabBytes = new byte[1]; tabBytes[0] = res; result.add(Array.toHexString(new DefaultArray(tabBytes))); } else if (name.equalsIgnoreCase(NAME_BIN_STATMIN)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); byte res = Byte.MAX_VALUE; for (int j = 0; j < data.length; j++) { if (data[j] < res) { res = data[j]; } } byte[] tabBytes = new byte[1]; tabBytes[0] = res; result.add(Array.toHexString(new DefaultArray(tabBytes))); } else if (name.equalsIgnoreCase(NAME_BIN_STATAVERAGE)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); byte[] res = new byte[1]; res[0] = calculeAverage(data); result.add(Array.toHexString(new DefaultArray(res))); } else if (name.equalsIgnoreCase(NAME_BIN_STATVARIANCE)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); double variance = calculeDeviation(data); result.add(formatDouble(variance)); } else if (name.equalsIgnoreCase(NAME_BIN_STATDEVIATION)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); double variance = calculeDeviation(data); double deviation = Math.sqrt(variance); result.add(formatDouble(deviation)); } else if (name.equalsIgnoreCase(NAME_BIN_STATPOPULAR)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); byte[] res = new byte[1]; res[0] = (byte) calculePopular(data, false); result.add(Array.toHexString(new DefaultArray(res))); } else if (name.equalsIgnoreCase(NAME_BIN_STATMAXFREQ)) { Array array = Array.fromHexString(param_1.get(i).toString()); byte[] data = array.getBytes(); result.add(formatDouble(((double) calculePopular(data, true)) / data.length)); } else if (name.equalsIgnoreCase(NAME_BIN_FROMIP)) { String val1 = param_1.get(i).toString(); InetAddress inetAddr = InetAddress.getByName(val1); byte[] bytesRes = inetAddr.getAddress(); String strRes = Array.toHexString(new DefaultArray(bytesRes)); result.add(strRes); } else if (name.equalsIgnoreCase(NAME_BIN_TOIP)) { String val1 = param_1.get(i).toString(); byte[] bytesVal1 = DefaultArray.fromHexString(val1).getBytes(); String strRes = Utils.toIPAddress(bytesVal1); result.add(strRes); } else if (name.equalsIgnoreCase(NAME_BIN_TONUMBER)) { BigInteger n = new BigInteger(param_1.get(i).toString(), 16); result.add(n.toString()); } else if (name.equalsIgnoreCase(NAME_BIN_RTPKEYDERIVATION)) { Parameter param_2 = assertAndGetParameter(operands, "value2"); Parameter param_3 = assertAndGetParameter(operands, "value3"); String lifetime = ""; String mki = ""; if (!param_1.get(0).toString().contains("AES_CM_128_HMAC_SHA1")) throw new ParameterException("Algorithm " + param_1.get(0).toString().split(" ")[1] + " is not supported, only AES_CM_128_HMAC_SHA1 is supported"); String inline = param_1.get(0).toString().split(" ")[2].substring(7); String[] inlineSplitted = inline.replace('|', ' ').split(" "); String keyAndSalt = inlineSplitted[0]; if (inlineSplitted.length == 2) { if (inlineSplitted[1].replace(':', ' ').split(" ").length == 2) mki = inlineSplitted[1]; else lifetime = inlineSplitted[1]; } if (inlineSplitted.length == 3) { lifetime = inlineSplitted[1]; mki = inlineSplitted[2]; } String algo = param_1.get(0).toString().split(" ")[1]; String[] decodedInline = decodeInline(keyAndSalt); long calculatedLifeTime = parseSRTPLifeTime(lifetime); Cipher AESCipher = Cipher.getInstance("AES/ECB/NOPADDING"); byte[][] derivatedKeys = deriveSRTPKeys(AESCipher, 0, calculatedLifeTime, decodedInline[1].getBytes(), decodedInline[0].getBytes()); String[] ret = new String[3]; ret[0] = ""; ret[1] = ""; ret[2] = ""; int a; for (a = 0; a < derivatedKeys[0].length; a++) ret[0] += String.format("%02x", derivatedKeys[0][a], 16); for (a = 0; a < derivatedKeys[1].length; a++) ret[1] += String.format("%02x", derivatedKeys[1][a], 16); for (a = 0; a < derivatedKeys[2].length; a++) ret[2] += String.format("%02x", derivatedKeys[2][a], 16); for (a = 0; a < ret.length; a++) result.add(ret[a]); } else if (name.equalsIgnoreCase(NAME_BIN_AUTHRTP)) { // param_1 = tab holding encrypted RTP packets to authenticate Parameter param_2 = assertAndGetParameter(operands, "value2"); // AUTH KEY Parameter param_3 = assertAndGetParameter(operands, "value3"); // ROC Parameter param_4 = assertAndGetParameter(operands, "value4"); // INLINE BLOCK String[] algo = param_4.get(0).toString().split(" ")[1].split("_"); int authTagLength = Integer.parseInt(algo[algo.length - 1]) / 8; String data = param_1.get(0).toString(); byte[] authKey = DatatypeConverter.parseHexBinary(param_2.get(0).toString()); int ROC = Integer.parseInt(param_3.get(0).toString()); Mac hmacSha1 = Mac.getInstance("HmacSHA1"); SecretKey key = new SecretKeySpec(authKey, "HMAC"); try { hmacSha1.init(key); } catch (InvalidKeyException e) { e.printStackTrace(); } hmacSha1.update(data.getBytes(), 0, data.getBytes().length); byte[] rb = new byte[4]; rb[0] = (byte) (ROC >> 24); rb[1] = (byte) (ROC >> 16); rb[2] = (byte) (ROC >> 8); rb[3] = (byte) ROC; hmacSha1.update(rb); byte[] authTag = hmacSha1.doFinal(); String ret = ""; for (int a = 0; a < authTagLength; a++) ret += String.format("%02x", authTag[a], 16); result.add(ret); } else if (name.equalsIgnoreCase(NAME_BIN_DIFFERENCE)) { String string1 = param_1.get(i).toString().replace(" ", ""); Parameter param_2 = assertAndGetParameter(operands, "value2"); String string2 = param_2.get(i).toString().replace(" ", ""); GenericWrapper wrapper1 = new GenericWrapper(string1); GenericWrapper wrapper2 = new GenericWrapper(string2); String stringRes = calculateDifference(wrapper1, wrapper2); string1 = (String) wrapper1.getObject(); string2 = (String) wrapper2.getObject(); param_1.set(i, string1); param_2.set(i, string2); result.add(stringRes); if (i == param_1.length() - 1) { runner.getParameterPool().traceInfo("SET", "[value ]", param_1.toString()); runner.getParameterPool().traceInfo("SET", "[value2 ]", param_2.toString()); } } else if (name.equalsIgnoreCase(NAME_BIN_XMLTOASN)) { String string1 = param_1.get(i).toString(); Parameter param_2 = assertAndGetParameter(operands, "value2"); String className = param_2.get(i).toString().replace(" ", ""); Parameter param_3 = assertAndGetParameter(operands, "value3"); String dictionary = param_3.get(i).toString().replace(" ", ""); Class thisClass = Class.forName(className); int pos = className.lastIndexOf('.'); String packageName = ""; if (pos > 0) { packageName = className.substring(0, pos + 1); } Document doc = Utils.stringParseXML(string1, false); Element element = doc.getRootElement(); Object objASN; objASN = thisClass.newInstance(); String resultPath = ""; ASNMessage message = new BN_ASNMessage(dictionary); XMLToASNParser.getInstance().parseFromXML(resultPath, message, objASN, element, packageName); // Library binarynotes IEncoder<java.lang.Object> encoderMAP = CoderFactory.getInstance().newEncoder("BER"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); encoderMAP.encode(objASN, outputStream); byte[] bytesMAP = outputStream.toByteArray(); Array arrayMAP = new DefaultArray(bytesMAP); String ret = Array.toHexString(arrayMAP); result.add(ret); } else if (name.equalsIgnoreCase(NAME_BIN_ASNTOXML)) { Array array = Array.fromHexString(param_1.get(i).toString()); Parameter param_2 = assertAndGetParameter(operands, "value2"); String className = param_2.get(i).toString().replace(" ", ""); Parameter param_3 = assertAndGetParameter(operands, "value3"); String dictionary = param_3.get(i).toString().replace(" ", ""); // Library binarynotes IDecoder decoder = CoderFactory.getInstance().newDecoder("BER"); InputStream inputStream = new ByteArrayInputStream(array.getBytes()); Class<?> cl = Class.forName(className); Object objASN = cl.newInstance(); objASN = decoder.decode(inputStream, cl); String ret = ""; String resultPath = ""; ASNMessage message = new BN_ASNMessage(dictionary); ret += ASNToXMLConverter.getInstance().toXML(resultPath, message, null, "value", objASN, null, ASNToXMLConverter.NUMBER_SPACE_TABULATION * 2); result.add(ret); } else if (name.equalsIgnoreCase(NAME_BIN_ENDIAN)) { String string1 = param_1.get(i).toString(); Array array = Array.fromHexString(string1); Array arrayResult = transformEndian(array); result.add(Array.toHexString(arrayResult)); } else if (name.equalsIgnoreCase(NAME_BIN_ENCODE)) { String string1 = param_1.get(i).toString(); Array array = Array.fromHexString(string1); Parameter param_2 = assertAndGetParameter(operands, "value2"); int nbBits = Integer.valueOf(param_2.get(i).toString()).intValue(); Parameter paramEndian = operands.get("value3"); boolean endian = true; if (paramEndian != null) { endian = Boolean.valueOf(paramEndian.get(i).toString()).booleanValue(); } Array arrayResult = encodeNumberBits(array, nbBits, endian); result.add(Array.toHexString(arrayResult)); } else if (name.equalsIgnoreCase(NAME_BIN_DECODE)) { String string1 = param_1.get(i).toString(); Array array = Array.fromHexString(string1); Parameter param_2 = assertAndGetParameter(operands, "value2"); int nbBits = Integer.valueOf(param_2.get(i).toString()).intValue(); Parameter paramEndian = operands.get("value3"); boolean endian = true; if (paramEndian != null) { endian = Boolean.valueOf(paramEndian.get(i).toString()).booleanValue(); } Array arrayResult = decodeNumberBits(array, nbBits, endian); result.add(Array.toHexString(arrayResult)); } else { throw new RuntimeException("unsupported operation " + name); } } } catch (Exception e) { throw new ParameterException("Error in operation " + name, e); } return result; }