Package org.appng.xml.transformation
Class StyleSheetProvider
- java.lang.Object
-
- org.appng.xml.transformation.StyleSheetProvider
-
public class StyleSheetProvider extends Object
AStyleSheetProvider
assembles a XSL-stylesheet from one master XSL-file and a various number of other XSL-files to include. The insertion-point for the additional files must be set viasetInsertBefore(String)
.- Author:
- Matthias Müller
-
-
Constructor Summary
Constructors Constructor Description StyleSheetProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStyleSheet(InputStream styleSheet, String reference)
Adds an additional XSL-source to be included into the master sourcevoid
cleanup()
Closes all the previously usedInputStream
s.protected void
close(InputStream is)
DocumentBuilder
getDocumentBuilder()
DocumentBuilderFactory
getDocumentBuilderFactory()
String
getId()
Returns a unique ID for thisStyleSheetProvider
, which is build from the sorted set of reference names of the additional stylesheets added viaaddStyleSheet(InputStream, String)
.String
getInsertBefore()
Returns the actual insertion-pointString
getName()
byte[]
getStyleSheet(boolean deleteIncludes)
byte[]
getStyleSheet(boolean deleteIncludes, OutputStream additionalOut)
Assembles the complete XSL stylesheet by including the sources added viaaddStyleSheet(InputStream, String)
and embedding them into the master source at the defined insertion-point.Transformer
getTransformer()
TransformerFactory
getTransformerFactory()
void
init()
boolean
isValid()
Checks if thisStyleSheetProvider
is valid, i.e.void
setDocumentBuilder(DocumentBuilder documentBuilder)
void
setDocumentBuilderFactory(DocumentBuilderFactory documentBuilderFactory)
void
setInsertBefore(String insertBefore)
Sets the insertion point for the master source, at which additional stylesheets should be embedded.void
setMasterSource(InputStream masterXsl, String templateRoot)
Sets the master XSL source for thisStyleSheetProvider
.void
setName(String name)
void
setTransformer(Transformer transformer)
void
setTransformerFactory(TransformerFactory transformerFactory)
-
-
-
Method Detail
-
init
public void init()
-
setMasterSource
public void setMasterSource(InputStream masterXsl, String templateRoot)
Sets the master XSL source for thisStyleSheetProvider
.- Parameters:
masterXsl
- the master sourcetemplateRoot
- the absolute path to the directory where template resides
-
addStyleSheet
public void addStyleSheet(InputStream styleSheet, String reference)
Adds an additional XSL-source to be included into the master source- Parameters:
styleSheet
- the additional sourcereference
- the name of the source, used for XSL-comments and logging
-
getStyleSheet
public byte[] getStyleSheet(boolean deleteIncludes)
- See Also:
getStyleSheet(boolean, OutputStream)
-
getStyleSheet
public byte[] getStyleSheet(boolean deleteIncludes, OutputStream additionalOut)
Assembles the complete XSL stylesheet by including the sources added viaaddStyleSheet(InputStream, String)
and embedding them into the master source at the defined insertion-point.- Parameters:
deleteIncludes
- If set totrue
, all<xsl:include>
s eventually contained in the master source will be removed before assembling the stylesheet. If set tofalse
, the<xsl:include>
s are being kept and processed.additionalOut
- an additionalOutputStream
to write the stylesheet to (optional)- Returns:
- the complete stylesheet as an array of bytes
-
close
protected void close(InputStream is)
-
getDocumentBuilderFactory
public DocumentBuilderFactory getDocumentBuilderFactory()
-
setDocumentBuilderFactory
public void setDocumentBuilderFactory(DocumentBuilderFactory documentBuilderFactory)
-
getTransformerFactory
public TransformerFactory getTransformerFactory()
-
setTransformerFactory
public void setTransformerFactory(TransformerFactory transformerFactory)
-
getDocumentBuilder
public DocumentBuilder getDocumentBuilder()
-
setDocumentBuilder
public void setDocumentBuilder(DocumentBuilder documentBuilder)
-
getTransformer
public Transformer getTransformer()
-
setTransformer
public void setTransformer(Transformer transformer)
-
getInsertBefore
public String getInsertBefore()
Returns the actual insertion-point- Returns:
- the actual insertion-point
-
setInsertBefore
public void setInsertBefore(String insertBefore)
Sets the insertion point for the master source, at which additional stylesheets should be embedded.- Parameters:
insertBefore
- the insertion-point to use
-
getName
public String getName()
-
setName
public void setName(String name)
-
getId
public String getId()
Returns a unique ID for thisStyleSheetProvider
, which is build from the sorted set of reference names of the additional stylesheets added viaaddStyleSheet(InputStream, String)
.- Returns:
- the ID
- See Also:
addStyleSheet(InputStream, String)
-
cleanup
public void cleanup()
Closes all the previously usedInputStream
s.
-
isValid
public boolean isValid()
Checks if thisStyleSheetProvider
is valid, i.e. the master source is notnull
.- Returns:
true
the master source is notnull
,false
otherwise
-
-