List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator();
From source file:com.zimbra.cs.client.soap.LmcGetInfoRequest.java
License:Open Source License
protected LmcSoapResponse parseResponseXML(Element responseXML) throws ServiceException { HashMap prefMap = new HashMap(); LmcGetInfoResponse response = new LmcGetInfoResponse(); // iterate over all the elements we received for (Iterator it = responseXML.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(AccountConstants.E_NAME)) { response.setAcctName(e.getText()); } else if (elementType.equals(AccountConstants.E_LIFETIME)) { response.setLifetime(e.getText()); } else if (elementType.equals(AccountConstants.E_PREF)) { // add this preference to our map addPrefToMultiMap(prefMap, e); }//from w w w.j a v a2s.c o m } if (!prefMap.isEmpty()) response.setPrefMap(prefMap); return response; }
From source file:com.zimbra.cs.client.soap.LmcSearchRequest.java
License:Open Source License
protected void parseResponse(LmcSearchResponse response, Element responseXML) throws ServiceException, LmcSoapClientException { // get the offset and more attributes from the <SearchResponse> element response.setOffset(DomUtil.getAttr(responseXML, MailConstants.A_QUERY_OFFSET)); response.setMore(DomUtil.getAttr(responseXML, MailConstants.A_QUERY_MORE)); /*/* ww w . j ava2 s . com*/ * Iterate through the elements and put them in a generic ArrayList. * XXX: Should validate that the correct types are returned. */ ArrayList mailItems = new ArrayList(); for (Iterator it = responseXML.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); Object o; if (elementType.equals(MailConstants.E_CONV)) { o = parseConversation(e); } else if (elementType.equals(MailConstants.E_MSG)) { o = parseMessage(e); } else if (elementType.equals(MailConstants.E_MIMEPART)) { o = parseMimePart(e); } else if (elementType.equals(MailConstants.E_CONTACT)) { o = parseContact(e); } else if (elementType.equals(MailConstants.E_NOTE)) { o = parseNote(e); } else if (elementType.equals(MailConstants.E_DOC)) { o = parseDocument(e); } else if (elementType.equals(MailConstants.E_WIKIWORD)) { o = parseWiki(e); } else { // unknown element type as search result throw new LmcSoapClientException("Unexpected element type " + elementType); } // add the object to the ArrayList mailItems.add(o); } response.setResults(mailItems); }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
protected LmcConversation parseConversation(Element conv) throws LmcSoapClientException, ServiceException { LmcConversation result = new LmcConversation(); // get the conversation attributes result.setID(conv.attributeValue(MailConstants.A_ID)); result.setTags(conv.attributeValue(MailConstants.A_TAGS)); String numMsgs = conv.attributeValue(MailConstants.A_NUM); if (numMsgs != null) result.setNumMessages(Integer.parseInt(numMsgs)); result.setDate(conv.attributeValue(MailConstants.A_DATE)); result.setFlags(conv.attributeValue(MailConstants.A_FLAGS)); result.setFolder(conv.attributeValue(MailConstants.A_FOLDER)); /*// w w w . j a v a 2s . c o m * iterate over subelements. allowed subelements are e-mail addresses, * subject, fragment, and messages. this assumes no particular order is * required for correctness. */ ArrayList emailAddrs = new ArrayList(); ArrayList msgs = new ArrayList(); for (Iterator it = conv.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_FRAG)) { // fragment result.setFragment(e.getText()); } else if (elementType.equals(MailConstants.E_EMAIL)) { // e-mail address LmcEmailAddress ea = parseEmailAddress(e); emailAddrs.add(ea); } else if (elementType.equals(MailConstants.E_SUBJECT)) { // subject result.setSubject(e.getText()); } else if (elementType.equals(MailConstants.E_MSG)) { // message LmcMessage m = parseMessage(e); msgs.add(m); } else { // don't know what it is throw new LmcSoapClientException("unknown element " + elementType + " within conversation"); } } // set the arrays in the result object if (!emailAddrs.isEmpty()) { LmcEmailAddress a[] = new LmcEmailAddress[emailAddrs.size()]; result.setParticipants((LmcEmailAddress[]) emailAddrs.toArray(a)); } if (!msgs.isEmpty()) { LmcMessage m[] = new LmcMessage[msgs.size()]; result.setMessages((LmcMessage[]) msgs.toArray(m)); } return result; }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
protected LmcMessage parseMessage(Element msg) throws ServiceException, LmcSoapClientException { LmcMessage result = new LmcMessage(); // get the message attributes result.setID(DomUtil.getAttr(msg, MailConstants.A_ID)); result.setFlags(msg.attributeValue(MailConstants.A_FLAGS)); String size = msg.attributeValue(MailConstants.A_SIZE); if (size != null) result.setSize(Integer.parseInt(size)); result.setContentMatched(msg.attributeValue(MailConstants.A_CONTENTMATCHED)); result.setDate(msg.attributeValue(MailConstants.A_DATE)); result.setConvID(msg.attributeValue(MailConstants.A_CONV_ID)); result.setFolder(msg.attributeValue(MailConstants.A_FOLDER)); result.setOriginalID(msg.attributeValue(MailConstants.A_ORIG_ID)); /*/*from w w w. j a v a 2 s . c o m*/ * iterate over subelements. allowed subelements are content (at most * 1), subject, fragment, and msg parts. this assumes no particular * order is required for correctness. */ ArrayList emailAddrs = new ArrayList(); for (Iterator it = msg.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_FRAG)) { // fragment result.setFragment(e.getText()); } else if (elementType.equals(MailConstants.E_EMAIL)) { // e-mail address LmcEmailAddress ea = parseEmailAddress(e); emailAddrs.add(ea); } else if (elementType.equals(MailConstants.E_SUBJECT)) { // subject result.setSubject(e.getText()); } else if (elementType.equals(MailConstants.E_MIMEPART)) { // MIME part LmcMimePart mp = parseMimePart(e); result.addMimePart(mp); } else if (elementType.equals(MailConstants.E_MSG_ID_HDR)) { // message ID header result.setMsgIDHeader(e.getText()); } else if (elementType.equals(MailConstants.E_INVITE)) { // ignore appointment invites for now } else { // don't know what it is throw new LmcSoapClientException("unknown element " + elementType + " within message"); } } if (!emailAddrs.isEmpty()) { LmcEmailAddress a[] = new LmcEmailAddress[emailAddrs.size()]; result.setEmailAddresses((LmcEmailAddress[]) emailAddrs.toArray(a)); } return result; }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
protected LmcMimePart parseMimePart(Element mp) throws LmcSoapClientException, ServiceException { LmcMimePart result = new LmcMimePart(); // get the attributes result.setPartName(DomUtil.getAttr(mp, MailConstants.A_PART)); result.setIsBody(mp.attributeValue(MailConstants.A_BODY)); result.setSize(mp.attributeValue(MailConstants.A_SIZE)); result.setMessageID(mp.attributeValue(MailConstants.A_MESSAGE_ID)); result.setConvID(mp.attributeValue(MailConstants.A_CONV_ID)); result.setContentType(mp.attributeValue(MailConstants.A_CONTENT_TYPE)); result.setContentTypeName(mp.attributeValue(MailConstants.A_CONTENT_NAME)); result.setContentDisp(mp.attributeValue(MailConstants.A_CONTENT_DISPOSITION)); result.setContentDispFilename(mp.attributeValue(MailConstants.A_CONTENT_FILENAME)); // XXX assume that content description is an attr of <mp> and not <content> result.setContentDesc(mp.attributeValue(MailConstants.A_CONTENT_DESCRIPTION)); // parse any interior elements (content or another MIME part) ArrayList subMimeParts = new ArrayList(); for (Iterator it = mp.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_CONTENT)) { addContent(result, e);/* w w w.j ava2s . com*/ } else if (elementType.equals(MailConstants.E_MIMEPART)) { LmcMimePart nextPart = parseMimePart(e); subMimeParts.add(nextPart); } else { // unexpected element throw new LmcSoapClientException("unexpected element " + elementType); } } if (!subMimeParts.isEmpty()) { LmcMimePart mpArr[] = new LmcMimePart[subMimeParts.size()]; result.setSubParts((LmcMimePart[]) subMimeParts.toArray(mpArr)); } return result; }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
private LmcDocument parseDocumentCommon(Element doc, LmcDocument result) { result.setID(doc.attributeValue(MailConstants.A_ID)); result.setName(doc.attributeValue(MailConstants.A_NAME)); result.setContentType(doc.attributeValue(MailConstants.A_CONTENT_TYPE)); result.setFolder(doc.attributeValue(MailConstants.A_FOLDER)); result.setRev(doc.attributeValue(MailConstants.A_VERSION)); result.setLastModifiedDate(doc.attributeValue(MailConstants.A_DATE)); result.setLastEditor(doc.attributeValue(MailConstants.A_LAST_EDITED_BY)); result.setRestUrl(doc.attributeValue(MailConstants.A_REST_URL)); result.setCreator(doc.attributeValue(MailConstants.A_CREATOR)); result.setCreateDate(doc.attributeValue(MailConstants.A_CREATED_DATE)); for (Iterator it = doc.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_FRAG)) { // fragment result.setFragment(e.getText()); }// ww w . j a va 2 s. co m } return result; }
From source file:com.zimbra.cs.dav.service.DavServlet.java
License:Open Source License
private boolean isCtagRequest(DavContext ctxt) throws DavException { String httpMethod = ctxt.getRequest().getMethod(); if (PropFind.PROPFIND.equalsIgnoreCase(httpMethod) && ctxt.hasRequestMessage()) { Document doc = ctxt.getRequestMessage(); Element top = doc.getRootElement(); if (top == null || !top.getQName().equals(DavElements.E_PROPFIND)) return false; Element prop = top.element(DavElements.E_PROP); if (prop == null) return false; Iterator<?> iter = prop.elementIterator(); while (iter.hasNext()) { prop = (Element) iter.next(); if (prop.getQName().equals(DavElements.E_GETCTAG)) return true; }/*from ww w . j av a 2 s. co m*/ } return false; }
From source file:com.zimbra.cs.dav.service.method.AddressbookQuery.java
License:Open Source License
public void handle(DavContext ctxt) throws DavException, ServiceException { DavResource rsc = ctxt.getRequestedResource(); if (!(rsc instanceof AddressbookCollection)) throw new DavException("not an addressbook resource", HttpServletResponse.SC_BAD_REQUEST, null); Element query = ctxt.getRequestMessage().getRootElement(); if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_QUERY)) throw new DavException("msg " + query.getName() + " is not addressbook-query", HttpServletResponse.SC_BAD_REQUEST, null); Element f = query.element(DavElements.CardDav.E_FILTER); if (f == null) throw new DavException("msg " + query.getName() + " is missing filter", HttpServletResponse.SC_BAD_REQUEST, null); Filter filter = new Filter.PropFilter((Element) f.elementIterator().next()); Collection<AddressObject> contacts = filter.match(ctxt, ((AddressbookCollection) rsc)); RequestProp reqProp = ctxt.getRequestProp(); DavResponse resp = ctxt.getDavResponse(); resp.createResponse(ctxt);/* ww w . j a v a 2 s . c o m*/ for (AddressObject c : contacts) { resp.addResource(ctxt, c, reqProp, false); } }
From source file:com.zimbra.cs.service.formatter.ContactCSV.java
License:Open Source License
private static void readMapping(InputStream is) throws XmlParseException { delimiterInfo = new HashMap<String, Character>(); dateOrderInfo = new HashMap<String, String>(); Element root = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(is).getRootElement(); for (Iterator elements = root.elementIterator(); elements.hasNext();) { Element elem = (Element) elements.next(); if (elem.getQName().equals(FIELDS)) { populateFields(elem);//w ww . j av a2 s . co m } else if (elem.getQName().equals(FORMAT)) { addFormat(elem); } else if (elem.getQName().equals(DELIMITERS)) { populateDelimiterInfo(elem); } else if (elem.getQName().equals(DATEFORMATS)) { populateDateFormatInfo(elem); } } }
From source file:controllers.FXMLScicumulusController.java
public void importWorkflow() throws DocumentException { //Impota o workflow e cria o grafo System.out.println("Importando..."); SAXReader reader = new SAXReader(); Document docXml = reader.read("src/main/java/br/com/uft/scicumulus/files/SciCumulus.xml"); Element root = docXml.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); // tempList.addElement(element.attributeValue("id")); for (Iterator j = element.elementIterator(); j.hasNext();) { Element innerElement = (Element) j.next(); System.out.println(innerElement.getData().toString()); }//from ww w .j a va 2 s. c om } }