List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.nokia.helium.diamonds.XMLMerger.java
License:Open Source License
/** * Merging two XML elements. It only keeps difference. * /* www . j a v a 2s. c om*/ * @param dest * @param src */ @SuppressWarnings("unchecked") protected void mergeNode(Element dest, Element src) { for (Iterator<Element> node = src.elements().iterator(); node.hasNext();) { Element element = node.next(); List<Element> ses = dest.elements(element.getName()); boolean add = true; for (Element se : ses) { if (areSame(se, element)) { log.debug("Element " + element.getName() + " already found in dest."); add = false; } } if (add) { log.debug("Adding node " + element.getName() + " to " + dest.getName()); dest.add(element.detach()); } else if (ses.size() > 0) { log.debug("Merging " + ses.get(0).getName() + " to " + element.getName()); mergeNode(ses.get(0), element); } } }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.TimeLine.java
License:Open Source License
private void mapAllEvents(Element pr) { Element pl = (Element) pr.selectSingleNode("videoplaylist"); //System.out.println("PLNODE="+pl); //sometimes a presentation on accident doesn't have an videoplaylist if (pl == null) { return;/*from w w w. j a v a 2 s. c o m*/ } for (Iterator<Node> iter = pl.elements().iterator(); iter.hasNext();) { Element node = (Element) iter.next(); //System.out.println("NODE NAME="+node.getName()); if (!node.getName().equals("video") && !node.getName().equals("properties")) { oldnodes.add(node); //System.out.println("N="+node.asXML()); } } //System.out.println("OLDNODES="+oldnodes.size()); }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.TimeLine.java
License:Open Source License
public void remapVideoEvents(Element fsxml) { Element pl = (Element) _presentation.selectSingleNode("videoplaylist"); //System.out.println("PLNODE="+pl); float offset = 0; int mapcounter = 0; for (Iterator<Node> iter = pl.elements().iterator(); iter.hasNext();) { Element node = (Element) iter.next(); if (node.getName().equals("video")) { //System.out.println("V1="+node.asXML()); float starttime = 0f; if (node.selectSingleNode("properties/starttime") != null && !node.selectSingleNode("properties/starttime").getText().equals("")) { starttime = Float.valueOf(node.selectSingleNode("properties/starttime").getText()); }/*from w w w . j a v a2 s. c o m*/ float duration = 999999999f; // a bit of a hack if (node.selectSingleNode("properties/duration") != null && !node.selectSingleNode("properties/duration").getText().equals("")) { duration = Float.valueOf(node.selectSingleNode("properties/duration").getText()); } String referid = node.attributeValue("referid"); //System.out.println("XMLL="+fsxml.asXML()); Element videonode = (Element) fsxml.selectSingleNode("video[@fullid='" + referid + "']"); //error case, but sometimes occurs if (videonode == null) { return; } //Element videonode = (FSXMLRequestHandler.instance().getNodeProperties(referid,true)).getRootElement().element("video"); //System.out.println("VID="+referid); for (Iterator<Node> viter = videonode.elements().iterator(); viter.hasNext();) { Element lnode = (Element) viter.next(); String name = lnode.getName(); if (!name.equals("properties") && !name.equals("rawvideo") && !name.equals("screens")) { // so we have a node lets remap it and place it in the timeline Element nnode = (Element) lnode.clone(); float ns = 0; float nd = 0; if (nnode.selectSingleNode("properties/starttime") != null && nnode.selectSingleNode("properties/starttime").getText() != null) { try { ns = Float.valueOf(nnode.selectSingleNode("properties/starttime").getText()); } catch (Exception e) { /* ignore */ } } if (nnode.selectSingleNode("properties/duration") != null && nnode.selectSingleNode("properties/duration").getText() != null) { try { nd = Float.valueOf(nnode.selectSingleNode("properties/duration").getText()); } catch (Exception e) { /* ignore */ } } //System.out.println("LN="+lnode.getName()+" "+lnode.asXML()); //these are our defaults, no need to shift if these are the same float defaultDuration = 999999999f; if (Float.compare(ns, nd) == 0 && Float.compare(ns, starttime) == 0 && Float.compare(duration, defaultDuration) == 0) { continue; } // is this block used in this video's start/duration range ? if (ns >= starttime && ns <= (starttime + duration)) { // we need to shift the starttime by both the offset and starttime // does the end point also fall in the range, if not we need to shorten it float newstart = ((ns - starttime) + offset); if ((ns + nd) < (starttime + duration)) { // yes no need to cut try { nnode.selectSingleNode("properties/starttime").setText("" + newstart); } catch (Exception e) { /* ignore */ } } else { //System.out.println("LN="+lnode.getName()+" "+lnode.asXML()); //System.out.println("NEED CUT "+ns+" "+nd+" "+starttime+" "+duration+" "+newstart); //System.out.println("NEW DUR "+((ns+nd)-(starttime+duration))); try { nnode.selectSingleNode("properties/starttime").setText("" + newstart); nnode.selectSingleNode("properties/duration") .setText("" + ((ns + nd) - (starttime + duration))); } catch (Exception e) { /* ignore */ } } newnodes.add(nnode); mapcounter++; } } } offset += duration; // shift the offset so all the events of the next video are shifted } } //System.out.println("MAPCOUNTER="+mapcounter); }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.TimeLine.java
License:Open Source License
public void remapOldEvents() { Element pl = (Element) _presentation.selectSingleNode("videoplaylist"); //System.out.println("PLNODE="+pl); float offset = 0; int mapcounter = 0; for (Iterator<Node> iter = pl.elements().iterator(); iter.hasNext();) { Element node = (Element) iter.next(); if (node.getName().equals("video")) { //System.out.println("V1="+node.asXML()); float starttime = 0; if (node.selectSingleNode("properties/starttime") != null && !node.selectSingleNode("properties/starttime").getText().equals("")) { starttime = Float.valueOf(node.selectSingleNode("properties/starttime").getText()); }//from w w w . j a va 2 s . com float duration = 999999999; // a bit of a hack if (node.selectSingleNode("properties/duration") != null && !node.selectSingleNode("properties/duration").getText().equals("")) { duration = Float.valueOf(node.selectSingleNode("properties/duration").getText()); } for (Iterator<Node> viter = oldnodes.iterator(); viter.hasNext();) { Element lnode = (Element) viter.next(); String name = lnode.getName(); if (!name.equals("properties") && !name.equals("rawvideo") && !name.equals("screens")) { // so we have a node lets remap it and place it in the timeline Element nnode = (Element) lnode.clone(); float ns = 0L; float nd = 0L; if (nnode.selectSingleNode("properties/starttime") != null && nnode.selectSingleNode("properties/starttime").getText() != null) { try { ns = Float.valueOf(nnode.selectSingleNode("properties/starttime").getText()); } catch (Exception e) { //System.out.println("NS="+nnode.selectSingleNode("properties/starttime").getText()); //e.printStackTrace(); } } else { Element nnnode = (Element) nnode.selectSingleNode("//properties"); nnnode.addElement("starttime").addText(Float.toString(ns)); } if (nnode.selectSingleNode("properties/duration") != null && nnode.selectSingleNode("properties/duration").getText() != null) { try { nd = Float.valueOf(nnode.selectSingleNode("properties/duration").getText()); } catch (Exception e) { /* ignore */ } } else { Element nnnode = (Element) nnode.selectSingleNode("//properties"); nnnode.addElement("duration").addText(Float.toString(nd)); } // is this block used in this video's start/duration range ? if ((ns >= starttime && ns <= (starttime + duration)) || ((ns + nd) > starttime)) { // we need to shift the starttime by both the offset and starttime // does the end point also fall in the range, if not we need to shorten it float newstart = ((ns - starttime) + offset); /* Daniel/Pieter removed because not sure what it did, first check if trouble. if(((ns+nd)>starttime)) { newstart = starttime + offset; } */ if ((ns + nd) < (starttime + duration)) { // yes no need to cut nnode.selectSingleNode("properties/starttime").setText("" + newstart); } else { //System.out.println("LN="+lnode.getName()+" "+lnode.asXML()); //System.out.println("NEED CUT "+ns+" "+nd+" "+starttime+" "+duration+" "+newstart); //System.out.println("NEW DUR "+(nd-((ns+nd)-(starttime+duration)))); nnode.selectSingleNode("properties/starttime").setText("" + newstart); nnode.selectSingleNode("properties/duration") .setText("" + (nd - ((ns + nd) - (starttime + duration)))); } newnodes.add(nnode); mapcounter++; } } } offset += duration; // shift the offset so all the events of the next video are shifted } } //System.out.println("MAPCOUNTER OLD="+mapcounter); }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.TimeLine.java
License:Open Source License
public void insertNodesInPresentation() { //System.out.println("COPY IN PRES "+newnodes.size()); // remove all the old event nodes, so we can replace them with the new ones. Element pl = (Element) _presentation.selectSingleNode("videoplaylist"); for (Iterator<Node> iter = pl.elements().iterator(); iter.hasNext();) { Element node = (Element) iter.next(); if (!node.getName().equals("video") && !node.getName().equals("properties")) { node.detach();//from w w w . j a v a2s . c o m } } for (Iterator<Node> iter = newnodes.iterator(); iter.hasNext();) { Element newnode = (Element) iter.next(); //System.out.println("NEWNODE="+newnode.asXML()); ((Element) _presentation.selectSingleNode("videoplaylist")).add(newnode); } }
From source file:com.oakhole.core.uitls.XMLMapper.java
License:Apache License
/** * SAX??xml,//from w w w . jav a2 s . co m * * @param inputStream * @return * @throws Exception */ public static Map<String, String> parseXml(InputStream inputStream) throws Exception { Map<String, String> map = Maps.newHashMap(); SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); Element root = document.getRootElement(); List<Element> elementList = root.elements(); for (Element e : elementList) { map.put(e.getName(), e.getText()); } inputStream.close(); inputStream = null; return map; }
From source file:com.onion.master.MasterConf.java
License:Apache License
public List<InetSocketAddress> getWorkerAddresses() throws Exception { Element address = root.element("InetAddress"); List<Element> addList = address.elements(); for (Element element : addList) { String[] addStr = element.getText().split(":"); if (addStr.length < 2) { throw new Exception("The type of InetAddress is no correct!"); }//from w w w. java 2 s .c o m workerAddresses.add(new InetSocketAddress(addStr[0], Integer.parseInt(addStr[1]))); } return workerAddresses; }
From source file:com.openkm.openmeetings.service.RoomService.java
License:Open Source License
/** * getRoomsPublic// ww w .j a v a2s . c o m */ public static List<Room> getRoomsPublic(String SID, long roomType) throws Exception { log.debug("getRoomsPublic({},{})", SID, roomType); List<Room> rooms = new ArrayList<Room>(); String restURL = OpenMeetingsUtils.getOpenMeetingServerURL() + "/services/RoomService/getRoomsPublic?" + "SID=" + SID + "&roomtypes_id=" + String.valueOf(roomType); List<Element> result = RestService.callList(restURL, null); for (Element element : result) { if (element.elements().size() > 0) { // Evaluate null case ( has no elements inside ) Room room = new Room(element); rooms.add(room); } } return rooms; }
From source file:com.openkm.openmeetings.service.RoomService.java
License:Open Source License
/** * getRoomsWithCurrentUsersByListAndType *///www .j a v a 2 s . c om public static List<Room> getRoomsWithCurrentUsersByListAndType(String SID, int start, int max, String orderBy, Boolean asc, String externalRoomType) throws Exception { List<Room> rooms = new ArrayList<Room>(); String restURL = OpenMeetingsUtils.getOpenMeetingServerURL() + "/services/RoomService/getRoomsWithCurrentUsersByListAndType?" + "SID=" + SID + "&start=" + String.valueOf(start) + "&max=" + String.valueOf(max) + "&orderby=" + orderBy + "&asc=" + asc.toString() + "&externalRoomType=" + externalRoomType; List<Element> result = RestService.callList(restURL, null); for (Element element : result) { if (element.elements().size() > 0) { // Evaluate null case ( has no elements inside ) Room room = new Room(element); // only returns room_id need extra call to get complete room information room = getRoomById(SID, room.getId()); rooms.add(room); } } return rooms; }
From source file:com.orange.atk.atkUI.corecli.reportGenerator.resultLink.ResultLink.java
License:Apache License
/** * Create <code>Resultvalue</code> object from result element * @param elem// w w w . j a va2 s. c o m * @return the created <code>Resultvalue</code> object. */ public static Resultvalue getResultvalue(Element elem, Unmarshaller unmarshaller) { String kind = elem.attributeValue("kind"); Resultvalue resultvalue = null; if (kind == null || !kind.equals("use")) { Element resultvalueElem = (Element) elem.elements().get(0); Document documentResultvalue = DocumentHelper.createDocument(); documentResultvalue.add(resultvalueElem.createCopy()); DOMWriter d4Writer = new org.dom4j.io.DOMWriter(); try { org.w3c.dom.Document doc = d4Writer.write(documentResultvalue); // Unmarshal the data resultvalue = (Resultvalue) unmarshaller.unmarshal(doc); } catch (Exception e) { Logger.getLogger(ResultLink.class).debug(e); e.printStackTrace(); } } return resultvalue; }