IterationStrategy become a IdData attribute (before was IdsDataByIndex), the idea is to set it in <table> than in <tr>.

This commit is contained in:
administrateur 2007-02-08 03:29:52 +01:00
parent f2f70ce931
commit 062b838a82
12 changed files with 175 additions and 308 deletions

View file

@ -146,6 +146,7 @@
<target name="clean">
<delete dir="${build}"/>
<delete dir="build_test"/>
<delete dir="build_demo"/>
</target>
<!-- *********** Produce ZIP release file ******** -->

View file

@ -1,128 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE project>
<!-- Builds the XID Framework jar filen. -->
<project name="xid" default="all" basedir=".">
<property name="targetjar" value="xid.jar"/>
<property name="zip_file" value="xid.zip"/> <!-- Release zip file -->
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="doc" value="doc"/>
<property name="dist" value="dist"/>
<property name="resources" value="resources"/>
<property name="debug" value="on"/>
<target name="all" depends="build_xid,dist_xid,build_test,dist_test,examples" />
<!-- ******* Init ******* -->
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="build_test/classes"/>
<mkdir dir="${build}/classes"/>
<mkdir dir="${dist}"/>
</target>
<!-- ******* build ******* -->
<target name="build_xid" depends="init">
<javac srcdir="${src}" destdir="${build}/classes" debug="${debug}" deprecation="on">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
</classpath>
</javac>
</target>
<!-- ****** dist_xid ****** -->
<target name="dist_xid" depends="build_xid">
<jar update="no" jarfile="dist/xid.jar">
<fileset dir="build/classes" includes="xid/**.class" />
<fileset dir="resources" includes="**" />
</jar>
</target>
<!-- ******* build_test ******* -->
<target name="build_test" depends="dist_xid">
<javac srcdir="test" destdir="build_test/classes" debug="${debug}" deprecation="on">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
<pathelement path="dist/xid.jar"/>
</classpath>
</javac>
</target>
<!-- ****** dist_test ****** -->
<target name="dist_test" depends="build_test">
<jar update="no" jarfile="dist/test.jar">
<fileset dir="build_test/classes" includes="xid/test/**.class" />
<fileset dir="resources" includes="**" />
</jar>
</target>
<!-- *********** dotest ******** -->
<target name="dotest" depends="dist_test">
<java classname="xid.test.Test" maxmemory="20m" fork="true">
<classpath>
<fileset dir="lib" includes="**/*.jar" />
<fileset dir="resources" includes="**" />
<pathelement path="dist/xid.jar"/>
<pathelement path="dist/test.jar"/>
</classpath>
</java>
</target>
<!-- ******* Examples (the webapp). ******* -->
<target name="examples" depends="dist_xid">
<copy todir="webapp-examples/WEB-INF/lib">
<fileset dir="lib" includes="*.jar" excludes="servlet-api.jar"/>
<fileset dir="dist" includes="*.jar"/>
</copy>
<copy file="${dist}/xid.jar" todir="webapp-examples/WEB-INF/lib" overwrite="yes" preservelastmodified="yes"/>
<delete>
<fileset dir="webapp-examples/WEB-INF/classes/" includes="**.class"/>
<fileset dir="webapp-examples/WEB-INF/classes/" includes="**/**.class"/>
</delete>
<javac srcdir="webapp-examples/WEB-INF/classes/" destdir="webapp-examples/WEB-INF/classes/" debug="${debug}" deprecation="on">
<classpath>
<fileset dir="webapp-examples/WEB-INF/lib" includes="**.jar"/>
</classpath>
</javac>
</target>
<!-- ****** JavaDoc ****** -->
<target name="javadoc" depends="build_xid">
<javadoc sourcepath="${src}" packageNames="xid.*" destdir="${doc}">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
</classpath>
</javadoc>
</target>
<!-- *************** Clean ***********************-->
<target name="clean">
<delete dir="${build}"/>
<delete dir="build_test"/>
</target>
<!-- *********** Produce ZIP release file ******** -->
<target name="zip">
<zip update="no" zipfile="../${zip_file}" basedir=".">
<include name=".project" />
<include name=".classpath" />
<include name="build.xml" />
<include name="src/**" />
<include name="resources/**" />
<include name="lib/*.jar" />
</zip>
</target>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -125,29 +125,29 @@ class Demo
// Populate attributes of Test 03.
System.out.println ("----------------------------");
datas = new Data ();
datas.setContent ("identity", 0, "nom", "Jemba");
datas.setContent ("identity", 0, "prenom", "Epo");
datas.setContent ("identity", 1, "nom", "Momon");
datas.setContent ("identity", 1, "prenom", "Christian");
datas.setContent ("identity", 2, "nom", "Tronche");
datas.setContent ("identity", 2, "prenom", "Christophe");
datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("identity", 1, "first_name", "Christian");
datas.setContent ("identity", 2, "last_name", "Tronche");
datas.setContent ("identity", 2, "first_name", "Christophe");
errorMessage = new StringBuffer ();
StringBuffer source = new StringBuffer ();
source.append ("<table>\n");
source.append (" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append (" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append ("</table>");
htmlSource = source.toString ();
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println ("datas = new Data ();");
System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println ("+");
System.out.println (htmlSource);
@ -158,13 +158,12 @@ class Demo
// Populate attributes of Test 03.
System.out.println ("----------------------------");
datas = new Data ();
datas.setContent ("identity", 0, "nom", "Jemba");
datas.setContent ("identity", 0, "prenom", "Epo");
datas.setContent ("identity", 1, "nom", "Momon");
datas.setContent ("identity", 1, "prenom", "Christian");
datas.setContent ("identity", 2, "nom", "Tronche");
datas.setContent ("identity", 2, "prenom", "Christophe");
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("identity", 1, "first_name", "Christian");
datas.setContent ("identity", 2, "last_name", "Tronche");
datas.setContent ("identity", 2, "first_name", "Christophe");
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS);
@ -172,42 +171,52 @@ class Demo
errorMessage = new StringBuffer ();
source = new StringBuffer ();
source.append ("<table>\n");
source.append (" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append (" <tr id='identityBis'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n");
source.append (" <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n");
source.append ("</table>");
source.append ("<table id=\"identities\">\n");
source.append (" <tr id='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></tr>\n");
source.append (" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append (" <tr id='identity_bis'><td>noid</td><td id='first_name_bis'>a first name</td><td id='last_name_bis'>a last name</td></tr>\n");
source.append (" <tr><td>noid</td><td id='first_name_ter'>a first name more</td><td id='last_name_ter'>a last name more</td></tr>\n");
source.append ("</table>\n");
htmlSource = source.toString ();
System.out.println ("datas = new Data ();");
System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println ("+");
System.out.println (htmlSource);
System.out.println ("=>");
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
System.out.println ("ONLY_FIRST_ROW:");
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
System.out.println ("");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
System.out.println ("ONLY_FIRST_TWO_ROWS:");
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);
System.out.println ("");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID);
System.out.println ("ONLY_ROWS_WITH_ID:");
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
System.out.println ("");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
System.out.println ("ONLY_ROWS_WITHOUT_ID:");
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS);
System.out.println ("");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ALL_ROWS);
System.out.println ("ALL_ROWS:");
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);

