Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/formatTags/millisecondsTag.html2
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/formatTags/uuidTag.html2
-rw-r--r--plugins/org.eclipse.jet/plugin.xml6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java40
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/UuidTag.java6
5 files changed, 47 insertions, 9 deletions
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/millisecondsTag.html b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/millisecondsTag.html
index eb1d828..f4e268e 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/millisecondsTag.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/millisecondsTag.html
@@ -18,7 +18,7 @@
</TABLE>
<HR>
<P><B>milliseconds</B></P>
-<P>Writes out a current system milliseconds value.</P>
+<P>Writes out a current system milliseconds value.<P>If the variable 'org.eclipse.jet.formatTags.test' is defined, the tag will return a sequence of values, starting at one. This facilitates testing of results that include data based on the tag results.</P>
<HR>
<TABLE border="1" width="100%">
<TBODY>
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/uuidTag.html b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/uuidTag.html
index 5d34e2a..e0a6a9d 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/formatTags/uuidTag.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/formatTags/uuidTag.html
@@ -18,7 +18,7 @@
</TABLE>
<HR>
<P><B>uuid</B></P>
-<P>Generate a universally unique identifier (UUID).</P>
+<P>Generate a universally unique identifier (UUID).<P>If the variable 'org.eclipse.jet.formatTags.test' is defined, the tag will return a sequence of values of the form '-Fake_UUID-n-000000000'. This facilitates testing of results that include data based on the tag results.</P>
<HR>
<TABLE border="1" width="100%">
<TBODY>
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 3713ed9..aae86c6 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -955,7 +955,8 @@ If 'offset' is specified, start conversion from the specified character, otherwi
if 'length' is specified, convert only the specified number of characters, otherwise, convert all characters from the start character on.
</description>
</functionTag><emptyTag name="milliseconds" class="org.eclipse.jet.internal.taglib.format.MillisecondsTag">
- <description>Writes out a current system milliseconds value.</description>
+ <description>Writes out a current system milliseconds value.
+If the variable &apos;org.eclipse.jet.formatTags.test&apos; is defined, the tag will return a sequence of values, starting at one. This facilitates testing of results that include data based on the tag results.</description>
</emptyTag><functionTag
class="org.eclipse.jet.internal.taglib.format.ReplaceAllTag"
name="replaceAll">
@@ -1030,7 +1031,8 @@ if 'length' is specified, convert only the specified number of characters, other
<description>Writes out a unique integer value</description>
</emptyTag>
<emptyTag name="uuid" class="org.eclipse.jet.internal.taglib.format.UuidTag" >
- <description>Generate a universally unique identifier (UUID).</description>
+ <description>Generate a universally unique identifier (UUID).
+If the variable &apos;org.eclipse.jet.formatTags.test&apos; is defined, the tag will return a sequence of values of the form &apos;-Fake_UUID-n-000000000&apos;. This facilitates testing of results that include data based on the tag results.</description>
</emptyTag>
<functionTag
class="org.eclipse.jet.internal.taglib.format.XPathTag"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
index 68ff1aa..6977d47 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 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
@@ -26,6 +26,12 @@ import org.eclipse.jet.JET2Context;
public final class FormatContextExtender
{
+ /**
+ * The name of the JET variable, that, if set, indicates that format tags that return
+ * random values should generate pseudo random values.
+ */
+ public static final String FORMAT_TAGS_TEST_FLAG = "org.eclipse.jet.formatTags.test"; //$NON-NLS-1$
+
private static String PRIVATE_CONTEXT_DATA_KEY = FormatContextExtender.class.getName();
/**
@@ -43,21 +49,28 @@ public final class FormatContextExtender
FormatContextExtender ex = (FormatContextExtender)context.getPrivateData(PRIVATE_CONTEXT_DATA_KEY);
if (ex == null)
{
- ex = new FormatContextExtender();
+ ex = new FormatContextExtender(context);
context.addPrivateData(PRIVATE_CONTEXT_DATA_KEY, ex);
}
return ex;
}
private long lastMilliseconds = 0;
+
+ private long pseudoUUIDBase = 0;
+ private long pseudoLastMilliseconds = 0;
private int lastUnique = 0;
+ private final JET2Context context;
+
/**
+ * @param context
*/
- private FormatContextExtender()
+ private FormatContextExtender(JET2Context context)
{
super();
+ this.context = context;
}
/**
@@ -65,7 +78,8 @@ public final class FormatContextExtender
*/
public long getMilliseconds()
{
- long next = System.currentTimeMillis();
+ long next = !context.hasVariable(FORMAT_TAGS_TEST_FLAG)
+ ? System.currentTimeMillis() : pseudoLastMilliseconds + 1;
if (next <= lastMilliseconds)
{
next = lastMilliseconds + 1;
@@ -84,4 +98,22 @@ public final class FormatContextExtender
return unique;
}
+ public String getPseudoUUID()
+ {
+ // similar ECoreUtil.generateUUID(), which returns a 24 character string using base 64 digits:
+ // A-Za-z0-9-_ .
+ pseudoUUIDBase++;
+
+ StringBuffer result = new StringBuffer(23);
+ result.append("-Fake_UUID-"); //$NON-NLS-1$
+ result.append(Long.toHexString(pseudoUUIDBase));
+ result.append('-');
+ int padding = 24 - result.length();
+ for(int i = 0; i < padding; i++) {
+ result.append('0');
+ }
+
+ return result.toString();
+ }
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/UuidTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/UuidTag.java
index 3bdb560..f40fb51 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/UuidTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/UuidTag.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -48,7 +48,11 @@ public class UuidTag extends AbstractEmptyTag {
*/
public void doAction(TagInfo tagInfo, JET2Context context, JET2Writer out) throws JET2TagException {
+ if(!context.hasVariable(FormatContextExtender.FORMAT_TAGS_TEST_FLAG)) {
out.write(EcoreUtil.generateUUID());
+ } else {
+ out.write(FormatContextExtender.getInstance(context).getPseudoUUID());
+ }
/**
* End doAction logic

Back to the top