Difference between revisions of "XSLTUtils"
(Created page with "Class FQN: '''it.greenvulcano.util.xml.XSLTUtils''' ==Following the XSLTUtils public static methods== <syntaxhighlight lang="java5"> /** * @param str * @return the string in upp...") |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Class FQN: '''it.greenvulcano.util.xml.XSLTUtils''' | Class FQN: '''it.greenvulcano.util.xml.XSLTUtils''' | ||
− | == | + | ==XSLTUtils public static methods== |
+ | *String manipulation: | ||
+ | |||
<syntaxhighlight lang="java5"> | <syntaxhighlight lang="java5"> | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @return the string in upper case | + | * @return the string in upper case |
− | */ | + | */ |
public static synchronized String upperCase(String str) | public static synchronized String upperCase(String str) | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @return the string in lower case | + | * @return the string in lower case |
− | */ | + | */ |
public static synchronized String lowerCase(String str) | public static synchronized String lowerCase(String str) | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @param width | + | * @param width |
− | * @param padding | + | * @param padding |
− | * @return the string left filled with padding character passed | + | * @return the string left filled with padding character passed |
− | */ | + | */ |
public static synchronized String leftPad(String str, int width, char padding) | public static synchronized String leftPad(String str, int width, char padding) | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @param width | + | * @param width |
− | * @param padding | + | * @param padding |
− | * @return the string right filled with padding character passed | + | * @return the string right filled with padding character passed |
− | */ | + | */ |
public static synchronized String rightPad(String str, int width, char padding) | public static synchronized String rightPad(String str, int width, char padding) | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @return the trimmed string | + | * @return the trimmed string |
− | * | + | * |
− | * @see java.lang.String#trim() | + | * @see java.lang.String#trim() |
− | */ | + | */ |
public static synchronized String trim(String str) | public static synchronized String trim(String str) | ||
/** | /** | ||
− | * @param str | + | * @param str |
− | * @param find | + | * @param find |
− | * @param replace | + | * @param replace |
− | * @return the replaced string | + | * @return the replaced string |
− | */ | + | */ |
public static String replace(String str, String find, String replace) | public static String replace(String str, String find, String replace) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | *Serialization: | ||
+ | <syntaxhighlight lang="java5"> | ||
/** | /** | ||
− | * | + | * Serialize a given DOM to an XML string, using a specified character |
− | */ | + | * encoding for the output XML string. If the specified encoding is not |
+ | * supported or is null, defaults on UTF-8. Use as default omit_xml_decl | ||
+ | * property false, as default indent property falseIt. uses JAXP XSL APIs. | ||
+ | * | ||
+ | * @param doc | ||
+ | * The input DOM | ||
+ | * @param encoding | ||
+ | * The desiderd character encoding for the output XML string | ||
+ | * @return the serialized document (as a <tt>String</tt> encoded using the | ||
+ | * specified character encoding) | ||
+ | * @throws XMLUtilsException | ||
+ | * on errors | ||
+ | */ | ||
+ | |||
public static String serializeNode(Node node, String encoding) | public static String serializeNode(Node node, String encoding) | ||
+ | </syntaxhighlight> | ||
+ | *Date/time manipulation: | ||
+ | |||
+ | <syntaxhighlight lang="java5"> | ||
/** | /** | ||
− | * @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String) | + | * @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String) |
− | */ | + | */ |
public static String convertDate(String date, String formatIn, String formatOut) | public static String convertDate(String date, String formatIn, String formatOut) | ||
/** | /** | ||
− | * @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String, String, String) | + | * @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String, String, String) |
− | */ | + | */ |
public static String convertDate(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut) | public static String convertDate(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut) | ||
/** | /** | ||
− | * @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String) | + | * @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String) |
− | */ | + | */ |
public static String nowToString(String formatOut) | public static String nowToString(String formatOut) | ||
/** | /** | ||
− | * @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String, String) | + | * @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String, String) |
− | */ | + | */ |
− | public static String nowToString(String tZoneOut, | + | public static String nowToString(String formatOut, String tZoneOut) |
+ | </syntaxhighlight> | ||
+ | |||
+ | ==Example== | ||
+ | An example of utilization of the XSLTUtils: | ||
+ | <syntaxhighlight lang="xml"> | ||
+ | <xsl:element name="formattedDate"> | ||
+ | <xsl:value-of select="java:it.greenvulcano.util.xml.XSLTUtils.convertDate(col[7], 'yyyyMMdd HH:mm:ss', 'dd/MM/yyyy HH:mm:ss')"/> | ||
+ | </xsl:element> | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 11:31, 19 July 2013
Class FQN: it.greenvulcano.util.xml.XSLTUtils
XSLTUtils public static methods
- String manipulation:
/**
* @param str
* @return the string in upper case
*/
public static synchronized String upperCase(String str)
/**
* @param str
* @return the string in lower case
*/
public static synchronized String lowerCase(String str)
/**
* @param str
* @param width
* @param padding
* @return the string left filled with padding character passed
*/
public static synchronized String leftPad(String str, int width, char padding)
/**
* @param str
* @param width
* @param padding
* @return the string right filled with padding character passed
*/
public static synchronized String rightPad(String str, int width, char padding)
/**
* @param str
* @return the trimmed string
*
* @see java.lang.String#trim()
*/
public static synchronized String trim(String str)
/**
* @param str
* @param find
* @param replace
* @return the replaced string
*/
public static String replace(String str, String find, String replace)
- Serialization:
/**
* Serialize a given DOM to an XML string, using a specified character
* encoding for the output XML string. If the specified encoding is not
* supported or is null, defaults on UTF-8. Use as default omit_xml_decl
* property false, as default indent property falseIt. uses JAXP XSL APIs.
*
* @param doc
* The input DOM
* @param encoding
* The desiderd character encoding for the output XML string
* @return the serialized document (as a <tt>String</tt> encoded using the
* specified character encoding)
* @throws XMLUtilsException
* on errors
*/
public static String serializeNode(Node node, String encoding)
- Date/time manipulation:
/**
* @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String)
*/
public static String convertDate(String date, String formatIn, String formatOut)
/**
* @see it.greenvulcano.util.xml.XSLTUtils#convertDate(String, String, String, String, String)
*/
public static String convertDate(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut)
/**
* @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String)
*/
public static String nowToString(String formatOut)
/**
* @see it.greenvulcano.util.xml.XSLTUtils#nowToString(String, String)
*/
public static String nowToString(String formatOut, String tZoneOut)
Example
An example of utilization of the XSLTUtils:
<xsl:element name="formattedDate">
<xsl:value-of select="java:it.greenvulcano.util.xml.XSLTUtils.convertDate(col[7], 'yyyyMMdd HH:mm:ss', 'dd/MM/yyyy HH:mm:ss')"/>
</xsl:element>