New core for datas.

This commit is contained in:
administrateur 2007-01-23 18:43:32 +01:00
parent cc9cc6018d
commit 5609135257
17 changed files with 666 additions and 416 deletions

View file

@ -11,7 +11,7 @@
<property name="resources" value="resources"/>
<property name="debug" value="on"/>
<target name="all" depends="build,xid_dist,build_test,examples" />
<target name="all" depends="build_xid,dist_xid,build_test,dist_test,examples" />
<!-- ******* Init ******* -->
<target name="init">
@ -24,7 +24,7 @@
<!-- ******* build ******* -->
<target name="build" depends="init">
<target name="build_xid" depends="init">
<javac srcdir="${src}" destdir="${build}/classes" debug="${debug}" deprecation="on">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
@ -33,8 +33,8 @@
</target>
<!-- ****** xid_dist ****** -->
<target name="xid_dist" depends="build">
<!-- ****** 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="**" />
@ -43,27 +43,31 @@
<!-- ******* build_test ******* -->
<target name="build_test" depends="xid_dist">
<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>
<!-- ****** test_dist ****** -->
<target name="test_dist" depends="build_test">
<!-- ****** 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="test_dist">
<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>
@ -72,7 +76,7 @@
<!-- ******* Examples (the webapp). ******* -->
<target name="examples" depends="xid_dist">
<target name="examples" depends="dist_xid">
<copy todir="webapp-examples/WEB-INF/lib">
<fileset dir="lib" includes="*.jar" excludes="servlet-api.jar"/>
@ -95,7 +99,7 @@
<!-- ****** JavaDoc ****** -->
<target name="javadoc" depends="build">
<target name="javadoc" depends="build_xid">
<javadoc sourcepath="${src}" packageNames="xid.*" destdir="${doc}">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>

View file

@ -11,18 +11,20 @@
<property name="resources" value="resources"/>
<property name="debug" value="on"/>
<target name="all" depends="compile,xid_dist,examples" />
<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>
<!-- ******* Compile ******* -->
<target name="compile" depends="init">
<!-- ******* build ******* -->
<target name="build_xid" depends="init">
<javac srcdir="${src}" destdir="${build}/classes" debug="${debug}" deprecation="on">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
@ -30,17 +32,51 @@
</javac>
</target>
<!-- ****** xid.jar ****** -->
<target name="xid_dist" depends="compile">
<!-- ****** 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="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" />
<pathelement path="dist/xid.jar"/>
<pathelement path="dist/test.jar"/>
<pathelement path="test/log4j.properties"/>
</classpath>
</java>
</target>
<!-- ******* Examples (the webapp). ******* -->
<target name="examples" depends="xid_dist">
<target name="examples" depends="dist_xid">
<copy todir="webapp-examples/WEB-INF/lib">
<fileset dir="lib" includes="*.jar" excludes="servlet-api.jar"/>
@ -63,7 +99,7 @@
<!-- ****** JavaDoc ****** -->
<target name="javadoc" depends="compile">
<target name="javadoc" depends="build_xid">
<javadoc sourcepath="${src}" packageNames="xid.*" destdir="${doc}">
<classpath>
<fileset dir="lib" includes="**/*.jar"/>
@ -75,6 +111,7 @@
<!-- *************** Clean ***********************-->
<target name="clean">
<delete dir="${build}"/>
<delete dir="build_test"/>
</target>
<!-- *********** Produce ZIP release file ******** -->

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
dist/test.jar vendored

Binary file not shown.

BIN
dist/xid.jar vendored

Binary file not shown.

View file

