public boolean readToDescendant(String localName, String namespaceURI) throws XMLStreamException { if (!this.isStartElement()) { return false; } XMLEvent startEvent = this.presentEvent; XMLEvent event = this.presentEvent; do { if (event.isStartElement()) { QName qEName = event.asStartElement().getName(); if (qEName.getLocalPart().equals(localName) && qEName.getNamespaceURI().equals(namespaceURI)) { return true; } } event = this.xmlReader.nextEvent(); } while (!checkEndElement(startEvent, event)); return false; }
/** * Read element value. * * @return String * @throws Exception the exception */ public String readElementValue() throws Exception { this.ensureCurrentNodeIsStartElement(); return this.readElementValue(this.getNamespacePrefix(), this .getLocalName()); }
/** * Read XML element. * * @param xmlNamespace The XML namespace * @param localName Name of the local * @param nodeType Type of the node * @throws Exception the exception */ private void internalReadElement(XmlNamespace xmlNamespace, String localName, XmlNodeType nodeType) throws Exception { if (xmlNamespace == XmlNamespace.NotSpecified) { this.internalReadElement("", localName, nodeType); } else { this.read(nodeType); if ((!this.getLocalName().equals(localName)) || (!this.getNamespaceUri().equals(EwsUtilities .getNamespaceUri(xmlNamespace)))) { throw new ServiceXmlDeserializationException( String .format( "An element node '%s:%s' of the type %s was expected, but node '%s' of type %s was found.", EwsUtilities .getNamespacePrefix( xmlNamespace), localName, nodeType.toString(), this .getName(), this.getNodeType() .toString())); } } }
/** * Skips the current element. * * @throws Exception the exception */ public void skipCurrentElement() throws Exception { this.skipElement(this.getNamespacePrefix(), this.getLocalName()); }
/** * Read element value. * * @param <T> the generic type * @param cls the cls * @return T * @throws Exception the exception */ public <T> T readElementValue(Class<T> cls) throws Exception { this.ensureCurrentNodeIsStartElement(); T value = null; if (!this.isEmptyElement()) { value = this.readValue(cls); } return value; }
/** * Loads from XML. * * @param reader The reader. * @throws Exception the exception */ public void loadFromXml(EwsXmlReader reader) throws Exception { do { reader.read(); if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) { if (reader.getLocalName().equals(XmlElementNames.ErrorCode)) { this.errorCode = reader .readElementValue(AutodiscoverErrorCode.class); } else if (reader.getLocalName().equals( XmlElementNames.ErrorMessage)) { this.errorMessage = reader.readElementValue(); } else if (reader.getLocalName().equals( XmlElementNames.SettingName)) { this.settingName = reader.readElementValue(); } } } while (!reader.isEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettingError)); }
/** * Parses the message xml. * * @param reader the reader * @throws Exception the exception * @throws ServiceXmlDeserializationException the service xml deserialization exception */ private void parseMessageXml(EwsXmlReader reader) throws Exception, ServiceXmlDeserializationException, Exception { // E14:172881: E12 and E14 return the MessageXml element in different // namespaces (types namespace for E12, errors namespace in E14). To // avoid this problem, the parser will match the namespace from the // start and end elements. XmlNamespace elementNS = EwsUtilities.getNamespaceFromUri(reader.getNamespaceUri()); if (!reader.isEmptyElement()) { do { reader.read(); if (reader.isStartElement() && !reader.isEmptyElement()) { String localName = reader.getLocalName(); if (localName.equals(XmlElementNames.Value)) { this.errorDetails.put(reader .readAttributeValue(XmlAttributeNames.Name), reader.readElementValue()); } } } while (!reader .isEndElement(elementNS, XmlElementNames.MessageXml)); } else { reader.read(); } }
reader.read(); if (reader.getNodeType().getNodeType() == XmlNodeType.START_DOCUMENT) { reader.read(); if (!reader.isStartElement() || (!reader.getLocalName().equals( XmlElementNames.SOAPEnvelopeElementName))) { return null; .getNamespaceFromUri(reader.getNamespaceUri()); if (soapNamespace == XmlNamespace.NotSpecified) { return null; reader.read(); if (reader.isStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.read(); } while (!reader.isEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); reader.read(); if (reader.isStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.read();
EwsXmlReader ewsXmlReader = new EwsXmlReader(memoryStreamIn); ewsXmlReader.read(); if (ewsXmlReader.getNodeType().getNodeType() == XmlNodeType.START_DOCUMENT) { ewsXmlReader.readStartElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName); } else if ((ewsXmlReader.getNodeType().getNodeType() != XmlNodeType.START_ELEMENT) || (!ewsXmlReader.getLocalName().equals( XmlElementNames.SOAPEnvelopeElementName)) || (!ewsXmlReader.getNamespaceUri().equals( EwsUtilities.getNamespaceUri(XmlNamespace.Soap)))) { throw new ServiceXmlDeserializationException("The Autodiscover service response was invalid."); ewsXmlReader.readEndElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName);
/** * Read XML element. * * @param namespacePrefix The namespace prefix * @param localName Name of the local * @param nodeType Type of the node * @throws Exception the exception */ private void internalReadElement(String namespacePrefix, String localName, XmlNodeType nodeType) throws Exception { read(nodeType); if ((!this.getLocalName().equals(localName)) || (!this.getNamespacePrefix().equals(namespacePrefix))) { throw new ServiceXmlDeserializationException(String.format( "An element node '%s:%s' of the type %s was expected, but node '%s' of type %s was found.", namespacePrefix, localName, nodeType.toString(), this.getName(), this.getNodeType() .toString())); } }
ExchangeServerInfo serverInfo = new ExchangeServerInfo(); do { reader.read(); if (reader.isStartElement()) { if (reader.getLocalName().equals(XmlElementNames.MajorVersion)) { serverInfo.setMajorVersion(reader .readElementValue(Integer.class)); } else if (reader.getLocalName().equals( XmlElementNames.MinorVersion)) { serverInfo.setMinorVersion(reader .readElementValue(Integer.class)); } else if (reader.getLocalName().equals( XmlElementNames.MajorBuildNumber)) { serverInfo.setMajorBuildNumber(reader .readElementValue(Integer.class)); } else if (reader.getLocalName().equals( XmlElementNames.MinorBuildNumber)) { serverInfo.setMinorBuildNumber(reader .readElementValue(Integer.class)); } else if (reader.getLocalName() .equals(XmlElementNames.Version)) { serverInfo.setVersionString(reader.readElementValue()); } while (!reader.isEndElement(XmlNamespace.Autodiscover, XmlElementNames.ServerVersionInfo));
/** * Determines whether current element is a start element. * * @param xmlNamespace the xml namespace * @param localName the local name * @return true for matching start element; false otherwise. */ public boolean isStartElement(XmlNamespace xmlNamespace, String localName) { return this.isStartElement() && StringUtils.equals(getLocalName(), localName) && ( StringUtils.equals(getNamespacePrefix(), EwsUtilities.getNamespacePrefix(xmlNamespace)) || StringUtils.equals(getNamespaceUri(), EwsUtilities.getNamespaceUri(xmlNamespace))); }
if (this.presentEvent.isStartElement()) { this.read(keepWhiteSpace); if (this.presentEvent.isCharacters()) { final StringBuilder elementValue = new StringBuilder(); do { if (this.getNodeType().nodeType == XmlNodeType.CHARACTERS) { Characters characters = (Characters) this.presentEvent; if (keepWhiteSpace || (!characters.isIgnorableWhiteSpace() this.read(); } while (!this.presentEvent.isEndElement()); } else { throw new ServiceXmlDeserializationException( getReadValueErrMsg("Could not find " + XmlNodeType.getString(XmlNodeType.CHARACTERS))); final StringBuilder data = new StringBuilder(charData == null ? "" : charData); do { this.read(keepWhiteSpace); if (this.getNodeType().nodeType == XmlNodeType.CHARACTERS) { Characters characters = (Characters) this.presentEvent; if (keepWhiteSpace || (!characters.isIgnorableWhiteSpace() getReadValueErrMsg("Expected is " + XmlNodeType.getString(XmlNodeType.START_ELEMENT)) );
/** * Reads the specified node type. * * @param nodeType Type of the node. * @throws Exception the exception */ public void read(XmlNodeType nodeType) throws Exception { this.read(); if (!this.getNodeType().equals(nodeType)) { throw new ServiceXmlDeserializationException(String .format("The expected XML node type was %s, but the actual type is %s.", nodeType, this .getNodeType())); } }
/** * Initializes a new instance of the AutodiscoverResponse class. * * @param reader the reader * @param endElementName the end element name * @throws Exception the exception */ public void loadFromXml(EwsXmlReader reader, String endElementName) throws Exception { if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.ErrorCode)) { this.errorCode = reader .readElementValue(AutodiscoverErrorCode.class); } else if (reader.getLocalName().equalsIgnoreCase( XmlElementNames.ErrorMessage)) { this.errorMessage = reader.readElementValue(); } }
/** * Tries to read the current XML element. * * @param reader the reader * @return true is the current element was read, false otherwise * @throws Exception the exception */ @Override public boolean tryReadCurrentXmlElement(EwsXmlReader reader) throws Exception { if (!super.tryReadCurrentXmlElement(reader)) { if (reader.getLocalName().equals(XmlElementNames.User)) { this.user.loadFromXml(reader); return true; } else if (reader.getLocalName().equals(XmlElementNames.Account)) { this.account.loadFromXml(reader); return true; } else { reader.skipCurrentElement(); return false; } } else { return true; } }
ByteArrayInputStream memoryStreamIn = new ByteArrayInputStream( memoryStream.toByteArray()); EwsXmlReader reader = new EwsXmlReader(memoryStreamIn); reader.read(new XmlNodeType(XmlNodeType.START_DOCUMENT)); settings.loadFromXml(reader); EwsXmlReader reader = new EwsXmlReader(serviceResponseStream); reader.read(new XmlNodeType(XmlNodeType.START_DOCUMENT)); settings.loadFromXml(reader);
/** * Reads the base64 element value. * * @param outputStream the output stream * @throws Exception the exception */ public void readBase64ElementValue(OutputStream outputStream) throws Exception { this.ensureCurrentNodeIsStartElement(); byte[] buffer = null; buffer = Base64.decodeBase64(this.xmlReader.getElementText().toString()); outputStream.write(buffer); outputStream.flush(); }
/** * Initializes a new instance of the EwsXmlReader class. * * @param stream the stream * @throws Exception on error */ public EwsXmlReader(InputStream stream) throws Exception { this.xmlReader = initializeXmlReader(stream); }
/** * Tries to read the current XML element. * * @param reader the reader * @return True is the current element was read, false otherwise. * @throws Exception the exception */ public boolean tryReadCurrentXmlElement(EwsXmlReader reader) throws Exception { if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Error)) { this.error = AutodiscoverError.parse(reader); return true; } else { return false; } }