Remove the TagData management. The goal of XID is to manage ID only, not TAG.

This commit is contained in:
Christian P. MOMON 2010-02-23 17:06:59 +01:00
parent 1aee3cbde1
commit f85b1a5b33
13 changed files with 50 additions and 259 deletions

View file

@ -207,33 +207,5 @@ class XidDemo
System.out.println (html); System.out.println (html);
// Populate attributes of Test 03.
System.out.println ("----------------------------");
datas = new Data ();
datas.setAttribute ("<div>", "class", "aDivClass");
datas.setAttribute ("<div>", "style", "background-color: #000000;");
datas.setAttribute ("number", "style", "background-color: #0000FF;");
errorMessage = new StringBuffer ();
source = new StringBuffer ();
source.append ("<div>\n");
source.append (" <h1>one</h1>\n");
source.append ("</div>\n");
source.append ("<div id=\"number\">\n");
source.append (" <h1>three</h1>\n");
source.append ("</div>");
htmlSource = source.toString ();
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
System.out.println (htmlSource);
System.out.println ("+");
System.out.println ("datas = new Data ();");
System.out.println ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");");
System.out.println ("datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");");
System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");");
System.out.println ("=>");
System.out.println (html);
} }
} }

View file

@ -8,7 +8,6 @@ package fr.devinsy.xid;
public class Data public class Data
{ {
protected IdsDataById idsDataById; protected IdsDataById idsDataById;
protected TagsDataById tagsDataById;
/** /**
@ -17,7 +16,6 @@ public class Data
public Data () public Data ()
{ {
this.idsDataById = new IdsDataById (); this.idsDataById = new IdsDataById ();
this.tagsDataById = new TagsDataById ();
} }
@ -35,20 +33,6 @@ public class Data
} }
/**
*
*/
public TagsDataById getTagsDataById ()
{
TagsDataById result;
result = this.tagsDataById;
//
return (result);
}
/** /**
* *
*/ */
@ -160,25 +144,9 @@ public class Data
*/ */
public void setContent (String id, String content) public void setContent (String id, String content)
{ {
if (id.startsWith ("<")) IdData idData = this.getIdData (id);
{
String tagName = id.substring (1, id.length () - 1);
TagData tag = this.tagsDataById.getId (tagName); idData.setContent (content);
if (tag == null)
{
tag = new TagData ();
this.tagsDataById.setId (tagName, tag);
}
tag.setContent (content);
}
else
{
IdData idData = this.getIdData (id);
idData.setContent (content);
}
} }
@ -247,25 +215,9 @@ public class Data
*/ */
public void setAttribute (String id, String label, String value) public void setAttribute (String id, String label, String value)
{ {
if (id.startsWith ("<")) IdData tag = this.getIdData (id);
{
String tagName = id.substring (1, id.length () - 1);
TagData tag = this.tagsDataById.getId (tagName); tag.getAttributes ().setAttribute (label, value);
if (tag == null)
{
tag = new TagData ();
this.tagsDataById.setId (tagName, tag);
}
tag.getAttributes ().setAttribute (label, value);
}
else
{
IdData tag = this.getIdData (id);
tag.getAttributes ().setAttribute (label, value);
}
} }

View file

@ -140,13 +140,13 @@ public class DomPresenter extends Presenter
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas, StringBuffer errorOutput)
{ {
return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); return (doXid (datas.getIdsDataById (), errorOutput));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
@ -160,7 +160,7 @@ public class DomPresenter extends Presenter
else else
{ {
// Build the web page. // Build the web page.
result = Presenter.doXid (this.doc, datas, tagsData, this.webappPath, errorOutput); result = Presenter.doXid (this.doc, datas, this.webappPath, errorOutput);
} }
// //
@ -172,18 +172,10 @@ public class DomPresenter extends Presenter
* Xid a file with data. * Xid a file with data.
*/ */
static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath, StringBuffer errorOutput) static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{
return (doXid (doc, datas, null, webappPath, errorOutput));
}
/*
* Xid a file with data.
*/
static public StringBuffer doXid (Document doc, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (doc, datas, tagsData, webappPath, errorOutput); result = Presenter.process (doc, datas, webappPath, errorOutput);
// //
return (result); return (result);

View file

@ -91,14 +91,14 @@ public class FilePresenter extends DomPresenter
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas, StringBuffer errorOutput)
{ {
return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); return (doXid (datas.getIdsDataById (), errorOutput));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
@ -134,7 +134,7 @@ public class FilePresenter extends DomPresenter
} }
// Build the web page. // Build the web page.
result = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput); result = Presenter.doXid (doc, datas, this.webappPath, errorOutput);
// //
return (result); return (result);
@ -158,7 +158,7 @@ public class FilePresenter extends DomPresenter
{ {
Presenter.addMetaTag (doc, "generator", "XID 0.0"); Presenter.addMetaTag (doc, "generator", "XID 0.0");
result = Presenter.doXid (doc, null, null, webappPath, errorOutput); result = Presenter.doXid (doc, null, webappPath, errorOutput);
} }
// //

