Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-04-28 15:35:24 -0400
committerpelder2008-04-28 15:35:24 -0400
commit1d9958f895f9125728a27eea5ac698a5f126c766 (patch)
treeeb6a3e026f01a09c39dd6fb4a0e3e4a34c2d64b0
parent235d78e10b1fbb70cfa9f6b14a8bd685fa1fdffd (diff)
downloadorg.eclipse.jet-1d9958f895f9125728a27eea5ac698a5f126c766.tar.gz
org.eclipse.jet-1d9958f895f9125728a27eea5ac698a5f126c766.tar.xz
org.eclipse.jet-1d9958f895f9125728a27eea5ac698a5f126c766.zip
[191228] Provide tools to aid in indenting generated content.
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/formatTags/indentTag.html89
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/formatTags/overview.html7
-rw-r--r--doc/org.eclipse.jet.doc/tocformatTags.xml1
-rw-r--r--plugins/org.eclipse.jet/plugin.xml27
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java105
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/TagFactory.java37
8 files changed, 251 insertions, 18 deletions
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/indentTag.html b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/indentTag.html
new file mode 100644
index 0000000..5241cdc
--- /dev/null
+++ b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/indentTag.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<HEAD>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META name="GENERATOR" content="IBM Software Development Platform">
+<link rel="STYLESHEET" href="../../../book.css" charset="ISO-8859-1" type="text/css"/>
+<TITLE>&lt;f:indent&gt; - Standard JET2 Format Tags</TITLE>
+</HEAD>
+<BODY>
+<TABLE border="0" cellpadding="0" cellspacing="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH align="left">
+ <P>&lt;f:indent&gt;</P></TH>
+ <TH align="right"><A href="overview.html">Standard JET2 Format Tags</A></TH>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<P><B>indent</B></P>
+<P><P> Indent the tag contents the specified number of times.<P> </P>
+<HR>
+<TABLE border="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Tag Summary</TH></TR>
+ <TR>
+ <TD width="10%">required</TD>
+ <TD><SPAN style="font-family: monospace">
+ &lt;f:indent text=&quot;<I>value</I>&quot;&gt;<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;<I>content consumed by tag evaluation</I><BR>
+ &lt;/f:indent&gt;
+ </SPAN></TD>
+ </TR>
+ <TR>
+ <TD width="10%">full tag</TD>
+ <TD><SPAN style="font-family: monospace">
+ &lt;f:indent text=&quot;<I>value</I>&quot; depth=&quot;<I>value</I>&quot;&gt;<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;<I>content consumed by tag evaluation</I><BR>
+ &lt;/f:indent&gt;
+ </SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Required Attributes</TH></TR>
+ <TR>
+ <TD width="10%">text</TD>
+ <TD><BR> Specifies the indentation text.<BR> </TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Optional Attributes</TH></TR>
+ <TR>
+ <TR>
+ <TD width="10%">depth</TD>
+ <TD><BR> Specify the depth of indentation. The text specified in the text attribute is inserted the number of times specified by depth. Default value is one (1).<BR> </TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Example</TH></TR>
+ <TR>
+ <TD width="10%"></TD>
+ <TD><SPAN style="font-family: monospace">
+<!-- Begin indent example -->
+ &lt;%--Wrap text in Java/C++ style comment--%&gt;<br>
+ &lt;f:indent text=&quot;&nbsp;&nbsp;&nbsp;&nbsp;&quot; depth="2"&gt;<br>
+ /*<br>
+ &lt;f:indent text=" * "&gt;&lt;c:get select="$myModel/@description"/&gt;&lt;/f:indent&gt;<br>
+ &nbsp;*/<br>
+ &lt;/f:indent&gt;
+<!-- End indent example -->
+</SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<P></P></BODY>
+</HTML>
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/overview.html b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/overview.html
index 0103933..b9ee76c 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/overview.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/overview.html
@@ -32,6 +32,13 @@
</TD>
</TR>
<TR>
+ <TD width="10%"><A href="indentTag.html">&lt;f:indent&gt;</A></TD>
+ <TD><!-- Begin indent description -->
+ <P> Indent the tag contents the specified number of times
+ <!-- End indent description -->
+ </TD>
+ </TR>
+ <TR>
<TD width="10%"><A href="lcTag.html">&lt;f:lc&gt;</A></TD>
<TD><!-- Begin lc description -->
<P> Convert the tag contents to lower case
diff --git a/doc/org.eclipse.jet.doc/tocformatTags.xml b/doc/org.eclipse.jet.doc/tocformatTags.xml
index 9ce4fb9..3ae4997 100644
--- a/doc/org.eclipse.jet.doc/tocformatTags.xml
+++ b/doc/org.eclipse.jet.doc/tocformatTags.xml
@@ -4,6 +4,7 @@
<toc label="Standard JET2 Format Tags" link_to="toc.xml#tagReference">
<topic label="Standard JET2 Format Tags" href="references/taglibs/formatTags/overview.html" >
<topic label="f:formatNow" href="references/taglibs/formatTags/formatNowTag.html"/>
+ <topic label="f:indent" href="references/taglibs/formatTags/indentTag.html"/>
<topic label="f:lc" href="references/taglibs/formatTags/lcTag.html"/>
<topic label="f:milliseconds" href="references/taglibs/formatTags/millisecondsTag.html"/>
<topic label="f:replaceAll" href="references/taglibs/formatTags/replaceAllTag.html"/>
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 1e3bc23..3713ed9 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -911,7 +911,32 @@ This tag may occur only once in a template.
<description>The pattern with which to format the current data and time. See documentation for the Java class java.util.SimpleDateFormat for more details.</description>
</attribute>
<description>Formats and writes out the current date and time</description>
- </emptyTag><functionTag class="org.eclipse.jet.internal.taglib.format.LowerCaseTag" name="lc">
+ </emptyTag>
+ <functionTag
+ allowAsEmpty="false"
+ class="org.eclipse.jet.internal.taglib.format.IndentTag"
+ name="indent"
+ whenContainingLineIsEmpty="remove">
+ <description>
+ Indent the tag contents the specified number of times.
+ </description>
+ <attribute
+ name="depth"
+ type="string"
+ use="optional">
+ <description>
+ Specify the depth of indentation. The text specified in the text attribute is inserted the number of times specified by depth. Default value is one (1).
+ </description>
+ </attribute>
+ <attribute
+ name="text"
+ type="string"
+ use="required">
+ <description>
+ Specifies the indentation text.
+ </description>
+ </attribute>
+ </functionTag><functionTag class="org.eclipse.jet.internal.taglib.format.LowerCaseTag" name="lc">
<attribute name="offset" use="optional">
<description>
The starting offset (0-based) of the conversion. When omitted, 0 (the start of the content to be converted) is assumed.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
index 6453d83..79246c2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
@@ -124,6 +124,8 @@ public class JET2Messages extends NLS
public static String ImportsLocationTag_MissingImportsLocation;
+ public static String IndentTag_AttributeValueMustBeInteger;
+
public static String JET2Bundle_ErrorOpeningJar;
public static String JET2Bundle_CouldNotLoadLoader;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
index 653de2d..ceb26dd 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
@@ -114,6 +114,7 @@ LogTag_BadSeverity=Invalid severity: {0}
ImportsLocationTag_AllowedOnlyOnce=An occurence if this tag has already executed in this template. Only one is allowed.
ImportsLocationTag_MissingImportsLocation=There must be a an executed occurrence of the 'importsLocation' tag prior to this tag.
+IndentTag_AttributeValueMustBeInteger=Value of {0} attribute ({1}) must be an integer.
SafeCustomRuntimeTag_ErrorExecutingHandler=Error executing tag handler: {0}
TagFactoryImpl_TagCreateFailed=Failed to create tag {0} in tag library {1}
TagDefinitionImpl_MissingName=Missing attribute definition requires attribute ''name''. Extension {0} in plugin {1}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java
new file mode 100644
index 0000000..ac73d3d
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java
@@ -0,0 +1,105 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: IndentTag.java,v 1.1 2008/04/28 19:35:24 pelder Exp $
+ */
+package org.eclipse.jet.internal.taglib.format;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.taglib.AbstractFunctionTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Implement &lt;f:indent text="..." [depth="n"]&gt;content&lt;/f:indent&gt;
+ */
+public class IndentTag extends AbstractFunctionTag
+{
+
+ private static final String TEXT_ATTR = "text"; //$NON-NLS-1$
+ private static final String DEPTH_ATTR = "depth"; //$NON-NLS-1$
+ private static final String NL_REGEX = "([\\n][\\r]?|[\\r][\\n]?)"; //$NON-NLS-1$
+ private static final Pattern NL_PATTERN = Pattern.compile(NL_REGEX, Pattern.MULTILINE);
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.FunctionTag#doFunction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, java.lang.String)
+ */
+ public String doFunction(TagInfo td, JET2Context context, String bodyContent) throws JET2TagException
+ {
+ final String indentText = getAttribute(TEXT_ATTR);
+ final String depthValue = getAttribute(DEPTH_ATTR);
+ try
+ {
+ final int depth = depthValue == null ? 1 : Integer.decode(depthValue).intValue();
+ return indent(bodyContent, indentText, depth);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new JET2TagException(NLS.bind(JET2Messages.IndentTag_AttributeValueMustBeInteger, DEPTH_ATTR, depthValue));
+ }
+ }
+
+ public static String indent(String content, String indent, int depth) {
+ final String totalIndent = computeTotalIndent(indent, depth);
+ if(totalIndent.length() == 0) {
+ return content;
+ }
+ boolean indentIsWhitespace = totalIndent.matches("\\s*"); //$NON-NLS-1$
+
+ final Matcher matcher = NL_PATTERN.matcher(content);
+ final StringBuffer result = new StringBuffer(content.length() * 2); // a guess
+ int lineStart;
+ for(lineStart = 0; matcher.find(lineStart); lineStart = matcher.end()) {
+ String line = content.substring(lineStart, matcher.start());
+ if(line.length() > 0 || !indentIsWhitespace) {
+ result.append(totalIndent);
+ }
+ result.append(line);
+ result.append(NL);
+ lineStart = matcher.end();
+ }
+
+ // loook for final line without a NL character...
+ if(lineStart < content.length()) {
+ String line = content.substring(lineStart);
+ result.append(totalIndent).append(line);
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * @param indent
+ * @param depth
+ * @return
+ */
+ private static String computeTotalIndent(String indent, int depth)
+ {
+ final StringBuffer buffer = new StringBuffer(
+ depth * indent.length()
+ );
+ if(indent != null) {
+ for(int i = 0; i < depth; i++) {
+ buffer.append(indent);
+ }
+ }
+ return buffer.toString();
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/TagFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/TagFactory.java
index b7e64f3..f3a5df5 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/TagFactory.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/TagFactory.java
@@ -32,17 +32,18 @@ public class TagFactory implements TagInstanceFactory
*/
public TagFactory()
{
- tagOrdinalByName = new HashMap(9);
+ tagOrdinalByName = new HashMap(10);
tagOrdinalByName.put("formatNow",new Integer(1)); //$NON-NLS-1$
- tagOrdinalByName.put("lc",new Integer(2)); //$NON-NLS-1$
- tagOrdinalByName.put("milliseconds",new Integer(3)); //$NON-NLS-1$
- tagOrdinalByName.put("replaceAll",new Integer(4)); //$NON-NLS-1$
- tagOrdinalByName.put("strip",new Integer(5)); //$NON-NLS-1$
- tagOrdinalByName.put("uc",new Integer(6)); //$NON-NLS-1$
- tagOrdinalByName.put("unique",new Integer(7)); //$NON-NLS-1$
- tagOrdinalByName.put("uuid",new Integer(8)); //$NON-NLS-1$
- tagOrdinalByName.put("xpath",new Integer(9)); //$NON-NLS-1$
+ tagOrdinalByName.put("indent",new Integer(2)); //$NON-NLS-1$
+ tagOrdinalByName.put("lc",new Integer(3)); //$NON-NLS-1$
+ tagOrdinalByName.put("milliseconds",new Integer(4)); //$NON-NLS-1$
+ tagOrdinalByName.put("replaceAll",new Integer(5)); //$NON-NLS-1$
+ tagOrdinalByName.put("strip",new Integer(6)); //$NON-NLS-1$
+ tagOrdinalByName.put("uc",new Integer(7)); //$NON-NLS-1$
+ tagOrdinalByName.put("unique",new Integer(8)); //$NON-NLS-1$
+ tagOrdinalByName.put("uuid",new Integer(9)); //$NON-NLS-1$
+ tagOrdinalByName.put("xpath",new Integer(10)); //$NON-NLS-1$
}
public CustomTag createCustomTag(String name)
@@ -52,21 +53,23 @@ public class TagFactory implements TagInstanceFactory
switch(ordinal == null ? 0 : ordinal.intValue()) {
case 1: // formatNow
return new org.eclipse.jet.internal.taglib.format.FormatNowTag();
- case 2: // lc
+ case 2: // indent
+ return new org.eclipse.jet.internal.taglib.format.IndentTag();
+ case 3: // lc
return new org.eclipse.jet.internal.taglib.format.LowerCaseTag();
- case 3: // milliseconds
+ case 4: // milliseconds
return new org.eclipse.jet.internal.taglib.format.MillisecondsTag();
- case 4: // replaceAll
+ case 5: // replaceAll
return new org.eclipse.jet.internal.taglib.format.ReplaceAllTag();
- case 5: // strip
+ case 6: // strip
return new org.eclipse.jet.internal.taglib.format.StripTag();
- case 6: // uc
+ case 7: // uc
return new org.eclipse.jet.internal.taglib.format.UpperCaseTag();
- case 7: // unique
+ case 8: // unique
return new org.eclipse.jet.internal.taglib.format.UniqueTag();
- case 8: // uuid
+ case 9: // uuid
return new org.eclipse.jet.internal.taglib.format.UuidTag();
- case 9: // xpath
+ case 10: // xpath
return new org.eclipse.jet.internal.taglib.format.XPathTag();
default:
throw new JET2TagException("Unknown Tag: " + name); //$NON-NLS-1$

Back to the top