use of com.helger.xsds.bdxr.smp1.ExtensionType in project peppol-commons by phax.
the class SMPExtensionConverterTest method testConvertFromExtensionType.
@Test
public void testConvertFromExtensionType() {
// Try converting an empty extension
assertNull(SMPExtensionConverter.convertToString((ExtensionType) null));
assertNull(SMPExtensionConverter.convertToString(new ObjectFactory().createExtensionType()));
}
use of com.helger.xsds.bdxr.smp1.ExtensionType in project peppol-commons by phax.
the class SMPExtensionConverterTest method testConvertFromString.
@Test
public void testConvertFromString() {
// Use elements
final String sXML = "<any xmlns=\"urn:foo\"><child>text1</child><child2 /></any>";
final ExtensionType aExtension = SMPExtensionConverter.convert(sXML);
assertNotNull(aExtension);
assertNotNull(aExtension.getAny());
assertNull(SMPExtensionConverter.convert((String) null));
assertNull(SMPExtensionConverter.convert(""));
// Convert back to String
final String sXML2 = SMPExtensionConverter.convertToString(aExtension);
assertEquals(sXML, sXML2);
// Cannot convert non-element
assertNull(SMPExtensionConverter.convert("Plain text"));
}
use of com.helger.xsds.bdxr.smp1.ExtensionType in project peppol-commons by phax.
the class BDXR1ExtensionConverter method convert.
/**
* Convert the passed Json string to a list of SMP extensions.
*
* @param sJson
* the Json representation to be converted.
* @return <code>null</code> if the passed string is empty or cannot be
* interpreted as JSON.
*/
@Nullable
public static ICommonsList<ExtensionType> convert(@Nullable final String sJson) {
if (StringHelper.hasText(sJson)) {
// Try to interpret as JSON
final IJson aJson = JsonReader.readFromString(sJson);
if (aJson == null || !aJson.isArray()) {
LOGGER.warn("Error in parsing extension JSON '" + sJson + "'");
} else {
final ICommonsList<ExtensionType> ret = new CommonsArrayList<>();
aJson.getAsArray().forEach(aChild -> {
final IJsonObject aObject = aChild.getAsObject();
final ExtensionType aExt = new ExtensionType();
aExt.setExtensionID(aObject.getAsString(JSON_ID));
aExt.setExtensionName(aObject.getAsString(JSON_NAME));
aExt.setExtensionAgencyID(aObject.getAsString(JSON_AGENCY_ID));
aExt.setExtensionAgencyName(aObject.getAsString(JSON_AGENCY_NAME));
aExt.setExtensionAgencyURI(aObject.getAsString(JSON_AGENCY_URI));
aExt.setExtensionVersionID(aObject.getAsString(JSON_VERSION_ID));
aExt.setExtensionURI(aObject.getAsString(JSON_URI));
aExt.setExtensionReasonCode(aObject.getAsString(JSON_REASON_CODE));
aExt.setExtensionReason(aObject.getAsString(JSON_REASON));
final String sAny = aObject.getAsString(JSON_ANY);
if (StringHelper.hasText(sAny)) {
final Document aDoc = DOMReader.readXMLDOM(sAny);
if (aDoc != null)
aExt.setAny(aDoc.getDocumentElement());
}
ret.add(aExt);
});
return ret;
}
}
return null;
}
use of com.helger.xsds.bdxr.smp1.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 com.helger.xsds.bdxr.smp1.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);
}
Aggregations