Table of Content
Table of Contents | ||||||||
---|---|---|---|---|---|---|---|---|
|
Maven Dependencies
The CIP4 xJdfLib Java Library is based on Java. The latest stable version always is being published on the CIP4 Website on page “Technical Resources -> Downloads -> Internal Source”. Furthermore, the library is an Apache Maven project. So the latest stable version also is available in the public Central Maven Repositroy:
...
Code Block | ||
---|---|---|
| ||
<dependency> <groupId>org.cip4.lib.xjdf</groupId> <artifactId>xJdfLib</artifactId> <version>0.6-SNAPSHOT</version> </dependency> |
Components Description
XJDF Data Types
The XJDF Specification specifies several data types. At this time not all but the most significant data types already are implemented in CIP4 XJDF Java Library. The next versions of xJdfLib will complete the list step by step.
All XJDF Type classes are derived from AbstractXJdfType and provide a custom toString() method for converting a data type to a string expression. The way around is coverted by a custom constructor. Each XJDF Data Type provides at least a default and several custom constructor for initializing.
Data Type: DateTime
A DateTime object represents a specific instant of time. It must be a Coordinated Universal Time (UTC) or the time zone must be indicated by the offset to UTC. In other words, the time must be unique in all time zones around the world.
...
Code Block | ||
---|---|---|
| ||
// read DateTime DateTime dateTime = new DateTime(); dateTime.getCalendar() |
Data Type: Duration
Durations are a component of time intervals and define the amount of intervening time in a time interval. Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S.
...
Code Block | ||
---|---|---|
| ||
// read Duration Duration duration = new Duration(0, 6); int year = duration.getYear(); int month = duration.getMonth(); int day = duration.getDay(); int hour = duration.getHour(); // 6 int minute = duration.getMinute(); int second = duration.getSecond(); |
Data Type: IntegerList
An IntegerList is an enumerated set of Integers, which is expressed as a list of space separated values.
...
Code Block | ||
---|---|---|
| ||
// read IntegerList IntegerList integerList = new IntegerList(4, 0); List<Integer> lst = integerList.getList(); |
Data Type: Matrix
Coordinate transformation matrices are widely used throughout the whole printing Process, especially in Layout Resources. They represent two dimensional transformations as defined by [PS] and [PDF1.6]. For more information, refer to the respective reference manuals, and look for "Coordinate Systems and Transformations." The "identity matrix", which is "1 0 0 1 0 0", is often used as a default throughout this specification. When another matrix is factored against a matrix with the identity matrix value, the result is that the original matrix remains unchanged. Coordinate transformation matrices are primitive data types and are encoded as a list of six numbers (as doubles), separated by whitespace: "a b c d Tx Ty". The variables Tx and Ty describe distances and are defined in points.
...
Code Block | ||
---|---|---|
| ||
// read matrix Matrix matrix = new Matrix(1, 2, 3, 4, 5, 6); double a = matrix.getA(); // 1.0 double b = matrix.getB(); // 2.0 double c = matrix.getC(); // 3.0 double d = matrix.getD(); // 4.0 double tx = matrix.getTx(); // 5.0 double ty = matrix.getTy(); // 6.0 |
Data Type: NMTokens
NMTOKENS is an enumerated set of NMTOKEN, which is expressed as a list of space separated values.
...
Code Block | ||
---|---|---|
| ||
// read NMTokens NMTokens nmTokens = new NMTokens("Val_1 Val_2 Val_3"); List<String> lst = nmTokens.getList(); |
Data Type: Rectangle
Rectangles are used to describe rectangular locations on the page, sheet or other printable surface. A rectangle is represented as an array of four numbers — llx lly urx ury — specifying the lower-left x, lowerleft y, upper-right x and upper-right y coordinates of the rectangle, in that order. This is equivalent to the ordering: Left Bottom Right Top. All numbers are defined in points.
...
Code Block | ||
---|---|---|
| ||
// read Rectangle Rectangle rectangle = new Rectangle(1, 2, 3, 4); double llx = rectangle.getLlx(); double lly = rectangle.getLly(); double urx = rectangle.getUrx(); double ury = rectangle.getUry(); |
Data Type: Shape
Shape data types are used to describe a three dimensional box. A shape is represented as an array of three (positive or zero) numbers x y z specifying the Width x, height y and depth z coordinates of the shape, in that order.
...
Code Block | ||
---|---|---|
| ||
// read Shape Shape shape = new Shape(10.5, 15.2); double x = shape.getX(); // 10.5 double y = shape.getY(); // 15.2 double z = shape.getZ(); // 0.0 |
Data Type: XYPair
XYPairs are used to describe sizes like Dimensions and StartPosition. They can also be used to describe positions on a page. All numbers that describe lengths are defined in points. XYPair Attributes are primitive data types and are encoded as a string of two numbers, separated by whitespace: "x y".
...
Code Block |
---|
// read XYPair XYPair xyPair = new XYPair(4.5, 5.0); double x = xyPair.getX(); double y = xyPair.getY(); |
XJdfNodeFactory
The XJdfNodeFactory is the factory class for creating new instances of XJDF-Node-Objects. The class provides at least one simple Creation-Method per XJDF Node defined in XJDF Specification. Moreover, the class also provides extended Creation-Methods for commonly used nodes (e. g. GeneralID, RunList etc.) which also initializes the object after creation.
...
Code Block | ||
---|---|---|
| ||
// new factory instance XJdfNodeFactory nf = new XJdfNodeFactory(); // best practice creating indivudal nodes RunList runList = nf.createRunList("http://192.168.1.113:80/10496"); runList.getFileSpec().setUserFileName("myFileName.pdf"); |
Builder Classes
Most of the XJDF-Node-Objects can easily be created using the XJdfNodeFactory as described in the chapter before. How ever, more complex nodes like the XJDF-Root-Node or the Product-Node are nodes which contain a set of subnodes in a well defined structure. This requires additional logic to organize all child nodes within the parent node. Builder classes are designed to achieve this.
...
- XJdfBuilder
Creation of XJDF Documents. Manages the dealing with Products and Parameters. - ProductBuilder
Creation of Product-Nodes. Handles all Intent nodes. - ContactBuilder
Creation of Contact-Nodes. Organize the handling with contact details.
XJDFBuilder
The XJdfBuilder is responsible for the creation and management of XJDF-Root-Nodes as well as the main structure in XJDF Documents. All child nodes can easily be appended by calling the associated "add-" methods. The logic where exactely a specific node has to be put is covered by the builder class.
...
Code Block | ||
---|---|---|
| ||
// new factory instance XJdfNodeFactory nf = new XJdfNodeFactory(); Contact contact = [...]; Product product = [...]; // create XJDF with builder XJdfBuilder xJdfBuilder = XJdfBuilder.newInstance("FA-SIG-123456"); xJdfBuilder.addParameter(nf.createRunList("test_file.pdf")); xJdfBuilder.addParameter(contact); xJdfBuilder.addProduct(product); XJDF xjdf = xJdfBuilder.build(); // build XJDF Doc XJDF xJdf = xJdfBuilder.build(); |
Partitioning of Parameter Nodes
Following a sample of a XJDF Document with a partitioned RunList. The XJDF Document references the PDF files for cover and body separately. This mechanism is called partitioning and requires an Part-Node per item.
...
Code Block | ||
---|---|---|
| ||
// new factory instance XJdfNodeFactory nf = new XJdfNodeFactory(); // create XJDF Document ProductBuilder productBuilder = new ProductBuilder(1500); Product product = productBuilder.build(); Part partCover = nf.createPart(); partCover.setRun("cover"); Part partBody = nf.createPart(); partBody.setRun("body"); XJdfBuilder xJdfBuilder = new XJdfBuilder("FA-SIG-123456", "Web2Print"); xJdfBuilder.addParameter(nf.createRunList("cover.pdf"), partCover); xJdfBuilder.addParameter(nf.createRunList("body.pdf"), partBody); xJdfBuilder.addProduct(product); XJDF xjdf = xJdfBuilder.build(); |
ProductBuilder
The Product-Node is another signification element in an XJDF Document. This node specifies the product configuration how desired by the customer. In XJDF, most product configurations are defined as Intent-Nodes. A Product-Node consists of at least itself, its attributes and a set of Intent-Node subelements. The ProductBuilder organizes the creation of a Product-Node as well as the handling of all its Intent-Nodes.
...
Code Block | ||
---|---|---|
| ||
// new factory instance XJdfNodeFactory nf = new XJdfNodeFactory(); // create product node ProductBuilder productBuilder = new ProductBuilder(1500); productBuilder.addIntent(nf.createMediaIntent("IPG_90")); productBuilder.addIntent(nf.createLayoutIntent(2, "TwoSidedHeadToHead", new Shape(297.63779528, 419.52755906))); productBuilder.addIntent(nf.createColorIntent(new IntegerList(4, 4))); Product product = productBuilder.build(); XJdfBuilder xJdfBuilder = new XJdfBuilder("FA-SIG-123456", "Web2Print"); xJdfBuilder.addProduct(product); XJDF xjdf = xJdfBuilder.build(); |
ContactBuilder
The ContactBuilder simplify the creation of Contact-Nodes. Contact-Nodes hold all the customers contact and delivery details and can be added as parameter to an XJDF Document. Usually, a contact parameter consists of the Contact-Node with at least an Address-Node, a Company-Node and a ComChannel-Node as subelements.
...
Code Block | ||
---|---|---|
| ||
// create contact node ContactBuilder contactBuilder = new ContactBuilder(); contactBuilder.addCompany("flyeralarm GmbH"); contactBuilder.addPerson("Meissner", "Stefan", null); contactBuilder.addAddress("Alfred-Nobel-Strasse 15", "97082", "Wuerzburg"); contactBuilder.addComChannel("Phone", "tel:+49.931.465840"); contactBuilder.addContactType("Delivery"); contactBuilder.addContactType("Customer"); Contact contact = contactBuilder.build(); XJdfBuilder xJdfBuilder = new XJdfBuilder("FA-SIG-123456", "Web2Print"); xJdfBuilder.addParameter(contact); XJDF xjdf = xJdfBuilder.build(); |
XJdfParser
The XJdfParser writes an XJDF Document Object Tree either to a binary stream or to a byte array and vice versa. Cases of practical use are dealing with XJDF Documents and http transmissions or working on file system. When using binary streams, internally the parser is working with the Java interfaces java.io.InputStream and java.io.OutputStream. So it doesn’t matter which kind of stream is used for reading or writing. The following is a sample of how to save an XJDF Document to a local file system.
...
Info | ||
---|---|---|
| ||
In order to analyze or extract details from an XJDF Document it is recommended to work with XPath expressions. Parsing the whole document and working with the DOM Tree Objects is no longer state of the art. This mechanism consumes time and raises code complexity. Besides, parsing an InputStream is also prone to errors because it requires fully conform documents. CIP4 xJdfLib provides an extra class XJdfNavigator for dealing with XPath expressions in XJDF Documents. XJDF is desinged for XPath so the preferred way of reading XJDF Documents is XPath. |
XJdfValidator
The XJdfValidator class validates an XJDF Binary Stream against the latest XJDF Schema. A new instance is required for each validation process. So when validating an XJDF Document, first of all a new validator object has to be created. The method isValid() runs the validation process and finally returns the result as Boolean.
...