List of usage examples for javax.xml.stream XMLStreamReader isStartElement
public boolean isStartElement();
From source file:org.apache.axiom.util.stax.XMLStreamReaderUtilsTest.java
private void testGetDataHandlerFromElementWithUnexpectedContent(boolean useDHR) throws Exception { XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test>\n<child/>\n</test>")); if (useDHR) { reader = new XOPDecodingStreamReader(reader, null); }/*from w w w .jav a2 s . co m*/ try { reader.next(); // Check precondition assertTrue(reader.isStartElement()); try { XMLStreamReaderUtils.getDataHandlerFromElement(reader); fail("Expected XMLStreamException"); } catch (XMLStreamException ex) { // Expected } } finally { reader.close(); } }
From source file:org.apache.axiom.util.stax.XMLStreamReaderUtilsTest.java
private void testGetDataHandlerFromElementNonCoalescing(boolean useDHR) throws Exception { // We generate base64 that is sufficiently large to force the parser to generate // multiple CHARACTER events StringBuffer buffer = new StringBuffer("<test>"); Base64EncodingStringBufferOutputStream out = new Base64EncodingStringBufferOutputStream(buffer); byte[] data = new byte[65536]; new Random().nextBytes(data); out.write(data);/*from ww w.ja v a2s. c om*/ out.complete(); buffer.append("</test>"); XMLStreamReader reader = StAXUtils.createXMLStreamReader(StAXParserConfiguration.NON_COALESCING, new StringReader(buffer.toString())); if (useDHR) { reader = new XOPDecodingStreamReader(reader, null); } try { reader.next(); // Check precondition assertTrue(reader.isStartElement()); DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader); // Check postcondition assertTrue(reader.isEndElement()); assertTrue(Arrays.equals(data, IOUtils.toByteArray(dh.getInputStream()))); } finally { reader.close(); } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static Object getAnyTypeObject(XMLStreamReader xmlStreamReader, Class extensionMapperClass) throws XMLStreamException { Object returnObject = null;/*from w w w .j a v a 2s . c o m*/ // make sure reader is at the first element. while (!xmlStreamReader.isStartElement()) { xmlStreamReader.next(); } // first check whether this element is null or not String nillableValue = xmlStreamReader.getAttributeValue(Constants.XSI_NAMESPACE, "nil"); if ("true".equals(nillableValue) || "1".equals(nillableValue)) { returnObject = null; xmlStreamReader.next(); } else { String attributeType = xmlStreamReader.getAttributeValue(Constants.XSI_NAMESPACE, "type"); if (attributeType != null) { String attributeTypePrefix = ""; if (attributeType.indexOf(":") > -1) { attributeTypePrefix = attributeType.substring(0, attributeType.indexOf(":")); attributeType = attributeType.substring(attributeType.indexOf(":") + 1); } NamespaceContext namespaceContext = xmlStreamReader.getNamespaceContext(); String attributeNameSpace = namespaceContext.getNamespaceURI(attributeTypePrefix); if (Constants.XSD_NAMESPACE.equals(attributeNameSpace)) { if ("base64Binary".equals(attributeType)) { returnObject = XMLStreamReaderUtils.getDataHandlerFromElement(xmlStreamReader); } else { String attribValue = xmlStreamReader.getElementText(); if (attribValue != null) { if (attributeType.equals("string")) { returnObject = attribValue; } else if (attributeType.equals("int")) { returnObject = new Integer(attribValue); } else if (attributeType.equals("QName")) { String namespacePrefix = null; String localPart = null; if (attribValue.indexOf(":") > -1) { namespacePrefix = attribValue.substring(0, attribValue.indexOf(":")); localPart = attribValue.substring(attribValue.indexOf(":") + 1); returnObject = new QName(namespaceContext.getNamespaceURI(namespacePrefix), localPart); } } else if ("boolean".equals(attributeType)) { returnObject = new Boolean(attribValue); } else if ("anyURI".equals(attributeType)) { try { returnObject = new URI(attribValue); } catch (URI.MalformedURIException e) { throw new XMLStreamException("Invalid URI"); } } else if ("date".equals(attributeType)) { returnObject = ConverterUtil.convertToDate(attribValue); } else if ("dateTime".equals(attributeType)) { returnObject = ConverterUtil.convertToDateTime(attribValue); } else if ("time".equals(attributeType)) { returnObject = ConverterUtil.convertToTime(attribValue); } else if ("byte".equals(attributeType)) { returnObject = new Byte(attribValue); } else if ("short".equals(attributeType)) { returnObject = new Short(attribValue); } else if ("float".equals(attributeType)) { returnObject = new Float(attribValue); } else if ("long".equals(attributeType)) { returnObject = new Long(attribValue); } else if ("double".equals(attributeType)) { returnObject = new Double(attribValue); } else if ("decimal".equals(attributeType)) { returnObject = new BigDecimal(attribValue); } else if ("unsignedLong".equals(attributeType)) { returnObject = new UnsignedLong(attribValue); } else if ("unsignedInt".equals(attributeType)) { returnObject = new UnsignedInt(attribValue); } else if ("unsignedShort".equals(attributeType)) { returnObject = new UnsignedShort(attribValue); } else if ("unsignedByte".equals(attributeType)) { returnObject = new UnsignedByte(attribValue); } else if ("positiveInteger".equals(attributeType)) { returnObject = new PositiveInteger(attribValue); } else if ("negativeInteger".equals(attributeType)) { returnObject = new NegativeInteger(attribValue); } else if ("nonNegativeInteger".equals(attributeType)) { returnObject = new NonNegativeInteger(attribValue); } else if ("nonPositiveInteger".equals(attributeType)) { returnObject = new NonPositiveInteger(attribValue); } else { throw new ADBException("Unknown type ==> " + attributeType); } } else { throw new ADBException("Attribute value is null"); } } } else { try { Method getObjectMethod = extensionMapperClass.getMethod("getTypeObject", new Class[] { String.class, String.class, XMLStreamReader.class }); returnObject = getObjectMethod.invoke(null, new Object[] { attributeNameSpace, attributeType, xmlStreamReader }); } catch (NoSuchMethodException e) { throw new ADBException( "Can not find the getTypeObject method in the " + "extension mapper class ", e); } catch (IllegalAccessException e) { throw new ADBException( "Can not access the getTypeObject method in the " + "extension mapper class ", e); } catch (InvocationTargetException e) { throw new ADBException( "Can not invoke the getTypeObject method in the " + "extension mapper class ", e); } } } else { throw new ADBException("Any type element type has not been given"); } } return returnObject; }
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 w w. java 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.apache.syncope.client.console.widgets.reconciliation.ReconciliationReportParser.java
public static ReconciliationReport parse(final Date run, final InputStream in) throws XMLStreamException { XMLStreamReader streamReader = INPUT_FACTORY.createXMLStreamReader(in); streamReader.nextTag(); // root streamReader.nextTag(); // report streamReader.nextTag(); // reportlet ReconciliationReport report = new ReconciliationReport(run); List<Missing> missing = new ArrayList<>(); List<Misaligned> misaligned = new ArrayList<>(); Set<String> onSyncope = null; Set<String> onResource = null; Any user = null;/*from w ww. ja v a2 s .c om*/ Any group = null; Any anyObject = null; String lastAnyType = null; while (streamReader.hasNext()) { if (streamReader.isStartElement()) { switch (streamReader.getLocalName()) { case "users": Anys users = new Anys(); users.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total"))); report.setUsers(users); break; case "user": user = new Any(); user.setType(AnyTypeKind.USER.name()); user.setKey(streamReader.getAttributeValue("", "key")); user.setName(streamReader.getAttributeValue("", "username")); report.getUsers().getAnys().add(user); break; case "groups": Anys groups = new Anys(); groups.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total"))); report.setGroups(groups); break; case "group": group = new Any(); group.setType(AnyTypeKind.GROUP.name()); group.setKey(streamReader.getAttributeValue("", "key")); group.setName(streamReader.getAttributeValue("", "groupName")); report.getGroups().getAnys().add(group); break; case "anyObjects": lastAnyType = streamReader.getAttributeValue("", "type"); Anys anyObjects = new Anys(); anyObjects.setAnyType(lastAnyType); anyObjects.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total"))); report.getAnyObjects().add(anyObjects); break; case "anyObject": anyObject = new Any(); anyObject.setType(lastAnyType); anyObject.setKey(streamReader.getAttributeValue("", "key")); final String anyType = lastAnyType; IterableUtils.find(report.getAnyObjects(), new Predicate<Anys>() { @Override public boolean evaluate(final Anys anys) { return anyType.equals(anys.getAnyType()); } }).getAnys().add(anyObject); break; case "missing": missing.add(new Missing(streamReader.getAttributeValue("", "resource"), streamReader.getAttributeValue("", "connObjectKeyValue"))); break; case "misaligned": misaligned.add(new Misaligned(streamReader.getAttributeValue("", "resource"), streamReader.getAttributeValue("", "connObjectKeyValue"), streamReader.getAttributeValue("", "name"))); break; case "onSyncope": onSyncope = new HashSet<>(); break; case "onResource": onResource = new HashSet<>(); break; case "value": Set<String> set = onSyncope == null ? onResource : onSyncope; set.add(streamReader.getElementText()); break; default: } } else if (streamReader.isEndElement()) { switch (streamReader.getLocalName()) { case "user": user.getMissing().addAll(missing); user.getMisaligned().addAll(misaligned); missing.clear(); misaligned.clear(); break; case "group": group.getMissing().addAll(missing); group.getMisaligned().addAll(misaligned); missing.clear(); misaligned.clear(); break; case "anyObject": anyObject.getMissing().addAll(missing); anyObject.getMisaligned().addAll(misaligned); missing.clear(); misaligned.clear(); break; case "onSyncope": misaligned.get(misaligned.size() - 1).getOnSyncope().addAll(onSyncope); onSyncope = null; break; case "onResource": misaligned.get(misaligned.size() - 1).getOnResource().addAll(onResource); onResource = null; break; default: } } streamReader.next(); } return report; }
From source file:org.deegree.metadata.MetadataRecordFactory.java
/** * Creates a {@link MetadataRecord} instance out a {@link XMLStreamReader}. The reader must point to the * START_ELEMENT of the record. After reading the record the stream points to the END_ELEMENT of the record. * //from w w w . j a v a2 s. c o m * @param xmlStream * xmlStream must point to the START_ELEMENT of the record, must not be <code>null</code> * @return a {@link MetadataRecord} instance, never <code>null</code> */ public static MetadataRecord create(XMLStreamReader xmlStream) { if (!xmlStream.isStartElement()) { throw new XMLParsingException(xmlStream, "XMLStreamReader does not point to a START_ELEMENT."); } String ns = xmlStream.getNamespaceURI(); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLStreamWriter writer = null; XMLStreamReader recordAsXmlStream; InputStream in = null; try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out); writer.writeStartDocument(); XMLAdapter.writeElement(writer, xmlStream); writer.writeEndDocument(); writer.close(); in = new ByteArrayInputStream(out.toByteArray()); recordAsXmlStream = XMLInputFactory.newInstance().createXMLStreamReader(in); } catch (XMLStreamException e) { throw new XMLParsingException(xmlStream, e.getMessage()); } catch (FactoryConfigurationError e) { throw new XMLParsingException(xmlStream, e.getMessage()); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } if (ISO_RECORD_NS.equals(ns)) { return new ISORecord(recordAsXmlStream); } if (RIM_NS.equals(ns)) { throw new UnsupportedOperationException( "Creating ebRIM records from XMLStreamReader is not implemented yet."); } if (DC_RECORD_NS.equals(ns)) { throw new UnsupportedOperationException( "Creating DC records from XMLStreamReader is not implemented yet."); } throw new IllegalArgumentException("Unknown / unsuppported metadata namespace '" + ns + "'."); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
Pair<Graphic, Continuation<Graphic>> parseGraphic(XMLStreamReader in) throws XMLStreamException { in.require(START_ELEMENT, null, "Graphic"); Graphic base = new Graphic(); Continuation<Graphic> contn = null; while (!(in.isEndElement() && in.getLocalName().equals("Graphic"))) { in.nextTag();/*from w ww. ja v a 2s . co m*/ if (in.getLocalName().equals("Mark")) { final Pair<Mark, Continuation<Mark>> pair = parseMark(in); if (pair != null) { base.mark = pair.first; if (pair.second != null) { contn = new Continuation<Graphic>(contn) { @Override public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) { pair.second.evaluate(base.mark, f, evaluator); } }; } } } else if (in.getLocalName().equals("ExternalGraphic")) { try { final Triple<BufferedImage, String, Continuation<List<BufferedImage>>> p = parseExternalGraphic( in); if (p.third != null) { contn = new Continuation<Graphic>(contn) { @Override public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) { LinkedList<BufferedImage> list = new LinkedList<BufferedImage>(); p.third.evaluate(list, f, evaluator); base.image = list.poll(); } }; } else { base.image = p.first; base.imageURL = p.second; } } catch (IOException e) { LOG.debug("Stack trace", e); LOG.warn("External graphic could not be loaded. Location: line '{}' column '{}' of file '{}'.", new Object[] { in.getLocation().getLineNumber(), in.getLocation().getColumnNumber(), in.getLocation().getSystemId() }); } } else if (in.getLocalName().equals("Opacity")) { contn = context.parser.updateOrContinue(in, "Opacity", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.opacity = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("Size")) { contn = context.parser.updateOrContinue(in, "Size", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.size = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("Rotation")) { contn = context.parser.updateOrContinue(in, "Rotation", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.rotation = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("AnchorPoint")) { while (!(in.isEndElement() && in.getLocalName().equals("AnchorPoint"))) { in.nextTag(); if (in.getLocalName().equals("AnchorPointX")) { contn = context.parser.updateOrContinue(in, "AnchorPointX", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.anchorPointX = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("AnchorPointY")) { contn = context.parser.updateOrContinue(in, "AnchorPointY", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.anchorPointY = Double.parseDouble(val); } }, contn).second; } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } } else if (in.getLocalName().equals("Displacement")) { while (!(in.isEndElement() && in.getLocalName().equals("Displacement"))) { in.nextTag(); if (in.getLocalName().equals("DisplacementX")) { contn = context.parser.updateOrContinue(in, "DisplacementX", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.displacementX = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("DisplacementY")) { contn = context.parser.updateOrContinue(in, "DisplacementY", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.displacementY = Double.parseDouble(val); } }, contn).second; } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } in.require(END_ELEMENT, null, "Graphic"); return new Pair<Graphic, Continuation<Graphic>>(base, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Pair<Mark, Continuation<Mark>> parseMark(XMLStreamReader in) throws XMLStreamException { in.require(START_ELEMENT, null, "Mark"); Mark base = new Mark(); Continuation<Mark> contn = null; in.nextTag();/*from ww w . j a v a2 s . c o m*/ while (!(in.isEndElement() && in.getLocalName().equals("Mark"))) { if (in.isEndElement()) { in.nextTag(); } if (in.getLocalName().equals("WellKnownName")) { String wkn = in.getElementText(); try { base.wellKnown = SimpleMark.valueOf(wkn.toUpperCase()); } catch (IllegalArgumentException e) { LOG.warn("Specified unsupported WellKnownName of '{}', using square instead.", wkn); base.wellKnown = SimpleMark.SQUARE; } } else sym: if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) { LOG.debug("Loading mark from external file."); Triple<InputStream, String, Continuation<StringBuffer>> pair = getOnlineResourceOrInlineContent( in); if (pair == null) { in.nextTag(); break sym; } InputStream is = pair.first; in.nextTag(); in.require(START_ELEMENT, null, "Format"); String format = in.getElementText(); in.require(END_ELEMENT, null, "Format"); in.nextTag(); if (in.getLocalName().equals("MarkIndex")) { base.markIndex = Integer.parseInt(in.getElementText()); } if (is != null) { try { java.awt.Font font = null; if (format.equalsIgnoreCase("ttf")) { font = createFont(TRUETYPE_FONT, is); } if (format.equalsIgnoreCase("type1")) { font = createFont(TYPE1_FONT, is); } if (format.equalsIgnoreCase("svg")) { base.shape = ShapeHelper.getShapeFromSvg(is, pair.second); } if (font == null && base.shape == null) { LOG.warn("Mark was not loaded, because the format '{}' is not supported.", format); break sym; } if (font != null && base.markIndex >= font.getNumGlyphs() - 1) { LOG.warn("The font only contains {} glyphs, but the index given was {}.", font.getNumGlyphs(), base.markIndex); break sym; } base.font = font; } catch (FontFormatException e) { LOG.debug("Stack trace:", e); LOG.warn("The file was not a valid '{}' file: '{}'", format, e.getLocalizedMessage()); } catch (IOException e) { LOG.debug("Stack trace:", e); LOG.warn("The file could not be read: '{}'.", e.getLocalizedMessage()); } finally { closeQuietly(is); } } } else if (in.getLocalName().equals("Fill")) { final Pair<Fill, Continuation<Fill>> fill = context.fillParser.parseFill(in); base.fill = fill.first; if (fill.second != null) { contn = new Continuation<Mark>(contn) { @Override public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) { fill.second.evaluate(base.fill, f, evaluator); } }; } } else if (in.getLocalName().equals("Stroke")) { final Pair<Stroke, Continuation<Stroke>> stroke = context.strokeParser.parseStroke(in); base.stroke = stroke.first; if (stroke.second != null) { contn = new Continuation<Mark>(contn) { @Override public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) { stroke.second.evaluate(base.stroke, f, evaluator); } }; } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } in.require(END_ELEMENT, null, "Mark"); return new Pair<Mark, Continuation<Mark>>(base, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Triple<BufferedImage, String, Continuation<List<BufferedImage>>> parseExternalGraphic( final XMLStreamReader in) throws IOException, XMLStreamException { // TODO color replacement in.require(START_ELEMENT, null, "ExternalGraphic"); String format = null;//from w ww .j a v a2s. c om BufferedImage img = null; String url = null; Triple<InputStream, String, Continuation<StringBuffer>> pair = null; Continuation<List<BufferedImage>> contn = null; // needs to be list to be updateable by reference... while (!(in.isEndElement() && in.getLocalName().equals("ExternalGraphic"))) { in.nextTag(); if (in.getLocalName().equals("Format")) { format = in.getElementText(); } else if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) { pair = getOnlineResourceOrInlineContent(in); } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } try { if (pair != null) { if (pair.first != null && format != null && (format.toLowerCase().indexOf("svg") == -1)) { img = ImageIO.read(pair.first); } url = pair.second; final Continuation<StringBuffer> sbcontn = pair.third; if (pair.third != null) { final LinkedHashMap<String, BufferedImage> cache = new LinkedHashMap<String, BufferedImage>( 256) { private static final long serialVersionUID = -6847956873232942891L; @Override protected boolean removeEldestEntry(Map.Entry<String, BufferedImage> eldest) { return size() > 256; // yeah, hardcoded max size... TODO } }; contn = new Continuation<List<BufferedImage>>() { @Override public void updateStep(List<BufferedImage> base, Feature f, XPathEvaluator<Feature> evaluator) { StringBuffer sb = new StringBuffer(); sbcontn.evaluate(sb, f, evaluator); String file = sb.toString(); if (cache.containsKey(file)) { base.add(cache.get(file)); return; } try { BufferedImage i; if (context.location != null) { i = ImageIO.read(context.location.resolve(file)); } else { i = ImageIO.read(resolve(file, in)); } base.add(i); cache.put(file, i); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; } } } finally { if (pair != null) { try { pair.first.close(); } catch (Exception e) { LOG.trace("Stack trace when closing input stream:", e); } } } return new Triple<BufferedImage, String, Continuation<List<BufferedImage>>>(img, url, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Triple<InputStream, String, Continuation<StringBuffer>> getOnlineResourceOrInlineContent( XMLStreamReader in) throws XMLStreamException { if (in.getLocalName().equals("OnlineResource")) { String str = in.getAttributeValue(XLNNS, "href"); if (str == null) { Continuation<StringBuffer> contn = context.parser.updateOrContinue(in, "OnlineResource", new StringBuffer(), SBUPDATER, null).second; return new Triple<InputStream, String, Continuation<StringBuffer>>(null, null, contn); }/* w w w. j ava 2 s. co m*/ String strUrl = null; try { URL url; if (context.location != null) { url = context.location.resolveToUrl(str); } else { url = resolve(str, in); } strUrl = url.toExternalForm(); LOG.debug("Loading from URL '{}'", url); in.nextTag(); return new Triple<InputStream, String, Continuation<StringBuffer>>(url.openStream(), strUrl, null); } catch (IOException e) { LOG.debug("Stack trace:", e); LOG.warn("Could not retrieve content at URL '{}'.", str); return null; } } else if (in.getLocalName().equals("InlineContent")) { String format = in.getAttributeValue(null, "encoding"); if (format.equalsIgnoreCase("base64")) { ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(in.getElementText())); return new Triple<InputStream, String, Continuation<StringBuffer>>(bis, null, null); } // if ( format.equalsIgnoreCase( "xml" ) ) { // // TODO // } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } return null; }