public interface ITransformerService extends IService
javax.xml.transform.Source. The XML input can be a file, stream,
DOM or other customized class. The source classes provided by the JDK are:
javax.xml.transform.stream.StreamSourcejavax.xml.transform.sax.SAXSource javax.xml.transform.dom.DOMSource HTTPStreamSource, is used for working with URL based XML
sources that use the portal cache, proxy settings and PCD attributes to
load XML files from the internet. It is highly recommended to work with this
class when loading XML files from the internet.
javax.xml.transform.result. The result of the transformation
is kept in the format specified by the last transformer in the
transformation pipe. Result classes provided by the JDK are:
javax.xml.transform.stream.StreamResultjavax.xml.transform.sax.SAXResult javax.xml.transform.dom.DOMResult
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)
{
// ...
}
| Modifier and Type | Field and Description |
|---|---|
static String |
BUILT_IN_TRANSFORMERS_FILE
A constant that defines the definition file for built-in transformers.
|
static String |
BUILT_IN_TRANSFORMERS_FOLDER
A constant that defines the base folder for built-in transformers.
|
static String |
BUILT_IN_TRANSFORMERS_KEY
A constant that defines the component name for built-in transformers.
|
static String |
KEY
The service key.
|
static String |
RESOURCE_BUNDLE_NAME
A constant that defines the name of the default resource.
|
static String |
RESOURCE_BUNDLE_PARAMETER_NAME
A constant that defines the name of the transformer parameter for the
resource bundles.
|
static String |
TRANSFORMATION_LOG_SUBLOC
A constant that defines the sublocation of the log for the transformer service.
|
static String |
TRANSFORMERS_REGISTRY_ROOT_PATH
A constant that defines the path for the transformer providers in the
portal registry.
|
static String |
TRNSFRMR_SVC_LOC_STR
A constant that defines the location of the log for the transformer service.
|
| Modifier and Type | Method and Description |
|---|---|
ITransformerInformation |
createTransformerInformation(String componentName,
String transformerName,
Float transformerVersion,
TransformerType transformerType,
String fromUri,
String toUri,
String description)
Creates a new instance of ITransformerInformation.
|
ITransformerInformation |
getTransformerInformation(String transformerKey)
Gets a single transformer information object according to the specified
key.
|
List |
getTransformersInformation(TransformerType transformerType,
String componentName,
String transformerName,
Float transformerVersion,
String fromUri,
String toUri)
Gets a list of transformers that match the specified properties.
|
void |
releaseTransformers(String componentName)
Releases transformers for the specified component.
|
boolean |
setTransformer(ITransformerInformation transformerInfo,
EPSAXDefaultHandler saxTransformer,
boolean overwrite)
Registers a SAX transformer that uses the supplied SAX handler.
|
boolean |
setTransformer(ITransformerInformation transformerInfo,
Source source,
boolean overwrite)
Registers an XSL transformer from the XML source that is already loaded.
|
boolean |
setTransformer(ITransformerInformation transformerInfo,
String xslUri,
boolean overwrite)
Registers an XSL transformer by loading the XSL file from the specified
location.
|
void |
transform(Source source,
List transformers,
Map[] paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
Map objectsMap,
Result output)
Activates the transformation process using a list of transformers.
|
void |
transform(Source source,
String transformerKey,
Map paramMap,
com.sapportals.htmlb.rendering.IPageContext context,
Map objectsMap,
Result output)
Activates the transformation process using one transformer.
|
static final String BUILT_IN_TRANSFORMERS_KEY
static final String BUILT_IN_TRANSFORMERS_FOLDER
static final String BUILT_IN_TRANSFORMERS_FILE
static final String KEY
static final String TRANSFORMERS_REGISTRY_ROOT_PATH
static final String RESOURCE_BUNDLE_PARAMETER_NAME
static final String RESOURCE_BUNDLE_NAME
static final String TRNSFRMR_SVC_LOC_STR
static final String TRANSFORMATION_LOG_SUBLOC
void transform(Source source, List transformers, Map[] paramMap, com.sapportals.htmlb.rendering.IPageContext context, Map objectsMap, Result output) throws TransformationServiceException
ITransformerInformation
objects, transformers keys or a combination of both.
HTTPStreamSource object.source - the source for the transformationtransformers - a list of transformersparamMap - an array holding the parameters
for each transformercontext - the page contextobjectsMap - for future useoutput - the result of the transformationTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers does not
exist or if an error occurs
during the transformationITransformerInformation.getKey()void transform(Source source, String transformerKey, Map paramMap, com.sapportals.htmlb.rendering.IPageContext context, Map objectsMap, Result output) throws TransformationServiceException
source - the source for the transformationtransformerKey - the key of the transformerparamMap - the parameters for the transformercontext - the page contextobjectsMap - for future useoutput - the result of the transformationTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers doesn't
exist or if an error occurs
during the transformationboolean setTransformer(ITransformerInformation transformerInfo, String xslUri, boolean overwrite) throws TransformationServiceException
transformerInfo - the transformer informationxslUri - the URI of the transformer,overwrite - when true and the
transformer already exists,
the service replaces the existing
transformer with the new onetrue if the
transformer was added to the
service, false if
it was not addedTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers doesn't
exist or if an error occurs
during the transformationboolean setTransformer(ITransformerInformation transformerInfo, Source source, boolean overwrite) throws TransformationServiceException
transformerInfo - the transformer informationsource - the source for the transformationoverwrite - when true and the
transformer already exists, the
service replaces the current
transformer with the new onetrue if the
transformer was added to the
service,
false if it was
not addedTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers doesn't
exist or if an error occurs
during the transformationboolean 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
associated with this transformeroverwrite - when true and the
transformer already exists, the
service replaces the current
transformer with the new onetrue if the
transformer was added to the
service, false
if it was not addedTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers doesn't
exist or if an error occurs
during the transformationvoid releaseTransformers(String componentName)
componentName - the component nameITransformerInformation createTransformerInformation(String componentName, String transformerName, Float transformerVersion, TransformerType transformerType, String fromUri, String toUri, String description) throws TransformationServiceException
componentName - the component nametransformerName - the transformer nametransformerVersion - the transformer versiontransformerType - the transformer typefromUri - the source schemetoUri - the result schemedescription - the transformer descriptionTransformationServiceException - if the source data is corrupt,
if it cannot write to the result,
if one of the transformers doesn't
exist or if an error occurs
during the transformationList getTransformersInformation(TransformerType transformerType, String componentName, String transformerName, Float transformerVersion, String fromUri, String toUri)
transformerType - the type of the requested
transformerscomponentName - the component nametransformerName - the transformer nametransformerVersion - the version of the transformerfromUri - the source schemetoUri - the result schemeITransformerInformation getTransformerInformation(String transformerKey)
transformerKey - the transformer key| Access Rights |
|---|
| SC | DC | Public Part | ACH |
|---|---|---|---|
[sap.com] EP-ADMIN
|
[sap.com] tc/ep/admin/api/extd
|
api
|
EP-PIN
|
Copyright 2021 SAP SE Complete Copyright Notice