List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:org.apache.flex.compiler.config.Configuration.java
/** * Write the data to rdf/xml//from www . j av a2s . c om * * @param writer * @throws XMLStreamException */ private void writeDate(XMLStreamWriter writer) throws XMLStreamException { if (date == null) { date = DateFormat.getDateInstance().format(new Date()); } writer.writeStartElement(DC_URI, "date"); writer.writeCharacters(date); writer.writeEndElement(); }
From source file:org.apache.flex.compiler.config.Configuration.java
/** * Write a map of values to rdf/xml// ww w .j av a 2 s. c o m * * @param writer * @param namespaceURI * @param localName * @param mapData * @throws XMLStreamException */ private void writeMap(XMLStreamWriter writer, String namespaceURI, String localName, Map<String, String> mapData) throws XMLStreamException { if (mapData.size() > 0) { writer.writeStartElement(namespaceURI, localName); if ((mapData.size() == 1) && (mapData.get("x-default") != null)) { String data = mapData.get("x-default"); writer.writeCharacters(data); } else { writer.writeStartElement(RDF_URI, "Alt"); for (final String key : mapData.keySet()) { final String value = mapData.get(key); writer.writeStartElement(RDF_URI, "li"); writer.writeAttribute("xml", "", "lang", key); writer.writeCharacters(value); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } }
From source file:org.apache.flex.compiler.config.Configuration.java
/** * Write a collection values to rdf/xml. * /*from ww w . ja v a 2 s . c o m*/ * @param writer * @param namespaceURI * @param localName * @param values * @throws XMLStreamException */ private void writeCollection(XMLStreamWriter writer, String namespaceURI, String localName, Collection<String> values) throws XMLStreamException { if (values.isEmpty()) return; writer.writeStartElement(namespaceURI, localName); if (values.size() > 1) writer.writeStartElement(RDF_URI, "Bag"); for (String value : values) { writer.writeCharacters(value); } if (values.size() > 1) writer.writeEndElement(); writer.writeEndElement(); }
From source file:org.apache.nifi.authorization.FileAccessPolicyProvider.java
@Override public String getFingerprint() throws AuthorizationAccessException { final List<AccessPolicy> policies = new ArrayList<>(getAccessPolicies()); Collections.sort(policies, Comparator.comparing(AccessPolicy::getIdentifier)); XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try {/* w w w . j a va 2 s . c om*/ writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("accessPolicies"); for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { // nothing to do here } } } return out.toString(); }
From source file:org.apache.nifi.authorization.FileAccessPolicyProvider.java
private void writePolicy(final XMLStreamWriter writer, final AccessPolicy policy) throws XMLStreamException { // sort the users for the policy List<String> policyUsers = new ArrayList<>(policy.getUsers()); Collections.sort(policyUsers); // sort the groups for this policy List<String> policyGroups = new ArrayList<>(policy.getGroups()); Collections.sort(policyGroups); writer.writeStartElement(POLICY_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, policy.getIdentifier()); writer.writeAttribute(RESOURCE_ATTR, policy.getResource()); writer.writeAttribute(ACTIONS_ATTR, policy.getAction().name()); for (String policyUser : policyUsers) { writer.writeStartElement(POLICY_USER_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, policyUser); writer.writeEndElement(); }//from ww w .ja v a 2 s .c o m for (String policyGroup : policyGroups) { writer.writeStartElement(POLICY_GROUP_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, policyGroup); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.apache.nifi.authorization.FileUserGroupProvider.java
@Override public String getFingerprint() throws AuthorizationAccessException { final UserGroupHolder usersAndGroups = userGroupHolder.get(); final List<User> users = new ArrayList<>(usersAndGroups.getAllUsers()); Collections.sort(users, Comparator.comparing(User::getIdentifier)); final List<Group> groups = new ArrayList<>(usersAndGroups.getAllGroups()); Collections.sort(groups, Comparator.comparing(Group::getIdentifier)); XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try {//from ww w . j a v a2 s . c o m writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("tenants"); for (User user : users) { writeUser(writer, user); } for (Group group : groups) { writeGroup(writer, group); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { // nothing to do here } } } return out.toString(); }
From source file:org.apache.nifi.authorization.FileUserGroupProvider.java
private void writeUser(final XMLStreamWriter writer, final User user) throws XMLStreamException { writer.writeStartElement(USER_ELEMENT); writer.writeAttribute(IDENTIFIER_ATTR, user.getIdentifier()); writer.writeAttribute(IDENTITY_ATTR, user.getIdentity()); writer.writeEndElement(); }
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 v a2 s .co m*/ 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.nifi.authorization.StandardManagedAuthorizer.java
@Override public String getFingerprint() throws AuthorizationAccessException { XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try {/*from w ww. ja va2 s.c om*/ writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("managedAuthorizations"); writer.writeStartElement(ACCESS_POLICY_PROVIDER_ELEMENT); if (accessPolicyProvider instanceof ConfigurableAccessPolicyProvider) { writer.writeCharacters(((ConfigurableAccessPolicyProvider) accessPolicyProvider).getFingerprint()); } writer.writeEndElement(); writer.writeStartElement(USER_GROUP_PROVIDER_ELEMENT); if (userGroupProvider instanceof ConfigurableUserGroupProvider) { writer.writeCharacters(((ConfigurableUserGroupProvider) userGroupProvider).getFingerprint()); } writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { // nothing to do here } } } return out.toString(); }
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void collection(final XMLStreamWriter writer, final ValueType valueType, final EdmPrimitiveTypeKind kind, final List<?> value) throws XMLStreamException, EdmPrimitiveTypeException { for (Object item : value) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, namespaceMetadata); value(writer, valueType, kind, item); writer.writeEndElement(); }/* ww w . j av a2s . c om*/ }