List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void parseElementForOutput(TreeObject[] xobjs) { for (TreeObject xobj : xobjs) { TreeObject subParent = xobj;//from w ww .j a v a 2s . c o m while (subParent.getParent().getType() != 0) { subParent = subParent.getParent(); } Element modelElem = getParentElement(subParent); if (!outPutSchemas.containsKey(modelElem.getName())) { Element copyElem = (Element) modelElem.clone(); copyElem.clearContent(); copyElem.setText(modelElem.getTextTrim()); outPutSchemas.put(modelElem.getName(), copyElem); } subParent = xobj; TreeObject categorySubRoot = null; while (subParent.getParent().getType() == TreeObject.CATEGORY_FOLDER) { categorySubRoot = subParent.getParent(); subParent = subParent.getParent(); } Element divisionElem = null; Element copyModelElem = outPutSchemas.get(modelElem.getName()); Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc; String division = xobj.getType() == TreeObject.TRANSFORMER ? "Process" : "Trigger";//$NON-NLS-1$//$NON-NLS-2$ String xpathForDivision = ".//child::" + division + "[text()='" + xobj.getType() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (categorySubRoot != null) { Element categoryElem = getParentElement(categorySubRoot); if (categoryElem.getParent() != modelElem) { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(categoryElem.getParent().getName()); divisionElem.setText(categoryElem.getParent().getTextTrim()); } } else { divisionElem = copyModelElem; } Element categoryElementClone = (Element) categoryElem.clone(); String xpath = "./child::" + categoryElem.getName() + "[text()='" + TreeObject.CATEGORY_FOLDER //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ if (divisionElem.selectNodes(xpath).size() == 0) { divisionElem.add(categoryElementClone); } } else { // individual xobject Element xobjElem = pingElement(getXPathForTreeObject(xobj), doc.getRootElement()); Element parentElem = xobjElem.getParent(); if (parentElem == modelElem) { parentElem = copyModelElem; } else { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(parentElem.getName()); divisionElem.setText(parentElem.getTextTrim()); } } String xpath = ".//child::" + xobjElem.getName() + "[text()='" + xobjElem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (divisionElem != null && pingElement(xpath, divisionElem) == null) { divisionElem.add((Element) xobjElem.clone()); } } } // filter those excluded from xobjects out of categorys String xpath = ".//descendant::*[text() ='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ Iterator<Element> iter = outPutSchemas.values().iterator(); while (iter.hasNext()) { Element divisionElement = iter.next(); List<Element> categorys = divisionElement.selectNodes(xpath); if (categorys != null) { for (Element categoryElems : categorys) { List objs = categoryElems.content(); List<Element> elemToDel = new ArrayList<Element>(); for (Object obj : objs) { if (obj instanceof Element) { Element categoryElement = (Element) obj; if (categoryElement.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) { continue; } boolean match = false; for (TreeObject xobj : xobjs) { if (filterOutBlank(xobj.getDisplayName()).equals(categoryElement.getName()) && categoryElement.getTextTrim().equals(xobj.getType() + "")) {//$NON-NLS-1$ match = true; break; } } if (!match) { elemToDel.add(categoryElement); } } } for (Element del : elemToDel) { categoryElems.remove(del); } } } } ArrayList<String> schemas = new ArrayList<String>(); Iterator<Element> iterd = outPutSchemas.values().iterator(); while (iterd.hasNext()) { schemas.add(iterd.next().asXML()); } }
From source file:com.amalto.workbench.utils.MDMServerHelper.java
License:Open Source License
private static Element getRootElement() { Document logininfoDocument; Element rootElement;//from w w w.j av a 2 s . co m if (new File(workbenchConfigFile).exists()) { try { SAXReader reader = new SAXReader(); logininfoDocument = reader.read(new File(workbenchConfigFile)); } catch (DocumentException e) { log.error(e.getMessage(), e); return null; } rootElement = logininfoDocument.getRootElement(); } else { logininfoDocument = DocumentHelper.createDocument(); rootElement = logininfoDocument.addElement(ROOT); } return rootElement; }
From source file:com.amalto.workbench.utils.ResourcesUtil.java
License:Open Source License
public static HashMap<String, String> getResourcesMapFromURI(String uri, TreeObject treeObject) { HashMap<String, String> contentMap = new HashMap<String, String>(); String responseBody = getXMLString(uri, treeObject); Document document = parsXMLString(responseBody); if (document == null) { return contentMap; }// ww w . ja v a 2 s . c om for (Iterator iterator = document.getRootElement().elementIterator("entry"); iterator.hasNext();) {//$NON-NLS-1$ Element element = (Element) iterator.next(); Element nameElement = element.element("name");//$NON-NLS-1$ Element uriElement = element.element("uri");//$NON-NLS-1$ if (nameElement != null && uriElement != null) { contentMap.put(nameElement.getStringValue(), uriElement.getStringValue()); } else { contentMap.put(element.getStringValue(), uri + "/" + element.getStringValue());//$NON-NLS-1$ } } return contentMap; }
From source file:com.amalto.workbench.utils.ResourcesUtil.java
License:Open Source License
public static List<String> getResourcesNameListFromURI(String uri, TreeObject treeObject) throws Exception { List<String> nameList = new ArrayList<String>(); String responseBody = getXMLString(uri, treeObject); // nameList=getNameList(responseBody); Document document = parsXMLString(responseBody); if (document == null) { return nameList; }/*from ww w .java 2 s . co m*/ for (Iterator iterator = document.getRootElement().elementIterator("entry"); iterator.hasNext();) {//$NON-NLS-1$ Element element = (Element) iterator.next(); Element nameElement = element.element("name");//$NON-NLS-1$ if (nameElement != null) { nameList.add(nameElement.getStringValue()); } else { nameList.add(element.getStringValue()); } } return nameList; }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static void iterate(Document document, ElementProcess elementProcess) throws DocumentException { Element root = document.getRootElement(); iterate(root, elementProcess);//from w w w . ja v a 2 s.co m }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static void iterate(Document document, String elementName, ElementProcess elementProcess) throws DocumentException { Element root = document.getRootElement(); iterate(root, elementName, elementProcess); }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static void iterateAttribute(Document document, AttributeProcess attributeProcess) throws DocumentException { Element root = document.getRootElement(); iterateAttribute(root, attributeProcess); }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static void treeWalk(Document document, NodeProcess nodeProcess) { treeWalk(document.getRootElement(), nodeProcess); }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static void visit(Document document, VisitorSupport visitor) { visit(document.getRootElement(), visitor); }
From source file:com.aoyun.serviceOld.GetValForYKPOne.java
/** * ?XMLoracle?//from w ww. j av a 2s . c o m * * @param xmlFileList * @throws Exception */ public void getValueForXml(List<File> xmlFileList, JdbcOperate jdbcOperate) throws Exception { ArrayList<JSONObject> parkingLPRJSONList = new ArrayList<JSONObject>(); List<ParkingLPRBean> parkingLPRList = new ArrayList<ParkingLPRBean>();//ParkingLPR(?)? ParkingLPRBean parkingLPR = null;// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (File file : xmlFileList) { try { parkingLPR = new ParkingLPRBean(); SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); String code = getCode(); parkingLPR.setId(code); if (root.element("device_id") == null) { parkingLPR.setDeviceId(""); } else { parkingLPR.setDeviceId(root.element("device_id").getText()); } parkingLPR.setVersion("10000001"); if (root.element("plate_license") == null) { parkingLPR.setPlateNumber(""); } else { parkingLPR.setPlateNumber(root.element("plate_license").getText()); } if (root.element("plate_color") == null) { parkingLPR.setPlateColor(""); } else { String plateColor = getPlateColor(root.element("plate_color").getText()); parkingLPR.setPlateColor(plateColor); } if (root.element("capture_time") == null) { parkingLPR.setPassTime(""); } else { parkingLPR.setPassTime(root.element("capture_time").getText()); } if (root.element("camera_ipaddr") == null) { parkingLPR.setDeviceIp(""); } else { parkingLPR.setDeviceIp(root.element("camera_ipaddr").getText()); } if (root.element("longitude") == null) { parkingLPR.setLongitude(""); } else { parkingLPR.setLongitude(root.element("longitude").getText()); } if (root.element("latitude") == null) { parkingLPR.setLatitude(""); } else { parkingLPR.setLatitude(root.element("latitude").getText()); } if (root.element("site_code") == null) { parkingLPR.setParkingId(""); } else { String siteCode = root.element("site_code").getText(); String substring = siteCode.substring(0, 4); parkingLPR.setParkingId(substring); } if (root.element("direction") == null) { parkingLPR.setInOut(""); } else { parkingLPR.setInOut(root.element("direction").getText()); } String date = dateFormat.format(new Date()); parkingLPR.setCreateTime(date); parkingLPR.setSource("1"); if (root.element("plate_type") == null) { parkingLPR.setPlateType(""); } else { parkingLPR.setPlateType(root.element("plate_type").getText()); } if (root.element("car_color") == null) { parkingLPR.setCarColor(""); } else { parkingLPR.setCarColor(root.element("car_color").getText()); } if (root.element("car_type") == null) { parkingLPR.setCarType(""); } else { parkingLPR.setCarType(root.element("car_type").getText()); } if (root.element("lane") == null) { parkingLPR.setLane(""); } else { parkingLPR.setLane(root.element("lane").getText()); } if (root.element("cs") == null) { parkingLPR.setCs(0); } else { parkingLPR.setCs(Integer.parseInt(root.element("cs").getText())); } //list? parkingLPRList.add(parkingLPR); //????ID????IP????ID?ID String carNo = root.element("plate_license").getText(); String parkcode = root.element("site_code").getText(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String ctStr = root.element("capture_time").getText(); String inOut = root.element("direction").getText(); String num = ""; if (inOut.equals("0")) { num = "-1"; } else { num = "1"; } long capture_time = format.parse(ctStr).getTime();//? List<NameValuePair> list = new ArrayList<NameValuePair>();//??? list.add(new BasicNameValuePair("parkcode", parkcode)); list.add(new BasicNameValuePair("qty", num)); YKPMain.elementList.add(root); YKPMain.list.add(list); List<NameValuePair> nvps = new ArrayList<NameValuePair>();//? nvps.add(new BasicNameValuePair("parkcode", parkcode)); nvps.add(new BasicNameValuePair("carnumber", carNo)); nvps.add(new BasicNameValuePair("regtime", capture_time + "")); nvps.add(new BasicNameValuePair("direction", inOut)); YKPMain.carList.add(nvps);// } catch (DocumentException e) { logger.error("?XML:" + file.getPath()); } } //beanjsonJSON list try { for (ParkingLPRBean parkingLPRs : parkingLPRList) { JSONObject parkingLPRJSON = beanUtil.convertBeanToJson(parkingLPRs); parkingLPRJSONList.add(parkingLPRJSON); } } catch (Exception e) { logger.error("?JSON" + e.getMessage()); } //keys String keys[] = { "id", "deviceId", "version", "plateNumber", "plateColor", "passTime", "deviceIp", "longitude", "latitude", "parkingId", "inOut", "source", "plateType", "carColor", "carType", "lane" }; //?sql? String sql = "insert into parking_lpr(id,device_id,version,plate_number,plate_color,pass_time,device_ip,longitude,latitude," + "parking_id,in_out,create_time,source,plate_type,car_color,car_type,lane)" + "values(?,?,?,?,?,to_date(?,'yyyy-mm-dd hh24:mi:ss'),?,?,?,?,?,sysdate,?,?,?,?,?)"; //???array JSONArray array = jdbcOperate.executeBatchPre(sql, parkingLPRJSONList, keys); JSONObject jsonObject = null; //???? if (array.size() == 0) { logger.info(":" + array.size() + "???"); //0oraclexml for (File file : xmlFileList) { file.delete(); } xmlFileList.clear(); } else { int begin = 0; int end = 0; for (int i = 0; i < array.size(); i++) { jsonObject = array.getJSONObject(i); System.out.println(jsonObject); Set<Map.Entry<String, Object>> entrySet = jsonObject.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { String key = entry.getKey(); if (key.equals("begin")) { begin = Integer.parseInt(entry.getValue().toString()); } else if (key.equals("end")) { end = Integer.parseInt(entry.getValue().toString()); } } logger.error(":" + array.size() + "?" + "" + begin + "-" + end + "??"); //?XML getXMLForError(begin, end, xmlFileList); for (int j = 0; j < XMLListForError.size(); j++) { logger.error(begin + "---" + end + " :?" + XMLListForError.get(j).getPath()); } } //??XML(??)? for (int i = 0; i < xmlFileList.size(); i++) { for (int j = i; j < XMLListForError.size(); j++) { if (xmlFileList.get(i).getName().equals(XMLListForError.get(j).getName())) { break; } } if (i > XMLListForError.size()) { xmlFileList.get(i).delete(); } } System.out.println(XMLListForError.size()); XMLListForError.clear(); xmlFileList.clear(); } }