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;
}
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);
}
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();
}
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"));
}
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;
}
Aggregations