use of com.helger.peppol.sbdh.spec12.TextContentType in project peppol-commons by phax.
the class PeppolSBDHDocumentTest method testText.
@Test
public void testText() {
final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
final PeppolSBDHDocument dd = new PeppolSBDHDocument(aIF);
dd.setBusinessMessageTextOnly("abc", CMimeType.APPLICATION_OCTET_STREAM);
assertNotNull(dd.getBusinessMessage());
assertEquals("<TextContent xmlns=\"http://peppol.eu/xsd/ticc/envelope/1.0\" mimeType=\"application/octet-stream\">abc</TextContent>", XMLWriter.getNodeAsString(dd.getBusinessMessage()).trim());
final TextContentType aTC = dd.getBusinessMessageAsTextContent();
assertNotNull(aTC);
assertEquals("abc", aTC.getValue());
assertEquals(CMimeType.APPLICATION_OCTET_STREAM.getAsString(), aTC.getMimeType());
assertNull(dd.getBusinessMessageAsBinaryContent());
}
use of com.helger.peppol.sbdh.spec12.TextContentType in project peppol-commons by phax.
the class PeppolSBDHPayloadReaderTest method testText.
@Test
public void testText() {
// Regular case
TextContentType aCT = PeppolSBDHPayloadReader.textContent().read("<TextContent xmlns='http://peppol.eu/xsd/ticc/envelope/1.0' mimeType='bla/foo'>Payload</TextContent>");
assertNotNull(aCT);
assertEquals("bla/foo", aCT.getMimeType());
assertEquals("Payload", aCT.getValue());
// Empty value
aCT = PeppolSBDHPayloadReader.textContent().read("<TextContent xmlns='http://peppol.eu/xsd/ticc/envelope/1.0' mimeType='bla/foo' />");
assertNotNull(aCT);
assertEquals("bla/foo", aCT.getMimeType());
assertEquals("", aCT.getValue());
// Empty value again
aCT = PeppolSBDHPayloadReader.textContent().read("<TextContent xmlns='http://peppol.eu/xsd/ticc/envelope/1.0' mimeType='bla/foo'></TextContent>");
assertNotNull(aCT);
assertEquals("bla/foo", aCT.getMimeType());
assertEquals("", aCT.getValue());
// Wrong NS
assertNull(PeppolSBDHPayloadReader.textContent().read("<TextContent xmlns='ttp://peppol.eu/xsd/ticc/envelope/1.0' mimeType='bla/foo'>Payload</TextContent>"));
// Wrong element name
assertNull(PeppolSBDHPayloadReader.textContent().read("<TextContent2 xmlns='http://peppol.eu/xsd/ticc/envelope/1.0' mimeType='bla/foo'>Payload</TextContent2>"));
// No MimeType attribute
assertNull(PeppolSBDHPayloadReader.textContent().read("<TextContent xmlns='http://peppol.eu/xsd/ticc/envelope/1.0' mimeType2='bla/foo'>Payload</TextContent>"));
}
use of com.helger.peppol.sbdh.spec12.TextContentType in project peppol-commons by phax.
the class PeppolSBDHDocument method setBusinessMessageTextOnly.
/**
* Set a business message with text payload. Based on the Peppol SBDH v1.2
* text payload specification. Note: the character set of the wrapped text
* must be identical to the character set of the SBDH surrounding it. In case
* the payload requires a specific character set, it is suggested to use the
* binary message.
*
* @param sTextPayload
* The text to be wrapped. May not be <code>null</code>.
* @param aMimeType
* The MIME type to use. May not be <code>null</code>.
* @return this for chaining
* @see #setBusinessMessage(Element)
* @see #setBusinessMessageBinaryOnly(byte[], IMimeType, Charset)
* @see #getBusinessMessageAsTextContent()
* @since 6.2.4
*/
@Nonnull
public PeppolSBDHDocument setBusinessMessageTextOnly(@Nonnull final String sTextPayload, @Nonnull final IMimeType aMimeType) {
ValueEnforcer.notNull(sTextPayload, "TextPayload");
ValueEnforcer.notNull(aMimeType, "MimeType");
final TextContentType aTC = new TextContentType();
aTC.setValue(sTextPayload);
aTC.setMimeType(aMimeType.getAsString());
final Document aDoc = PeppolSBDHPayloadWriter.textContent().getAsDocument(aTC);
if (aDoc == null)
throw new IllegalStateException("Failed to create 'TextContent' element.");
m_aBusinessMessage = aDoc.getDocumentElement();
return this;
}
Aggregations