@ -1,10 +1,9 @@
/*
*
*/
package xid;
import java.util.*;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import org.xml.sax.*;
import org.w3c.dom.*;
@ -91,7 +90,7 @@ public class Presenter
/*
*
*/
public StringBuffer doXid (TagsData datas, StringBuffer errorOutput)
public StringBuffer doXid (TagsDataById datas, StringBuffer errorOutput)
{
StringBuffer result;
@ -135,7 +134,7 @@ public class Presenter
/*
*
* Xid a file without data.
*/
static public StringBuffer doXid (String fileName, String webappPath, StringBuffer errorOutput)
{
@ -160,28 +159,71 @@ public class Presenter
/*
*
* Xid a string with html in.
*/
static public StringBuffer doXid (Document doc, TagsData datas, String webappPath, StringBuffer errorOutput)
static public StringBuffer doXid (String html, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
StringBuffer result;
result = Presenter.process (doc, datas, webappPath, errorOutput);
String htmlSource;
if ((html.startsWith ("<!DOCTYPE")) ||
(html.startsWith ("<!doctype")) ||
(html.startsWith ("<html>")) ||
(html.startsWith ("<HTML>")))
{
htmlSource = html;
}
else
{
htmlSource = "<html><head></head><body>\n" + html + "</body></html>";
}
Document doc = null;
// StringBufferInputStream is deprecated so we use another solution.
// (see http://www.developpez.net/forums/archive/index.php/t-14101.html).
doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()), errorOutput);
StringBuffer htmlTarget;
htmlTarget = Presenter.process (doc, datas, webappPath, errorOutput);
if (htmlTarget == null)
{
result = null;
}
else if ((html.startsWith ("<!DOCTYPE")) ||
(html.startsWith ("<!doctype")) ||
(html.startsWith ("<html>")) ||
(html.startsWith ("<HTML>")))
{
result = htmlTarget;
}
else
{
String bodyContent = extractBodyContent (htmlTarget);
if (bodyContent == null)
{
result = null;
}
else
{
result = new StringBuffer (bodyContent);
}
}
//
return (result);
}
/*
*
* Xid a file with data.
*/
static public StringBuffer doXid (String html, TagsData datas, String webappPath, StringBuffer errorOutput)
static public StringBuffer doXid (Document doc, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
StringBuffer result;
Document doc = null;
result = Presenter.process (doc, datas, webappPath, errorOutput);
//
@ -223,7 +265,7 @@ public class Presenter
/*
*
*/
static protected StringBuffer processChildren (Node node, TagsData datas, String webappPath, StringBuffer errorOutput)
static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
StringBuffer result;
@ -258,7 +300,7 @@ public class Presenter
* @param attrMap
* @param idAttr
*/
static protected StringBuffer processObjectTag (Node node, NamedNodeMap attrMap, Node idAttr, TagsData datas, String webappPath, StringBuffer errorOutput)
static protected StringBuffer processObjectTag (Node node, NamedNodeMap attrMap, Node idAttr, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
StringBuffer result;
@ -291,7 +333,7 @@ public class Presenter
}
else
{
log.info ("object action");
log.debug ("object action");
result.append ("<!-- STARTING INCLUDE XID FILE " + attrMap.getNamedItem ("data") + " -->");
// Build the file name.
@ -307,7 +349,7 @@ public class Presenter
catch (Exception ex)
{
result.append ("unable to build the file tree");
log.info ("unable to build the file tree");
log.debug ("unable to build the file tree");
}
// Extract the 'body' section.
@ -319,7 +361,7 @@ public class Presenter
if (nodes.getLength () == 0)
{
result.append ("no body tag in include html");
log.info ("no body tag in include html");
log.debug ("no body tag in include html");
}
else
{
@ -329,7 +371,7 @@ public class Presenter
catch (Exception e)
{
result.append ("error getting child");
log.info ("error getting child");
log.debug ("error getting child");
}
// Process the body child as part of the primary tree.
@ -347,7 +389,7 @@ public class Presenter
//
result.append ("<!-- ENDING INCLUDE XID FILE " + attrMap.getNamedItem ("data") + " -->");
}
log.info ("end of object action");
log.debug ("end of object action");
//
return (result);
}
@ -368,7 +410,7 @@ public class Presenter
static protected StringBuffer processElementWithId (Node node,
NamedNodeMap attrs,
Node idAttr,
TagsData datas,
TagsDataById datas,
String webappPath,
StringBuffer errorOutput)
{
@ -378,10 +420,19 @@ public class Presenter
String tag = node.getNodeName();
String idValue = idAttr.getNodeValue();
log.info ("tag=" + tag);
log.debug ("tag=" + tag);
// Get data of this id.
TagData data = datas.get (idAttr.getNodeValue ());
TagDataCore dataCore = datas.get (idAttr.getNodeValue ());
if (dataCore == null)
{
result.append (Presenter.processElementBasically (node, datas, webappPath, errorOutput));
}
else if (dataCore instanceof TagData)
{
TagData data = (TagData) dataCore;
String theClass;
if (data == null)
{
@ -394,23 +445,22 @@ public class Presenter
if ((theClass == null) ||
(!theClass.equals ("xid:nodisplay")))
{
if ((tag.equals ("a")) ||
(tag.equals ("b")) ||
(tag.equals ("div")) ||
(tag.equals ("em")) ||
(tag.equals ("p")) ||
(tag.equals ("span")))
{
// Open the tag.
result.append ('<');
result.append ("<");
result.append (node.getNodeName());
// Build the tag attributes.
// Build attributes.
result.append (processAttributes (attrs, data));
//result.append (attributesFromNode (attrs));
//result.append (attributesFromTagData (data));
if ((node.getChildNodes () == null) &&
((data == null) || data.display ().equals ("")))
{
// Close the tag.
result.append (" />");
}
else
{
result.append ('>');
// Insert data.
@ -429,53 +479,23 @@ public class Presenter
result.append (node.getNodeName());
result.append ('>');
}
else if (tag.equals("img"))
{
// Possibility to merge with previous case if <div /> is a correct tag.
// Open the tag.
result.append ("<");
result.append (node.getNodeName());
// Build the tag attributes.
result.append (processAttributes (attrs, data));
//result.append (attributesFromNode (attrs));
//result.append (attributesFromTagData (data));
result.append ("/>");
}
else if (tag.equals("textarea"))
{
result.append ("[textarea]");
}
else if (tag.equals("select"))
else if (dataCore instanceof TagsData)
{
result.append ("[select]");
TagsData data = (TagsData) dataCore;
}
else if (tag.equals("input"))
else if (dataCore instanceof TagsDataById)
{
result.append ("[input]");
}
else if (tag.equals("table"))
{
result.append ("[table]");
}
else if (tag.equals("tbody"))
{
result.append ("[tbody]");
}
else if (tag.equals("object"))
{
result.append (processObjectTag (node, attrs, idAttr, datas, webappPath, errorOutput));
TagsDataById data = (TagsDataById) dataCore;
}
else
{
log.info ("Id on <" + tag + "> not supported.");
}
log.warn ("Unknow type of TagDataId");
}
//
log.info ("Exit");
log.debug ("Exit");
return (result);
}
@ -485,9 +505,9 @@ public class Presenter
* Recursive method that processes a node and any child nodes.
*
*/
static protected StringBuffer process (Node node, TagsData datas, String webappPath, StringBuffer errorOutput)
static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
log.info ("Enter");
log.debug ("Enter");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
String TRANSITIONAL_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 "
+ "Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
@ -498,7 +518,7 @@ public class Presenter
// Is there anything to do?
if (node != null)
{
log.info ("nodeName=" + node.getNodeName ());
log.debug ("nodeName=" + node.getNodeName ());
// Find the name attribute value.
String name;
@ -513,8 +533,11 @@ public class Presenter
{
case Node.DOCUMENT_NODE:
{
log.info ("case Node.DOCUMENT_NODE");
log.debug ("case Node.DOCUMENT_NODE");
DocumentType dt = ((Document) node).getDoctype();
if (dt != null)
{
String publicId = dt.getPublicId();
String systemId = dt.getSystemId();
@ -525,6 +548,7 @@ public class Presenter
// Log.write(Log.TRACE,"publicId = " + publicId);
// Log.write(Log.TRACE,"systemId = " + systemId);
}
result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, errorOutput));
@ -533,7 +557,7 @@ public class Presenter
case Node.ELEMENT_NODE:
{
log.info ("case Node.ELEMENT_NODE");
log.debug ("case Node.ELEMENT_NODE");
NamedNodeMap attrs = node.getAttributes ();
Node idAttr = attrs.getNamedItem ("id");
@ -553,7 +577,7 @@ public class Presenter
// handle entity reference nodes
case Node.ENTITY_REFERENCE_NODE:
{
log.info ("case Node.ENTITY_REFERENCE_NODE");
log.debug ("case Node.ENTITY_REFERENCE_NODE");
result.append ('&');
result.append (node.getNodeName());
@ -564,7 +588,7 @@ public class Presenter
// print cdata sections
case Node.CDATA_SECTION_NODE:
{
log.info ("case Node.CDATA_SECTION_NODE");
log.debug ("case Node.CDATA_SECTION_NODE");
result.append ("<![CDATA[");
result.append (node.getNodeValue());
@ -576,7 +600,7 @@ public class Presenter
// print text
case Node.TEXT_NODE:
{
log.info ("case Node.TEXTE_NODE");
log.debug ("case Node.TEXTE_NODE");
result.append (restoreEntities (new StringBuffer(node.getNodeValue())));
break;
}
@ -584,7 +608,7 @@ public class Presenter
// print processing instruction
case Node.PROCESSING_INSTRUCTION_NODE:
{
log.info ("Node.PROCESSING_INSTRUCTION_NODE");
log.debug ("Node.PROCESSING_INSTRUCTION_NODE");
result.append ("<?");
result.append (node.getNodeName());
@ -603,14 +627,14 @@ public class Presenter
//
//log.info ("result=" + result);
log.info ("Exit");
log.debug ("Exit");
return (result);
}
/*
*/
static StringBuffer processElementBasically (Node node, TagsData datas, String webappPath, StringBuffer errorOutput)
static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput)
{
StringBuffer result;
result = new StringBuffer ();
@ -674,28 +698,10 @@ public class Presenter
/*
*
*/
static protected Document fileToTree (String fileName, StringBuffer errorOutput)
static protected Document buildTree (InputStream source, StringBuffer errorOutput)
{
Document result;
File source = new File (fileName);
if (source == null)
{
String errorMessage = "source file not defined (null)";
errorOutput.append (errorMessage);
log.error (errorMessage);
result = null;
}
else if (!source.exists ())
{
String errorMessage = "source file not found (" + fileName + ")";
errorOutput.append (errorMessage);
log.error (errorMessage);
result = null;
}
else
{
try
{
// Create a DocumentBuilderFactory and configure it.
@ -721,10 +727,10 @@ public class Presenter
db.setErrorHandler (errorHandler);
Schema schema = db.getSchema ();
log.info ("schema=" + schema);
log.debug ("schema=" + schema);
// Parse the input file.
result = db.parse (fileName);
result = db.parse (source);
if (errorHandler.hasError ())
{
@ -752,6 +758,29 @@ public class Presenter
log.error (errorMessage);
result = null;
}
//
return (result);
}
/*
*
*/
static protected Document fileToTree (String fileName, StringBuffer errorOutput)
{
Document result;
try
{
result = buildTree (new FileInputStream (new File (fileName)), errorOutput);
}
catch (IOException exception)
{
String errorMessage = "IOError during parsing." + exception.getMessage ();
errorOutput.append (errorMessage);
log.error (errorMessage);
result = null;
}
//
@ -1026,4 +1055,33 @@ public class Presenter
//
return (result);
}
/*
*
*/
static public String extractBodyContent (StringBuffer data)
{
String result = null;
// Extract the body content.
String dataLowerCase = data.toString ().toLowerCase ();
int startBody = dataLowerCase.indexOf ("<body>");
int endBody = dataLowerCase.indexOf ("</body>");
// Note: as failed search is improbable, no care about complexity
// in failed search case.
if ((startBody == -1) || (endBody == -1))
{
result = null;
}
else
{
result = data.substring (startBody + 6, endBody).trim ();
}
//
return (result);
}
}

View file

@ -15,7 +15,7 @@ import java.io.*;
* application may also implement it's own TagData classes.
*
*/
public abstract class TagData implements Serializable
public class TagData implements Serializable, TagDataCore
{
public enum MODE {REPLACE, APPEND, IGNORE};
@ -23,22 +23,60 @@ public abstract class TagData implements Serializable
protected boolean excludeSection;
protected MODE displayMode = MODE.REPLACE;
String content;
/*
*
*/
public TagData ()
{
attributes = null;
excludeSection = false;
displayMode = MODE.REPLACE;
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = "";
}
/*
*
*/
public abstract String display();
public TagData (String text)
{
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = text;
}
/*
*
*/
public String display ()
{
String result;
if (this.content == null)
{
result = "";
}
else
{
result = this.content;
}
//
return (result);
}
/*
*
*/
public void setContent (String text)
{
this.content = text;
}
/*
@ -62,14 +100,6 @@ public abstract class TagData implements Serializable
return (result);
}
/*
* ??
*/
public String getValue()
{
return display();
}
/*
*

View file

@ -6,7 +6,7 @@ import java.io.*;
/*
*
*/
public class TagsData extends HashMap<String, TagData>
public class TagsData extends Vector<TagDataCore> implements TagDataCore
{
/**
*
@ -15,33 +15,4 @@ public class TagsData extends HashMap<String, TagData>
{
super ();
}
/*
*
*/
public void setId (String id, TagData data)
{
this.put (id, data);
}
/*
*
*/
public TagData getId (String id)
{
TagData result;
if (this.containsKey (id))
{
result = this.get (id);
}
else
{
result = null;
}
//
return (result);
}
}

View file

@ -1,91 +0,0 @@
package xid;
import java.io.*;
/**
* This class can be used to set up text for display.
*
*/
public class TextTagData extends TagData implements Serializable
{
private static final long serialVersionUID = -4117726979708043231L;
protected String text;
/**
* Constructs a TextTagData with the text supplied.
*
* @param text The text to be displayed.
*/
public TextTagData (String text)
{
super ();
this.text = text;
}
/*
*
*/
public TextTagData()
{
super();
this.text = "";
this.displayMode = MODE.IGNORE;
}
/**
* This method will be called by the View when it encounters
* an id for a TextTagData object.
*/
public String display ()
{
String result;
if (text == null)
{
result = "";
}
else
{
result = this.text;
}
//
return (result);
}
/**
* Allows the text content to be changed.
* @param text
*/
public void setText (String text)
{
this.text = text;
}
/**
* Returns the value as an int.
*
* @return The users input as an int or -1 if not a valid number.
*/
public int getValueAsInt()
{
int result;
try
{
result = Integer.parseInt(text);
}
catch (NumberFormatException e)
{
result = -1;
}
//
return (result);
}
}

View file

@ -1,73 +1,227 @@
package xid;
package xid.test;
import java.util.*;
import java.io.*;
import xid.*;
interface TTagDataCore
{
}
class TTagData implements TTagDataCore
{
public String a;
}
class TTagsDataById extends HashMap<String, Object> implements TTagDataCore
{
}
class TTagsData extends Vector<Object> implements TTagDataCore
{
}
class TTagsMatrix extends TTagsDataById
{
}
/**
*
*/
class Test
{
public static void test ()
{
System.out.println ("doing a test");
TTagsDataById tags = new TTagsDataById ();
TTagData tag = new TTagData ();
tag.a = "label a1";
tags.put ("id1", tag);
tag = new TTagData ();
tag.a = "label a2";
tags.put ("id2", tag);
TTagsData tag2 = new TTagsData ();
tags.put ("id3", tag2);
TTagsDataById tag3 = new TTagsDataById ();
tags.put ("id4", tag3);
TTagsMatrix tag4 = new TTagsMatrix ();
tags.put ("id5", tag4);
System.out.println ("tags=" + tags);
Set keys = tags.keySet ();
Iterator it = keys.iterator ();
while (it.hasNext ())
{
String key = (String) it.next ();
Object obj = tags.get (key);
StringBuffer comment = new StringBuffer ();
comment.append ("(" + key + "=> " + obj + "-> ");
if (obj instanceof TTagData)
{
comment.append ("class TTagData");
}
else if (obj instanceof TTagsData)
{
comment.append ("class TTagsData");
}
else if (obj instanceof TTagsDataById)
{
comment.append ("class TTagsDataById");
}
if (obj instanceof TTagDataCore)
{
comment.append (" TTagDataCore");
}
comment.append (")");
System.out.println (comment);
}
}
static private org.apache.log4j.Logger log;
static
{
// Initialize log.
org.apache.log4j.Logger log = null;
org.apache.log4j.BasicConfigurator.configure ();
log = org.apache.log4j.Logger.getRootLogger ();
//log.setLevel (org.apache.log4j.Level.INFO);
log.setLevel (org.apache.log4j.Level.INFO);
log.info ("Enter");
//
log.info ("Set the log file format...");
// log = org.apache.log4j.Category.getInstance(Application.class.getName());
log.info ("... done.");
log.debug ("Exit");
log = org.apache.log4j.Logger.getLogger (Test.class.getName ());
}
/**
*
*/
public static void main(String[] args)
{
System.out.println("Hello World!");
Presenter xid = new Presenter (getServletContext ().getRealPath ("/"), "testXid.html");
//test ();
//
TagsData datas = new TagsData ();
TextTagData text;
TagsDataById datas;
TagData tag;
// Populate attributes of Test 03.
text = new TextTagData ();
datas.put ("test03", text);
text.setText ("mummy");
text.getAttributes ().appendAttribute ("style", "background: blue;");
text.getAttributes ().appendAttribute ("style", "foreground: red;");
text.getAttributes ().setAttribute ("class", "totoClass");
StringBuffer html;
StringBuffer errorMessage;
// Populate attributes of Test 03.
datas = new TagsDataById ();
tag = new TagData ();
tag.setContent ("Superman");
datas.put ("name", tag);
errorMessage = new StringBuffer ();
html = xid.doXid (datas, errorMessage);
html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage);
System.out.println ("----------------------------");
System.out.println ("datas = new TagsDataId ();");
System.out.println ("tag = new TagData ();");
System.out.println ("tag.setContent (\"Superman\");");
System.out.println ("datas.put (\"name\", tag););");
System.out.println ("+");
System.out.println ("<div id='name'>a name</div >");
System.out.println ("=>");
System.out.println (html);
// Display page.
response.setContentType ("text/html");
PrintWriter out = response.getWriter();
// Populate attributes of Test 03.
datas = new TagsDataById ();
datas.setContent ("name", "Superman");
out.println ("<html>");
out.println ("<head>");
out.println ("<title>XID TEST</title>");
out.println ("</head>");
out.println ("<body bgcolor=\"orange\">");
errorMessage = new StringBuffer ();
html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage);
out.println ("<hr />");
out.println ("XID TEST<br/>");
System.out.println ("----------------------------");
System.out.println ("datas = new TagsDataId ();");
System.out.println ("datas.setContent (\"name\", \"Superman\");");
System.out.println ("+");
System.out.println ("<div id='name'>a name</div >");
System.out.println ("=>");
System.out.println (html);
if (errorMessage.length () != 0)
{
out.println ("An error occured in Xid treatment.<br/>");
out.println ("<pre>");
out.println (errorMessage);
out.println ("</pre>");
out.println ("<hr />");
out.println ("<pre>" + Presenter.restoreEntities (html) + "</pre>");
out.println ("<hr />");
}
else
{
out.println ("<pre>" + Presenter.restoreEntities (html) + "</pre>");
}
out.println ("</body>");
out.println ("</html>");
// Populate attributes of Test 03.
datas = new TagsDataById ();
tag = new TagData ();
tag.setContent ("Spiderman");
tag.getAttributes ().appendAttribute ("style", "background: blue;");
tag.getAttributes ().appendAttribute ("style", "foreground: red;");
tag.getAttributes ().setAttribute ("class", "nameClass");
datas.put ("lastname", tag);
log.info ("Exit");
errorMessage = new StringBuffer ();
html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage);
System.out.println ("----------------------------");
System.out.println ("datas = new TagsDataId ();");
System.out.println ("tag = new TagData ();");
System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");");
System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"background: blue;\");");
System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"foreground: red;\");");
System.out.println ("tag.setContent (\"Spiderman\");");
System.out.println ("datas.put (\"lastname\", tag););");
System.out.println ("+");
System.out.println ("<div id='lastname'>a last name</div>");
System.out.println ("=>");
System.out.println (html);
// Populate attributes of Test 03.
datas = new TagsDataById ();
datas.setContent ("lastname", "Spiderman");
datas.appendAttribute ("lastname", "style", "background: blue;");
datas.appendAttribute ("lastname", "style", "foreground: red;");
datas.setAttribute ("lastname", "class", "nameClass");
errorMessage = new StringBuffer ();
html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage);
System.out.println ("----------------------------");
System.out.println ("datas = new TagsDataId ();");
System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");");
System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");");
System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\"");
System.out.println ("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");");
System.out.println ("+");
System.out.println ("<div id='lastname'>a last name</div>");
System.out.println ("=>");
System.out.println (html);
System.out.println ("----------------------------");
}
}

