use of com.opentext.ia.sdk.sip.XmlPdiAssembler in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class MultipleDomainObjects method run.
private void run() throws IOException {
System.out.println("\nSample 6: Assembling multiple domain object types into a single PDI");
// Assembler for PDI, where the domain object is flexible
PdiAssembler<Aiu> pdiAssembler = new XmlPdiAssembler<Aiu>(NAMESPACE, "aiu") {
@Override
protected void doAdd(Aiu aiu, Map<String, ContentInfo> ignored) {
aiu.addTo(getBuilder());
}
};
// Collect the PDI XML in an in-memory buffer. For large PDIs, use a FileBuffer instead.
DataBuffer dataBuffer = new MemoryBuffer();
pdiAssembler.start(dataBuffer);
try {
// Assemble the PDI by adding domain objects to it.
// In this sample, the domain objects are flexible objects
pdiAssembler.add(wrapDomainObject(new Animal("Gnu")));
pdiAssembler.add(wrapDomainObject(new Person("Remon", "Sinnema")));
} finally {
pdiAssembler.end();
}
try (InputStream pdi = dataBuffer.openForReading()) {
System.out.println(IOUtils.toString(pdi, StandardCharsets.UTF_8));
}
}
use of com.opentext.ia.sdk.sip.XmlPdiAssembler in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class HelloSip method run.
private void run() throws IOException {
System.out.println("\nSample 1: Creating our first SIP");
// Tell InfoArchive where and how to archive the data
URI entityUri = URI.create("urn:com.opentext.ia.sdk.sample.greeting:1.0");
String entityName = "greeting";
PackagingInformation prototype = PackagingInformation.builder().dss().application("greetingApplication").holding("greetingHolding").producer("world").entity(entityName).schema(entityUri.toString()).end().build();
// Define a mapping from our domain object to the PDI XML
PdiAssembler<Greeting> pdiAssembler = new XmlPdiAssembler<Greeting>(entityUri, entityName) {
@Override
protected void doAdd(Greeting greeting, Map<String, ContentInfo> ignored) {
getBuilder().element("message", greeting.getMessage());
}
};
// Assemble the SIP
SipAssembler<Greeting> sipAssembler = SipAssembler.forPdi(prototype, pdiAssembler);
FileGenerator<Greeting> generator = new FileGenerator<>(sipAssembler, () -> new File("hello-sip.zip"));
Greeting greeting = new Greeting("Hello, SIP");
SipMetrics metrics = (SipMetrics) generator.generate(greeting).getMetrics();
long numAius = metrics.numAius();
System.out.printf(" Added %d %s to SIP of %d bytes in %d ms%n", numAius, English.plural("AIU", (int) numAius), metrics.sipFileSize(), metrics.assemblyTime());
}
Aggregations