View file

@ -147,11 +147,11 @@ public class Data
/**
*
*/
public void setIterationStrategy (String id, IdsDataByIndex.IterationStrategy strategy)
public void setIterationStrategy (String id, IdData.IterationStrategy strategy)
{
IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId (id);
IdData tag = (IdData) this.getIdData (id);
tags.setIterationStrategy (strategy);
tag.setIterationStrategy (strategy);
}

View file

@ -17,6 +17,11 @@ import java.io.*;
*/
public class IdData implements Serializable, IdDataCore
{
public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS}
protected IterationStrategy iterationStrategy;
public enum MODE {REPLACE, APPEND, IGNORE};
protected Attributes attributes;
@ -33,6 +38,7 @@ public class IdData implements Serializable, IdDataCore
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = "";
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
@ -45,6 +51,7 @@ public class IdData implements Serializable, IdDataCore
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
@ -135,5 +142,27 @@ public class IdData implements Serializable, IdDataCore
{
return excludeSection;
}
/**
*
*/
public void setIterationStrategy (IterationStrategy strategy)
{
this.iterationStrategy = strategy;
}
/**
*
*/
public IterationStrategy getIterationStrategy ()
{
IterationStrategy result;
result = this.iterationStrategy;
//
return (result);
}
}

View file

