|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.infinityloop.util.xslt.ExtensionFunctions
public class ExtensionFunctions
This class encapsulates XSLT extension function implementations for some often-needed handy utilities.
Except when noted otherwise for a function, the general usage pattern is as follows:
<xsl:stylesheet> element, e.g.:
xmlns:ilext="java:de.infinityloop.util.xslt.ExtensionFunctions" (for Saxon) or
xmlns:ilext="xalan://de.infinityloop.util.xslt.ExtensionFunctions" (for Xalan)
ilext:functionName( ...parameters if any... )
<xsl:stylesheet> element:
exclude-result-prefixes="ilext ...other prefixes..."
Example:
<xsl:value-of select="ilext:URLToLocal(@href)" />
The above converts the value of the href attribute, which is supposed to be a URI reference, to local file naming convention.
| Constructor Summary | |
|---|---|
ExtensionFunctions()
|
|
| Method Summary | |
|---|---|
static double |
absolutizeLength(java.lang.String length,
java.lang.String fontsize,
java.lang.String referenceValue,
java.lang.String resultDimension)
Converts and absolutizes the passed length specification to the given dimension. |
static double |
addLengths(java.lang.String length1,
java.lang.String length2,
java.lang.String resultDimension)
Adds two absolute length values, even if using different dimensions. |
static java.lang.String |
calcCALSTablegrid(java.lang.String xml)
|
static java.lang.String |
calcTableColgroup(java.lang.String tableXMLCode)
Returns a serialized colspec element mirroring the column widths of the passed table code. |
static double |
convertLength(java.lang.String length,
java.lang.String resultDimension)
Converts the passed absolute length specification to the given dimension. |
static java.lang.String |
emptyString(boolean whatever)
Returns an empty string |
static java.lang.String |
emptyString(java.lang.String whatever)
Returns an empty string |
static java.lang.String |
FileCalcAbsolutePath(java.lang.String basePath,
java.lang.String relativePath)
Returns the absolute path for the relative one passed in, based on the absolute base path also specified. |
static java.lang.String |
FileCalcRelativePath(java.lang.String basePath,
java.lang.String destPath)
Returns the relative path from the base path to the destination path in URL format. |
static boolean |
FileExists(java.lang.String name)
Tests if a local file or folder exists already in the file system. |
static java.lang.String |
FileGetBasename(java.lang.String name)
Retrieves only the basename (i.e. the name without path, extension and trailing dot) of the specified file (if it is a file), the name otherwise. |
static java.lang.String |
FileGetName(java.lang.String name)
Retrieves the name of the specified file (including extension). |
static java.lang.String |
FileGetPathOnly(java.lang.String name)
Retrieves the folder path to the specified file (if it is a file), otherwise returns the argument unaltered. |
static java.lang.String |
filterCSSExcluding(java.lang.String src,
java.util.List filter)
Filter the passed string of CSS property definitions so that it contains all properties not matching one of the elements in the Sequence of filter string. |
static java.lang.String |
filterCSSIncluding(java.lang.String src,
java.util.List filter)
Filter the passed string of CSS property definitions so that it contains all properties matching one of the elements in the Sequence of filter string. |
static java.lang.String |
getRealmValue(java.lang.String pipelineInstanceId,
java.lang.String realm,
java.lang.String name,
java.lang.String dflt)
This method retrieves the value of a variable in a specified realm. |
static int |
getUnicodeFromFontchar(java.lang.String pipelineInstanceId,
java.lang.String fontFamily,
int index)
This method tries to retrieve the Unicode codepoint equivalent of character index in font fontFamily. |
static int |
getUnicodeFromFontchar(java.lang.String pipelineUID,
java.lang.String fontFamily,
java.lang.String string)
|
static java.lang.String |
getVersion()
retrieves version information |
static java.lang.String |
localToURL(java.lang.String local)
Returns the URL representation of the passed local filename. |
static void |
main(java.lang.String[] args)
Extension function test method |
static java.lang.String |
makeValidXML_ID(java.lang.String src)
Transform a passed string in such a way that the result conforms to the rules for an XML 1.0 'Name' (as used e.g. for element names or xml:id). |
static java.lang.String |
makeValidXMLName(java.lang.String src)
Transform a passed string in such a way that the result conforms to the rules for an XML 1.0 'Name' (as used e.g. for element names or xml:id). |
static double |
multiplyLength(java.lang.String length,
double factor,
java.lang.String resultDimension)
Multiply an absolute length by some factor. |
static int |
parseInteger(java.lang.String numberstring,
int radix)
This method parses a string into an integer using the specified numbering base. |
static org.w3c.dom.DocumentFragment |
parsePersonname(java.lang.String s)
SAXON EXTENSION function: parse a string into a personname document fragment. |
static void |
setRealmValue(java.lang.String pipelineInstanceId,
java.lang.String realm,
java.lang.String name,
java.lang.String value)
This method sets a value in the specified realm. |
static double |
subtractLengths(java.lang.String length1,
java.lang.String length2,
java.lang.String resultDimension)
Subtracts two absolute length values, even if using different dimensions. |
static java.lang.String |
toHexString(long value)
This method converts the passed long value to its corresponding representation as a string of hexadecimal digits. |
static java.lang.String |
toHexString(long value,
int length)
This method converts the passed long value to its corresponding representation as a string of hexadecimal digits. |
static java.lang.String |
url2xml(java.lang.String url)
This method parses a passed URL into its constituents and returns a string of XML source code that encapsulates the various parts into appropriate elements. |
static java.lang.String |
URLToLocal(java.lang.String url)
Returns the local file name representation of the passed URL, if it's a file: URL; returns the normalized URL otherwise. |
static boolean |
writeLineToFile(java.lang.String url,
java.lang.String line,
boolean append)
Writes the passed String followed by the platform-specific new line character to the specified file, optionally appending the data (instead of replacing any existing data). |
static boolean |
writeLineToFile(java.lang.String url,
java.lang.String line,
boolean append,
java.lang.String encoding)
Writes the passed String followed by the platform-specific new line character to the specified file, optionally appending the data (instead of replacing any existing data). |
static boolean |
writeStringToFile(java.lang.String url,
java.lang.String data,
boolean append)
Writes the passed String to the specified file, optionally appending the data (instead of replacing any existing data). |
static boolean |
writeStringToFile(java.lang.String url,
java.lang.String data,
boolean append,
java.lang.String encoding)
Writes the passed String to the specified file, optionally appending the data (instead of replacing any existing data). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ExtensionFunctions()
| Method Detail |
|---|
public static java.lang.String emptyString(java.lang.String whatever)
whatever -
public static java.lang.String emptyString(boolean whatever)
whatever -
public static java.lang.String localToURL(java.lang.String local)
local - the file name in local format
public static java.lang.String URLToLocal(java.lang.String url)
url - the file name in URL format
public static boolean FileExists(java.lang.String name)
name - the file to test for in URL format
public static java.lang.String FileGetBasename(java.lang.String name)
name - the absolute file name in either URL or local notation
public static java.lang.String FileGetName(java.lang.String name)
name - the absolute file name in either URL or local notation
public static java.lang.String FileGetPathOnly(java.lang.String name)
name - the absolute file name in either URL or local notation
public static java.lang.String FileCalcAbsolutePath(java.lang.String basePath,
java.lang.String relativePath)
FileCalcAbsolutePath( "/usr/test/dir/", "../" ) returns "/usr/test/" (incl.
trailing folder separator).
basePath - the basepath where relativePath should be interpreted relative torelativePath - the relative path to make absolute with respect to the base path. If it is already absolute, it
is returned unaltered.
public static java.lang.String FileCalcRelativePath(java.lang.String basePath,
java.lang.String destPath)
basePath - the path where we start navigationdestPath - the path where we want to be
public static double addLengths(java.lang.String length1,
java.lang.String length2,
java.lang.String resultDimension)
length1 - the first length, e.g. "2mm"length2 - the second length to add, e.g. "3.67in"resultDimension - the dimension the result should be returned in, e.g. "cm"
public static double convertLength(java.lang.String length,
java.lang.String resultDimension)
length - the first length, e.g. "2mm"resultDimension - the dimension the result should be returned in, e.g. "in"
public static double absolutizeLength(java.lang.String length,
java.lang.String fontsize,
java.lang.String referenceValue,
java.lang.String resultDimension)
length - the specified length, e.g. "2mm" or "100%" or "1.2em"fontsize - the current fontsizereferenceValue - the reference value for percent specificationsresultDimension - the dimension the result should be returned in, e.g. "in"
public static double subtractLengths(java.lang.String length1,
java.lang.String length2,
java.lang.String resultDimension)
length1 - the first length, e.g. "2mm"length2 - the length to subtract from length1, e.g. "3.67in"resultDimension - the dimension the result should be returned in, e.g. "cm"
public static double multiplyLength(java.lang.String length,
double factor,
java.lang.String resultDimension)
length - the first length, e.g. "2mm"factor - the factor to multiply the length with, e.g. "2.54"resultDimension - the dimension the result should be returned in, e.g. "cm"
public static java.lang.String makeValidXMLName(java.lang.String src)
:'
will not be allowed by this function, as it has special meaning in XML Namespaces. Therefore, consider
the passed string as only the local name of an element.
Important Note: This method does not guarantee that for different source
strings the output will be different as well! For example, both 1elem and _1elem will be converted
to _1elem: The first will be modified by prepending a '_', while the second is already a valid
XML Name and therefore passed unchanged.
src - the source string
Name production.public static java.lang.String makeValidXML_ID(java.lang.String src)
makeValidXMLName(), but additionally allows the colon character ':' .
Important Note: This method does not guarantee that for different source
strings the output will be different as well! For example, both 1elem and _1elem will be converted
to _1elem: The first will be modified by prepending a '_', while the second is already a valid
XML Name and therefore passed unchanged.
src - the source string
Name production.
public static java.lang.String filterCSSExcluding(java.lang.String src,
java.util.List filter)
Filter the passed string of CSS property definitions so that it contains all properties not matching one of the elements in the Sequence of filter string. For the string sequence of filter, you either pass the (unquoted) full property name, or you can use the '*' qualifier to be used after some prefix. E.g. to filter out all Mozilla-proprietary CSS properties, use a filter sequence of ('-moz-*').
Example:
ilext:filterCSSExcluding( @style, (, 'width', '-moz-*') ) removes the width property and all
properties starting with -moz- from the property list string in the style attribute of the context element.
src - the source string, consisting of property definitionsfilter - a sequence of filter strings
public static java.lang.String filterCSSIncluding(java.lang.String src,
java.util.List filter)
Filter the passed string of CSS property definitions so that it contains all properties matching one of the elements in the Sequence of filter string. For the string sequence of filter, you either pass the (unquoted) full property name, or you can use the '*' qualifier to be used after some prefix. E.g. to only retain all Mozilla-proprietary CSS properties, use a filter sequence of ('-moz-*').
Example:
ilext:filterCSSIncluding( @style, (, 'width', '-moz-*') ) removes all properties except for the
width property and all properties starting with -moz- from the property list string
in the style attribute of the context element.
src - the source string, consisting of property definitionsfilter - a sequence of filter strings
public static java.lang.String toHexString(long value)
value - the value to encode
public static java.lang.String toHexString(long value,
int length)
value - the value to encodelength - the expected length in characters of the resulting string
public static int parseInteger(java.lang.String numberstring,
int radix)
numberstring - the integer number to convert as string. Leading zeroes are allowed.radix - the numbering system base to use. This is 10 for decimal system, 16 for hex numbers, 8 for octal numbers, and 2 for binary numbers (consisting of 0 and 1 digits).
java.lang.NumberFormatException - when the string does not represent a parseable number in the specified numbering systempublic static org.w3c.dom.DocumentFragment parsePersonname(java.lang.String s)
public static java.lang.String getVersion()
public static boolean writeStringToFile(java.lang.String url,
java.lang.String data,
boolean append)
url - the file to write todata - the data to writeappend - when true, data is appended to existing file
public static boolean writeStringToFile(java.lang.String url,
java.lang.String data,
boolean append,
java.lang.String encoding)
url - the file to write todata - the data to writeappend - when true, data is appended to existing fileencoding - the Java encoding name to use for writing; UTF-8 when the empty string
public static boolean writeLineToFile(java.lang.String url,
java.lang.String line,
boolean append)
url - the file to write toline - the line of text to writeappend - when true, data is appended to existing file
public static boolean writeLineToFile(java.lang.String url,
java.lang.String line,
boolean append,
java.lang.String encoding)
url - the file to write toline - the line of text to writeappend - when true, data is appended to existing fileencoding - the Java encoding name to use for writing; UTF-8 when the empty stringpublic static java.lang.String url2xml(java.lang.String url)
This method parses a passed URL into its constituents and returns a string of XML source code that encapsulates the various parts into appropriate elements. You can use e.g. saxon:parse() to make an XML document from the returned string and extract parts of the tree using standard XSLT code.
Example:
http://login:passwd@infinity-loop.de:1234/dir1/dir2/file.html?par1&par2=v2&par3=v3#fragment-id
will be translated into a string like
<url source="http://login:passwd@infinity-loop.de:1234/dir1/dir2/file.html?par1&par2=v2&par3=v3#fragment-id"> <protocol>http</protocol> <default-port>80</default-port> <authority> <literal>login:passwd@infinity-loop.de:1234</literal> <user-info> <literal>login:passwd</literal> <login>login</login> <password>passwd</password> </user-info> <host>infinity-loop.de</host> <port>1234</port> </authority> <path> <literal>/dir1/dir2/file.html</literal> <elem index="1">dir1</elem> <elem index="2">dir2</elem> <elem index="3">file.html</elem> </path> <query> <literal>par1&par2=v2&par3=v3</literal> <param index="1" name="par1" value="" /> <param index="2" name="par2" value="v2" /> <param index="3" name="par3" value="v3" /> </query> <fragment>fragment-id</fragment> </url>
url - the URL to parse
public static java.lang.String calcCALSTablegrid(java.lang.String xml)
public static java.lang.String calcTableColgroup(java.lang.String tableXMLCode)
tableXMLCode - the XML code for the table to calculate the column widths for. We recognize table, tr, th and td.
public static java.lang.String getRealmValue(java.lang.String pipelineInstanceId,
java.lang.String realm,
java.lang.String name,
java.lang.String dflt)
${pipeline:PipelineInstanceId}.
pipelineInstanceId - the pipeline's instance idrealm - the variable realm to retrieve a value from, e.g. application, pipeline or javapropertyname - the name of the variabledflt - the default value to be returned when either the pipeline object can not be retrieved or the specified variable does not exist
public static void setRealmValue(java.lang.String pipelineInstanceId,
java.lang.String realm,
java.lang.String name,
java.lang.String value)
${pipeline:PipelineInstanceId}.
pipelineInstanceId - the pipeline's instance idrealm - the variable realm to set the value in. Currently, this can only be the single realm value pipelinename - the name of the variablevalue - the value to be set
java.lang.Exception - when the value could not be set
public static int getUnicodeFromFontchar(java.lang.String pipelineInstanceId,
java.lang.String fontFamily,
int index)
index in font fontFamily. You must supply the pipeline's instance id to this
function, which you should pass as a parameter to your stylesheet. The pipeline's instance id can be retrieved using ${pipeline:PipelineInstanceId}. The method consults
the pipeline's font configuration setting and uses the resolution fallbacks described in the upCast manual.
When there is no Unicode codepoint equivalent for the font+character index passed in, the codepoint for the Unicode replacement character U+FFFD (65533) is returned.
pipelineInstanceId - the pipeline's instance idfontFamily - the font family name the character index is inindex - the character index in the specified font in the range from 0..255 for single-byte characters. Values greater than 255 are interpreted as meaning a double-byte
character sequence where bits 15..8 are the first byte and bits 7..0 are the second byte of the DBCS.
public static int getUnicodeFromFontchar(java.lang.String pipelineUID,
java.lang.String fontFamily,
java.lang.String string)
public static void main(java.lang.String[] args)
args -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||