diff --git a/build/classes/fr/devinsy/xid/DomPresenter.class b/build/classes/fr/devinsy/xid/DomPresenter.class index b1eb8b0..06f6aa4 100644 Binary files a/build/classes/fr/devinsy/xid/DomPresenter.class and b/build/classes/fr/devinsy/xid/DomPresenter.class differ diff --git a/build/classes/fr/devinsy/xid/FilePresenter.class b/build/classes/fr/devinsy/xid/FilePresenter.class index 0e555c5..ee698d8 100644 Binary files a/build/classes/fr/devinsy/xid/FilePresenter.class and b/build/classes/fr/devinsy/xid/FilePresenter.class differ diff --git a/build/classes/fr/devinsy/xid/Presenter.class b/build/classes/fr/devinsy/xid/Presenter.class index ff98787..5404eb7 100644 Binary files a/build/classes/fr/devinsy/xid/Presenter.class and b/build/classes/fr/devinsy/xid/Presenter.class differ diff --git a/build/classes/fr/devinsy/xid/StringPresenter.class b/build/classes/fr/devinsy/xid/StringPresenter.class index 8e160a5..8dd411f 100644 Binary files a/build/classes/fr/devinsy/xid/StringPresenter.class and b/build/classes/fr/devinsy/xid/StringPresenter.class differ diff --git a/src/fr/devinsy/xid/DomPresenter.java b/src/fr/devinsy/xid/DomPresenter.java index a79d0da..7775b5e 100644 --- a/src/fr/devinsy/xid/DomPresenter.java +++ b/src/fr/devinsy/xid/DomPresenter.java @@ -1,5 +1,7 @@ package fr.devinsy.xid; +import java.io.StringWriter; + import org.w3c.dom.*; /** @@ -116,8 +118,9 @@ public class DomPresenter extends Presenter else { // Build the web page. - result = new StringBuffer (); - Presenter.doXid (result, this.doc, datas); + StringWriter htmlCode = new StringWriter(); + Presenter.doXid (htmlCode, this.doc, datas); + result = new StringBuffer (htmlCode.toString()); } // @@ -132,8 +135,9 @@ public class DomPresenter extends Presenter { StringBuffer result; - result = new StringBuffer(); - Presenter.process (result, doc, datas); + StringWriter htmlCode = new StringWriter(); + Presenter.process (htmlCode, doc, datas); + result = htmlCode.getBuffer(); // return (result); diff --git a/src/fr/devinsy/xid/FilePresenter.java b/src/fr/devinsy/xid/FilePresenter.java index 9bf879b..d748307 100644 --- a/src/fr/devinsy/xid/FilePresenter.java +++ b/src/fr/devinsy/xid/FilePresenter.java @@ -113,8 +113,9 @@ public class FilePresenter extends DomPresenter } // Build the web page. - result = new StringBuffer (Presenter.estimatedTargetLength(source.length())); - Presenter.doXid (result, doc, datas); + StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(source.length())); + Presenter.doXid (htmlCode, doc, datas); + result = htmlCode.getBuffer(); // return (result); diff --git a/src/fr/devinsy/xid/Presenter.java b/src/fr/devinsy/xid/Presenter.java index 19c24e6..be2ee26 100644 --- a/src/fr/devinsy/xid/Presenter.java +++ b/src/fr/devinsy/xid/Presenter.java @@ -25,7 +25,7 @@ public class Presenter /* * Xid a file with data. */ - static public void doXid (StringBuffer result, Document doc, IdsDataById datas) throws Exception + static public void doXid (Writer result, Document doc, IdsDataById datas) throws Exception { Presenter.process (result, doc, datas); } @@ -82,11 +82,11 @@ public class Presenter { result = new Attributes (target); - Iterator iterator = source.entrySet().iterator(); + Iterator> iterator = source.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry attribute = (Map.Entry) iterator.next(); + Map.Entry attribute = iterator.next(); String currentValue = target.get (attribute.getKey ()); @@ -109,10 +109,11 @@ public class Presenter return (result); } + /* * */ - static protected void processChildren (StringBuffer result, Node node, IdsDataById datas) throws Exception + static protected void processChildren (Writer result, Node node, IdsDataById datas) throws Exception { processChildren (result, node, datas, ""); } @@ -121,10 +122,7 @@ public class Presenter /* * */ - static protected void processChildren (StringBuffer result, - Node node, - IdsDataById datas, - String suffix) throws Exception + static protected void processChildren (Writer result, Node node, IdsDataById datas, String suffix) throws Exception { // Get the iteration strategy. IdData.IterationStrategy strategy; @@ -267,18 +265,10 @@ public class Presenter * @param idAttr * The ID. */ - static protected StringBuffer processElementWithId (Node node, - NamedNodeMap attrs, - Node idAttr, - IdsDataById datas) throws Exception + static protected void processElementWithId (Writer result, Node node, NamedNodeMap attrs, Node idAttr, IdsDataById datas) throws Exception { - StringBuffer result; - - result = processElementWithId (node, attrs, idAttr, datas, ""); - - // - return (result); + processElementWithId (result, node, attrs, idAttr, datas, ""); } @@ -293,18 +283,11 @@ public class Presenter * @param idAttr * The ID. */ - static protected StringBuffer processElementWithId (Node node, - NamedNodeMap attrs, - Node idAttr, - IdsDataById datas, - String suffix) throws Exception + static protected void processElementWithId (Writer result, Node node, NamedNodeMap attrs, Node idAttr, IdsDataById datas, String suffix) throws Exception { - StringBuffer result; - result = new StringBuffer (); - String tag = node.getNodeName(); - String idValue = idAttr.getNodeValue(); + // String idValue = idAttr.getNodeValue(); logger.debug ("tag=" + tag); @@ -313,7 +296,7 @@ public class Presenter if (dataCore == null) { - result.append (Presenter.processElementBasically (node, datas, suffix)); + Presenter.processElementBasically (result, node, datas, suffix); } else if (dataCore instanceof IdData) { @@ -420,7 +403,7 @@ public class Presenter // Manage a Hashmap. IdsDataById data = (IdsDataById) tags.elementAt (nLine); - result.append (Presenter.processElementWithId (node, attrs, idAttr, data, Integer.toString (nLine))); + Presenter.processElementWithId (result, node, attrs, idAttr, data, Integer.toString (nLine)); result.append ('\n'); } } @@ -432,7 +415,6 @@ public class Presenter // logger.debug ("Exit"); - return (result); } @@ -440,7 +422,7 @@ public class Presenter /** * */ - static protected void process (StringBuffer result, Node node, IdsDataById datas) throws Exception + static protected void process (Writer result, Node node, IdsDataById datas) throws Exception { Presenter.process (result, node, datas, ""); } @@ -450,7 +432,7 @@ public class Presenter * Recursive method that processes a node and any child nodes. * */ - static protected void process (StringBuffer result, Node node, IdsDataById datas, String suffix) throws Exception + static protected void process (Writer result, Node node, IdsDataById datas, String suffix) throws Exception { logger.debug ("process - started"); String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; @@ -479,7 +461,7 @@ public class Presenter if (dt != null) { - String publicId = dt.getPublicId(); + // String publicId = dt.getPublicId(); String systemId = dt.getSystemId(); if (systemId.equals(TRANSITIONAL_DTD)) @@ -505,15 +487,11 @@ public class Presenter if (idAttr != null) { - result.append (Presenter.processElementWithId (node, - attrs, - idAttr, - datas, - suffix)); + Presenter.processElementWithId (result, node, attrs, idAttr, datas, suffix); } else { - result.append (Presenter.processElementBasically (node, datas, suffix)); + Presenter.processElementBasically (result, node, datas, suffix); } break; @@ -579,25 +557,18 @@ public class Presenter /* * */ - static StringBuffer processElementBasically (Node node, IdsDataById datas) throws Exception + static void processElementBasically (Writer result, Node node, IdsDataById datas) throws Exception { - StringBuffer result; - - result = processElementBasically (node, datas, ""); - - // - return (result); + processElementBasically (result, node, datas, ""); } /* * */ - static StringBuffer processElementBasically (Node node, IdsDataById datas, String suffix) throws Exception + static void processElementBasically (Writer result, Node node, IdsDataById datas, String suffix) throws Exception { - StringBuffer result; logger.debug("processElementBasically - started"); - result = new StringBuffer (); // Open the tag. result.append ('<'); @@ -605,7 +576,7 @@ public class Presenter // Build the tag attributes. - Attributes tagAttributes; + //Attributes tagAttributes; result.append (processAttributes (node.getAttributes (), null, @@ -628,9 +599,6 @@ public class Presenter } logger.debug("processElementBasically - ended"); - - // - return (result); } @@ -981,11 +949,11 @@ public class Presenter // Put model attributes in the merged attributes list. if (dataAttributes != null) { - Iterator iterator = dataAttributes.entrySet().iterator(); + Iterator> iterator = dataAttributes.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry attribute = (Map.Entry) iterator.next(); + Map.Entry attribute = iterator.next(); if (mergedAttributes.containsKey (attribute.getKey ())) { @@ -1006,10 +974,10 @@ public class Presenter } // Display the attributes - Iterator iterator = mergedAttributes.entrySet().iterator(); + Iterator> iterator = mergedAttributes.entrySet().iterator(); while (iterator.hasNext ()) { - Map.Entry attribute = (Map.Entry) iterator.next(); + Map.Entry attribute = iterator.next(); if ((attribute.getKey ().equals ("id")) && (suffix.length () != 0)) { diff --git a/src/fr/devinsy/xid/StringPresenter.java b/src/fr/devinsy/xid/StringPresenter.java index 8091f2d..36eb0c0 100644 --- a/src/fr/devinsy/xid/StringPresenter.java +++ b/src/fr/devinsy/xid/StringPresenter.java @@ -98,8 +98,9 @@ public class StringPresenter extends DomPresenter doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ())); } - StringBuffer htmlTarget = new StringBuffer (Presenter.estimatedTargetLength(this.html.length())); - Presenter.doXid (htmlTarget, doc, datas); + StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(this.html.length())); + Presenter.doXid (htmlCode, doc, datas); + StringBuffer htmlTarget = htmlCode.getBuffer(); if (htmlTarget == null) {