java-utilities.xsl revision 4a622c45ad6426287954754f34fc3ab8a4b9c2c5
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! CDDL HEADER START
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! The contents of this file are subject to the terms of the
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! Common Development and Distribution License, Version 1.0 only
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! (the "License"). You may not use this file except in compliance
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! with the License.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! You can obtain a copy of the license at
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! See the License for the specific language governing permissions
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! and limitations under the License.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! When distributing Covered Code, include this CDDL HEADER in each
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! file and include the License file at
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! add the following below this CDDL HEADER, with the fields enclosed
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! by brackets "[]" replaced with your own identifying information:
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! Portions Copyright [yyyy] [name of copyright owner]
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! CDDL HEADER END
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ! Portions Copyright 2007 Sun Microsystems, Inc.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift This XSLT file contains utility templates which can be used for any
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift generating Java code.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:output method="text" encoding="us-ascii" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Add a copyright notice to the top of a Java source file.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift TODO: it would be nice to generate the copyright year automatically.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="concat('/*
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * CDDL HEADER START
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * The contents of this file are subject to the terms of the
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * Common Development and Distribution License, Version 1.0 only
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * (the "License"). You may not use this file except in compliance
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * with the License.
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * You can obtain a copy of the license at
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * trunk/opends/resource/legal-notices/OpenDS.LICENSE
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * See the License for the specific language governing permissions
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * and limitations under the License.
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * When distributing Covered Code, include this CDDL HEADER in each
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * file and include the License file at
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * add the following below this CDDL HEADER, with the fields enclosed
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * by brackets "[]" replaced with your own identifying information:
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * Portions Copyright [yyyy] [name of copyright owner]
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * CDDL HEADER END
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' * Portions Copyright 2007 Sun Microsystems, Inc.
',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ' */
')" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Convert an entity or property ID to a Java mixed-cased name.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift For example, the string "my-string-value" will be converted to
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift the string "myStringValue".
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift The ID string to be converted to a Java name.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="substring-before($value, '-')" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="substring-after($value, '-')" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="value" select="$head" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="value" select="$tail" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="value" select="$value" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Convert an entity or property ID to a Java constant name.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift For example, the string "my-string-value" will be converted to
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift the string "MY_STRING_VALUE".
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift The ID string to be converted to a Java constant.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="translate($value,
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift 'abcdefghijklmnopqrstuvwxyz-',
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Add a Java comment. This template handles two levels of
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift indentation: the indentation string for the first line, and a
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift second indentation string used for subsequent lines. The template
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift will output the content wrapping at the nearest word boundary to
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @param indent-text
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift The indentation text used for the first line.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @param indent-text2
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift The indentation text used for all lines except
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift the first - defaults to the value of indent-text.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @param content
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift The content to be output in the comment.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:param name="indent-text2" select="$indent-text" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="indent-text" select="$indent-text" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="indent-text2" select="$indent-text2" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="wrap-column" select="'70'" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="content" select="$content" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Add a Java comment at the specified indentation.
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift This template handles embedded newline characters
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift and will also indent individual lines according to
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift the number of leading spaces they contain.
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift @param indent
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift The indentation column for the comment.
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift @param content
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift The content to be output in the comment.
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Compute the indentation string. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent" select="$indent + 1" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Output the comment header. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent" select="$indent" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Output the comment contents. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:call-template name="add-java-comment-line">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text" select="$indent-text" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="content" select="$content" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Output the header trailer. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:value-of select="concat($indent-text, '/
')" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Creates a padding string of the required length. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent" select="$indent - 1" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Get the next line. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="substring-before($content, '
')" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="substring-after($content, '
')" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Case #1 - content is empty
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Case #2 - no newline
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Case #3 - contains a new line
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Case #3.1 - begins with newline
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift Case #3.2 - ends with newline
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Do nothing. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:when test="not(contains($content, '
'))">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Single line of text. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text" select="$indent-text" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="line" select="$content" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Output the first line and repeat for remaining lines. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text" select="$indent-text" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:call-template name="add-java-comment-line">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text" select="$indent-text" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="content" select="$tail" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Formats a line of comment text. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- First count the number of leading spaces to determine the indent. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:call-template name="java-format-line-help">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="substring($line, $leading-spaces + 1)" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent" select="$leading-spaces" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- We need to use indent2 for certain javadoc keywords. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:when test="starts-with($content, '@return')">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:value-of select="concat($padding1, ' ')" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Now output the line, wrapping as necessary. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text" select="$padding1" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="indent-text2" select="$padding2" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="wrap-column" select="'70'" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="content" select="$content" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <!-- Determines the number of leading spaces in the provided string. -->
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:call-template name="java-format-line-help">
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="substring-after($line, ' ')" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift <xsl:with-param name="count" select="$count + 1" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Utility template for removing duplicate values from a node-set.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift This template is based on the version published on the XSLT site.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift It is not capable of normalizing nodes - so they must be
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift pre-normalized before this template is called.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @param nodes A node-set containing the duplicate nodes.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="nodes" select="$nodes" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <!-- set-distinct helper template -->
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:variable name="value" select="$nodes[1]" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:with-param name="distinct" select="$distinct" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="$nodes[position() > 1]" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="$distinct | $nodes[1]" />
4a622c45ad6426287954754f34fc3ab8a4b9c2c5matthew_swift select="$nodes[position() > 1]" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:apply-templates select="$distinct" mode="set-distinct" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <!-- set-distinct helper template -->
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:template match="node()|@*" mode="set-distinct">
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Generate a set of import statements.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift This template takes a result tree fragment as a parameter
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift containing elements of the form:
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <import>java.net.InetAddress</import>
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <import>...</import>
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift This template will normalize each element and remove duplicates
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift before generating the output.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @param imports The result tree fragment containing the import elements.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:template name="generate-import-statements">
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Normalize the import elements since the set-distinct
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift template cannot handle additional whitespace
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:for-each select="exsl:node-set($imports)/import">
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Now remove the duplicates
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="exsl:node-set($normalized-imports)/import" />
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift Now output the import statements
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift <xsl:for-each select="exsl:node-set($unique)/import">
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift select="concat('import ', normalize-space(),';
')" />