java-utilities.xsl revision 1008
1008N/A ! The contents of this file are subject to the terms of the 1008N/A ! Common Development and Distribution License, Version 1.0 only 1008N/A ! (the "License"). You may not use this file except in compliance 1008N/A ! You can obtain a copy of the license at 1008N/A ! See the License for the specific language governing permissions 1008N/A ! and limitations under the License. 1008N/A ! When distributing Covered Code, include this CDDL HEADER in each 1008N/A ! file and include the License file at 1008N/A ! add the following below this CDDL HEADER, with the fields enclosed 1008N/A ! by brackets "[]" replaced with your own identifying information: 1008N/A ! Portions Copyright [yyyy] [name of copyright owner] 1008N/A ! Portions Copyright 2007 Sun Microsystems, Inc. 1008N/A<
xsl:
stylesheet version="1.0" 1008N/A This XSLT file contains utility templates which can be used for any 1008N/A <
xsl:
output method="text" encoding="us-ascii" />
1008N/A Add a copyright notice to the top of a Java source file. 1008N/A TODO: it would be nice to generate the copyright year automatically. 1008N/A <
xsl:
template name="copyright-notice">
1008N/A ' * CDDL HEADER START
', 1008N/A ' * The contents of this file are subject to the terms of the
', 1008N/A ' * Common Development and Distribution License, Version 1.0 only
', 1008N/A ' * (the "License"). You may not use this file except in compliance
', 1008N/A ' * with the License.
', 1008N/A ' * You can obtain a copy of the license at
', 1008N/A ' * See the License for the specific language governing permissions
', 1008N/A ' * and limitations under the License.
', 1008N/A ' * When distributing Covered Code, include this CDDL HEADER in each
', 1008N/A ' * file and include the License file at
', 1008N/A ' * add the following below this CDDL HEADER, with the fields enclosed
', 1008N/A ' * by brackets "[]" replaced with your own identifying information:
', 1008N/A ' * Portions Copyright [yyyy] [name of copyright owner]
', 1008N/A ' * Portions Copyright 2007 Sun Microsystems, Inc.
', 1008N/A Convert an entity or property ID to a Java mixed-cased name. 1008N/A For example, the string "my-string-value" will be converted to 1008N/A the string "myStringValue". 1008N/A The ID string to be converted to a Java name. 1008N/A <
xsl:
template name="name-to-java">
1008N/A <
xsl:
if test="string-length($value)">
1008N/A <
xsl:
when test="contains($value, '-')">
1008N/A select="substring-before($value, '-')" />
1008N/A select="substring-after($value, '-')" />
1008N/A <
xsl:
call-
template name="to-title-case">
1008N/A <
xsl:
with-
param name="value" select="$head" />
1008N/A <
xsl:
call-
template name="name-to-java">
1008N/A <
xsl:
with-
param name="value" select="$tail" />
1008N/A <
xsl:
call-
template name="to-title-case">
1008N/A <
xsl:
with-
param name="value" select="$value" />
1008N/A Convert an entity or property ID to a Java constant name. 1008N/A For example, the string "my-string-value" will be converted to 1008N/A the string "MY_STRING_VALUE". 1008N/A The ID string to be converted to a Java constant. 1008N/A <
xsl:
template name="name-to-java-constant">
1008N/A 'abcdefghijklmnopqrstuvwxyz-', 1008N/A 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')" />
1008N/A Add a Java comment. This template handles two levels of 1008N/A indentation: the indentation string for the first line, and a 1008N/A second indentation string used for subsequent lines. The template 1008N/A will output the content wrapping at the nearest word boundary to 1008N/A The indentation text used for the first line. 1008N/A The indentation text used for all lines except 1008N/A the first - defaults to the value of indent-text. 1008N/A The content to be output in the comment. 1008N/A <
xsl:
template name="add-java-comment">
1008N/A <
xsl:
param name="indent-text" />
1008N/A <
xsl:
param name="indent-text2" select="$indent-text" />
1008N/A <
xsl:
param name="content" />
1008N/A <
xsl:
call-
template name="format-text">
1008N/A <
xsl:
with-
param name="indent-text" select="$indent-text" />
1008N/A <
xsl:
with-
param name="indent-text2" select="$indent-text2" />
1008N/A <
xsl:
with-
param name="wrap-column" select="'70'" />
1008N/A <
xsl:
with-
param name="content" select="$content" />
1008N/A Utility template for removing duplicate values from a node-set. 1008N/A This template is based on the version published on the XSLT site. 1008N/A It is not capable of normalizing nodes - so they must be 1008N/A pre-normalized before this template is called. 1008N/A @param nodes A node-set containing the duplicate nodes. 1008N/A <
xsl:
template name="set-distinct">
1008N/A <
xsl:
param name="nodes" select="/.." />
1008N/A <
xsl:
call-
template name="_set-distinct">
1008N/A <
xsl:
with-
param name="nodes" select="$nodes" />
1008N/A <!-- set-distinct helper template --> 1008N/A <
xsl:
template name="_set-distinct">
1008N/A <
xsl:
param name="nodes" select="/.." />
1008N/A <
xsl:
param name="distinct" select="/.." />
1008N/A <
xsl:
variable name="value" select="$nodes[1]" />
1008N/A <
xsl:
when test="$distinct[. = $value]">
1008N/A <
xsl:
call-
template name="_set-distinct">
1008N/A <
xsl:
with-
param name="distinct" select="$distinct" />
1008N/A <
xsl:
with-
param name="nodes" select="$nodes[position() > 1]" />
1008N/A <
xsl:
call-
template name="_set-distinct">
1008N/A <
xsl:
with-
param name="distinct" select="$distinct | $nodes[1]" />
1008N/A <
xsl:
with-
param name="nodes" select="$nodes[position() > 1]" />
1008N/A <
xsl:
apply-
templates select="$distinct" mode="set-distinct" />
1008N/A <!-- set-distinct helper template --> 1008N/A <
xsl:
template match="node()|@*" mode="set-distinct">
1008N/A Generate a set of import statements. 1008N/A This template takes a result tree fragment as a parameter 1008N/A containing elements of the form: 1008N/A This template will normalize each element and remove duplicates 1008N/A before generating the output. 1008N/A @param imports The result tree fragment containing the import elements. 1008N/A <
xsl:
template name="generate-import-statements">
1008N/A <
xsl:
param name="imports" select="/.." />
1008N/A Normalize the import elements since the set-distinct 1008N/A template cannot handle additional whitespace 1008N/A <
xsl:
variable name="normalized-imports">
1008N/A <
xsl:
for-
each select="exsl:node-set($imports)/import">
1008N/A <
xsl:
element name="import">
1008N/A <
xsl:
value-
of select="normalize-space()" />
1008N/A <
xsl:
variable name="unique">
1008N/A <
xsl:
call-
template name="set-distinct">
1008N/A <
xsl:
with-
param name="nodes" 1008N/A select="exsl:node-set($normalized-imports)/import" />
1008N/A Now output the import statements 1008N/A <
xsl:
for-
each select="exsl:node-set($unique)/import">
1008N/A <
xsl:
sort select="normalize-space()" />
1008N/A select="concat('import ', normalize-space(),';
')" />