View file

@ -1,16 +1,132 @@
package xid;
package xid.test;
import java.util.*;
import java.io.*;
import xid.*;
interface TTagDataCore
{
}
class TTagData implements TTagDataCore
{
public String a;
}
class TTagsDataById extends HashMap<String, Object> implements TTagDataCore
{
}
class TTagsData extends Vector<Object> implements TTagDataCore
{
}
class TTagsMatrix extends TTagsDataById
{
}
/**
*
*/
class Test
{
public static void test ()
{
System.out.println ("doing a test");
TTagsDataById tags = new TTagsDataById ();
TTagData tag = new TTagData ();
tag.a = "label a1";
tags.put ("id1", tag);
tag = new TTagData ();
tag.a = "label a2";
tags.put ("id2", tag);
TTagsData tag2 = new TTagsData ();
tags.put ("id3", tag2);
TTagsDataById tag3 = new TTagsDataById ();
tags.put ("id4", tag3);
TTagsMatrix tag4 = new TTagsMatrix ();
tags.put ("id5", tag4);
System.out.println ("tags=" + tags);
Set keys = tags.keySet ();
Iterator it = keys.iterator ();
while (it.hasNext ())
{
String key = (String) it.next ();
Object obj = tags.get (key);
StringBuffer comment = new StringBuffer ();
comment.append ("(" + key + "=> " + obj + "-> ");
if (obj instanceof TTagData)
{
comment.append ("class TTagData");
}
else if (obj instanceof TTagsData)
{
comment.append ("class TTagsData");
}
else if (obj instanceof TTagsDataById)
{
comment.append ("class TTagsDataById");
}
if (obj instanceof TTagDataCore)
{
comment.append (" TTagDataCore");
}
comment.append (")");
System.out.println (comment);
}
}
static private org.apache.log4j.Logger log;
static
{
log = org.apache.log4j.Logger.getLogger (Test.class.getName ());
}
/**
*
*/
public static void main(String[] args)
{
System.out.println("Hello World!");
//test ();
//
TagsDataById datas = new TagsDataById ();
TagData tag;
// Populate attributes of Test 03.
tag = new TagData ();
tag.setContent ("hello");
tag.getAttributes ().appendAttribute ("style", "background: blue;");
tag.getAttributes ().appendAttribute ("style", "foreground: red;");
tag.getAttributes ().setAttribute ("class", "totoClass");
datas.put ("test03", tag);
StringBuffer html;
StringBuffer errorMessage;
errorMessage = new StringBuffer ();
html = Presenter.doXid ("<X id='test03'>bla</X>", datas, "", errorMessage);
System.out.println ("----------------------------");
System.out.println (html);
System.out.println ("----------------------------");
}
}

View file

@ -131,35 +131,6 @@ public class Test extends HttpServlet
log.info ("Exit");
}
/*
*
*/
static public String extractBody (StringBuffer data)
{
String result = null;
// Extraire le contenu du body.
String dataLowerCase = data.toString ().toLowerCase ();
int startBody = dataLowerCase.indexOf ("<body>") + 6;
int endBody = dataLowerCase.indexOf ("</body>");
// Note: as failed search is improbable, no care about complexity
// in failed search case.
if ((startBody == -1) || (endBody == -1))
{
result = null;
}
else
{
result = data.substring (startBody, endBody).trim ();
}
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

Binary file not shown.