diff --git a/build/classes/xid/Presenter.class b/build/classes/xid/Presenter.class index bc99068..6b26d0c 100644 Binary files a/build/classes/xid/Presenter.class and b/build/classes/xid/Presenter.class differ diff --git a/build/classes/xid/TagData$MODE.class b/build/classes/xid/TagData$MODE.class deleted file mode 100644 index c394f13..0000000 Binary files a/build/classes/xid/TagData$MODE.class and /dev/null differ diff --git a/build/classes/xid/TagData.class b/build/classes/xid/TagData.class index 02372ee..fdbd824 100644 Binary files a/build/classes/xid/TagData.class and b/build/classes/xid/TagData.class differ diff --git a/build/classes/xid/TagsData.class b/build/classes/xid/TagsData.class index 68212a5..eee90b1 100644 Binary files a/build/classes/xid/TagsData.class and b/build/classes/xid/TagsData.class differ diff --git a/build/classes/xid/TextTagData.class b/build/classes/xid/TextTagData.class deleted file mode 100644 index 5773284..0000000 Binary files a/build/classes/xid/TextTagData.class and /dev/null differ diff --git a/build_test/classes/xid/test/Test.class b/build_test/classes/xid/test/Test.class index 9785932..a1ac41d 100644 Binary files a/build_test/classes/xid/test/Test.class and b/build_test/classes/xid/test/Test.class differ diff --git a/dist/test.jar b/dist/test.jar index 4d6118d..d1eb21d 100644 Binary files a/dist/test.jar and b/dist/test.jar differ diff --git a/dist/xid.jar b/dist/xid.jar index 4e752e3..31716c8 100644 Binary files a/dist/xid.jar and b/dist/xid.jar differ diff --git a/src/xid/IdData.java b/src/xid/IdData.java new file mode 100644 index 0000000..c217244 --- /dev/null +++ b/src/xid/IdData.java @@ -0,0 +1,139 @@ +package xid; + +import java.util.*; +import java.io.*; + +/** + * IdData class is used to hold application data and + * the business logic that operates on the data. + * + * The only requirement of a IdData class is that it must implement a + * display method. The display method must return a text representation + * of the data, suitable for display in a web page. + * + * XID provides a User Input IdData, Text IdData and ... + * application may also implement it's own IdData classes. + * + */ +public class IdData implements Serializable, IdDataCore +{ + public enum MODE {REPLACE, APPEND, IGNORE}; + + protected Attributes attributes; + protected boolean excludeSection; + protected MODE displayMode = MODE.REPLACE; + protected String content; + + /* + * + */ + public IdData () + { + this.attributes = null; + this.excludeSection = false; + this.displayMode = MODE.REPLACE; + this.content = ""; + } + + + /* + * + */ + public IdData (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; + } + + + /* + * + */ + public void setDisplayMode(MODE displayMode) + { + this.displayMode = displayMode; + } + + + /* + * + */ + public MODE getDisplayMode() + { + MODE result; + + result = this.displayMode; + + return (result); + } + + + /* + * + */ + public Attributes getAttributes () + { + Attributes result; + + if (this.attributes == null) + { + this.attributes = new Attributes (); + } + + result = this.attributes; + + // + return (result); + } + + + /* + * + */ + public void setExcludeSection(boolean excludeSection) + { + this.excludeSection = excludeSection; + } + + + /* + * + */ + public boolean getExcludeSection() + { + return excludeSection; + } + +} diff --git a/src/xid/TagDataCore.java b/src/xid/IdDataCore.java similarity index 85% rename from src/xid/TagDataCore.java rename to src/xid/IdDataCore.java index 8865ed8..5fa290c 100644 --- a/src/xid/TagDataCore.java +++ b/src/xid/IdDataCore.java @@ -13,6 +13,6 @@ import java.io.*; * This interface helps to express this fact. * */ -public interface TagDataCore +public interface IdDataCore { } diff --git a/src/xid/IdsData.java b/src/xid/IdsData.java new file mode 100644 index 0000000..503ec5b --- /dev/null +++ b/src/xid/IdsData.java @@ -0,0 +1,223 @@ +package xid; + +import java.util.*; +import java.io.*; + +/* + * + */ +public class IdsData extends IdsDataById +{ + /** + * + */ + public IdsData () + { + super (); + } + + + /** + * + */ + public IdData getIdData (String id) + { + IdData result; + + // Be sure that IdData is existing and get item. + result = (IdData) this.get (id); + + if (result == null) + { + this.put (id, new IdData ()); + + result = (IdData) this.get (id); + } + + + // + return (result); + } + + + /** + * + */ + public IdData getIdData (String id, int line) + { + IdData result; + + // Be sure that IdsData are existing. + IdsDataByIndex tags = (IdsDataByIndex) this.get (id); + if (tags == null) + { + this.put (id, new IdsDataByIndex ()); + + tags = (IdsDataByIndex) this.get (id); + } + + // Be sure that lines are existing. + int nbLines = tags.size (); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add (nLine, new IdData ()); + } + + // Get item. + result = (IdData) tags.elementAt (line); + + // + return (result); + } + + + /** + * + */ + public IdData getIdData (String id, int line, String column) + { + IdData result; + + // Be sure that IdsData are existing. + IdsDataByIndex tags = (IdsDataByIndex) this.get (id); + if (tags == null) + { + this.put (id, new IdsDataByIndex ()); + + tags = (IdsDataByIndex) this.get (id); + } + + // Be sure that lines are existing. + int nbLines = tags.size (); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add (nLine, new IdsDataById ()); + } + + // Get item. + IdsDataById lineData = (IdsDataById) tags.elementAt (line); + + result = (IdData) lineData.get (column); + + if (result == null) + { + lineData.put (column, new IdData ()); + + result = (IdData) lineData.get (column); + } + + // + return (result); + } + + + /** + * + */ + public void setIterationStrategy (String id, IdsDataByIndex.IterationStrategy strategy) + { + IdsDataByIndex tags = (IdsDataByIndex) this.get (id); + + tags.setIterationStrategy (strategy); + } + + + + /** + * + */ + public void setContent (String id, String content) + { + IdData tag = this.getIdData (id); + + tag.setContent (content); + } + + + /** + * + */ + public void setContent (String id, int line, String content) + { + IdData tag = this.getIdData (id, line); + + tag.setContent (content); + } + + + /** + * + */ + public void setContent (String id, int line, String column, String content) + { + IdData tag = this.getIdData (id, line, column); + + tag.setContent (content); + } + + + /** + * + */ + public void setAttribute (String id, String label, String value) + { + IdData tag = this.getIdData (id); + + tag.getAttributes ().setAttribute (label, value); + } + + + /** + * + */ + public void setAttribute (String id, int line, String label, String value) + { + IdData tag = this.getIdData (id, line); + + tag.getAttributes ().setAttribute (label, value); + } + + + /** + * + */ + public void setAttribute (String id, int line, String column, String label, String value) + { + IdData tag = this.getIdData (id, line, column); + + tag.getAttributes ().setAttribute (label, value); + } + + + /** + * + */ + public void appendAttribute (String id, String label, String value) + { + IdData tag = this.getIdData (id); + + tag.getAttributes ().appendAttribute (label, value); + } + + + /** + * + */ + public void appendContent (String id, int line, String label, String value) + { + IdData tag = this.getIdData (id, line); + + tag.getAttributes ().appendAttribute (label, value); + } + + + /** + * + */ + public void appendContent (String id, int line, String column, String label, String value) + { + IdData tag = this.getIdData (id, line, column); + + tag.getAttributes ().appendAttribute (label, value); + } +} diff --git a/src/xid/IdsDataById.java b/src/xid/IdsDataById.java new file mode 100644 index 0000000..e9f1d1c --- /dev/null +++ b/src/xid/IdsDataById.java @@ -0,0 +1,40 @@ +package xid; + +import java.util.*; +import java.io.*; + +/* + * + */ +public class IdsDataById extends HashMap implements IdDataCore +{ + /* + * + */ + public IdsDataById () + { + super (); + } + + /* + * + */ + public void setId (String id, IdDataCore data) + { + this.put (id, data); + } + + /* + * + */ + public IdDataCore getId (String id) + { + IdDataCore result; + + result = this.get (id); + + // + return (result); + } + +} diff --git a/src/xid/TagsDataByIndex.java b/src/xid/IdsDataByIndex.java similarity index 80% rename from src/xid/TagsDataByIndex.java rename to src/xid/IdsDataByIndex.java index e8ee8d9..6f70081 100644 --- a/src/xid/TagsDataByIndex.java +++ b/src/xid/IdsDataByIndex.java @@ -6,7 +6,7 @@ import java.io.*; /* * */ -public class TagsDataByIndex extends Vector implements TagDataCore +public class IdsDataByIndex extends Vector implements IdDataCore { public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS} @@ -15,7 +15,7 @@ public class TagsDataByIndex extends Vector implements TagDataCore /** * */ - public TagsDataByIndex () + public IdsDataByIndex () { super (); this.iterationStrategy = IterationStrategy.ONLY_FIRST_ROW; diff --git a/src/xid/Presenter.java b/src/xid/Presenter.java index 280bba9..0f3ce99 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -91,7 +91,15 @@ public class Presenter /* * */ - public StringBuffer doXid (TagsDataById datas, StringBuffer errorOutput) + public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput) + { + return (doXid (datas, null, errorOutput)); + } + + /* + * + */ + public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) { StringBuffer result; @@ -127,7 +135,7 @@ public class Presenter } // Build the web page. - result = Presenter.doXid (doc, datas, this.webappPath, errorOutput); + result = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput); // return (result); @@ -151,7 +159,7 @@ public class Presenter { Presenter.addMetaTag (doc, "generator", "XID 0.0"); - result = Presenter.doXid (doc, null, webappPath, errorOutput); + result = Presenter.doXid (doc, null, null, webappPath, errorOutput); } // @@ -162,7 +170,15 @@ public class Presenter /* * Xid a string with html in. */ - static public StringBuffer doXid (String html, TagsDataById 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; @@ -186,7 +202,7 @@ public class Presenter doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()), errorOutput); StringBuffer htmlTarget; - htmlTarget = Presenter.process (doc, datas, webappPath, errorOutput); + htmlTarget = Presenter.process (doc, datas, tagsData, webappPath, errorOutput); if (htmlTarget == null) { @@ -221,11 +237,19 @@ public class Presenter /* * Xid a file with data. */ - static public StringBuffer doXid (Document doc, TagsDataById 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; - result = Presenter.process (doc, datas, webappPath, errorOutput); + result = Presenter.process (doc, datas, tagsData, webappPath, errorOutput); // return (result); @@ -313,11 +337,11 @@ public class Presenter /* * */ - static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput) + static protected StringBuffer processChildren (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) { StringBuffer result; - result = processChildren (node, datas, webappPath, "", errorOutput); + result = processChildren (node, datas, tagsData, webappPath, "", errorOutput); // return (result); @@ -327,7 +351,12 @@ public class Presenter /* * */ - static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) + static protected StringBuffer processChildren (Node node, + IdsDataById datas, + TagsDataById tagsData, + String webappPath, + String suffix, + StringBuffer errorOutput) { StringBuffer result; result = new StringBuffer (); @@ -342,9 +371,9 @@ public class Presenter else { // - // Is there a TagsDataByIndex associated with the first ELEMENT_NODE child? + // Is there a IdsDataByIndex associated with the first ELEMENT_NODE child? // - TagsDataByIndex tagsData; + IdsDataByIndex idsData; // Find the first ELEMENT_NODE child. int childIndex = 0; @@ -370,7 +399,7 @@ public class Presenter if (child == null) { - tagsData = null; + idsData = null; } else { @@ -402,39 +431,39 @@ public class Presenter // Searching for the datas associated to the childId. if (childId == null) { - tagsData = null; + idsData = null; } else { - // Check if the data is a TagsDataByIndex. - if (datas.getId (childId) instanceof TagsDataByIndex) + // Check if the data is a IdsDataByIndex. + if (datas.getId (childId) instanceof IdsDataByIndex) { - tagsData = (TagsDataByIndex) datas.getId (childId); + idsData = (IdsDataByIndex) datas.getId (childId); } else { - tagsData = null; + idsData = null; } } } // So, is there? - if (tagsData == null) + if (idsData == null) { for (int i = 0; i < childrenCount; i++) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput)); } } else { - switch (tagsData.getIterationStrategy ()) + switch (idsData.getIterationStrategy ()) { case ONLY_FIRST_ROW: for (int i = 0; i <= childIndex; i++) { - result.append (process (children.item (i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item (i), datas, tagsData, webappPath, suffix, errorOutput)); } break; @@ -446,7 +475,7 @@ public class Presenter if ((attrs2 != null) && (attrs2.getNamedItem ("id") != null)) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput)); } } break; @@ -461,7 +490,7 @@ public class Presenter if ((attrs2 == null) || (attrs2.getNamedItem ("id") == null)) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput)); } } break; @@ -469,7 +498,7 @@ public class Presenter case ALL_ROWS: for (int i = 0; i < childrenCount; i++) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, tagsData, webappPath, suffix, errorOutput)); } break; } @@ -489,7 +518,7 @@ public class Presenter * @param attrMap * @param idAttr */ - static protected StringBuffer processObjectTag (Node node, NamedNodeMap attrMap, Node idAttr, TagsDataById datas, String webappPath, StringBuffer errorOutput) + static protected StringBuffer processObjectTag (Node node, NamedNodeMap attrMap, Node idAttr, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) { StringBuffer result; @@ -518,7 +547,7 @@ public class Presenter (attrMap.getNamedItem ("data") == null)) { // STU: do default action. - Presenter.processElementBasically (node, datas, webappPath, errorOutput); + Presenter.processElementBasically (node, datas, tagsData, webappPath, errorOutput); } else { @@ -571,7 +600,7 @@ public class Presenter int childCount = bodyChildren.getLength (); for (int childCounter = 0; childCounter < childCount; childCounter++) { - result.append (process (bodyChildren.item (childCounter), datas, webappPath, errorOutput)); + result.append (process (bodyChildren.item (childCounter), datas, tagsData, webappPath, errorOutput)); } } @@ -599,14 +628,14 @@ public class Presenter static protected StringBuffer processElementWithId (Node node, NamedNodeMap attrs, Node idAttr, - TagsDataById datas, + IdsDataById datas, String webappPath, StringBuffer errorOutput) { StringBuffer result; - result = processElementWithId (node, attrs, idAttr, datas, "", webappPath, errorOutput); + result = processElementWithId (node, attrs, idAttr, datas, null, "", webappPath, errorOutput); // return (result); @@ -627,9 +656,10 @@ public class Presenter static protected StringBuffer processElementWithId (Node node, NamedNodeMap attrs, Node idAttr, - TagsDataById datas, + IdsDataById datas, + TagsDataById tagsData, String webappPath, - String prefix, + String suffix, StringBuffer errorOutput) { StringBuffer result; @@ -641,15 +671,15 @@ public class Presenter log.debug ("tag=" + tag); // Get data of this id. - TagDataCore dataCore = datas.get (idAttr.getNodeValue ()); + IdDataCore dataCore = datas.get (idAttr.getNodeValue ()); if (dataCore == null) { - result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); } - else if (dataCore instanceof TagData) + else if (dataCore instanceof IdData) { - TagData data = (TagData) dataCore; + IdData data = (IdData) dataCore; String theClass; if (data == null) @@ -669,7 +699,25 @@ public class Presenter result.append (node.getNodeName()); // Build attributes. - result.append (processAttributes (attrs, data.getAttributes (), datas.getNamedTagAttributes (node.getNodeName ()), prefix)); + 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)); if ((node.getChildNodes () == null) && ((data == null) || data.display ().equals (""))) @@ -685,7 +733,7 @@ public class Presenter if ((data == null) || (data.display ().equals (""))) { - result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); } else { @@ -699,23 +747,41 @@ public class Presenter } } } - else if (dataCore instanceof TagsDataByIndex) + else if (dataCore instanceof IdsDataByIndex) { - TagsDataByIndex tags = (TagsDataByIndex) dataCore; + IdsDataByIndex tags = (IdsDataByIndex) dataCore; int nbLines = tags.size (); for (int nLine = 0; nLine < nbLines; nLine++) { - if (tags.elementAt (nLine) instanceof TagData) + if (tags.elementAt (nLine) instanceof IdData) { - TagData data = (TagData) tags.elementAt (nLine); + IdData data = (IdData) tags.elementAt (nLine); // Open the tag. result.append ("<"); result.append (node.getNodeName()); // Build attributes. - result.append (processAttributes (attrs, data.getAttributes (), datas.getNamedTagAttributes (node.getNodeName ()), 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) && ((data == null) || data.display ().equals (""))) @@ -731,7 +797,7 @@ public class Presenter if ((data == null) || (data.display ().equals (""))) { - result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); } else { @@ -747,16 +813,16 @@ public class Presenter else { // Manage a Hashmap. - TagsDataById data = (TagsDataById) tags.elementAt (nLine); + IdsDataById data = (IdsDataById) tags.elementAt (nLine); - result.append (Presenter.processElementWithId (node, attrs, idAttr, data, webappPath, Integer.toString (nLine), errorOutput)); + result.append (Presenter.processElementWithId (node, attrs, idAttr, data, tagsData, webappPath, Integer.toString (nLine), errorOutput)); result.append ('\n'); } } } else { - log.warn ("Unknow type of TagDataId"); + log.warn ("Unknow type of IdDataId"); } // @@ -769,11 +835,11 @@ public class Presenter /** * */ - static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput) + static protected StringBuffer process (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) { StringBuffer result; - result = Presenter.process (node, datas, webappPath, "", errorOutput); + result = Presenter.process (node, datas, tagsData, webappPath, "", errorOutput); // return (result); @@ -784,7 +850,7 @@ public class Presenter * Recursive method that processes a node and any child nodes. * */ - static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) + static protected StringBuffer process (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, String suffix, StringBuffer errorOutput) { log.debug ("Enter"); String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; @@ -828,7 +894,7 @@ public class Presenter // Log.write(Log.TRACE,"systemId = " + systemId); } - result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, prefix, errorOutput)); + result.append (Presenter.process (((Document) node).getDocumentElement(), datas, tagsData, webappPath, suffix, errorOutput)); break; } @@ -842,11 +908,18 @@ public class Presenter if (idAttr != null) { - result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput)); + result.append (Presenter.processElementWithId (node, + attrs, + idAttr, + datas, + tagsData, + webappPath, + suffix, + errorOutput)); } else { - result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); } break; @@ -913,11 +986,11 @@ public class Presenter /* * */ - static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput) + static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) { StringBuffer result; - result = processElementBasically (node, datas, webappPath, "", errorOutput); + result = processElementBasically (node, datas, tagsData, webappPath, "", errorOutput); // return (result); @@ -927,7 +1000,7 @@ public class Presenter /* * */ - static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) + static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, String suffix, StringBuffer errorOutput) { StringBuffer result; result = new StringBuffer (); @@ -937,10 +1010,28 @@ public class Presenter 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 (), - datas.getNamedTagAttributes (node.getNodeName ()), + tagAttributes, null, - prefix)); + suffix)); // if (node.getChildNodes () == null) @@ -951,7 +1042,7 @@ public class Presenter { result.append('>'); - result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); result.append(" attribute = (Map.Entry) iterator.next(); - if ((attribute.getKey ().equals ("id")) && (prefix.length () != 0)) + if ((attribute.getKey ().equals ("id")) && (suffix.length () != 0)) { - result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + Presenter.INDEX_SEPARATOR + prefix + "\""); + result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + Presenter.INDEX_SEPARATOR + suffix + "\""); } else { diff --git a/src/xid/TagData.java b/src/xid/TagData.java index 8bdd109..66b54f6 100644 --- a/src/xid/TagData.java +++ b/src/xid/TagData.java @@ -4,137 +4,33 @@ import java.util.*; import java.io.*; /** - * TagData class is used to hold application data and + * IdData class is used to hold application data and * the business logic that operates on the data. * - * The only requirement of a TagData class is that it must implement a + * The only requirement of a IdData class is that it must implement a * display method. The display method must return a text representation * of the data, suitable for display in a web page. * - * XID provides a User Input TagData, Text TagData and ... - * application may also implement it's own TagData classes. + * XID provides a User Input IdData, Text IdData and ... + * application may also implement it's own IdData classes. * */ -public class TagData implements Serializable, TagDataCore +public class TagData extends IdData implements Serializable { - public enum MODE {REPLACE, APPEND, IGNORE}; - - protected Attributes attributes; - protected boolean excludeSection; - protected MODE displayMode = MODE.REPLACE; - - String content; - /* * */ public TagData () { - this.attributes = null; - this.excludeSection = false; - this.displayMode = MODE.REPLACE; - this.content = ""; + super (); } - - + + /* * */ public TagData (String text) { - this.attributes = null; - this.excludeSection = false; - this.displayMode = MODE.REPLACE; - this.content = text; + super (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; - } - - - /* - * - */ - public void setDisplayMode(MODE displayMode) - { - this.displayMode = displayMode; - } - - - /* - * - */ - public MODE getDisplayMode() - { - MODE result; - - result = this.displayMode; - - return (result); - } - - - /* - * - */ - public Attributes getAttributes () - { - Attributes result; - - if (this.attributes == null) - { - this.attributes = new Attributes (); - } - - result = this.attributes; - - // - return (result); - } - - - /* - * - */ - public void setExcludeSection(boolean excludeSection) - { - this.excludeSection = excludeSection; - } - - - /* - * - */ - public boolean getExcludeSection() - { - return excludeSection; - } - } diff --git a/src/xid/TagsData.java b/src/xid/TagsData.java index cfc7b9c..9cbc888 100644 --- a/src/xid/TagsData.java +++ b/src/xid/TagsData.java @@ -24,7 +24,7 @@ public class TagsData extends TagsDataById { TagData result; - // Be sure that TagData is existing and get item. + // Be sure that data is existing and get item. result = (TagData) this.get (id); if (result == null) @@ -40,89 +40,6 @@ public class TagsData extends TagsDataById } - /** - * - */ - public TagData getTagData (String id, int line) - { - TagData result; - - // Be sure that TagsData are existing. - TagsDataByIndex tags = (TagsDataByIndex) this.get (id); - if (tags == null) - { - this.put (id, new TagsDataByIndex ()); - - tags = (TagsDataByIndex) this.get (id); - } - - // Be sure that lines are existing. - int nbLines = tags.size (); - for (int nLine = nbLines; nLine < line + 1; nLine++) - { - tags.add (nLine, new TagData ()); - } - - // Get item. - result = (TagData) tags.elementAt (line); - - // - return (result); - } - - - /** - * - */ - public TagData getTagData (String id, int line, String column) - { - TagData result; - - // Be sure that TagsData are existing. - TagsDataByIndex tags = (TagsDataByIndex) this.get (id); - if (tags == null) - { - this.put (id, new TagsDataByIndex ()); - - tags = (TagsDataByIndex) this.get (id); - } - - // Be sure that lines are existing. - int nbLines = tags.size (); - for (int nLine = nbLines; nLine < line + 1; nLine++) - { - tags.add (nLine, new TagsDataById ()); - } - - // Get item. - TagsDataById lineData = (TagsDataById) tags.elementAt (line); - - result = (TagData) lineData.get (column); - - if (result == null) - { - lineData.put (column, new TagData ()); - - result = (TagData) lineData.get (column); - } - - // - return (result); - } - - - /** - * - */ - public void setIterationStrategy (String id, TagsDataByIndex.IterationStrategy strategy) - { - TagsDataByIndex tags = (TagsDataByIndex) this.get (id); - - tags.setIterationStrategy (strategy); - } - - - /** * */ @@ -134,28 +51,6 @@ public class TagsData extends TagsDataById } - /** - * - */ - public void setContent (String id, int line, String content) - { - TagData tag = this.getTagData (id, line); - - tag.setContent (content); - } - - - /** - * - */ - public void setContent (String id, int line, String column, String content) - { - TagData tag = this.getTagData (id, line, column); - - tag.setContent (content); - } - - /** * */ @@ -167,28 +62,6 @@ public class TagsData extends TagsDataById } - /** - * - */ - public void setAttribute (String id, int line, String label, String value) - { - TagData tag = this.getTagData (id, line); - - tag.getAttributes ().setAttribute (label, value); - } - - - /** - * - */ - public void setAttribute (String id, int line, String column, String label, String value) - { - TagData tag = this.getTagData (id, line, column); - - tag.getAttributes ().setAttribute (label, value); - } - - /** * */ @@ -198,26 +71,4 @@ public class TagsData extends TagsDataById tag.getAttributes ().appendAttribute (label, value); } - - - /** - * - */ - public void appendContent (String id, int line, String label, String value) - { - TagData tag = this.getTagData (id, line); - - tag.getAttributes ().appendAttribute (label, value); - } - - - /** - * - */ - public void appendContent (String id, int line, String column, String label, String value) - { - TagData tag = this.getTagData (id, line, column); - - tag.getAttributes ().appendAttribute (label, value); - } } diff --git a/src/xid/TagsDataById.java b/src/xid/TagsDataById.java index 6975cc0..8b7d47b 100644 --- a/src/xid/TagsDataById.java +++ b/src/xid/TagsDataById.java @@ -6,7 +6,7 @@ import java.io.*; /* * */ -public class TagsDataById extends HashMap implements TagDataCore +public class TagsDataById extends HashMap { /* * @@ -19,7 +19,7 @@ public class TagsDataById extends HashMap implements TagDat /* * */ - public void setId (String id, TagDataCore data) + public void setId (String id, TagData data) { this.put (id, data); } @@ -27,9 +27,9 @@ public class TagsDataById extends HashMap implements TagDat /* * */ - public TagDataCore getId (String id) + public TagData getId (String id) { - TagDataCore result; + TagData result; result = this.get (id); @@ -37,38 +37,4 @@ public class TagsDataById extends HashMap implements TagDat return (result); } - - /* - * - */ - public Attributes getNamedTagAttributes (String name) - { - Attributes result; - - if (name == null) - { - result = null; - } - else - { - TagDataCore dataCore = this.getId ("<" + name + ">"); - if (dataCore == null) - { - result = null; - } - else if (!(dataCore instanceof TagData)) - { - result = null; - } - else - { - TagData data = (TagData) dataCore; - - result = data.getAttributes (); - } - } - - // - return (result); - } } diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index 816f07b..4b6e3bc 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -47,8 +47,8 @@ class Test //test (); // - TagsData datas; - TagData tag; + IdsData datas; + IdData tag; @@ -58,16 +58,16 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); - tag = new TagData (); + datas = new IdsData (); + tag = new IdData (); tag.setContent ("Superman"); datas.put ("name", tag); errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); - System.out.println ("tag = new TagData ();"); + System.out.println ("datas = new IdsData ();"); + System.out.println ("tag = new IdData ();"); System.out.println ("tag.setContent (\"Superman\");"); System.out.println ("datas.put (\"name\", tag););"); System.out.println ("+"); @@ -78,13 +78,13 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); System.out.println ("+"); System.out.println ("
a name
"); @@ -94,8 +94,8 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); - tag = new TagData (); + datas = new IdsData (); + tag = new IdData (); tag.setContent ("Spiderman"); tag.getAttributes ().appendAttribute ("style", "background: blue;"); tag.getAttributes ().appendAttribute ("style", "foreground: red;"); @@ -106,8 +106,8 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); - System.out.println ("tag = new TagData ();"); + System.out.println ("datas = new IdsData ();"); + System.out.println ("tag = new IdData ();"); 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;\");"); @@ -121,7 +121,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setContent ("lastname", "Spiderman"); datas.appendAttribute ("lastname", "style", "background: blue;"); datas.appendAttribute ("lastname", "style", "foreground: red;"); @@ -131,7 +131,7 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); @@ -144,7 +144,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 1, "bravo"); datas.setContent ("words", 2, "charlie"); @@ -156,7 +156,7 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); @@ -173,7 +173,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, "nom", "Momon"); @@ -190,7 +190,7 @@ class Test htmlSource = source.toString (); html = Presenter.doXid (htmlSource, datas, "", errorMessage); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); @@ -206,17 +206,17 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, "nom", "Momon"); datas.setContent ("identity", 1, "prenom", "Christian"); datas.setContent ("identity", 2, "nom", "Tronche"); datas.setContent ("identity", 2, "prenom", "Christophe"); - datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); - //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); - //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); - //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ALL_ROWS); + datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); + //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); errorMessage = new StringBuffer (); @@ -228,7 +228,7 @@ class Test source.append (""); htmlSource = source.toString (); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); @@ -241,22 +241,22 @@ class Test System.out.println ("=>"); - datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); + datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println ("ONLY_FIRST_ROW:"); html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println (html); - datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println (html); - datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println (html); - datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ALL_ROWS); + datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println ("ALL_ROWS:"); html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println (html); @@ -264,8 +264,9 @@ class Test // Populate attributes of Test 03. + /* System.out.println ("----------------------------"); - datas = new TagsData (); + datas = new IdsData (); datas.setAttribute ("
", "class", "aDivClass"); datas.setAttribute ("
", "style", "background-color: #000000;"); datas.setAttribute ("number", "style", "background-color: #0000FF;"); @@ -284,14 +285,13 @@ class Test System.out.println (htmlSource); System.out.println ("+"); - System.out.println ("datas = new TagsData ();"); + System.out.println ("datas = new IdsData ();"); System.out.println ("datas.setAttribute (\"
\", \"class\", \"aDivClass\");"); System.out.println ("datas.setAttribute (\"
\", \"style\", \"background-color: #000000;\");"); System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"); System.out.println ("=>"); System.out.println (html); - - + */ } } diff --git a/test/xid/test/Test.java~ b/test/xid/test/Test.java~ index 7b4873c..816f07b 100644 --- a/test/xid/test/Test.java~ +++ b/test/xid/test/Test.java~ @@ -57,6 +57,7 @@ class Test StringBuffer errorMessage; // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); tag = new TagData (); tag.setContent ("Superman"); @@ -65,7 +66,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.setContent (\"Superman\");"); @@ -77,13 +77,13 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); System.out.println ("+"); @@ -93,6 +93,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); tag = new TagData (); tag.setContent ("Spiderman"); @@ -105,7 +106,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");"); @@ -120,6 +120,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("lastname", "Spiderman"); datas.appendAttribute ("lastname", "style", "background: blue;"); @@ -130,7 +131,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); @@ -143,6 +143,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 1, "bravo"); @@ -155,7 +156,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); @@ -172,6 +172,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); @@ -182,10 +183,13 @@ class Test errorMessage = new StringBuffer (); - htmlSource = "\n \n
noidun nomun prenom
"; + StringBuffer source = new StringBuffer (); + source.append ("\n"); + source.append (" \n"); + source.append ("
noidun nomun prenom
"); + htmlSource = source.toString (); html = Presenter.doXid (htmlSource, datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); @@ -201,6 +205,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); @@ -215,7 +220,7 @@ class Test errorMessage = new StringBuffer (); - StringBuffer source = new StringBuffer (); + source = new StringBuffer (); source.append ("\n"); source.append (" \n"); source.append (" \n"); @@ -223,7 +228,6 @@ class Test source.append ("
noidun nomun prenom
noidun nomun prenom
"); htmlSource = source.toString (); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");