List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
public void property(final XMLStreamWriter writer, final Property property, final boolean standalone) throws XMLStreamException, EdmPrimitiveTypeException { if (standalone) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE, namespaceData); namespaces(writer);//ww w . j a v a2s . c o m } else { writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), namespaceData); } EdmTypeInfo typeInfo = null; if (StringUtils.isNotBlank(property.getType())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, Constants.ATTR_TYPE, typeInfo.external()); } } value(writer, property.getValueType(), typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(), property.getValue()); if (!property.isNull() && property.isComplex() && !property.isCollection()) { links(writer, property.asComplex().getAssociationLinks()); if (serverMode) { links(writer, property.asComplex().getNavigationLinks()); } else { writeNavigationLinks(writer, property.asComplex().getNavigationLinks()); } } writer.writeEndElement(); for (Annotation annotation : property.getAnnotations()) { annotation(writer, annotation, property.getName()); } }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void writeNavigationLinks(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException, EdmPrimitiveTypeException { final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>(); for (Link link : links) { if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) { writeLink(writer, link, new ExtraContent() { @Override//w w w. j a v a 2s . c o m public void write(XMLStreamWriter writer, Link link) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata); if (link.getInlineEntity() != null) { writer.writeStartElement(namespaceAtom, Constants.ATOM_ELEM_ENTRY); entity(writer, link.getInlineEntity()); writer.writeEndElement(); } if (link.getInlineEntitySet() != null) { writer.writeStartElement(namespaceAtom, Constants.ATOM_ELEM_FEED); entitySet(writer, link.getInlineEntitySet()); writer.writeEndElement(); } writer.writeEndElement(); // inline } }); } else if (link.getBindingLink() != null) { writeLink(writer, link, new ExtraContent() { @Override public void write(XMLStreamWriter writer, Link link) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeAttribute(Constants.ATTR_HREF, link.getBindingLink()); } }); } else if (link.getBindingLinks() != null && !link.getBindingLinks().isEmpty()) { writeLink(writer, link, new ExtraContent() { @Override public void write(XMLStreamWriter writer, Link link) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata); writer.writeStartElement(namespaceAtom, Constants.ATOM_ELEM_FEED); for (String binding : link.getBindingLinks()) { Entity entity = new Entity(); entity.setId(URI.create(binding)); inlineEntityRef(writer, entity); } writer.writeEndElement(); //feed writer.writeEndElement(); //inline } }); } else { if (isEntitySetNavigation(link)) { final List<String> uris; if (entitySetLinks.containsKey(link.getTitle())) { uris = entitySetLinks.get(link.getTitle()); } else { uris = new ArrayList<String>(); entitySetLinks.put(link.getTitle(), uris); } if (StringUtils.isNotBlank(link.getHref())) { uris.add(link.getHref()); } } else { writeLink(writer, link, new ExtraContent() { @Override public void write(XMLStreamWriter writer, Link link) throws XMLStreamException, EdmPrimitiveTypeException { } }); } } } for (String title : entitySetLinks.keySet()) { final List<String> entitySetLink = entitySetLinks.get(title); if (!entitySetLink.isEmpty()) { Link link = new Link(); link.setTitle(title); link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE); link.setRel(Constants.NS_NAVIGATION_LINK_REL + title); writeLink(writer, link, new ExtraContent() { @Override public void write(XMLStreamWriter writer, Link link) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata); writer.writeStartElement(namespaceAtom, Constants.ATOM_ELEM_FEED); for (String binding : entitySetLink) { Entity entity = new Entity(); entity.setId(URI.create(binding)); inlineEntityRef(writer, entity); } writer.writeEndElement(); writer.writeEndElement(); } }); } } }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void writeLink(final XMLStreamWriter writer, final Link link, final ExtraContent content) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.ATOM_ELEM_LINK); if (StringUtils.isNotBlank(link.getRel())) { writer.writeAttribute(Constants.ATTR_REL, link.getRel()); }// w w w . jav a 2s. com if (StringUtils.isNotBlank(link.getTitle())) { writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle()); } if (StringUtils.isNotBlank(link.getHref())) { writer.writeAttribute(Constants.ATTR_HREF, link.getHref()); } if (StringUtils.isNotBlank(link.getType())) { writer.writeAttribute(Constants.ATTR_TYPE, link.getType()); } content.write(writer, link); for (Annotation annotation : link.getAnnotations()) { annotation(writer, annotation, null); } writer.writeEndElement(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void common(final XMLStreamWriter writer, final AbstractODataObject object) throws XMLStreamException { if (StringUtils.isNotBlank(object.getTitle())) { writer.writeStartElement(Constants.ATOM_ELEM_TITLE); writer.writeAttribute(Constants.ATTR_TYPE, TYPE_TEXT); writer.writeCharacters(object.getTitle()); writer.writeEndElement(); }//w w w . j ava2 s . c o m }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION, namespaceMetadata); writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm()); if (target != null) { writer.writeAttribute(Constants.ATTR_TARGET, target); }/*from w w w. j a v a 2 s . co m*/ EdmTypeInfo typeInfo = null; if (StringUtils.isNotBlank(annotation.getType())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, Constants.ATTR_TYPE, typeInfo.external()); } } value(writer, annotation.getValueType(), typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(), annotation.getValue()); writer.writeEndElement(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void entity(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException, EdmPrimitiveTypeException { if (entity.getBaseURI() != null) { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entity.getBaseURI().toASCIIString()); }//from ww w.j av a 2 s. co m if (serverMode && StringUtils.isNotBlank(entity.getETag())) { writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_ETAG, entity.getETag()); } if (entity.getId() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ID); writer.writeCharacters(entity.getId().toASCIIString()); writer.writeEndElement(); } writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY); writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME); if (StringUtils.isNotBlank(entity.getType())) { writer.writeAttribute(Constants.ATOM_ATTR_TERM, new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external()); } writer.writeEndElement(); common(writer, entity); if (serverMode) { if (entity.getEditLink() != null) { links(writer, Collections.singletonList(entity.getEditLink())); } if (entity.getSelfLink() != null) { links(writer, Collections.singletonList(entity.getSelfLink())); } } links(writer, entity.getAssociationLinks()); if (serverMode) { links(writer, entity.getNavigationLinks()); } else { writeNavigationLinks(writer, entity.getNavigationLinks()); writeNavigationLinks(writer, entity.getNavigationBindings()); } links(writer, entity.getMediaEditLinks()); if (serverMode) { for (Operation operation : entity.getOperations()) { writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ACTION); writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor()); writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle()); writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); writer.writeEndElement(); } } writer.writeStartElement(Constants.ATOM_ELEM_CONTENT); if (entity.isMediaEntity()) { if (StringUtils.isNotBlank(entity.getMediaContentType())) { writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType()); } if (entity.getMediaContentSource() != null) { writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString()); } writer.writeEndElement(); writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES); properties(writer, entity.getProperties()); } else { writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.toContentTypeString()); writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES); properties(writer, entity.getProperties()); writer.writeEndElement(); } writer.writeEndElement(); for (Annotation annotation : entity.getAnnotations()) { annotation(writer, annotation, null); } }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void inlineEntityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ENTRY_REF); writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString()); writer.writeEndElement(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeDefaultNamespace(namespaceMetadata); writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString()); writer.writeEndElement(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void entity(final Writer outWriter, final ResWrap<Entity> container) throws XMLStreamException, EdmPrimitiveTypeException { final Entity entity = container.getPayload(); final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); if (entity.getType() == null && entity.getProperties().isEmpty()) { writer.writeStartDocument();/* w ww. j av a 2 s. c o m*/ writer.setDefaultNamespace(namespaceMetadata); entityRef(writer, container); } else { startDocument(writer, Constants.ATOM_ELEM_ENTRY); addContextInfo(writer, container); entity(writer, entity); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void entitySet(final XMLStreamWriter writer, final EntityCollection entitySet) throws XMLStreamException, EdmPrimitiveTypeException { if (entitySet.getBaseURI() != null) { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entitySet.getBaseURI().toASCIIString()); }// w w w . j a va 2 s. c o m if (entitySet.getCount() != null) { writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_COUNT); writer.writeCharacters(Integer.toString(entitySet.getCount())); writer.writeEndElement(); } if (entitySet.getId() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ID); writer.writeCharacters(entitySet.getId().toASCIIString()); writer.writeEndElement(); } common(writer, entitySet); for (Entity entity : entitySet) { if (entity.getType() == null && entity.getProperties().isEmpty()) { entityRef(writer, entity); } else { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); entity(writer, entity); writer.writeEndElement(); } } if (serverMode) { if (entitySet.getNext() != null) { final Link next = new Link(); next.setRel(Constants.NEXT_LINK_REL); next.setHref(entitySet.getNext().toASCIIString()); links(writer, Collections.<Link>singletonList(next)); } if (entitySet.getDeltaLink() != null) { final Link next = new Link(); next.setRel(Constants.NS_DELTA_LINK_REL); next.setHref(entitySet.getDeltaLink().toASCIIString()); links(writer, Collections.<Link>singletonList(next)); } } }