@ -8,39 +8,11 @@ import java.io.*;
*/
public class IdsDataByIndex extends Vector<IdDataCore> implements IdDataCore
{
public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS}
protected IterationStrategy iterationStrategy;
/**
*
*/
public IdsDataByIndex ()
{
super ();
this.iterationStrategy = IterationStrategy.ONLY_FIRST_ROW;
}
/**
*
*/
public void setIterationStrategy (IterationStrategy strategy)
{
this.iterationStrategy = strategy;
}
/**
*
*/
public IterationStrategy getIterationStrategy ()
{
IterationStrategy result;
result = this.iterationStrategy;
//
return (result);
}
}

View file

@ -381,148 +381,132 @@ public class Presenter
StringBuffer result;
result = new StringBuffer ();
NodeList children = node.getChildNodes();
int childrenCount = children.getLength ();
if ((children == null) || (childrenCount == 0))
// Get the iteration strategy.
IdData.IterationStrategy strategy;
NamedNodeMap attributes = node.getAttributes ();
if (attributes == null)
{
result.append (" ");
strategy = IdData.IterationStrategy.ALL_ROWS;
}
else
{
//
// Is there a IdsDataByIndex associated with the first ELEMENT_NODE child?
//
IdsDataByIndex idsData;
Node id = attributes.getNamedItem ("id");
// Find the first ELEMENT_NODE child.
int childIndex = 0;
Node child = null;
boolean ended = false;
while (!ended)
if (id == null)
{
if (childIndex >= childrenCount)
{
ended = true;
child = null;
}
else if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
ended = true;
child = children.item (childIndex);
}
else
{
childIndex += 1;
}
}
if (child == null)
{
idsData = null;
strategy = IdData.IterationStrategy.ALL_ROWS;
}
else
{
// Searching for the ID value of the child.
String childId;
NamedNodeMap attrsChild = child.getAttributes ();
if (attrsChild == null)
IdDataCore dataCore = datas.getId (id.getNodeValue ());
if (dataCore == null)
{
childId = null;
strategy = IdData.IterationStrategy.ALL_ROWS;
}
else if (dataCore instanceof IdData)
{
IdData data = (IdData) dataCore;
strategy = data.getIterationStrategy ();
}
else
{
Node idAttrChild;
idAttrChild = attrsChild.getNamedItem ("id");
if (idAttrChild == null)
{
childId = null;
}
else
{
childId = idAttrChild.getNodeValue ();
}
}
// Searching for the datas associated to the childId.
if (childId == null)
{
idsData = null;
}
else
{
// Check if the data is a IdsDataByIndex.
if (datas.getId (childId) instanceof IdsDataByIndex)
{
idsData = (IdsDataByIndex) datas.getId (childId);
}
else
{
idsData = null;
}
strategy = IdData.IterationStrategy.ALL_ROWS;
}
}
}
// Iterate.
NodeList children = node.getChildNodes();
int childrenCount = children.getLength ();
switch (strategy)
{
case ONLY_FIRST_ROW:
int lineCounter = 0;
for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{
if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
lineCounter += 1;
if (lineCounter == 1)
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
else
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
break;
// So, is there?
if (idsData == null)
case ONLY_FIRST_TWO_ROWS:
lineCounter = 0;
for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{
for (int i = 0; i < childrenCount; i++)
if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput));
lineCounter += 1;
if ((lineCounter == 1) || (lineCounter == 2))
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
else
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
else
break;
case ONLY_ROWS_WITH_ID:
for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{
switch (idsData.getIterationStrategy ())
if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
case ONLY_FIRST_ROW:
for (int i = 0; i <= childIndex; i++)
{
result.append (process (children.item (i), datas, tagsData, webappPath, suffix, errorOutput));
}
break;
NamedNodeMap attrs2 = children.item (childIndex).getAttributes ();
case ONLY_ROWS_WITH_ID:
for (int i = 0; i < childrenCount; i++)
if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null))
{
NamedNodeMap attrs2 = children.item (i).getAttributes ();
if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null))
{
result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput));
}
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
break;
case ONLY_ROWS_WITHOUT_ID:
for (int i = 0; i < childrenCount; i++)
{
// Process row?
boolean processRow;
NamedNodeMap attrs2 = children.item (i).getAttributes ();
if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null))
{
result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput));
}
}
break;
case ALL_ROWS:
for (int i = 0; i < childrenCount; i++)
{
result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput));
}
break;
}
else
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
break;
case ONLY_ROWS_WITHOUT_ID:
for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{
if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
NamedNodeMap attrs2 = children.item (childIndex).getAttributes ();
if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null))
{
result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
else
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
}
break;
case ALL_ROWS:
for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{
result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput));
}
break;
}
//