List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String localName) throws XMLStreamException;
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();/*from w w w . j a v a2 s . c o m*/ } if (StringUtils.isNotBlank(object.getSummary())) { writer.writeStartElement(Constants.ATOM_ELEM_SUMMARY); writer.writeAttribute(Constants.ATTR_TYPE, "text"); writer.writeCharacters(object.getSummary()); writer.writeEndElement(); } }
From source file:org.apache.olingo.commons.core.data.AtomSerializer.java
private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException { if (entry.getBaseURI() != null) { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString()); }/*from w w w . java 2s .com*/ if (StringUtils.isNotBlank(entry.getId())) { writer.writeStartElement(Constants.ATOM_ELEM_ID); writer.writeCharacters(entry.getId()); writer.writeEndElement(); } writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY); writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME)); writer.writeAttribute(Constants.ATOM_ATTR_TERM, entry.getType()); writer.writeEndElement(); if (entry instanceof AbstractAtomObject) { common(writer, (AbstractAtomObject) entry); } links(writer, entry.getAssociationLinks()); links(writer, entry.getNavigationLinks()); links(writer, entry.getMediaEditLinks()); writer.writeStartElement(Constants.ATOM_ELEM_CONTENT); if (entry.isMediaEntry()) { if (StringUtils.isNotBlank(entry.getMediaContentType())) { writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType()); } if (StringUtils.isNotBlank(entry.getMediaContentSource())) { writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource()); } writer.writeEndElement(); writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); properties(writer, entry.getProperties()); } else { writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML); writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); properties(writer, entry.getProperties()); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.apache.olingo.commons.core.data.AtomSerializer.java
private void link(final Writer outWriter, final Link link) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); writer.writeStartDocument();/*from w w w. j a v a 2 s .c o m*/ writer.writeStartElement(Constants.ELEM_LINKS); writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); writer.writeStartElement(Constants.ELEM_URI); writer.writeCharacters(link.getHref()); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
From source file:org.apache.olingo.commons.core.serialization.AtomSerializer.java
private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException, EdmPrimitiveTypeException { for (Link link : links) { writer.writeStartElement(Constants.ATOM_ELEM_LINK); if (StringUtils.isNotBlank(link.getRel())) { writer.writeAttribute(Constants.ATTR_REL, link.getRel()); }// w w w . ja v a 2 s.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()); } if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata); if (link.getInlineEntity() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); entity(writer, link.getInlineEntity()); writer.writeEndElement(); } if (link.getInlineEntitySet() != null) { writer.writeStartElement(Constants.ATOM_ELEM_FEED); entitySet(writer, link.getInlineEntitySet()); writer.writeEndElement(); } writer.writeEndElement(); } for (Annotation annotation : link.getAnnotations()) { annotation(writer, annotation, null); } writer.writeEndElement(); } }
From source file:org.apache.olingo.commons.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()); }/* w w w. j av a2s . c om*/ 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, version.getNamespace(ODataServiceVersion.NamespaceKey.SCHEME)); if (StringUtils.isNotBlank(entity.getType())) { writer.writeAttribute(Constants.ATOM_ATTR_TERM, new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); } writer.writeEndElement(); if (entity instanceof AbstractODataObject) { common(writer, (AbstractODataObject) 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()); links(writer, entity.getNavigationLinks()); links(writer, entity.getMediaEditLinks()); if (serverMode) { for (ODataOperation 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.commons.core.serialization.AtomSerializer.java
private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeNamespace(StringUtils.EMPTY, namespaceMetadata); writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString()); }
From source file:org.apache.olingo.commons.core.serialization.AtomSerializer.java
private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeNamespace(StringUtils.EMPTY, namespaceMetadata); addContextInfo(writer, container);/*from w w w. ja v a 2 s. com*/ writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString()); }
From source file:org.apache.syncope.client.cli.commands.migrate.MigrateConf.java
private static void exec(final String src, final String dst) throws XMLStreamException, IOException { XMLStreamWriter writer = new PrettyPrintXMLStreamWriter( OUTPUT_FACTORY.createXMLStreamWriter(new FileWriter(dst)), 2); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("dataset"); StringWriter reporterSW = new StringWriter(); XMLStreamWriter reporter = new PrettyPrintXMLStreamWriter(OUTPUT_FACTORY.createXMLStreamWriter(reporterSW), 2);/* w ww. j a v a 2 s .c o m*/ reporter.writeStartDocument("UTF-8", "1.0"); reporter.writeStartElement("dataset"); InputStream inputStream = Files.newInputStream(Paths.get(src)); XMLStreamReader reader = INPUT_FACTORY.createXMLStreamReader(inputStream); reader.nextTag(); // root reader.nextTag(); // dataset writer.writeStartElement("AnyType"); writer.writeAttribute("id", "USER"); writer.writeAttribute("kind", "USER"); writer.writeEndElement(); writer.writeStartElement("AnyTypeClass"); writer.writeAttribute("id", "BaseUser"); writer.writeEndElement(); writer.writeStartElement("AnyType_AnyTypeClass"); writer.writeAttribute("anyType_id", "USER"); writer.writeAttribute("anyTypeClass_id", "BaseUser"); writer.writeEndElement(); writer.writeStartElement("AnyType"); writer.writeAttribute("id", "GROUP"); writer.writeAttribute("kind", "GROUP"); writer.writeEndElement(); writer.writeStartElement("AnyTypeClass"); writer.writeAttribute("id", "BaseGroup"); writer.writeEndElement(); writer.writeStartElement("AnyType_AnyTypeClass"); writer.writeAttribute("anyType_id", "GROUP"); writer.writeAttribute("anyTypeClass_id", "BaseGroup"); writer.writeEndElement(); writer.writeStartElement("AnyTypeClass"); writer.writeAttribute("id", "BaseUMembership"); writer.writeEndElement(); Set<String> connInstanceCapabilities = new HashSet<>(); String lastUUID; String syncopeConf = UUID.randomUUID().toString(); Map<String, String> cPlainAttrs = new HashMap<>(); Map<String, String> policies = new HashMap<>(); Map<String, String> connInstances = new HashMap<>(); Map<String, String> provisions = new HashMap<>(); Map<String, String> mappings = new HashMap<>(); Map<String, String> tasks = new HashMap<>(); Map<String, String> notifications = new HashMap<>(); Map<String, String> reports = new HashMap<>(); String globalAccountPolicy = null; String globalPasswordPolicy = null; while (reader.hasNext()) { if (reader.isStartElement()) { switch (reader.getLocalName().toLowerCase()) { case "syncopeconf": writer.writeStartElement("SyncopeConf"); writer.writeAttribute("id", syncopeConf); writer.writeEndElement(); break; case "cschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("PlainSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeEndElement(); break; case "cattr": writer.writeStartElement("CPlainAttr"); copyAttrs(reader, writer, "owner_id", "schema_name"); lastUUID = UUID.randomUUID().toString(); writer.writeAttribute("id", lastUUID); writer.writeAttribute("owner_id", syncopeConf); writer.writeAttribute("schema_id", getAttributeValue(reader, "schema_name")); writer.writeEndElement(); cPlainAttrs.put(getAttributeValue(reader, "id"), lastUUID); break; case "cattrvalue": writer.writeStartElement("CPlainAttrValue"); copyAttrs(reader, writer, "attribute_id"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("attribute_id", cPlainAttrs.get(getAttributeValue(reader, "attribute_id"))); writer.writeEndElement(); break; case "uschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("PlainSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseUser"); writer.writeEndElement(); break; case "uderschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("DerSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseUser"); writer.writeEndElement(); break; case "uvirschema": reporter.writeStartElement("VirSchema"); copyAttrs(reader, reporter); reporter.writeAttribute("key", getAttributeValue(reader, "name")); reporter.writeEndElement(); break; case "rschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("PlainSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseGroup"); writer.writeEndElement(); break; case "rderschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("DerSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseGroup"); writer.writeEndElement(); break; case "rvirschema": reporter.writeStartElement("VirSchema"); reporter.writeAttribute("key", getAttributeValue(reader, "name")); copyAttrs(reader, reporter); reporter.writeEndElement(); break; case "mschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("PlainSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseUMembership"); writer.writeEndElement(); break; case "mderschema": writer.writeStartElement("SyncopeSchema"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeStartElement("DerSchema"); copyAttrs(reader, writer); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("anyTypeClass_id", "BaseUMembership"); writer.writeEndElement(); break; case "mvirschema": reporter.writeStartElement("VirSchema"); copyAttrs(reader, reporter); reporter.writeAttribute("key", getAttributeValue(reader, "name")); reporter.writeEndElement(); break; case "policy": String policyId = getAttributeValue(reader, "id"); lastUUID = UUID.randomUUID().toString(); policies.put(policyId, lastUUID); ObjectNode specification = (ObjectNode) OBJECT_MAPPER .readTree(getAttributeValue(reader, "specification")); switch (getAttributeValue(reader, "DTYPE")) { case "SyncPolicy": writer.writeStartElement("PullPolicy"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("description", getAttributeValue(reader, "description")); writer.writeEndElement(); break; case "PasswordPolicy": writer.writeStartElement("PasswordPolicy"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("description", getAttributeValue(reader, "description")); if ("GLOBAL_PASSWORD".equalsIgnoreCase(getAttributeValue(reader, "type"))) { globalPasswordPolicy = lastUUID; } JsonNode allowNullPassword = specification.get("allowNullPassword"); if (allowNullPassword != null) { writer.writeAttribute("allowNullPassword", allowNullPassword.asBoolean() ? "1" : "0"); specification.remove("allowNullPassword"); } JsonNode historyLength = specification.get("historyLength"); if (historyLength != null) { writer.writeAttribute("historyLength", historyLength.asText()); specification.remove("historyLength"); } specification.put("@class", "org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf"); writer.writeEndElement(); writer.writeStartElement("PasswordRuleConfInstance"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("passwordPolicy_id", lastUUID); writer.writeAttribute("serializedInstance", specification.toString()); writer.writeEndElement(); break; case "AccountPolicy": writer.writeStartElement("AccountPolicy"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("description", getAttributeValue(reader, "description")); if ("GLOBAL_ACCOUNT".equalsIgnoreCase(getAttributeValue(reader, "type"))) { globalAccountPolicy = lastUUID; } JsonNode propagateSuspension = specification.get("propagateSuspension"); if (propagateSuspension != null) { writer.writeAttribute("propagateSuspension", propagateSuspension.asBoolean() ? "1" : "0"); specification.remove("propagateSuspension"); } JsonNode permittedLoginRetries = specification.get("permittedLoginRetries"); if (permittedLoginRetries != null) { writer.writeAttribute("maxAuthenticationAttempts", permittedLoginRetries.asText()); specification.remove("permittedLoginRetries"); } specification.put("@class", "org.apache.syncope.common.lib.policy.DefaultAccountRuleConf"); writer.writeEndElement(); writer.writeStartElement("AccountRuleConfInstance"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("accountPolicy_id", lastUUID); writer.writeAttribute("serializedInstance", specification.toString()); writer.writeEndElement(); break; default: } break; case "conninstance": lastUUID = UUID.randomUUID().toString(); connInstances.put(getAttributeValue(reader, "id"), lastUUID); writer.writeStartElement("ConnInstance"); copyAttrs(reader, writer); writer.writeAttribute("id", lastUUID); writer.writeEndElement(); break; case "conninstance_capabilities": String connInstanceId = getAttributeValue(reader, "connInstance_id"); String connInstanceKey = connInstances.get(connInstanceId); String capabilities = getAttributeValue(reader, "capabilities"); if (capabilities.startsWith("ONE_PHASE_")) { capabilities = capabilities.substring(10); } else if (capabilities.startsWith("TWO_PHASES_")) { capabilities = capabilities.substring(11); } if (!connInstanceCapabilities.contains(connInstanceId + capabilities)) { writer.writeStartElement("ConnInstance_capabilities"); writer.writeAttribute("connInstance_id", connInstanceKey); writer.writeAttribute("capability", capabilities); writer.writeEndElement(); connInstanceCapabilities.add(connInstanceId + capabilities); } break; case "externalresource": writer.writeStartElement("ExternalResource"); copyAttrs(reader, writer, "syncTraceLevel", "userializedSyncToken", "rserializedSyncToken", "propagationMode", "propagationPrimary", "connector_id", "syncPolicy_id", "passwordPolicy_id", "creator", "lastModifier", "creationDate", "lastChangeDate"); writer.writeAttribute("id", getAttributeValue(reader, "name")); writer.writeAttribute("connector_id", connInstances.get(getAttributeValue(reader, "connector_id"))); writer.writeAttribute("provisioningTraceLevel", getAttributeValue(reader, "syncTraceLevel")); String syncPolicyKey = policies.get(getAttributeValue(reader, "syncPolicy_id")); if (StringUtils.isNotBlank(syncPolicyKey)) { writer.writeAttribute("pullPolicy_id", syncPolicyKey); } String passwordPolicyKey = policies.get(getAttributeValue(reader, "passwordPolicy_id")); if (StringUtils.isNotBlank(passwordPolicyKey)) { writer.writeAttribute("passwordPolicy_id", passwordPolicyKey); } writer.writeEndElement(); break; case "externalresource_propactions": writer.writeStartElement("ExternalResource_PropActions"); writer.writeAttribute("resource_id", getAttributeValue(reader, "externalResource_name")); String propActionClassName = getAttributeValue(reader, "element"); switch (propActionClassName) { case "org.apache.syncope.core.propagation.impl.LDAPMembershipPropagationActions": propActionClassName = "org.apache.syncope.core.provisioning.java.propagation." + "LDAPMembershipPropagationActions"; break; case "org.apache.syncope.core.propagation.impl.LDAPPasswordPropagationActions": propActionClassName = "org.apache.syncope.core.provisioning.java.propagation." + "LDAPPasswordPropagationActions"; break; case "org.apache.syncope.core.propagation.impl.DBPasswordPropagationActions": propActionClassName = "org.apache.syncope.core.provisioning.java.propagation." + "DBPasswordPropagationActions"; break; default: } writer.writeAttribute("actionClassName", propActionClassName); writer.writeEndElement(); break; case "policy_externalresource": writer.writeStartElement("AccountPolicy_ExternalResource"); writer.writeAttribute("accountPolicy_id", policies.get(getAttributeValue(reader, "account_policy_id"))); writer.writeAttribute("resource_id", getAttributeValue(reader, "resource_name")); writer.writeEndElement(); break; case "umapping": String umappingId = getAttributeValue(reader, "id"); lastUUID = UUID.randomUUID().toString(); provisions.put(umappingId, lastUUID); writer.writeStartElement("Provision"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("resource_id", getAttributeValue(reader, "resource_name")); writer.writeAttribute("anyType_id", "USER"); writer.writeAttribute("objectClass", "__ACCOUNT__"); writer.writeEndElement(); lastUUID = UUID.randomUUID().toString(); mappings.put(umappingId, lastUUID); writer.writeStartElement("Mapping"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("provision_id", provisions.get(umappingId)); String uaccountLink = getAttributeValue(reader, "accountlink"); if (StringUtils.isNotBlank(uaccountLink)) { writer.writeAttribute("connObjectLink", uaccountLink); } writer.writeEndElement(); break; case "umappingitem": String uIntMappingType = getAttributeValue(reader, "intMappingType"); if (uIntMappingType.endsWith("VirtualSchema")) { reporter.writeStartElement("MappingItem"); copyAttrs(reader, reporter, "accountid", "intMappingType"); reporter.writeEndElement(); } else { writer.writeStartElement("MappingItem"); copyAttrs(reader, writer, "accountid", "intMappingType", "mapping_id", "intMappingType", "intAttrName"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("mapping_id", mappings.get(getAttributeValue(reader, "mapping_id"))); writer.writeAttribute("connObjectKey", getAttributeValue(reader, "accountid")); writeIntAttrName(uIntMappingType, "intAttrName", mappings.get(getAttributeValue(reader, "intAttrName")), writer); writer.writeEndElement(); } break; case "rmapping": String rmappingId = "10" + getAttributeValue(reader, "id"); lastUUID = UUID.randomUUID().toString(); provisions.put(rmappingId, lastUUID); writer.writeStartElement("Provision"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("resource_id", getAttributeValue(reader, "resource_name")); writer.writeAttribute("anyType_id", "GROUP"); writer.writeAttribute("objectClass", "__GROUP__"); writer.writeEndElement(); lastUUID = UUID.randomUUID().toString(); mappings.put(rmappingId, lastUUID); writer.writeStartElement("Mapping"); writer.writeAttribute("id", lastUUID); writer.writeAttribute("provision_id", provisions.get(rmappingId)); String raccountLink = getAttributeValue(reader, "accountlink"); if (StringUtils.isNotBlank(raccountLink)) { writer.writeAttribute("connObjectLink", raccountLink); } writer.writeEndElement(); break; case "rmappingitem": String rIntMappingType = getAttributeValue(reader, "intMappingType"); if (rIntMappingType.endsWith("VirtualSchema")) { reporter.writeStartElement("MappingItem"); copyAttrs(reader, reporter, "accountid", "intMappingType"); reporter.writeEndElement(); } else { writer.writeStartElement("MappingItem"); copyAttrs(reader, writer, "accountid", "intMappingType", "mapping_id", "intAttrName"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("mapping_id", mappings.get("10" + getAttributeValue(reader, "mapping_id"))); writer.writeAttribute("connObjectKey", getAttributeValue(reader, "accountid")); writeIntAttrName(rIntMappingType, "intAttrName", mappings.get(getAttributeValue(reader, "intAttrName")), writer); writer.writeEndElement(); } break; case "task": writer.writeStartElement("Task"); copyAttrs(reader, writer, "DTYPE", "propagationMode", "subjectType", "subjectId", "xmlAttributes", "jobClassName", "userTemplate", "roleTemplate", "userFilter", "roleFilter", "propagationOperation", "syncStatus", "fullReconciliation", "resource_name"); lastUUID = UUID.randomUUID().toString(); tasks.put(getAttributeValue(reader, "id"), lastUUID); writer.writeAttribute("id", lastUUID); String resourceName = getAttributeValue(reader, "resource_name"); if (StringUtils.isNotBlank(resourceName)) { writer.writeAttribute("resource_id", resourceName); } String name = getAttributeValue(reader, "name"); if (StringUtils.isNotBlank(name)) { writer.writeAttribute("name", name); } switch (getAttributeValue(reader, "DTYPE")) { case "PropagationTask": writer.writeAttribute("DTYPE", "PropagationTask"); writer.writeAttribute("anyTypeKind", getAttributeValue(reader, "subjectType")); writer.writeAttribute("anyKey", getAttributeValue(reader, "subjectId")); writer.writeAttribute("attributes", getAttributeValue(reader, "xmlAttributes")); writer.writeAttribute("operation", getAttributeValue(reader, "propagationOperation")); writer.writeEndElement(); break; case "SyncTask": writer.writeAttribute("DTYPE", "PullTask"); writer.writeAttribute("syncStatus", getAttributeValue(reader, "syncStatus")); String fullReconciliation = getAttributeValue(reader, "fullReconciliation"); if ("1".equals(fullReconciliation)) { writer.writeAttribute("pullMode", "FULL_RECONCILIATION"); } else if ("0".equals(fullReconciliation)) { writer.writeAttribute("pullMode", "INCREMENTAL"); } writer.writeEndElement(); String userTemplate = getAttributeValue(reader, "userTemplate"); if (StringUtils.isNotBlank(userTemplate)) { ObjectNode template = (ObjectNode) OBJECT_MAPPER.readTree(userTemplate); JsonNode plainAttrs = template.remove("attrs"); template.set("plainAttrs", plainAttrs); writer.writeStartElement("AnyTemplatePullTask"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("pullTask_id", lastUUID); writer.writeAttribute("anyType_id", "USER"); writer.writeAttribute("template", template.toString()); writer.writeEndElement(); } String roleTemplate = getAttributeValue(reader, "roleTemplate"); if (StringUtils.isNotBlank(roleTemplate)) { ObjectNode template = (ObjectNode) OBJECT_MAPPER.readTree(roleTemplate); JsonNode plainAttrs = template.remove("attrs"); template.set("plainAttrs", plainAttrs); writer.writeStartElement("AnyTemplatePullTask"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("pullTask_id", lastUUID); writer.writeAttribute("anyType_id", "GROUP"); writer.writeAttribute("template", template.toString()); writer.writeEndElement(); } break; case "SchedTask": writer.writeAttribute("DTYPE", "SchedTask"); writer.writeAttribute("jobDelegateClassName", getAttributeValue(reader, "jobClassName")); writer.writeEndElement(); break; case "NotificationTask": writer.writeAttribute("DTYPE", "NotificationTask"); writer.writeEndElement(); break; case "PushTask": writer.writeAttribute("DTYPE", "PushTask"); writer.writeEndElement(); String userFilter = getAttributeValue(reader, "userFilter"); if (StringUtils.isNotBlank(userFilter)) { writer.writeStartElement("PushTaskAnyFilter"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("pushTask_id", lastUUID); writer.writeAttribute("anyType_id", "USER"); writer.writeAttribute("fiql", userFilter); writer.writeEndElement(); } String roleFilter = getAttributeValue(reader, "roleFilter"); if (StringUtils.isNotBlank(roleFilter)) { writer.writeStartElement("PushTaskAnyFilter"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("pushTask_id", lastUUID); writer.writeAttribute("anyType_id", "GROUP"); writer.writeAttribute("fiql", roleFilter); writer.writeEndElement(); } break; default: } break; case "taskexec": writer.writeStartElement("TaskExec"); copyAttrs(reader, writer, "task_id"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("task_id", tasks.get(getAttributeValue(reader, "task_id"))); writer.writeEndElement(); break; case "synctask_actionsclassnames": writer.writeStartElement("PullTask_actionsClassNames"); writer.writeAttribute("pullTask_id", tasks.get(getAttributeValue(reader, "syncTask_id"))); String syncActionClassName = getAttributeValue(reader, "element"); switch (syncActionClassName) { case "org.apache.syncope.core.sync.impl.LDAPMembershipSyncActions": syncActionClassName = "org.apache.syncope.core.provisioning.java.pushpull.LDAPMembershipPullActions"; break; case "org.apache.syncope.core.sync.impl.LDAPPasswordSyncActions": syncActionClassName = "org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions"; break; case "org.apache.syncope.core.sync.impl.DBPasswordSyncActions": syncActionClassName = "org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions"; break; default: } writer.writeAttribute("actionClassName", syncActionClassName); writer.writeEndElement(); break; case "notification": writer.writeStartElement("Notification"); lastUUID = UUID.randomUUID().toString(); notifications.put(getAttributeValue(reader, "id"), lastUUID); writer.writeAttribute("id", lastUUID); copyAttrs(reader, writer, "recipientAttrType", "template", "userAbout", "roleAbout", "recipients", "recipientAttrName"); String recipientAttrType = getAttributeValue(reader, "recipientAttrType"); writeIntAttrName(recipientAttrType, "recipientAttrName", mappings.get(getAttributeValue(reader, "recipientAttrName")), writer); String recipients = getAttributeValue(reader, "recipients"); if (StringUtils.isNotBlank(recipients)) { writer.writeAttribute("recipientsFIQL", getAttributeValue(reader, "recipients")); } writer.writeAttribute("template_id", getAttributeValue(reader, "template")); writer.writeEndElement(); String userAbout = getAttributeValue(reader, "userAbout"); if (StringUtils.isNotBlank(userAbout)) { writer.writeStartElement("AnyAbout"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("notification_id", lastUUID); writer.writeAttribute("anyType_id", "USER"); writer.writeAttribute("filter", userAbout); writer.writeEndElement(); } String roleAbout = getAttributeValue(reader, "roleAbout"); if (StringUtils.isNotBlank(roleAbout)) { writer.writeStartElement("AnyAbout"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("notification_id", lastUUID); writer.writeAttribute("anyType_id", "GROUP"); writer.writeAttribute("filter", roleAbout); writer.writeEndElement(); } break; case "notification_events": writer.writeStartElement("Notification_events"); copyAttrs(reader, writer, "notification_id", "events"); writer.writeAttribute("notification_id", notifications.get(getAttributeValue(reader, "notification_id"))); writer.writeAttribute("event", getAttributeValue(reader, "events").replaceAll("Controller", "Logic")); writer.writeEndElement(); break; case "notificationtask_recipients": writer.writeStartElement("NotificationTask_recipients"); copyAttrs(reader, writer, "notificationTask_id"); writer.writeAttribute("notificationTask_id", tasks.get(getAttributeValue(reader, "notificationTask_id"))); writer.writeEndElement(); break; case "report": writer.writeStartElement("Report"); copyAttrs(reader, writer); lastUUID = UUID.randomUUID().toString(); reports.put(getAttributeValue(reader, "id"), lastUUID); writer.writeAttribute("id", lastUUID); writer.writeAttribute("name", getAttributeValue(reader, "name")); writer.writeEndElement(); break; case "reportletconfinstance": writer.writeStartElement("ReportletConfInstance"); copyAttrs(reader, writer, "report_id"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("report_id", reports.get(getAttributeValue(reader, "report_id"))); writer.writeEndElement(); break; case "reportexec": writer.writeStartElement("ReportExec"); copyAttrs(reader, writer, "report_id"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("report_id", reports.get(getAttributeValue(reader, "report_id"))); writer.writeEndElement(); break; case "securityquestion": writer.writeStartElement("SecurityQuestion"); copyAttrs(reader, writer); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeEndElement(); break; default: } } reader.next(); } writer.writeStartElement("Realm"); writer.writeAttribute("id", UUID.randomUUID().toString()); writer.writeAttribute("name", "/"); if (globalAccountPolicy != null) { writer.writeAttribute("accountPolicy_id", globalAccountPolicy); } if (globalPasswordPolicy != null) { writer.writeAttribute("passwordPolicy_id", globalPasswordPolicy); } writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.close(); reporter.writeEndElement(); reporter.writeEndDocument(); reporter.close(); System.out.println("\nVirtual items, require manual intervention:\n" + reporterSW.toString()); }
From source file:org.chorusbdd.chorus.tools.webagent.jettyhandler.XmlStreamingHandler.java
protected void writeSimpleTextElement(XMLStreamWriter writer, String element, String elementText) throws XMLStreamException { writer.writeStartElement(element); writer.writeCharacters(elementText); writer.writeEndElement();//from w w w . ja v a 2 s . com }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes the passed node object to the passed {@link XMLStreamWriter}. * //from w w w . j a va2 s . c o m * @param node * to be persist * @param xml * stream to write data to * @param layerPositions * @throws XMLStreamException */ public void writeNode(XMLStreamWriter xml, Node node, Map<? extends Layer, Integer> layerPositions) throws XMLStreamException { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeStartElement(TAG_NODES); String type = ""; // write type as attribute if (node instanceof STextualDS) { type = TYPE_STEXTUALDS; } else if (node instanceof STimeline) { type = TYPE_STIMELINE; } else if (node instanceof SMedialDS) { type = TYPE_SAUDIODS; } else if (node instanceof SToken) { type = TYPE_STOKEN; } else if (node instanceof SSpan) { type = TYPE_SSPAN; } else if (node instanceof SStructure) { type = TYPE_SSTRUCTURE; } else if (node instanceof SDocument) { type = TYPE_SDOCUMENT; } else if (node instanceof SCorpus) { type = TYPE_SCORPUS; } xml.writeAttribute(NS_VALUE_XSI, ATT_XSI_TYPE, type); // write layers if (node.getLayers().size() > 0) { StringBuilder layerAtt = new StringBuilder(); Iterator<? extends Layer> layerIt = node.getLayers().iterator(); boolean isFirst = true; while (layerIt.hasNext()) { if (!isFirst) { layerAtt.append(" "); } isFirst = false; layerAtt.append("/"); if (writtenRootObjects != null) { layerAtt.append(writtenRootObjects.size()); } layerAtt.append("/@layers."); layerAtt.append(layerPositions.get(layerIt.next())); } xml.writeAttribute(ATT_LAYERS, layerAtt.toString()); } // write all labels Iterator<Label> labelIt = node.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeEndElement(); }