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"> <target name="clean">
<delete dir="${build}"/> <delete dir="${build}"/>
<delete dir="build_test"/> <delete dir="build_test"/>
<delete dir="build_demo"/>
</target> </target>
<!-- *********** Produce ZIP release file ******** --> <!-- *********** 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. // Populate attributes of Test 03.
System.out.println ("----------------------------"); System.out.println ("----------------------------");
datas = new Data (); datas = new Data ();
datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("identity", 1, "nom", "Momon"); datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("identity", 1, "prenom", "Christian"); datas.setContent ("identity", 1, "first_name", "Christian");
datas.setContent ("identity", 2, "nom", "Tronche"); datas.setContent ("identity", 2, "last_name", "Tronche");
datas.setContent ("identity", 2, "prenom", "Christophe"); datas.setContent ("identity", 2, "first_name", "Christophe");
errorMessage = new StringBuffer (); errorMessage = new StringBuffer ();
StringBuffer source = new StringBuffer (); StringBuffer source = new StringBuffer ();
source.append ("<table>\n"); 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>"); source.append ("</table>");
htmlSource = source.toString (); htmlSource = source.toString ();
html = Presenter.doXid (htmlSource, datas, errorMessage); html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println ("datas = new Data ();"); System.out.println ("datas = new Data ();");
System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println ("+"); System.out.println ("+");
System.out.println (htmlSource); System.out.println (htmlSource);
@ -158,13 +158,12 @@ class Demo
// Populate attributes of Test 03. // Populate attributes of Test 03.
System.out.println ("----------------------------"); System.out.println ("----------------------------");
datas = new Data (); datas = new Data ();
datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("identity", 1, "nom", "Momon"); datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("identity", 1, "prenom", "Christian"); datas.setContent ("identity", 1, "first_name", "Christian");
datas.setContent ("identity", 2, "nom", "Tronche"); datas.setContent ("identity", 2, "last_name", "Tronche");
datas.setContent ("identity", 2, "prenom", "Christophe"); datas.setContent ("identity", 2, "first_name", "Christophe");
datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS);
@ -172,42 +171,52 @@ class Demo
errorMessage = new StringBuffer (); errorMessage = new StringBuffer ();
source = new StringBuffer (); source = new StringBuffer ();
source.append ("<table>\n"); source.append ("<table id=\"identities\">\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='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></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 id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</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 (" <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 ("</table>"); 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 (); htmlSource = source.toString ();
System.out.println ("datas = new Data ();"); System.out.println ("datas = new Data ();");
System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println ("+"); System.out.println ("+");
System.out.println (htmlSource); System.out.println (htmlSource);
System.out.println ("=>"); 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:"); System.out.println ("ONLY_FIRST_ROW:");
html = Presenter.doXid (htmlSource, datas, errorMessage); html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html); 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:"); System.out.println ("ONLY_ROWS_WITH_ID:");
html = Presenter.doXid (htmlSource, datas, errorMessage); html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html); 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:"); System.out.println ("ONLY_ROWS_WITHOUT_ID:");
html = Presenter.doXid (htmlSource, datas, errorMessage); html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html); 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:"); System.out.println ("ALL_ROWS:");
html = Presenter.doXid (htmlSource, datas, errorMessage); html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html); 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 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}; public enum MODE {REPLACE, APPEND, IGNORE};
protected Attributes attributes; protected Attributes attributes;
@ -33,6 +38,7 @@ public class IdData implements Serializable, IdDataCore
this.excludeSection = false; this.excludeSection = false;
this.displayMode = MODE.REPLACE; this.displayMode = MODE.REPLACE;
this.content = ""; this.content = "";
this.iterationStrategy = IterationStrategy.ALL_ROWS;
} }
@ -45,6 +51,7 @@ public class IdData implements Serializable, IdDataCore
this.excludeSection = false; this.excludeSection = false;
this.displayMode = MODE.REPLACE; this.displayMode = MODE.REPLACE;
this.content = text; this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
} }
@ -135,5 +142,27 @@ public class IdData implements Serializable, IdDataCore
{ {
return excludeSection; 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 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 () public IdsDataByIndex ()
{ {
super (); 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; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer ();
NodeList children = node.getChildNodes(); // Get the iteration strategy.
int childrenCount = children.getLength (); IdData.IterationStrategy strategy;
if ((children == null) || (childrenCount == 0)) NamedNodeMap attributes = node.getAttributes ();
if (attributes == null)
{ {
result.append (" "); strategy = IdData.IterationStrategy.ALL_ROWS;
} }
else else
{ {
// Node id = attributes.getNamedItem ("id");
// Is there a IdsDataByIndex associated with the first ELEMENT_NODE child?
//
IdsDataByIndex idsData;
// Find the first ELEMENT_NODE child. if (id == null)
int childIndex = 0;
Node child = null;
boolean ended = false;
while (!ended)
{ {
if (childIndex >= childrenCount) strategy = IdData.IterationStrategy.ALL_ROWS;
{
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;
} }
else else
{ {
// Searching for the ID value of the child. IdDataCore dataCore = datas.getId (id.getNodeValue ());
String childId; if (dataCore == null)
NamedNodeMap attrsChild = child.getAttributes ();
if (attrsChild == null)
{ {
childId = null; strategy = IdData.IterationStrategy.ALL_ROWS;
}
else if (dataCore instanceof IdData)
{
IdData data = (IdData) dataCore;
strategy = data.getIterationStrategy ();
} }
else else
{ {
Node idAttrChild; strategy = IdData.IterationStrategy.ALL_ROWS;
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;
}
} }
} }
}
// 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? case ONLY_FIRST_TWO_ROWS:
if (idsData == null) 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: NamedNodeMap attrs2 = children.item (childIndex).getAttributes ();
for (int i = 0; i <= childIndex; i++)
{
result.append (process (children.item (i), datas, tagsData, webappPath, suffix, errorOutput));
}
break;
case ONLY_ROWS_WITH_ID: if ((attrs2 != null) &&
for (int i = 0; i < childrenCount; i++) (attrs2.getNamedItem ("id") != null))
{ {
NamedNodeMap attrs2 = children.item (i).getAttributes (); result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null))
{
result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput));
}
} }
break; }
else
case ONLY_ROWS_WITHOUT_ID: {
for (int i = 0; i < childrenCount; i++) result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
{
// 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;
} }
} }
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;
} }
// //