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