Search in sources :

Example 6 with ExtensionType

use of org.geotoolkit.wcs.xml.v200.ExtensionType in project peppol-commons by phax.

the class SMPExtensionConverter method convert.

/**
 * Convert the passed XML string to an SMP extension type.
 *
 * @param sXML
 *        the XML representation to be converted.
 * @return <code>null</code> if the passed string is empty or does not
 *         represent valid XML.
 */
@Nullable
public static ExtensionType convert(@Nullable final String sXML) {
    if (StringHelper.hasText(sXML)) {
        // Try to interpret as XML
        final Document aDoc = DOMReader.readXMLDOM(sXML);
        if (aDoc != null) {
            final ExtensionType aExtension = new ExtensionType();
            aExtension.setAny(aDoc.getDocumentElement());
            return aExtension;
        }
    }
    return null;
}
Also used : ExtensionType(com.helger.xsds.peppol.smp1.ExtensionType) Document(org.w3c.dom.Document) Nullable(javax.annotation.Nullable)

Example 7 with ExtensionType

use of org.geotoolkit.wcs.xml.v200.ExtensionType in project phoss-smp by phax.

the class SMPServiceGroupTest method testBDXRExtension.

@Test
public void testBDXRExtension() {
    final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
    final ExtensionType aExt = new ExtensionType();
    // The extension "any" MUST be in a different namespace that is not empty
    aExt.setAny(DOMReader.readXMLDOM("<foobar1 xmlns='abc'/>").getDocumentElement());
    final ExtensionType aExt2 = new ExtensionType();
    aExt2.setExtensionID("xyz");
    aExt2.setAny(DOMReader.readXMLDOM("<foobar2 xmlns='def'/>").getDocumentElement());
    // Must be an array!
    final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, BDXR1ExtensionConverter.convertToString(new CommonsArrayList<>(aExt, aExt2)));
    assertTrue(StringHelper.hasText(aSG.getID()));
    assertEquals(CSecurity.USER_ADMINISTRATOR_ID, aSG.getOwnerID());
    assertEquals(aPI, aSG.getParticipantIdentifier());
    assertNotNull(aSG.getExtensionsAsString());
    final com.helger.xsds.bdxr.smp1.ServiceGroupType aSGBDXR = aSG.getAsJAXBObjectBDXR1();
    aSGBDXR.setServiceMetadataReferenceCollection(new com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceCollectionType());
    assertEquals(2, aSGBDXR.getExtension().size());
    final Document aDoc = new BDXR1MarshallerServiceGroupType(true).getAsDocument(aSGBDXR);
    assertNotNull(aDoc);
}
Also used : BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) ExtensionType(com.helger.xsds.bdxr.smp1.ExtensionType) Document(org.w3c.dom.Document) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 8 with ExtensionType

use of org.geotoolkit.wcs.xml.v200.ExtensionType in project peppol-commons by phax.

the class SMPDebugHelper method getAsString.

@Nonnull
public static String getAsString(@Nonnull final ServiceGroupType aServiceGroup) {
    final StringBuilder aSB = new StringBuilder();
    aSB.append("ServiceGroup information:\n");
    aSB.append("ParticipantIdentifier: ").append(CIdentifier.getURIEncoded(aServiceGroup.getParticipantIdentifier())).append('\n');
    // References
    final ServiceMetadataReferenceCollectionType aSMRC = aServiceGroup.getServiceMetadataReferenceCollection();
    if (aSMRC != null && !aSMRC.getServiceMetadataReference().isEmpty()) {
        aSB.append("ServiceMetadataReferenceCollection:\n");
        for (final ServiceMetadataReferenceType aSMR : aSMRC.getServiceMetadataReference()) aSB.append("  ").append(aSMR.getHref()).append('\n');
    }
    // Extension
    final ExtensionType aExt = aServiceGroup.getExtension();
    if (aExt != null && aExt.getAny() != null) {
        aSB.append("Extension:\n");
        aSB.append("  Class = ").append(aExt.getAny().getClass().getName()).append('\n');
        aSB.append("  Value = ").append(aExt.getAny()).append('\n');
    }
    return aSB.toString();
}
Also used : ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) ServiceMetadataReferenceType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceType) ExtensionType(com.helger.xsds.peppol.smp1.ExtensionType) Nonnull(javax.annotation.Nonnull)

