summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-08-23 18:46:38 (EDT)
committerpelder2006-08-23 18:46:38 (EDT)
commit119c859a7c7e1b9c0489073795e4e29386316603 (patch)
tree4c9af6438379270defd1552689b4b56d021b6094
parent55c74eda57972d6092f8b09b70d1f5579607648f (diff)
downloadorg.eclipse.jet-119c859a7c7e1b9c0489073795e4e29386316603.zip
org.eclipse.jet-119c859a7c7e1b9c0489073795e4e29386316603.tar.gz
org.eclipse.jet-119c859a7c7e1b9c0489073795e4e29386316603.tar.bz2
[154929] Add 'unchangedMarker' attribute to <c:initialCode> tag.
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/controlTags/initialCodeTag.html14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java20
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java68
4 files changed, 98 insertions, 8 deletions
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/controlTags/initialCodeTag.html b/doc/org.eclipse.jet.doc/references/taglibs/controlTags/initialCodeTag.html
index 85fefc2..979d23d 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/controlTags/initialCodeTag.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/controlTags/initialCodeTag.html
@@ -35,7 +35,7 @@
<TR>
<TD width="10%">full tag</TD>
<TD><SPAN style="font-family: monospace">
- &lt;c:initialCode&gt;<br>
+ &lt;c:initialCode unmodifiedMarker=&quot;<I>value</I>&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<I>content to be written</I><BR>
&lt;/c:initialCode&gt;
</SPAN></TD>
@@ -55,6 +55,18 @@
<TABLE border="1" width="100%">
<TBODY>
<TR>
+ <TH colspan="2" align="left">Optional Attributes</TH></TR>
+ <TR>
+ <TR>
+ <TD width="10%">unmodifiedMarker</TD>
+ <TD><BR> A string that when present in the content of the existing code indicates that the code has not been modified by the user, and should be replace with the contents of this initial code block.<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>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
index 30d262f..e0c301f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
@@ -25,7 +25,6 @@ import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.AbstractContainerTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.taglib.UserRegionHelper;
/**
@@ -58,13 +57,14 @@ public class InitialCodeTag extends AbstractContainerTag
*/
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
+ String unmodifiedMarker = getAttribute("unmodifiedMarker"); //$NON-NLS-1$
if (!(getParent() instanceof UserRegionTag))
{
throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_IllegalParent, new Object []{ "userRegion" })); //$NON-NLS-1$
}
- UserRegionHelper.markInitialCode(out, initialCodeOffset, out.getDocument().getLength());
+ ((UserRegionTag)getParent()).setInitiaCodeRegion(initialCodeOffset, out.getDocument().getLength(), unmodifiedMarker);
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
index 9d389e6..181d724 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
@@ -34,6 +34,10 @@ public class UserRegionTag extends AbstractContainerTag
{
private int userRegionOffset;
+ private int initialCodeStart = -1;
+ private int initialCodeEnd = -1;
+ private String unmodifiedMarker = null;
+
/**
*
@@ -49,6 +53,10 @@ public class UserRegionTag extends AbstractContainerTag
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
UserRegionHelper.markUserRegion(out, userRegionOffset, out.getDocument().getLength());
+ if (initialCodeStart >= 0)
+ {
+ UserRegionHelper.markInitialCode(out, initialCodeStart, initialCodeEnd, unmodifiedMarker);
+ }
}
/* (non-Javadoc)
@@ -58,5 +66,17 @@ public class UserRegionTag extends AbstractContainerTag
{
userRegionOffset = out.getDocument().getLength();
}
+
+ /**
+ * Allow InitialCodeTag to register its region.
+ * @param start start of the initial code region (includsive of start)
+ * @param end end of the inital code region (exclusive of end)
+ * @param unmodifiedMarker an optional marker that indicates unmodified text.
+ */
+ void setInitiaCodeRegion(int start, int end, String unmodifiedMarker) {
+ this.initialCodeStart = start;
+ this.initialCodeEnd = end;
+ this.unmodifiedMarker = unmodifiedMarker;
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
index 77b4979..105fc59 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
@@ -1,5 +1,6 @@
package org.eclipse.jet.taglib;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jet.IWriterListener;
@@ -8,6 +9,7 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
+
/**
* Utility class that allows implementation of user regions like &lt;c:userRegion&;gt.
* <p>
@@ -22,15 +24,38 @@ import org.eclipse.jface.text.Position;
*/
public final class UserRegionHelper implements IWriterListener
{
+ /**
+ * Position subclass that tracks user regions that include an unmodified marker.
+ */
+ private static class PositionWithUnmodifiedMarker extends Position
+ {
+
+ public final String unmodifiedMarker;
+
+ /**
+ * @param offset
+ * @param length
+ */
+ public PositionWithUnmodifiedMarker(int offset, int length, String unmodifiedMarker)
+ {
+ super(offset, length);
+ this.unmodifiedMarker = unmodifiedMarker;
+
+ }
+
+ }
+
private static final String INITIALCODE_POSITION_CATEGORY = "org.eclipse.jet.internal.taglib.control.initialcode"; //$NON-NLS-1$
+
private static final String ROUNDTRIP_LISTENER_CATEGORY = "org.eclipse.jet.internal.taglib.control.userRegion"; //$NON-NLS-1$
+
private static final String USERREGION_POSITION_CATEGORY = "org.eclipse.jet.internal.taglib.control.userRegion"; //$NON-NLS-1$
private UserRegionHelper()
{
// do nothing, but prevent external construction.
}
-
+
public void finalizeContent(JET2Writer writer, Object file)
{
if (file instanceof IFile)
@@ -60,6 +85,14 @@ public final class UserRegionHelper implements IWriterListener
final Position userRegionPosition = rtPositions[i];
Position initialCodePosition = findContainedInitialCodePosition(userRegionPosition, icPositions);
+ if (initialCodePosition == null)
+ {
+ continue;
+ }
+
+ String unmodifiedMarker = initialCodePosition instanceof PositionWithUnmodifiedMarker
+ ? ((PositionWithUnmodifiedMarker)initialCodePosition).unmodifiedMarker : null;
+
final Position beginMarkerPosition = new Position(userRegionPosition.offset, initialCodePosition.offset
- userRegionPosition.offset);
int endMarkerOffset = initialCodePosition.offset + initialCodePosition.length;
@@ -76,7 +109,8 @@ public final class UserRegionHelper implements IWriterListener
if (existingEndMarkerOffset != -1)
{
final String existingRegion = fileContents.substring(existingRegionOffset, existingEndMarkerOffset + endMarker.length());
- if(!existingRegion.equals(document.get(userRegionPosition.offset, userRegionPosition.length)))
+ if (!existingRegion.equals(document.get(userRegionPosition.offset, userRegionPosition.length))
+ && (unmodifiedMarker == null || existingRegion.indexOf(unmodifiedMarker) == -1))
{
document.replace(userRegionPosition.offset, userRegionPosition.length, existingRegion);
}
@@ -124,13 +158,37 @@ public final class UserRegionHelper implements IWriterListener
* @param out a JET2Writer
* @param initialCodeStart the inclusive offset (zero-based) of the start of the region's initial code block (immediately after the start tag).
* @param initialCodeEnd the exclusive offset (zero-based) of the end of the region's initial code block (offset of the end tag).
+ * @param unmodifiedMarker if non-null, indicates a string, that if present in the documents initial code indicates the initial code is unmodifiedand may be replaced
+ * @since 0.7.1
*/
- public static void markInitialCode(JET2Writer out, final int initialCodeStart, int initialCodeEnd)
+ public static void markInitialCode(JET2Writer out, final int initialCodeStart, int initialCodeEnd, String unmodifiedMarker)
{
out.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
- out.addPosition(INITIALCODE_POSITION_CATEGORY, new Position(initialCodeStart, initialCodeEnd - initialCodeStart));
+ if (unmodifiedMarker == null)
+ {
+ out.addPosition(INITIALCODE_POSITION_CATEGORY, new Position(initialCodeStart, initialCodeEnd - initialCodeStart));
+ }
+ else
+ {
+ out.addPosition(INITIALCODE_POSITION_CATEGORY, new PositionWithUnmodifiedMarker(
+ initialCodeStart,
+ initialCodeEnd - initialCodeStart,
+ unmodifiedMarker));
+ }
}
-
+
+ /**
+ * Mark the initial code portion of the user region. Equivalent to
+ * <code>markInitialCode(out, initialCodeStart, initialCodeEnd, null)</code>.
+ * @param out a JET2Writer
+ * @param initialCodeStart the inclusive offset (zero-based) of the start of the region's initial code block (immediately after the start tag).
+ * @param initialCodeEnd the exclusive offset (zero-based) of the end of the region's initial code block (offset of the end tag).
+ * @see #markInitialCode(JET2Writer, int, int, String)
+ */
+ public static void markInitialCode(JET2Writer out, final int initialCodeStart, int initialCodeEnd) {
+ markInitialCode(out, initialCodeStart, initialCodeEnd, null);
+ }
+
/**
* Mark the user region on the output writer
* @param out a JET2Writer