|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Service that is responsible for transforming XMLs to various schemes using transformers. Users can add and remove transformers as they wish.
Transformers can be found according to their name, version, type and schemes definition.
The source of the transformation process must be an XML file and the result can be HTMLB, HTML, Other XML or any format depending on the
transformers.
Each transformation is thread safe and synchronized.
Usage example that transform BUSDOC to HTMLB and write the result to the response:
...
String fileLocation = getXMLFileLocation();
IPageContext context = PageContextFactory.createPageContext(request,response);
ITransformerService tService = (ITransformerService)request.getService(ITransformerService.KEY);
try
{
// Getting the BUSDOC transformer information according to it's name
List busdocTrans = tService.getTransformersInformation(TransformerType.BUILT_IN,ITransformerService.BUILT_IN_TRANSFORMERS_KEY,"BUSDOC_TO_XHTMLB",null,null,null);
// Getting XHTMLB transformer information according to the input and output types
List xhtmlbTrans = tService.getTransformersInformation(TransformerType.BUILT_IN,null,null,null,"XHTMLB","HTML");
// Building Transformers list
List trns = new ArrayList(2);
trns.add(busdocTrans.get(0));
trns.add(xhtmlbTrans.get(0));
// Building paramters maps array
Map[] paramsArray = new Map[2];
// Setting parameters to the RSS transformer
paramsArray[0] = new Hashtable(1);
paramsArray[0].put("VisibleRowsCount","5");
// Setting parameters to the XHTMLB transformer
paramsArray[1] = new Hashtable(2);
paramsArray[1].put(ITransformerService.BUILT_IN_TRANSFORMERS_KEY+ ".HTMLBRenderAtEnd",Boolean.TRUE);
// Getting source file
// Setting source stream
FileInputStream fis = null;
try
{
fis = new FileInputStream(fileLocation);
}
catch (FileNotFoundException e)
{
...
}
StreamSource source = new StreamSource(fis);
// Setting result stream
StreamResult strm = new StreamResult(response.getWriter());
// Transforming and writing to the response
tService.transform(source, trns, paramsArray, context, null, strm);
}
catch (TransformationServiceException e)
{
// ...
}
| Field Summary | |
static java.lang.String |
BUILT_IN_TRANSFORMERS_FILE
Built-in transformers definition file |
static java.lang.String |
BUILT_IN_TRANSFORMERS_FOLDER
Base folder of the built-in transformers |
static java.lang.String |
BUILT_IN_TRANSFORMERS_KEY
The component name for the built-in transformers |
static java.lang.String |
KEY
Service key |
static java.lang.String |
RESOURCE_BUNDLE_NAME
Name of the default resource |
static java.lang.String |
RESOURCE_BUNDLE_PARAMETER_NAME
Name of the transformer parameter of resource bundles |
static java.lang.String |
TRANSFORMATION_LOG_SUBLOC
Sub location of the log for the transformer service |
static java.lang.String |
TRANSFORMERS_REGISTRY_ROOT_PATH
The path of the transformer providers in the registry |
static java.lang.String |
TRNSFRMR_SVC_LOC_STR
Location of the log for the transformer service |
| Method Summary | |
ITransformerInformation |
createTransformerInformation(java.lang.String componentName,
java.lang.String transformerName,
java.lang.Float transformerVersion,
TransformerType transformerType,
java.lang.String fromUri,
java.lang.String toUri,
java.lang.String description)
Create new instance of ITransformerInformation. |
ITransformerInformation |
getTransformerInformation(java.lang.String transformerKey)
Get a single transformer information according to it's key. |
java.util.List |
getTransformersInformation(TransformerType transformerType,
java.lang.String componentName,
java.lang.String transformerName,
java.lang.Float transformerVersion,
java.lang.String fromUri,
java.lang.String toUri)
Gets a list of transformers that match all filter properties. |
void |
releaseTransformers(java.lang.String componentName)
Releases transformers of a specific component. |
boolean |
setTransformer(ITransformerInformation transformerInfo,
EPSAXDefaultHandler saxTransformer,
boolean overwrite)
Set a SAX transformer that will use the supplied SAX handler. |
boolean |
setTransformer(ITransformerInformation transformerInfo,
javax.xml.transform.Source source,
boolean overwrite)
Set an XSL transformer from XML source that was already loaded. |
boolean |
setTransformer(ITransformerInformation transformerInfo,
java.lang.String xslUri,
boolean overwrite)
Set an XSL transformer by loading XSL file from location specified in the URI parameter. |
void |
transform(javax.xml.transform.Source source,
java.util.List transformers,
java.util.Map[] paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
java.util.Map objectsMap,
javax.xml.transform.Result output)
Method that activates the transformation process over a list of transformers. |
void |
transform(javax.xml.transform.Source source,
java.lang.String transformerKey,
java.util.Map paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
java.util.Map objectsMap,
javax.xml.transform.Result output)
Method that activates transformation process by one transformer. |
| Methods inherited from interface com.sapportals.portal.prt.service.IService |
afterInit, configure, destroy, getContext, getKey, init, release |
| Field Detail |
public static final java.lang.String BUILT_IN_TRANSFORMERS_KEY
public static final java.lang.String BUILT_IN_TRANSFORMERS_FOLDER
public static final java.lang.String BUILT_IN_TRANSFORMERS_FILE
public static final java.lang.String KEY
public static final java.lang.String TRANSFORMERS_REGISTRY_ROOT_PATH
public static final java.lang.String RESOURCE_BUNDLE_PARAMETER_NAME
public static final java.lang.String RESOURCE_BUNDLE_NAME
public static final java.lang.String TRNSFRMR_SVC_LOC_STR
public static final java.lang.String TRANSFORMATION_LOG_SUBLOC
| Method Detail |
public void transform(javax.xml.transform.Source source,
java.util.List transformers,
java.util.Map[] paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
java.util.Map objectsMap,
javax.xml.transform.Result output)
throws TransformationServiceException
source - source for the transformation. Can be instances of SAXSource, StreamSource, DOMSource or and derived class from the previous
classestransformers - List of transformers information or transformers keysparamMap - array holding the parameters for each transformercontext - the page contextobjectsMap - future usageoutput - the output of the transformation. Can be instance of StreamResult,DOMResult or SAXResult.TransformationServiceException - when source data is corrupted, when cannot write to the result, when one of the transformers doesn't
exists and when error occures during the transformationITransformerInformation.getKey()
public void transform(javax.xml.transform.Source source,
java.lang.String transformerKey,
java.util.Map paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
java.util.Map objectsMap,
javax.xml.transform.Result output)
throws TransformationServiceException
source - source for the transformation. Can be instances of SAXSource, StreamSource or DOMSource.transformerKey - The key of the transformerparamMap - parameters for the transformercontext - the page contextobjectsMap - future usageoutput - the output of the transformation. Can be instance of StreamResult,DOMResult or SAXResult.TransformationServiceException - when source data is corrupted, when cannot write to the result, when one of the transformers doesn't
exists and when error occures during the transformation
public boolean setTransformer(ITransformerInformation transformerInfo,
java.lang.String xslUri,
boolean overwrite)
throws TransformationServiceException
transformerInfo - the transformer informationxslUri - the URI of the transformer. It can be a URL or location on the file system.overwrite - when true and the transformer already exists the service will replace the current transformer with the new oneTransformationServiceException - when the transformer cannot be built because of the file was not found, the XSL is not valid or other
general problems
public boolean setTransformer(ITransformerInformation transformerInfo,
javax.xml.transform.Source source,
boolean overwrite)
throws TransformationServiceException
transformerInfo - the transformer informationsource - DOMSource or StreamSource holding the data of the XSLoverwrite - when true and the transformer already exists the service will replace the current transformer with the new oneTransformationServiceException - when the transformer cannot be built because the XSL is not valid or other general problems
public boolean setTransformer(ITransformerInformation transformerInfo,
EPSAXDefaultHandler saxTransformer,
boolean overwrite)
throws TransformationServiceException
public void init(IPortalComponentInitContext initContext)
throws PortalComponentException
{
mm_initContext = initContext;
//Getting the service
ITransformerService tService = (ITransformerService) PortalRuntime.getRuntimeResources().getService(ITransformerService.KEY);
// Creating the SAX handlers instance. TestUIDSSAXHandler derives from EPSAXDefaultHandler.
TestUIDSSAXHandler hndlr = new TestUIDSSAXHandler();
try
{
// Creating the new transformer information
ITransformerInformation ti =
tService.createTransformerInformation(initContext.getApplicationName()
,"UID_ADDER",new Float(1.0)
,TransformerType.TEMPORARY
,"XML","XML","Temporary SAX unique ID adder");
// Setting the transformer
tService.setTransformer(ti,hndlr,false);
}
catch (TransformationServiceException e)
{
...
}
super.init(initContext);
}
transformerInfo - the transformer informationsaxTransformer - the sax handler that is assossiated with this transformeroverwrite - when true and the transformer already exists the service will replace the current transformer with the new oneTransformationServiceException - when the handler is a null pointer or it cannot be clonedpublic void releaseTransformers(java.lang.String componentName)
componentName - the protal component name
public ITransformerInformation createTransformerInformation(java.lang.String componentName,
java.lang.String transformerName,
java.lang.Float transformerVersion,
TransformerType transformerType,
java.lang.String fromUri,
java.lang.String toUri,
java.lang.String description)
throws TransformationServiceException
componentName - the component nametransformerName - the transformer nametransformerVersion - the version of the transformertransformerType - type of transformerfromUri - source schemetoUri - result schemedescription - transformer descriptionTransformationServiceException - when input data is missingby the defining it's properties
public java.util.List getTransformersInformation(TransformerType transformerType,
java.lang.String componentName,
java.lang.String transformerName,
java.lang.Float transformerVersion,
java.lang.String fromUri,
java.lang.String toUri)
transformerType - the type of the requested transformerscomponentName - the component nametransformerName - the nametransformerVersion - the versionfromUri - source scheme URItoUri - result scheme URIpublic ITransformerInformation getTransformerInformation(java.lang.String transformerKey)
transformerKey - the transformer key
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||