Example 9 with ExtensionType

use of org.geotoolkit.wcs.xml.v200.ExtensionType in project peppol-commons by phax.

the class BDXRExtensionConverterTest method testConvertFromString.

@Test
public void testConvertFromString() {
    // Use elements
    final String sJson = "[{\"ID\":\"a\",\"Name\":\"b\",\"AgencyID\":\"c\",\"AgencyName\":\"d\",\"AgencyURI\":\"e\",\"VersionID\":\"f\",\"URI\":\"g\",\"ReasonCode\":\"h\",\"Reason\":\"i\"," + "\"Any\":\"<any xmlns=\\\"urn:foo\\\"><child>text1</child><child2 /></any>\"}]";
    final ICommonsList<ExtensionType> aExtensions = BDXR1ExtensionConverter.convert(sJson);
    assertNotNull(aExtensions);
    assertEquals(1, aExtensions.size());
    final ExtensionType aExtension = aExtensions.get(0);
    assertNotNull(aExtension.getAny());
    assertTrue(aExtension.getAny() instanceof Node);
    assertNull(BDXR1ExtensionConverter.convert((String) null));
    assertNull(BDXR1ExtensionConverter.convert(""));
    // Convert back to String
    final String sJson2 = BDXR1ExtensionConverter.convertToString(new CommonsArrayList<>(aExtension));
    assertEquals(sJson, sJson2);
    // Cannot convert non-element
    assertNull(BDXR1ExtensionConverter.convert("Plain text"));
}
Also used : ExtensionType(com.helger.xsds.bdxr.smp1.ExtensionType) Node(org.w3c.dom.Node) Test(org.junit.Test)

Example 10 with ExtensionType

use of org.geotoolkit.wcs.xml.v200.ExtensionType in project peppol-commons by phax.

the class BDXR1ExtensionConverter method convertXMLToSingleExtension.

/**
 * Parse the provided XML, and if it is valid, convert it to a simple
 * extension. This method exists, so that compatibility to the old PEPPOL SMP
 * specification is available (single extension with only a DOM Element).
 *
 * @param sXML
 *        The XML to be parsed. May be <code>null</code>.
 * @return <code>null</code> if no XML or invalid XML is provided, a
 *         non-<code>null</code> list with a single extension otherwise.
 */
@Nullable
public static ICommonsList<ExtensionType> convertXMLToSingleExtension(@Nullable final String sXML) {
    if (StringHelper.hasText(sXML)) {
        final Document aDoc = DOMReader.readXMLDOM(sXML);
        if (aDoc != null) {
            final Element aElement = aDoc.getDocumentElement();
            if (aElement != null) {
                final ExtensionType aExtension = new ExtensionType();
                aExtension.setAny(aElement);
                return new CommonsArrayList<>(aExtension);
            }
        }
    }
    return null;
}
Also used : Element(org.w3c.dom.Element) SMPExtensionType(com.helger.xsds.bdxr.smp2.ec.SMPExtensionType) ExtensionType(com.helger.xsds.bdxr.smp1.ExtensionType) Document(org.w3c.dom.Document) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nullable(javax.annotation.Nullable)

Aggregations

ExtensionType (com.helger.xsds.bdxr.smp1.ExtensionType)5 ExtensionType (com.helger.xsds.peppol.smp1.ExtensionType)4 Test (org.junit.Test)4 Document (org.w3c.dom.Document)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 SMPExtensionType (com.helger.xsds.bdxr.smp2.ec.SMPExtensionType)3 Nullable (javax.annotation.Nullable)3 Nonnull (javax.annotation.Nonnull)2 IJson (com.helger.json.IJson)1 IJsonObject (com.helger.json.IJsonObject)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 BDXR1MarshallerServiceGroupType (com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType)1 ObjectFactory (com.helger.xsds.peppol.smp1.ObjectFactory)1 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)1 ServiceMetadataReferenceType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceType)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1