Show TOC Start of Content Area

Background documentation XML Transformation  Locate the document in its SAP Library structure

XML transformation is done with XSL and SAX transformers. With the transformation service you define the transformers once and then use them in combination with already defined transformers without needing to re-define them again before transforming. Transformation can be done on registered transformers only. Registered transformers can also be used by other content developers using the XML iView user interface from the portal.

Combining several transformers to generate one output is called Pipe Transformation. The Pipe transformation allows you to develop light weight transformers and connect them to one powerful transformer.

A transformer has the following attributes collected by interface ITransformerInformation:

Attribute

Type

Description

Name

String (cs)

The name of the transformer. The name has to be unique for an application component.

Component name

String (cs)

The name of the portal component or portal service that registered the transformer.

Version

Float

The version of the transformer. Using the correct version number will avoid errors when a transformer is upgraded.

Transformer type

TransformerType

Registration type of the transformer. There are the following types:

·        Built-in

Transformer was provided by the transformation service.

·        Persistent

Transformer was supplied by transformation provider (see chapter Providing Transformers).

·        Temporary

Transformer is temporally supplied from regular portal application.

From scheme

String (cs)

XML input format. The scheme from which the transformer gets the XML data..

To scheme

String (cs)

XML output format. Defines the output format of the transformer.

Description

String

General description of the transformer.

 

Activation

Following steps are necessary to activate a XML transformation:

...

       1.      Create a Transformer List

To get related transformers information according to the attributes, use the requested attributes as parameter of the method getTransformersInformation(). You should call this method for each transformer you want to add. The method returns all transformers that match the specified attribute.

       2.      Defining parameters

Create an array with the same size of the transformer list. Every item in the array must be a map of parameters related to the transformer with the same index.

       3.      Generate the XML source

Generate the XML source to be transformed. See XML Source for more details.

       4.      Generate XML result

Generate the object that will receive the result of the transformation. See XML Resultfor more details.

       5.      Activate transformation

Call method transform() of the service.

 

XML Source

The implementation of XML source must inherit from javax.xml.transform.Source. The XML input can be file, stream, DOM or another customized class. The source classed provided by the JDK are:

·        javax.xml.transform.stream.StreamSource

·        javax.xml.transform.sax.SAXSource

·        javax.xml.transform.dom.DOMSource

See the JDK Documentation for more details.

 

The HTTPStreamSource class, an addition of the transformation service, is used for working with URL based XML sources that uses the portal cache, proxy settings and PCD attributes to load XML files from the web. It is strongly recommended to work with this class when loading XML files from the web. For more details see the class definition in the transformation service Javadoc and examples.

 

XML Result

The implementation of XML result must inherit from javax.xml.transform.result. The class supplied keeps the result of the transformation in the format specified by the last transformer in the transformation pipe. Result classes provided by the JDK are:

·        javax.xml.transform.stream.StreamResult

·        javax.xml.transform.sax.SAXResult

·        javax.xml.transform.dom.DOMResult

See the JDK Documentation for more details.

 

Result Types

There are the following XML results:

 

·        IPortalComponentResponse

in-order for the results to be written directly to the response of the portal component you should create a new StreamResult object with the response writer.

Example:

    
    
// Setting result stream 
    
StreamResult strmResult = new StreamResult(response.getWriter());
    
// Transforming 
    
tService.transform(src,trns, paramsArr, context, null, strmRes);
    

 

·        HTMLB

When working with the XHTMLB transformer the result of the transformation is a set of HTMLB objects. Default behaviour is to create this set of objects in the page context, however it is possible to specify that the result should be rendered to the response by parameters (see Built-in Transformers for more details).

 

·        String

In order for the result to be written to a string you should create a StreamResult object with a ByteArrayOutputStream as its constructor input field. After the transformation is finished get the string from the created ByteArrayOutputStream object.

Example:

    OutputStream outStrm = new ByteArrayOutputStream(); 
    StreamResult strm = 
new StreamResult(outStrm);
    tService.transform(source, trns, params, context, 
null, strm); 
    . 
    . 
    tService.transform(source, trns, params, context, 
null, strm); 
    . 
    . 
    String result = outStrm.toString();

 

 

End of Content Area