List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:org.apache.nifi.authorization.FileUserGroupProvider.java
private void writeGroup(final XMLStreamWriter writer, final Group group) throws XMLStreamException { List<String> users = new ArrayList<>(group.getUsers()); Collections.sort(users);/*from w w w .j a va 2 s.c om*/ writer.writeStartElement(GROUP_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, group.getIdentifier()); writer.writeAttribute(NAME_ATTR, group.getName()); for (String user : users) { writer.writeStartElement(GROUP_USER_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, user); writer.writeEndElement(); } writer.writeEndElement(); }
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// ww w . j a va 2s. co 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()); }//from www. j a va 2s. c o m 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();/* www. ja va 2 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); }/* ww w.j av a2 s . c o 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 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 ww w . j av a 2 s. com }
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();/* w ww . j a v a2 s .c om*/ }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeDefaultNamespace(namespaceMetadata); addContextInfo(writer, container);/*from w ww. j av a 2s. com*/ writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString()); }
From source file:org.apache.olingo.commons.core.data.AtomSerializer.java
private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException { for (Link link : links) { writer.writeStartElement(Constants.ATOM_ELEM_LINK); if (StringUtils.isNotBlank(link.getRel())) { writer.writeAttribute(Constants.ATTR_REL, link.getRel()); }/*from w w w . j a v a2 s . co m*/ 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()); } if (link.getInlineEntry() != null || link.getInlineFeed() != null) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); if (link.getInlineEntry() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); entry(writer, link.getInlineEntry()); writer.writeEndElement(); } if (link.getInlineFeed() != null) { writer.writeStartElement(Constants.ATOM_ELEM_FEED); feed(writer, link.getInlineFeed()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } }
From source file:org.apache.olingo.commons.core.data.AtomSerializer.java
private void common(final XMLStreamWriter writer, final AbstractAtomObject 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 a v a 2 s . c om } if (StringUtils.isNotBlank(object.getSummary())) { writer.writeStartElement(Constants.ATOM_ELEM_SUMMARY); writer.writeAttribute(Constants.ATTR_TYPE, "text"); writer.writeCharacters(object.getSummary()); writer.writeEndElement(); } }