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);
// 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
{
protected IdsDataById idsDataById;
protected TagsDataById tagsDataById;
/**
@ -17,7 +16,6 @@ public class Data
public Data ()
{
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)
{
if (id.startsWith ("<"))
{
String tagName = id.substring (1, id.length () - 1);
IdData idData = this.getIdData (id);
TagData tag = this.tagsDataById.getId (tagName);
if (tag == null)
{
tag = new TagData ();
this.tagsDataById.setId (tagName, tag);
}
tag.setContent (content);
}
else
{
IdData idData = this.getIdData (id);
idData.setContent (content);
}
idData.setContent (content);
}
@ -247,25 +215,9 @@ public class Data
*/
public void setAttribute (String id, String label, String value)
{
if (id.startsWith ("<"))
{
String tagName = id.substring (1, id.length () - 1);
IdData tag = this.getIdData (id);
TagData tag = this.tagsDataById.getId (tagName);
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);
}
tag.getAttributes ().setAttribute (label, value);
}

View file

@ -140,13 +140,13 @@ public class DomPresenter extends Presenter
*/
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;
@ -160,7 +160,7 @@ public class DomPresenter extends Presenter
else
{
// 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.
*/
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;
result = Presenter.process (doc, datas, tagsData, webappPath, errorOutput);
result = Presenter.process (doc, datas, webappPath, errorOutput);
//
return (result);

View file

@ -91,14 +91,14 @@ public class FilePresenter extends DomPresenter
*/
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;
@ -134,7 +134,7 @@ public class FilePresenter extends DomPresenter
}
// Build the web page.
result = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput);
result = Presenter.doXid (doc, datas, this.webappPath, errorOutput);
//
return (result);
@ -158,7 +158,7 @@ public class FilePresenter extends DomPresenter
{
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.
*/
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;
result = Presenter.process (doc, datas, tagsData, webappPath, errorOutput);
result = Presenter.process (doc, datas, webappPath, errorOutput);
//
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;
result = processChildren (node, datas, tagsData, webappPath, "", errorOutput);
result = processChildren (node, datas, webappPath, "", errorOutput);
//
return (result);
@ -169,7 +161,6 @@ public class Presenter
*/
static protected StringBuffer processChildren (Node node,
IdsDataById datas,
TagsDataById tagsData,
String webappPath,
String suffix,
StringBuffer errorOutput)
@ -228,12 +219,12 @@ public class Presenter
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
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
}
}
break;
@ -248,12 +239,12 @@ public class Presenter
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
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
}
}
break;
@ -268,12 +259,12 @@ public class Presenter
if ((attrs2 != 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
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
}
}
break;
@ -287,12 +278,12 @@ public class Presenter
if ((attrs2 == 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
{
result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, webappPath, suffix, errorOutput));
}
}
break;
@ -300,7 +291,7 @@ public class Presenter
case ALL_ROWS:
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;
}
@ -322,7 +313,6 @@ public class Presenter
NamedNodeMap attrMap,
Node idAttr,
IdsDataById datas,
TagsDataById tagsData,
String webappPath,
StringBuffer errorOutput)
{
@ -352,7 +342,7 @@ public class Presenter
(attrMap.getNamedItem ("data") == null))
{
// STU: do default action.
Presenter.processElementBasically (node, datas, tagsData, webappPath, errorOutput);
Presenter.processElementBasically (node, datas, webappPath, errorOutput);
}
else
{
@ -411,7 +401,7 @@ public class Presenter
int childCount = bodyChildren.getLength ();
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;
result = processElementWithId (node, attrs, idAttr, datas, null, "", webappPath, errorOutput);
result = processElementWithId (node, attrs, idAttr, datas, "", webappPath, errorOutput);
//
return (result);
@ -469,7 +459,6 @@ public class Presenter
NamedNodeMap attrs,
Node idAttr,
IdsDataById datas,
TagsDataById tagsData,
String webappPath,
String suffix,
StringBuffer errorOutput)
@ -481,7 +470,7 @@ public class Presenter
if (tag.equals ("object"))
{
result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput));
result.append (processObjectTag (node, attrs, idAttr, datas, webappPath, errorOutput));
}
else
{
@ -494,7 +483,7 @@ public class Presenter
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)
{
@ -518,25 +507,7 @@ public class Presenter
result.append (node.getNodeName());
// Build 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 (attrs, data.getAttributes (), tagAttributes, suffix));
result.append (processAttributes (attrs, data.getAttributes (), suffix));
if ((node.getChildNodes () == null) &&
((data == null) || (data.display () == null)))
@ -554,7 +525,7 @@ public class Presenter
if ((data == null) ||
(data.display () == null))
{
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput));
result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
}
else
{
@ -583,26 +554,7 @@ public class Presenter
result.append ("<");
result.append (node.getNodeName());
// Build 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 (attrs, data.getAttributes (), tagAttributes, Integer.toString (nLine)));
result.append (processAttributes (attrs, data.getAttributes (), Integer.toString (nLine)));
if ((node.getChildNodes () == null) &&
((data == null) || (data.display () == null)))
@ -620,7 +572,7 @@ public class Presenter
// Insert data.
if ((data == null) || (data.display () == null))
{
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput));
result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
}
else
{
@ -638,7 +590,7 @@ public class Presenter
// Manage a Hashmap.
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');
}
}
@ -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;
result = Presenter.process (node, datas, tagsData, webappPath, "", errorOutput);
result = Presenter.process (node, datas, webappPath, "", errorOutput);
//
return (result);
@ -674,7 +626,7 @@ public class Presenter
* 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");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
@ -718,7 +670,7 @@ public class Presenter
// 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;
}
@ -736,7 +688,6 @@ public class Presenter
attrs,
idAttr,
datas,
tagsData,
webappPath,
suffix,
errorOutput));
@ -748,11 +699,11 @@ public class Presenter
if (tag.equals ("object"))
{
result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput));
result.append (processObjectTag (node, attrs, idAttr, datas, webappPath, errorOutput));
}
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;
result = processElementBasically (node, datas, tagsData, webappPath, "", errorOutput);
result = processElementBasically (node, datas, webappPath, "", errorOutput);
//
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;
result = new StringBuffer ();
@ -843,30 +794,6 @@ public class Presenter
result.append ('<');
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)
{
@ -876,7 +803,7 @@ public class Presenter
{
result.append('>');
result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput));
result.append (processChildren (node, datas, webappPath, suffix, errorOutput));
result.append("</");
result.append(node.getNodeName());

View file

@ -87,13 +87,13 @@ public class StringPresenter extends DomPresenter
*/
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;
@ -119,7 +119,7 @@ public class StringPresenter extends DomPresenter
}
StringBuffer htmlTarget;
htmlTarget = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput);
htmlTarget = Presenter.doXid (doc, datas, this.webappPath, errorOutput);
if (htmlTarget == null)
{
@ -156,7 +156,7 @@ public class StringPresenter extends DomPresenter
*/
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)
{
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.
*/
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;
StringPresenter presenter = new StringPresenter (webappPath, html);
result = presenter.doXid (datas, tagsData, errorOutput);
result = presenter.doXid (datas, errorOutput);
//
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);
}
}