View file

@ -54,18 +54,10 @@ public class Presenter
* Xid a file with data. * Xid a file with data.
*/ */
static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath, StringBuffer errorOutput) static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{
return (doXid (doc, datas, null, webappPath, errorOutput));
}
/*
* Xid a file with data.
*/
static public StringBuffer doXid (Document doc, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (doc, datas, tagsData, webappPath, errorOutput); result = Presenter.process (doc, datas, webappPath, errorOutput);
// //
return (result); return (result);
@ -153,11 +145,11 @@ public class Presenter
/* /*
* *
*/ */
static protected StringBuffer processChildren (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) static protected StringBuffer processChildren (Node node, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = processChildren (node, datas, tagsData, webappPath, "", errorOutput); result = processChildren (node, datas, webappPath, "", errorOutput);
// //
return (result); return (result);
@ -169,7 +161,6 @@ public class Presenter
*/ */
static protected StringBuffer processChildren (Node node, static protected StringBuffer processChildren (Node node,
IdsDataById datas, IdsDataById datas,
TagsDataById tagsData,
String webappPath, String webappPath,
String suffix, String suffix,
StringBuffer errorOutput) StringBuffer errorOutput)
@ -228,12 +219,12 @@ public class Presenter
lineCounter += 1; lineCounter += 1;
if (lineCounter == 1) if (lineCounter == 1)
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
break; break;
@ -248,12 +239,12 @@ public class Presenter
if ((lineCounter == 1) || (lineCounter == 2)) if ((lineCounter == 1) || (lineCounter == 2))
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
break; break;
@ -268,12 +259,12 @@ public class Presenter
if ((attrs2 != null) && if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null)) (attrs2.getNamedItem ("id") != null))
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
break; break;
@ -287,12 +278,12 @@ public class Presenter
if ((attrs2 == null) || if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null)) (attrs2.getNamedItem ("id") == null))
{ {
result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item(childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
} }
} }
break; break;
@ -300,7 +291,7 @@ public class Presenter
case ALL_ROWS: case ALL_ROWS:
for (int childIndex = 0; childIndex < childrenCount; childIndex++) for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{ {
result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput)); result.append (process (children.item(childIndex), datas, webappPath, suffix, errorOutput));
} }
break; break;
} }
@ -322,7 +313,6 @@ public class Presenter
NamedNodeMap attrMap, NamedNodeMap attrMap,
Node idAttr, Node idAttr,
IdsDataById datas, IdsDataById datas,
TagsDataById tagsData,
String webappPath, String webappPath,
StringBuffer errorOutput) StringBuffer errorOutput)
{ {
@ -352,7 +342,7 @@ public class Presenter
(attrMap.getNamedItem ("data") == null)) (attrMap.getNamedItem ("data") == null))
{ {
// STU: do default action. // STU: do default action.
Presenter.processElementBasically (node, datas, tagsData, webappPath, errorOutput); Presenter.processElementBasically (node, datas, webappPath, errorOutput);
} }
else else
{ {
@ -411,7 +401,7 @@ public class Presenter
int childCount = bodyChildren.getLength (); int childCount = bodyChildren.getLength ();
for (int childCounter = 0; childCounter < childCount; childCounter++) for (int childCounter = 0; childCounter < childCount; childCounter++)
{ {
result.append (process (bodyChildren.item (childCounter), datas, tagsData, webappPath, errorOutput)); result.append (process (bodyChildren.item (childCounter), datas, webappPath, errorOutput));
} }
} }
} }
@ -447,7 +437,7 @@ public class Presenter
{ {
StringBuffer result; StringBuffer result;
result = processElementWithId (node, attrs, idAttr, datas, null, "", webappPath, errorOutput); result = processElementWithId (node, attrs, idAttr, datas, "", webappPath, errorOutput);
// //
return (result); return (result);
@ -469,7 +459,6 @@ public class Presenter
NamedNodeMap attrs, NamedNodeMap attrs,
Node idAttr, Node idAttr,
IdsDataById datas, IdsDataById datas,
TagsDataById tagsData,
String webappPath, String webappPath,
String suffix, String suffix,
StringBuffer errorOutput) StringBuffer errorOutput)
@ -481,7 +470,7 @@ public class Presenter
if (tag.equals ("object")) if (tag.equals ("object"))
{ {
result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); result.append (processObjectTag (node, attrs, idAttr, datas, webappPath, errorOutput));
} }
else else
{ {
@ -494,7 +483,7 @@ public class Presenter
if (dataCore == null) if (dataCore == null)
{ {
result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append (Presenter.processElementBasically (node, datas, webappPath, suffix, errorOutput));
} }
else if (dataCore instanceof IdData) else if (dataCore instanceof IdData)
{ {
@ -518,25 +507,7 @@ public class Presenter
result.append (node.getNodeName()); result.append (node.getNodeName());
// Build attributes. // Build attributes.
Attributes tagAttributes; result.append (processAttributes (attrs, data.getAttributes (), suffix));
if (tagsData == null)
{
tagAttributes = null;
}
else
{
TagData tagData = tagsData.getId (node.getNodeName ());
if (tagData == null)
{
tagAttributes = null;
}
else
{
tagAttributes = tagData.getAttributes ();
}
}
result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, suffix));
if ((node.getChildNodes () == null) && if ((node.getChildNodes () == null) &&
((data == null) || (data.display () == null))) ((data == null) || (data.display () == null)))
@ -554,7 +525,7 @@ public class Presenter
if ((data == null) || if ((data == null) ||
(data.display () == null)) (data.display () == null))
{ {
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
} }
else else
{ {
@ -583,26 +554,7 @@ public class Presenter
result.append ("<"); result.append ("<");
result.append (node.getNodeName()); result.append (node.getNodeName());
// Build attributes. result.append (processAttributes (attrs, data.getAttributes (), Integer.toString (nLine)));
Attributes tagAttributes;
if (tagsData == null)
{
tagAttributes = null;
}
else
{
TagData tagData = tagsData.getId (node.getNodeName ());
if (tagData == null)
{
tagAttributes = null;
}
else
{
tagAttributes = tagData.getAttributes ();
}
}
result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, Integer.toString (nLine)));
if ((node.getChildNodes () == null) && if ((node.getChildNodes () == null) &&
((data == null) || (data.display () == null))) ((data == null) || (data.display () == null)))
@ -620,7 +572,7 @@ public class Presenter
// Insert data. // Insert data.
if ((data == null) || (data.display () == null)) if ((data == null) || (data.display () == null))
{ {
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
} }
else else
{ {
@ -638,7 +590,7 @@ public class Presenter
// Manage a Hashmap. // Manage a Hashmap.
IdsDataById data = (IdsDataById) tags.elementAt (nLine); IdsDataById data = (IdsDataById) tags.elementAt (nLine);
result.append (Presenter.processElementWithId (node, attrs, idAttr, data, tagsData, webappPath, Integer.toString (nLine), errorOutput)); result.append (Presenter.processElementWithId (node, attrs, idAttr, data, webappPath, Integer.toString (nLine), errorOutput));
result.append ('\n'); result.append ('\n');
} }
} }
@ -659,11 +611,11 @@ public class Presenter
/** /**
* *
*/ */
static protected StringBuffer process (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) static protected StringBuffer process (Node node, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (node, datas, tagsData, webappPath, "", errorOutput); result = Presenter.process (node, datas, webappPath, "", errorOutput);
// //
return (result); return (result);
@ -674,7 +626,7 @@ public class Presenter
* Recursive method that processes a node and any child nodes. * Recursive method that processes a node and any child nodes.
* *
*/ */
static protected StringBuffer process (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, String suffix, StringBuffer errorOutput) static protected StringBuffer process (Node node, IdsDataById datas, String webappPath, String suffix, StringBuffer errorOutput)
{ {
logger.debug ("Enter"); logger.debug ("Enter");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
@ -718,7 +670,7 @@ public class Presenter
// Log.write(Log.TRACE,"systemId = " + systemId); // Log.write(Log.TRACE,"systemId = " + systemId);
} }
result.append (Presenter.process (((Document) node).getDocumentElement(), datas, tagsData, webappPath, suffix, errorOutput)); result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, suffix, errorOutput));
break; break;
} }
@ -736,7 +688,6 @@ public class Presenter
attrs, attrs,
idAttr, idAttr,
datas, datas,
tagsData,
webappPath, webappPath,
suffix, suffix,
errorOutput)); errorOutput));
@ -748,11 +699,11 @@ public class Presenter
if (tag.equals ("object")) if (tag.equals ("object"))
{ {
result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); result.append (processObjectTag (node, attrs, idAttr, datas, webappPath, errorOutput));
} }
else else
{ {
result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append (Presenter.processElementBasically (node, datas, webappPath, suffix, errorOutput));
} }
} }
@ -820,11 +771,11 @@ public class Presenter
/* /*
* *
*/ */
static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) static StringBuffer processElementBasically (Node node, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = processElementBasically (node, datas, tagsData, webappPath, "", errorOutput); result = processElementBasically (node, datas, webappPath, "", errorOutput);
// //
return (result); return (result);
@ -834,7 +785,7 @@ public class Presenter
/* /*
* *
*/ */
static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, String suffix, StringBuffer errorOutput) static StringBuffer processElementBasically (Node node, IdsDataById datas, String webappPath, String suffix, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer ();
@ -843,30 +794,6 @@ public class Presenter
result.append ('<'); result.append ('<');
result.append (node.getNodeName()); result.append (node.getNodeName());
// Build the tag attributes.
Attributes tagAttributes;
if (tagsData == null)
{
tagAttributes = null;
}
else
{
TagData tagData = tagsData.getId (node.getNodeName ());
if (tagData == null)
{
tagAttributes = null;
}
else
{
tagAttributes = tagData.getAttributes ();
}
}
result.append (processAttributes (node.getAttributes (),
tagAttributes,
null,
suffix));
// //
if (node.getChildNodes () == null) if (node.getChildNodes () == null)
{ {
@ -876,7 +803,7 @@ public class Presenter
{ {
result.append('>'); result.append('>');
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
result.append("</"); result.append("</");
result.append(node.getNodeName()); result.append(node.getNodeName());

View file

@ -87,13 +87,13 @@ public class StringPresenter extends DomPresenter
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas, StringBuffer errorOutput)
{ {
return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); return (doXid (datas.getIdsDataById (), errorOutput));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
@ -119,7 +119,7 @@ public class StringPresenter extends DomPresenter
} }
StringBuffer htmlTarget; StringBuffer htmlTarget;
htmlTarget = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput); htmlTarget = Presenter.doXid (doc, datas, this.webappPath, errorOutput);
if (htmlTarget == null) if (htmlTarget == null)
{ {
@ -156,7 +156,7 @@ public class StringPresenter extends DomPresenter
*/ */
static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput) static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput)
{ {
return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), "", errorOutput)); return (doXid (html, datas.getIdsDataById (), "", errorOutput));
} }
@ -165,7 +165,7 @@ public class StringPresenter extends DomPresenter
*/ */
static public StringBuffer doXid (String html, Data datas, String webappPath, StringBuffer errorOutput) static public StringBuffer doXid (String html, Data datas, String webappPath, StringBuffer errorOutput)
{ {
return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), webappPath, errorOutput)); return (doXid (html, datas.getIdsDataById (), webappPath, errorOutput));
} }
@ -173,21 +173,12 @@ public class StringPresenter extends DomPresenter
* Xid a string with html in. * Xid a string with html in.
*/ */
static public StringBuffer doXid (String html, IdsDataById datas, String webappPath, StringBuffer errorOutput) static public StringBuffer doXid (String html, IdsDataById datas, String webappPath, StringBuffer errorOutput)
{
return (doXid (html, datas, null, webappPath, errorOutput));
}
/*
* Xid a string with html in.
*/
static public StringBuffer doXid (String html, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
StringPresenter presenter = new StringPresenter (webappPath, html); StringPresenter presenter = new StringPresenter (webappPath, html);
result = presenter.doXid (datas, tagsData, errorOutput); result = presenter.doXid (datas, errorOutput);
// //
return (result); return (result);

View file

@ -1,43 +0,0 @@
package fr.devinsy.xid;
import java.util.*;
/*
*
*/
public class TagsDataById extends HashMap<String, TagData>
{
private static final long serialVersionUID = 7818145931750600119L;
/*
*
*/
public TagsDataById ()
{
super ();
}
/*
*
*/
public void setId (String id, TagData data)
{
this.put (id, data);
}
/*
*
*/
public TagData getId (String id)
{
TagData result;
result = this.get (id);
//
return (result);
}
}