diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3cff4fe --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..50cb5de --- /dev/null +++ b/.project @@ -0,0 +1,36 @@ + + + Xid + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..bbb8e68 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7b0c98d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Oct 01 17:56:30 CEST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.jst.common.project.facet.core.prefs b/.settings/org.eclipse.jst.common.project.facet.core.prefs new file mode 100644 index 0000000..2c09e01 --- /dev/null +++ b/.settings/org.eclipse.jst.common.project.facet.core.prefs @@ -0,0 +1,4 @@ +#Thu Oct 01 17:01:30 CEST 2009 +classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType\:\:jdk1.6.0_11/owners=jst.java\:6.0 +classpath.helper/org.eclipse.jst.server.core.container\:\:org.eclipse.jst.server.tomcat.runtimeTarget\:\:Apache\ Tomcat\ v6.0/owners=jst.web\:2.5 +eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..b06506e --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..53d628c --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/build/classes/XidDemo.class b/build/classes/XidDemo.class new file mode 100644 index 0000000..001c22f Binary files /dev/null and b/build/classes/XidDemo.class differ diff --git a/build/classes/XidTest$MONTHS.class b/build/classes/XidTest$MONTHS.class new file mode 100644 index 0000000..1fc4c5c Binary files /dev/null and b/build/classes/XidTest$MONTHS.class differ diff --git a/build/classes/XidTest.class b/build/classes/XidTest.class new file mode 100644 index 0000000..06f1b2b Binary files /dev/null and b/build/classes/XidTest.class differ diff --git a/build/classes/fr/devinsy/xid/Attributes.class b/build/classes/fr/devinsy/xid/Attributes.class new file mode 100644 index 0000000..a7c60bc Binary files /dev/null and b/build/classes/fr/devinsy/xid/Attributes.class differ diff --git a/build/classes/fr/devinsy/xid/Data.class b/build/classes/fr/devinsy/xid/Data.class new file mode 100644 index 0000000..2d7c4a6 Binary files /dev/null and b/build/classes/fr/devinsy/xid/Data.class differ diff --git a/build/classes/fr/devinsy/xid/DomPresenter.class b/build/classes/fr/devinsy/xid/DomPresenter.class new file mode 100644 index 0000000..6020949 Binary files /dev/null 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 new file mode 100644 index 0000000..0799322 Binary files /dev/null and b/build/classes/fr/devinsy/xid/FilePresenter.class differ diff --git a/build/classes/fr/devinsy/xid/IdData$IterationStrategy.class b/build/classes/fr/devinsy/xid/IdData$IterationStrategy.class new file mode 100644 index 0000000..d66b8ec Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdData$IterationStrategy.class differ diff --git a/build/classes/fr/devinsy/xid/IdData$MODE.class b/build/classes/fr/devinsy/xid/IdData$MODE.class new file mode 100644 index 0000000..2b3da08 Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdData$MODE.class differ diff --git a/build/classes/fr/devinsy/xid/IdData.class b/build/classes/fr/devinsy/xid/IdData.class new file mode 100644 index 0000000..3d8200e Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdData.class differ diff --git a/build/classes/fr/devinsy/xid/IdDataCore.class b/build/classes/fr/devinsy/xid/IdDataCore.class new file mode 100644 index 0000000..0bf70c6 Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdDataCore.class differ diff --git a/build/classes/fr/devinsy/xid/IdsDataById.class b/build/classes/fr/devinsy/xid/IdsDataById.class new file mode 100644 index 0000000..f797556 Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdsDataById.class differ diff --git a/build/classes/fr/devinsy/xid/IdsDataByIndex.class b/build/classes/fr/devinsy/xid/IdsDataByIndex.class new file mode 100644 index 0000000..9270a0e Binary files /dev/null and b/build/classes/fr/devinsy/xid/IdsDataByIndex.class differ diff --git a/build/classes/fr/devinsy/xid/ParserErrorHandler.class b/build/classes/fr/devinsy/xid/ParserErrorHandler.class new file mode 100644 index 0000000..59d5547 Binary files /dev/null and b/build/classes/fr/devinsy/xid/ParserErrorHandler.class differ diff --git a/build/classes/fr/devinsy/xid/Presenter.class b/build/classes/fr/devinsy/xid/Presenter.class new file mode 100644 index 0000000..f9e70fb Binary files /dev/null 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 new file mode 100644 index 0000000..c16fc92 Binary files /dev/null and b/build/classes/fr/devinsy/xid/StringPresenter.class differ diff --git a/build/classes/fr/devinsy/xid/TagData.class b/build/classes/fr/devinsy/xid/TagData.class new file mode 100644 index 0000000..5f754dd Binary files /dev/null and b/build/classes/fr/devinsy/xid/TagData.class differ diff --git a/build/classes/fr/devinsy/xid/TagsDataById.class b/build/classes/fr/devinsy/xid/TagsDataById.class new file mode 100644 index 0000000..444d7df Binary files /dev/null and b/build/classes/fr/devinsy/xid/TagsDataById.class differ diff --git a/build/classes/fr/devinsy/xid/testXid.html b/build/classes/fr/devinsy/xid/testXid.html new file mode 100644 index 0000000..78a308e --- /dev/null +++ b/build/classes/fr/devinsy/xid/testXid.html @@ -0,0 +1,79 @@ + + + + test + + + Test 01: No id attribute + XHTML: Hello world. + no Java code + Result: Hello world. + + Test 02: id attribute with empty model + XHTML: Hello world. + no Java code + Result: Hello world. + + + Test 03: model changing the text + XHTML: Hello world. + // Populate attributes of Test 03. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "totoClass"); + text.setText ("mummy"); + datas.put ("test03", text); + Result: Hello world. + + + Test 04: model changing title + XHTML: Hello world. + // Populate attributes of Test 04. + text = new TextModel (); + text.getAttributes ().setAttribute ("title", "another title"); + datas.put ("test04", text); + Result: Hello world. + + + Test 05: model adding style attributes + XHTML: Hello world. + // Populate attributes of Test 05. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test05", text); + Result: Hello world. + + + Test 06: model appending style attributes + XHTML: Hello world. + // Populate attributes of Test 06. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test06", text); + Result: Hello world. + + + Test 07: image + XHTML: A picture pinguoin flottant. + // Populate attributes of Test 07. + text = new TextModel (); + text.getAttributes ().setAttribute ("width", "50%"); + datas.put ("test07", text); + Result: A picture pinguoin flottant. + + + Test 08: xhtml source contains no display order in a tag. + XHTML: Hello you there. + Result: Hello you there. + + + Test 09: dynamic addition of the nodisplay order. + XHTML: Hello you there. + Result: Hello you there. + + + \ No newline at end of file diff --git a/build/classes/fr/devinsy/xid/testXid.t b/build/classes/fr/devinsy/xid/testXid.t new file mode 100644 index 0000000..9037424 --- /dev/null +++ b/build/classes/fr/devinsy/xid/testXid.t @@ -0,0 +1,69 @@ + + + + test + + + Test 01: No id attribute + XHTML: Hello world. + no Java code + Result: Hello world. + + Test 02: id attribute with empty model + XHTML: Hello world. + no Java code + Result: Hello world. + + + Test 03: model changing the text + XHTML: Hello world. + // Populate attributes of Test 03. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "totoClass"); + text.setText ("mummy"); + datas.put ("test03", text); + Result: Hello world. + + + Test 04: model changing title + XHTML: Hello world. + // Populate attributes of Test 04. + text = new TextModel (); + text.getAttributes ().setAttribute ("title", "another title"); + datas.put ("test04", text); + Result: Hello world. + + + Test 05: model adding style attributes + XHTML: Hello world. + // Populate attributes of Test 05. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test05", text); + Result: Hello world. + + + Test 06: model appending style attributes + XHTML: Hello world. + // Populate attributes of Test 06. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test06", text); + Result: Hello world. + + + Test 07: image + XHTML: A picture pinguoin flottant. + // Populate attributes of Test 07. + text = new TextModel (); + text.getAttributes ().setAttribute ("width", "50%"); + datas.put ("test07", text); + Result: A picture pinguoin flottant. + + + \ No newline at end of file diff --git a/build/classes/fr/devinsy/xid/xhtml-lat1.ent b/build/classes/fr/devinsy/xid/xhtml-lat1.ent new file mode 100644 index 0000000..ffee223 --- /dev/null +++ b/build/classes/fr/devinsy/xid/xhtml-lat1.ent @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/classes/fr/devinsy/xid/xhtml-special.ent b/build/classes/fr/devinsy/xid/xhtml-special.ent new file mode 100644 index 0000000..cead4e8 --- /dev/null +++ b/build/classes/fr/devinsy/xid/xhtml-special.ent @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/classes/fr/devinsy/xid/xhtml-symbol.ent b/build/classes/fr/devinsy/xid/xhtml-symbol.ent new file mode 100644 index 0000000..63c2abf --- /dev/null +++ b/build/classes/fr/devinsy/xid/xhtml-symbol.ent @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/classes/fr/devinsy/xid/xhtml1-frameset.dtd b/build/classes/fr/devinsy/xid/xhtml1-frameset.dtd new file mode 100644 index 0000000..1a00936 --- /dev/null +++ b/build/classes/fr/devinsy/xid/xhtml1-frameset.dtd @@ -0,0 +1,1235 @@ + + + + + +%HTMLlat1; + + +%HTMLsymbol; + + +%HTMLspecial; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/classes/fr/devinsy/xid/xhtml1-transitional.dtd b/build/classes/fr/devinsy/xid/xhtml1-transitional.dtd new file mode 100644 index 0000000..e22581b --- /dev/null +++ b/build/classes/fr/devinsy/xid/xhtml1-transitional.dtd @@ -0,0 +1,1210 @@ + + + + + +%HTMLlat1; + + +%HTMLsymbol; + + +%HTMLspecial; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/xid/Attributes.java b/src/fr/devinsy/xid/Attributes.java new file mode 100644 index 0000000..98b2caf --- /dev/null +++ b/src/fr/devinsy/xid/Attributes.java @@ -0,0 +1,82 @@ +package fr.devinsy.xid; + +import java.util.*; + + + + +/** + * + * Note: no more AttrValue as in Brill, because the exception of style is managed + * in the attribute merging on the "style" string detection. + */ +public class Attributes extends HashMap +{ + private static final long serialVersionUID = 2802739066295665336L; + + + /* + * + */ + public Attributes () + { + super (); + } + + + /* + * Useful for the merge attributes. + */ + public Attributes (Attributes attributes) + { + super (attributes); + } + + + /* + * + */ + public void setAttribute (String label, String value) + { + this.put (label, value); + } + + + /* + * Add a value to an existing value. This is useful to the 'style' attribute. + * + */ + public void appendAttribute (String label, String value) + { + if (this.containsKey (label)) + { + this.put (label, this.get (label) + value); + } + else + { + this.put (label, value); + } + } + + + /* + * + */ + public String getAttribute (String label) + { + String result; + + if (this.containsKey (label)) + { + result = this.get (label); + } + else + { + result = null; + } + + // + return (result); + } + +} diff --git a/src/fr/devinsy/xid/Data.java b/src/fr/devinsy/xid/Data.java new file mode 100644 index 0000000..e20a4ba --- /dev/null +++ b/src/fr/devinsy/xid/Data.java @@ -0,0 +1,390 @@ +package fr.devinsy.xid; + + + +/* + * + */ +public class Data +{ + protected IdsDataById idsDataById; + protected TagsDataById tagsDataById; + + + /** + * + */ + public Data () + { + this.idsDataById = new IdsDataById (); + this.tagsDataById = new TagsDataById (); + } + + + /** + * + */ + public IdsDataById getIdsDataById () + { + IdsDataById result; + + result = this.idsDataById; + + // + return (result); + } + + + /** + * + */ + public TagsDataById getTagsDataById () + { + TagsDataById result; + + result = this.tagsDataById; + + // + return (result); + } + + + /** + * + */ + public IdData getIdData (String id) + { + IdData result; + + // Be sure that IdData is existing and get item. + result = (IdData) this.idsDataById.getId (id); + + if (result == null) + { + this.idsDataById.setId (id, new IdData ()); + + result = (IdData) this.idsDataById.getId (id); + } + + + // + return (result); + } + + + /** + * + */ + public IdData getIdData (String id, int line) + { + IdData result; + + // Be sure that IdsData are existing. + IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId (id); + if (tags == null) + { + this.idsDataById.setId (id, new IdsDataByIndex ()); + + tags = (IdsDataByIndex) this.idsDataById.getId (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.idsDataById.getId (id); + if (tags == null) + { + this.idsDataById.setId (id, new IdsDataByIndex ()); + + tags = (IdsDataByIndex) this.idsDataById.getId (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, IdData.IterationStrategy strategy) + { + IdData tag = (IdData) this.getIdData (id); + + tag.setIterationStrategy (strategy); + } + + + + /** + * + */ + public void setContent (String id, String content) + { + if (id.startsWith ("<")) + { + String tagName = id.substring (1, id.length () - 1); + + 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); + } + } + + + /** + * + */ + public void setContent (String id, int content) + { + setContent (id, (new Integer (content)).toString ()); + } + + + /** + * + */ + 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, int content) + { + setContent (id, line, (new Integer (content)).toString ()); + } + + + /** + * + */ + public void setContent (String id, int line, String column, String content) + { + IdData tag = this.getIdData (id, line, column); + + tag.setContent (content); + } + + + /** + * + */ + public void setContent (String id, int line, String column, int content) + { + setContent (id, line, column, (new Integer (content)).toString ()); + } + + + /** + * @TODO + */ + public void setContent (String id, int line, String subId, int subLine, String column, String content) + { + // IdData tag = this.getIdData (id, line, subId, subLine, column); + + //tag.setContent (content); + } + + + /** + * + */ + public void setAttribute (String id, String label, String value) + { + if (id.startsWith ("<")) + { + String tagName = id.substring (1, id.length () - 1); + + 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); + } + } + + + /** + * + */ + public void setAttribute (String id, String label, int value) + { + setAttribute (id, label, (new Integer (value)).toString ()); + } + + + /** + * + */ + 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 label, int value) + { + setAttribute (id, line, label, (new Integer (value)).toString ()); + } + + + /** + * + */ + 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 setAttribute (String id, int line, String column, String label, int value) + { + setAttribute (id, line, column, label, (new Integer (value)).toString ()); + } + + + /** + * + */ + public void appendAttribute (String id, int line, String column, String label, String value) + { + IdData tag = this.getIdData (id, line, column); + + tag.getAttributes ().appendAttribute (label, value); + } + + + /** + * + */ + public void appendAttribute (String id, String label, String value) + { + IdData tag = this.getIdData (id); + + tag.getAttributes ().appendAttribute (label, value); + } + + + /** + * + */ + public void appendAttribute (String id, String label, int value) + { + appendAttribute (id, label, (new Integer (value)).toString ()); + } + + + /** + * + */ + public void appendContent (String id, int line, String value) + { + IdData tag = this.getIdData (id, line); + + tag.appendContent (value); + } + + + /** + * + */ + public void appendContent (String id, int line, int value) + { + appendContent (id, line, (new Integer (value)).toString ()); + } + + + /** + * + */ + public void appendContent (String id, int line, String column, String value) + { + IdData tag = this.getIdData (id, line, column); + + tag.appendContent (value); + } + + + /** + * + */ + public void appendContent (String id, int line, String column, int value) + { + appendContent (id, line, column, (new Integer (value)).toString ()); + } +} diff --git a/src/fr/devinsy/xid/DomPresenter.java b/src/fr/devinsy/xid/DomPresenter.java new file mode 100644 index 0000000..e0f5e0c --- /dev/null +++ b/src/fr/devinsy/xid/DomPresenter.java @@ -0,0 +1,191 @@ +package fr.devinsy.xid; + +import org.w3c.dom.*; + +/** + * + */ +public class DomPresenter extends Presenter +{ + static final public char INDEX_SEPARATOR = '_'; + + static protected org.apache.log4j.Logger logger; + static + { + logger = org.apache.log4j.Logger.getLogger (DomPresenter.class); + } + + static protected String staticRootPath; + static + { + staticRootPath = null; + } + + + protected String webappPath; + protected Document doc; + + /* + * + */ + public DomPresenter () + { + this.webappPath = Presenter.staticRootPath; + this.doc = null; + } + + + /* + * + */ + public DomPresenter (Document doc) + { + this.webappPath = Presenter.staticRootPath; + this.doc = doc; + DomPresenter.addMetaTag (this.doc, "generator", "XID 0.0"); + } + + + /* + * + */ + public DomPresenter (String webappPath, Document doc) + { + if ((webappPath == null) || (webappPath.equals (""))) + { + this.webappPath = Presenter.staticRootPath; + } + else + { + this.webappPath = webappPath; + } + + this.doc = doc; + DomPresenter.addMetaTag (this.doc, "generator", "XID 0.0"); + } + + + /* + * + */ + public String getWebappPath () + { + String result; + + result = this.webappPath; + + // + return (result); + } + + /* + * + */ + public void setWebappPath (String path) + { + this.webappPath = path; + } + + + /** + * + */ + public Document getDom () + { + Document result; + + result = this.doc; + + // + return (result); + } + + + /** + * + */ + public void setDom (Document doc) + { + this.doc = doc; + } + + + /* + * + */ + public void setSource (Document doc) + { + this.doc = doc; + + Presenter.addMetaTag (this.doc, "generator", "XID 0.0"); + } + + + /* + * + */ + public Object getSource () + { + Object result; + + result = this.doc; + + // + return (result); + } + + + /* + * + */ + public StringBuffer doXid (Data datas, StringBuffer errorOutput) + { + return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); + } + + /* + * + */ + public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) + { + StringBuffer result; + + if (this.doc == null) + { + String errorMessage = "source not defined"; + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + else + { + // Build the web page. + result = Presenter.doXid (this.doc, datas, tagsData, this.webappPath, errorOutput); + } + + // + return (result); + } + + + /* + * 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); + + // + return (result); + } +} diff --git a/src/fr/devinsy/xid/FilePresenter.java b/src/fr/devinsy/xid/FilePresenter.java new file mode 100644 index 0000000..bfbb82a --- /dev/null +++ b/src/fr/devinsy/xid/FilePresenter.java @@ -0,0 +1,167 @@ +package fr.devinsy.xid; + +import java.io.*; +import org.w3c.dom.*; + + +/** + * + */ +public class FilePresenter extends DomPresenter +{ + static protected org.apache.log4j.Logger logger; + static + { + logger = org.apache.log4j.Logger.getLogger (FilePresenter.class); + } + + protected String sourceFileName; + protected long sourceFileTime; + + /* + * + */ + public FilePresenter () + { + this.webappPath = Presenter.staticRootPath; + this.sourceFileName = null; + this.sourceFileTime = 0; + this.doc = null; + } + + + /* + * + */ + public FilePresenter (String fileName) + { + this.webappPath = Presenter.staticRootPath; + this.sourceFileName = fileName; + this.sourceFileTime = 0; + this.doc = null; + } + + + /* + * + */ + public FilePresenter (String webappPath, String fileName) + { + if ((webappPath == null) || (webappPath.equals (""))) + { + this.webappPath = Presenter.staticRootPath; + } + else + { + this.webappPath = webappPath; + } + this.sourceFileName = fileName; + this.sourceFileTime = 0; + this.doc = null; + } + + + /* + * + */ + public void setSource (String fileName) + { + this.sourceFileName = fileName; + this.sourceFileTime = 0; + this.doc = null; + } + + + /* + * + */ + public String getSource () + { + String result; + + result = this.sourceFileName; + + // + return (result); + } + + + /* + * + */ + public StringBuffer doXid (Data datas, StringBuffer errorOutput) + { + return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); + } + + + /* + * + */ + public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) + { + StringBuffer result; + + String sourceFilePath = this.webappPath + File.separator + this.sourceFileName; + + // Get the good tree. + File source = new File (sourceFilePath); + + if (source == null) + { + String errorMessage = "source file not defined"; + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + else if (!source.exists ()) + { + String errorMessage = "source file defined but not found (" + sourceFilePath + ")"; + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + else if ((this.doc == null) || + (this.sourceFileTime != source.lastModified ())) + { + this.sourceFileTime = source.lastModified (); + this.doc = Presenter.fileToTree (sourceFilePath, errorOutput); + + if (this.doc != null) + { + Presenter.addMetaTag (doc, "generator", "XID 0.0"); + } + } + + // Build the web page. + result = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput); + + // + return (result); + } + + + /* + * Xid a file without data. + */ + static public StringBuffer doXid (String fileName, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + Document doc = Presenter.fileToTree (fileName, errorOutput); + + if (doc == null) + { + result = null; + } + else + { + Presenter.addMetaTag (doc, "generator", "XID 0.0"); + + result = Presenter.doXid (doc, null, null, webappPath, errorOutput); + } + + // + return (result); + } +} diff --git a/src/fr/devinsy/xid/IdData.java b/src/fr/devinsy/xid/IdData.java new file mode 100644 index 0000000..612119c --- /dev/null +++ b/src/fr/devinsy/xid/IdData.java @@ -0,0 +1,180 @@ +package fr.devinsy.xid; + +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 +{ + private static final long serialVersionUID = 8976245034682639923L; + + + public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS} + + + + + public enum MODE {REPLACE, APPEND, IGNORE}; + + protected IterationStrategy iterationStrategy; + 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 = null; + this.iterationStrategy = IterationStrategy.ALL_ROWS; + } + + + /* + * + */ + public IdData (String text) + { + this.attributes = null; + this.excludeSection = false; + this.displayMode = MODE.REPLACE; + this.content = text; + this.iterationStrategy = IterationStrategy.ALL_ROWS; + } + + + /* + * + */ + public String display () + { + String result; + + result = this.content; + + // + return (result); + } + + + /* + * + */ + public void setContent (String text) + { + this.content = text; + } + + + /* + * + */ + public void appendContent (String text) + { + if (this.content == null) + { + this.content = text; + } + else + { + 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; + } + + + /** + * + */ + public void setIterationStrategy (IterationStrategy strategy) + { + this.iterationStrategy = strategy; + } + + + /** + * + */ + public IterationStrategy getIterationStrategy () + { + IterationStrategy result; + + result = this.iterationStrategy; + + // + return (result); + } +} diff --git a/src/fr/devinsy/xid/IdDataCore.java b/src/fr/devinsy/xid/IdDataCore.java new file mode 100644 index 0000000..3b87323 --- /dev/null +++ b/src/fr/devinsy/xid/IdDataCore.java @@ -0,0 +1,15 @@ +package fr.devinsy.xid; + +/* + * Xid uses three class to describe data: + * - TagData + * - TagsData + * - TagsDataById + * Others class that doesn't extends these won't be use by Xid. + * + * This interface helps to express this fact. + * + */ +public interface IdDataCore +{ +} diff --git a/src/fr/devinsy/xid/IdsDataById.java b/src/fr/devinsy/xid/IdsDataById.java new file mode 100644 index 0000000..e1ec7c4 --- /dev/null +++ b/src/fr/devinsy/xid/IdsDataById.java @@ -0,0 +1,42 @@ +package fr.devinsy.xid; + +import java.util.*; + +/* + * + */ +public class IdsDataById extends HashMap implements IdDataCore +{ + + private static final long serialVersionUID = -5787252043825503554L; + + /* + * + */ + 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/fr/devinsy/xid/IdsDataByIndex.java b/src/fr/devinsy/xid/IdsDataByIndex.java new file mode 100644 index 0000000..c47e1b2 --- /dev/null +++ b/src/fr/devinsy/xid/IdsDataByIndex.java @@ -0,0 +1,21 @@ +package fr.devinsy.xid; + +import java.util.*; + + +/* + * + */ +public class IdsDataByIndex extends Vector implements IdDataCore +{ + + private static final long serialVersionUID = 215545720925753884L; + + /** + * + */ + public IdsDataByIndex () + { + super (); + } +} diff --git a/src/fr/devinsy/xid/ParserErrorHandler.java b/src/fr/devinsy/xid/ParserErrorHandler.java new file mode 100644 index 0000000..675def3 --- /dev/null +++ b/src/fr/devinsy/xid/ParserErrorHandler.java @@ -0,0 +1,159 @@ +package fr.devinsy.xid; + +import org.xml.sax.*; +import java.util.*; + +/** + * Extract from org.xml.sax Interface ErrorHandler: + * "If a SAX application needs to implement customized error handling, + * it must implement this interface and then register an instance with + * the XML reader using the setErrorHandler method. The parser will + * then report all errors and warnings through this interface." + * + */ +public class ParserErrorHandler implements ErrorHandler +{ + Vector messages; + int fatalErrorsCount; + int errorsCount; + int warningCount; + + public ParserErrorHandler () + { + fatalErrorsCount = 0; + errorsCount = 0; + warningCount = 0; + messages = new Vector (); + } + + + /** + * + */ + public int fatalErrorsCount () + { + int result; + + result = this.fatalErrorsCount; + + // + return (result); + } + + /** + * + */ + public int errorsCount () + { + int result; + + result = this.errorsCount; + + // + return (result); + } + + /** + * + */ + public int warningCount () + { + int result; + + result = this.warningCount; + + // + return (result); + } + + /** + * + */ + public int allErrorsCount () + { + int result; + + result = fatalErrorsCount () + errorsCount () + warningCount (); + + // + return (result); + } + + /** + * + */ + public boolean hasError () + { + boolean result; + + if (allErrorsCount () == 0) + { + result = false; + } + else + { + result = true; + } + + // + return (result); + } + + + /** + * Called by the XML parser to handle fatal errors. + * @param ex Parse Excpetion. Contains the warning text and the line number. + */ + public void error (SAXParseException exception) + { + String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + + this.errorsCount += 1; + this.messages.add (message); + } + + /** + * Called by the XML parser to handle fatal errors. + * @param ex Parse Excpetion. Contains the error text and the line number. + * When a fatal parse error occurs, the parse does not return a document. + */ + public void fatalError (SAXParseException exception) + { + String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + + this.fatalErrorsCount += 1; + this.messages.add (message); + } + + /** + * Called by the XML parser to handle warnings. + * @param ex Parse Excpetion. Contains the warning text and the line number. + */ + public void warning(SAXParseException exception) + { + String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage(); + + this.warningCount += 1; + this.messages.add (message); + } + + + /** + * + */ + public String toString () + { + StringBuffer result; + + result = new StringBuffer (); + + for (String message : messages) + { + result.append (message); + result.append ('\n'); + } + + // + return (result.toString ()); + } +} diff --git a/src/fr/devinsy/xid/Presenter.java b/src/fr/devinsy/xid/Presenter.java new file mode 100644 index 0000000..ec828b0 --- /dev/null +++ b/src/fr/devinsy/xid/Presenter.java @@ -0,0 +1,1331 @@ +package fr.devinsy.xid; + +import java.util.*; +import java.io.*; +import javax.xml.parsers.*; +import javax.xml.validation.Schema; +import org.xml.sax.*; +import org.w3c.dom.*; + + +/** + * + */ +public class Presenter +{ + static final public char INDEX_SEPARATOR = '_'; + + static protected org.apache.log4j.Logger logger; + static + { + logger = org.apache.log4j.Logger.getLogger (Presenter.class); + } + + static protected String staticRootPath; + static + { + staticRootPath = null; + } + + + /* + * + */ + static public void setStaticRootPath (String path) + { + Presenter.staticRootPath = path; + } + + + /* + * + */ + static public String getStaticRootPath () + { + String result; + + result = Presenter.staticRootPath; + + // + return (result); + } + + /* + * 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); + + // + return (result); + } + + + /* + * + */ + static public String getClassAttributeValue (Node node) + { + String result; + + NamedNodeMap attributes = node.getAttributes (); + if (attributes == null) + { + result = null; + } + else + { + Node nameAttribute = attributes.getNamedItem ("class"); + + if (nameAttribute == null) + { + result = null; + } + else + { + result = nameAttribute.getNodeValue (); + } + } + + // + return (result); + } + + + /** + * + */ + static public Attributes mergeAttributes (Attributes target, Attributes source) + { + Attributes result; + + // + if (target == null) + { + result = source; + } + else if (source == null) + { + result = target; + } + else + { + result = new Attributes (target); + + Iterator iterator = source.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry attribute = (Map.Entry) iterator.next(); + + String currentValue = target.get (attribute.getKey ()); + + if (currentValue == null) + { + result.put (attribute.getKey (), attribute.getValue ()); + } + else if (attribute.getKey ().equals ("style")) + { + result.put (attribute.getKey (), currentValue + attribute.getValue ()); + } + else + { + result.put (attribute.getKey (), attribute.getValue ()); + } + } + } + + // + return (result); + } + + /* + * + */ + static protected StringBuffer processChildren (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + result = processChildren (node, datas, tagsData, webappPath, "", errorOutput); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processChildren (Node node, + IdsDataById datas, + TagsDataById tagsData, + String webappPath, + String suffix, + StringBuffer errorOutput) + { + StringBuffer result; + result = new StringBuffer (); + + // Get the iteration strategy. + IdData.IterationStrategy strategy; + + NamedNodeMap attributes = node.getAttributes (); + if (attributes == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else + { + Node id = attributes.getNamedItem ("id"); + + if (id == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else + { + IdDataCore dataCore = datas.getId (id.getNodeValue ()); + if (dataCore == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else if (dataCore instanceof IdData) + { + IdData data = (IdData) dataCore; + strategy = data.getIterationStrategy (); + } + else + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + } + } + + + // Iterate. + NodeList children = node.getChildNodes(); + int childrenCount = children.getLength (); + + switch (strategy) + { + case ONLY_FIRST_ROW: + int lineCounter = 0; + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) + { + lineCounter += 1; + if (lineCounter == 1) + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + else + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + break; + + case ONLY_FIRST_TWO_ROWS: + lineCounter = 0; + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) + { + lineCounter += 1; + + if ((lineCounter == 1) || (lineCounter == 2)) + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + else + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + break; + + case ONLY_ROWS_WITH_ID: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) + { + NamedNodeMap attrs2 = children.item (childIndex).getAttributes (); + + if ((attrs2 != null) && + (attrs2.getNamedItem ("id") != null)) + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + else + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + break; + + case ONLY_ROWS_WITHOUT_ID: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) + { + NamedNodeMap attrs2 = children.item (childIndex).getAttributes (); + if ((attrs2 == null) || + (attrs2.getNamedItem ("id") == null)) + { + result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + else + { + result.append (process (children.item (childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + } + break; + + case ALL_ROWS: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + result.append (process (children.item(childIndex), datas, tagsData, webappPath, suffix, errorOutput)); + } + break; + } + + // + return (result); + } + + + + /** + * Includes another file into the current page. + * + * @param node + * @param attrMap + * @param idAttr + */ + static protected StringBuffer processObjectTag (Node node, + NamedNodeMap attrMap, + Node idAttr, + IdsDataById datas, + TagsDataById tagsData, + String webappPath, + StringBuffer errorOutput) + { + StringBuffer result; + + result = new StringBuffer (); + + // Find codetype. + String codetype; + if (attrMap == null) + { + codetype = null; + } + else if (attrMap.getNamedItem ("codetype") == null) + { + codetype = null; + } + else + { + codetype = attrMap.getNamedItem ("codetype").getNodeValue (); + } + + // Check tag requirements. + if ((attrMap == null) || + (codetype == null) || + (!codetype.equals ("application/xid")) || + (attrMap.getNamedItem ("data") == null)) + { + // STU: do default action. + Presenter.processElementBasically (node, datas, tagsData, webappPath, errorOutput); + } + else + { + logger.debug ("object action"); + result.append (""); + + // Build the file name. + String htmlFileName = webappPath + attrMap.getNamedItem ("data").getNodeValue (); + + + // Load file in tree. + Document childDoc = null; + try + { + childDoc = fileToTree (htmlFileName, errorOutput); + } + catch (Exception ex) + { + errorOutput.append ("unable to build the file tree"); + logger.debug ("unable to build the file tree"); + } + + // Extract the 'body' section. + Node body = null; + try + { + NodeList nodes = childDoc.getElementsByTagName ("body"); + + if (nodes.getLength () == 0) + { + errorOutput.append ("no body tag in include html"); + logger.debug ("no body tag in include html"); + } + else + { + body = nodes.item(0); + } + } + catch (Exception e) + { + errorOutput.append ("error getting child"); + logger.debug ("error getting child"); + } + + // Process the body child as part of the primary tree. + if (body == null) + { + errorOutput.append ("xid object body empty."); + } + else + { + NodeList bodyChildren = body.getChildNodes (); + + if (bodyChildren != null) + { + int childCount = bodyChildren.getLength (); + for (int childCounter = 0; childCounter < childCount; childCounter++) + { + result.append (process (bodyChildren.item (childCounter), datas, tagsData, webappPath, errorOutput)); + } + } + } + + // + result.append (""); + } + logger.debug ("end of object action"); + // + return (result); + } + + + + /** + * Processes a node that has dynamic content. Calls the appropriate code + * generator method, depending on the tag. + * + * @param node + * Current node. + * @param attrs + * The tag attributes. + * @param idAttr + * The ID. + */ + static protected StringBuffer processElementWithId (Node node, + NamedNodeMap attrs, + Node idAttr, + IdsDataById datas, + String webappPath, + StringBuffer errorOutput) + + { + StringBuffer result; + + result = processElementWithId (node, attrs, idAttr, datas, null, "", webappPath, errorOutput); + + // + return (result); + } + + + /** + * Processes a node that has dynamic content. Calls the appropriate code + * generator method, depending on the tag. + * + * @param node + * Current node. + * @param attrs + * The tag attributes. + * @param idAttr + * The ID. + */ + static protected StringBuffer processElementWithId (Node node, + NamedNodeMap attrs, + Node idAttr, + IdsDataById datas, + TagsDataById tagsData, + String webappPath, + String suffix, + StringBuffer errorOutput) + { + StringBuffer result; + result = new StringBuffer (); + + String tag = node.getNodeName(); + + if (tag.equals ("object")) + { + result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); + } + else + { + String idValue = idAttr.getNodeValue(); + + logger.debug ("tag=" + tag); + + // Get data of this id. + IdDataCore dataCore = datas.get (idAttr.getNodeValue ()); + + if (dataCore == null) + { + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + else if (dataCore instanceof IdData) + { + IdData data = (IdData) dataCore; + + String theClass; + if (data == null) + { + theClass = null; + } + else + { + theClass = data.getAttributes ().getAttribute ("class"); + } + + if ((theClass == null) || + (!theClass.equals ("xid:nodisplay"))) + { + // Open the tag. + 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, suffix)); + + if ((node.getChildNodes () == null) && + ((data == null) || (data.display () == null))) + { + // Close the tag. + result.append (" />"); + } + else + { + result.append ('>'); + + // CHANGED, cpm: + + // Insert data. + if ((data == null) || + (data.display () == null)) + { + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + else + { + result.append (data.display ()); + } + + // Close the tag. + result.append ("'); + } + } + } + else if (dataCore instanceof IdsDataByIndex) + { + IdsDataByIndex tags = (IdsDataByIndex) dataCore; + + int nbLines = tags.size (); + for (int nLine = 0; nLine < nbLines; nLine++) + { + if (tags.elementAt (nLine) instanceof IdData) + { + IdData data = (IdData) tags.elementAt (nLine); + + // Open the tag. + 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))); + + if ((node.getChildNodes () == null) && + ((data == null) || (data.display () == null))) + { + // Close the tag. + result.append (" />\n"); + } + else + { + result.append ('>'); + + + // CHANGED, cpm + + // Insert data. + if ((data == null) || (data.display () == null)) + { + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + else + { + result.append (data.display ()); + } + + // Close the tag. + result.append ("\n"); + } + } + else + { + // 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 ('\n'); + } + } + } + else + { + logger.warn ("Unknow type of IdDataId"); + } + } + + // + logger.debug ("Exit"); + return (result); + } + + + + /** + * + */ + static protected StringBuffer process (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + result = Presenter.process (node, datas, tagsData, webappPath, "", errorOutput); + + // + return (result); + } + + + /** + * 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) + { + logger.debug ("Enter"); + String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; + String TRANSITIONAL_DOCTYPE = "\n"; + + StringBuffer result; + result = new StringBuffer (); + + // Is there anything to do? + if (node != null) + { + logger.debug ("nodeName=" + node.getNodeName ()); + // Find the name attribute value. + String name; + name = getClassAttributeValue (node); + + if ((name == null) || + ((name != null) && + (!name.equals ("xid:nodisplay")))) + { + int type = node.getNodeType(); + switch (type) + { + case Node.DOCUMENT_NODE: + { + logger.debug ("case Node.DOCUMENT_NODE"); + DocumentType dt = ((Document) node).getDoctype(); + + if (dt != null) + { + String publicId = dt.getPublicId(); + String systemId = dt.getSystemId(); + + if (systemId.equals(TRANSITIONAL_DTD)) + { + result.append(TRANSITIONAL_DOCTYPE); + } + + // Log.write(Log.TRACE,"publicId = " + publicId); + // Log.write(Log.TRACE,"systemId = " + systemId); + } + + result.append (Presenter.process (((Document) node).getDocumentElement(), datas, tagsData, webappPath, suffix, errorOutput)); + + break; + } + + case Node.ELEMENT_NODE: + { + logger.debug ("case Node.ELEMENT_NODE"); + + NamedNodeMap attrs = node.getAttributes (); + Node idAttr = attrs.getNamedItem ("id"); + + if (idAttr != null) + { + result.append (Presenter.processElementWithId (node, + attrs, + idAttr, + datas, + tagsData, + webappPath, + suffix, + errorOutput)); + } + else + { + + String tag = node.getNodeName(); + + if (tag.equals ("object")) + { + result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); + } + else + { + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + } + + break; + } + + // handle entity reference nodes + case Node.ENTITY_REFERENCE_NODE: + { + logger.debug ("case Node.ENTITY_REFERENCE_NODE"); + + result.append ('&'); + result.append (node.getNodeName()); + result.append (';'); + break; + } + + // print cdata sections + case Node.CDATA_SECTION_NODE: + { + logger.debug ("case Node.CDATA_SECTION_NODE"); + + result.append (""); + + break; + } + + // print text + case Node.TEXT_NODE: + { + logger.debug ("case Node.TEXTE_NODE"); + result.append (restoreEntities (new StringBuffer(node.getNodeValue()))); + break; + } + + // print processing instruction + case Node.PROCESSING_INSTRUCTION_NODE: + { + logger.debug ("Node.PROCESSING_INSTRUCTION_NODE"); + + result.append (" 0)) + { + result.append (' '); + result.append (data); + } + result.append ("?>"); + break; + } + } + } + } + + // + //logger.info ("result=" + result); + logger.debug ("Exit"); + return (result); + } + + + /* + * + */ + static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + result = processElementBasically (node, datas, tagsData, webappPath, "", errorOutput); + + // + return (result); + } + + + /* + * + */ + static StringBuffer processElementBasically (Node node, IdsDataById datas, TagsDataById tagsData, String webappPath, String suffix, StringBuffer errorOutput) + { + StringBuffer result; + result = new StringBuffer (); + + // Open the tag. + 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) + { + result.append(" />"); + } + else + { + result.append('>'); + + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); + + result.append("'); + } + + + // + return (result); + } + + + + /* + * + */ + static protected Document buildTree (InputStream source, StringBuffer errorOutput) + { + Document result; + + try + { + // Create a DocumentBuilderFactory and configure it. + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); + + // Set various configuration options. + dbf.setValidating (true); + dbf.setIgnoringComments (true); + dbf.setIgnoringElementContentWhitespace (false); + dbf.setCoalescing (false); + + // Keep entity references as they are. + dbf.setExpandEntityReferences(false); + + // Create a DocumentBuilder that satisfies the constraints + // specified by the DocumentBuilderFactory. + DocumentBuilder db = dbf.newDocumentBuilder (); + + ParserErrorHandler errorHandler; + errorHandler = new ParserErrorHandler(); + + // Set the error handler. + db.setErrorHandler (errorHandler); + + Schema schema = db.getSchema (); + logger.debug ("schema=" + schema); + + // Parse the input file. + result = db.parse (source); + + if (errorHandler.hasError ()) + { + errorOutput.append (errorHandler.toString ()); + } + else + { + DomPresenter.addMetaTag (result, "generator", "XID 0.0"); + } + } + catch (ParserConfigurationException exception) + { + String errorMessage = "Parser configuration exception: " + exception.getMessage (); + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + catch (SAXException exception) + { + String errorMessage = "Error during SAX parsing: " + exception.getMessage (); + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage (); + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + + // + return (result); + } + + + + + /* + * + */ + static protected void addMetaTag (Document doc, String name, String content) + { + // Find head tag. + + Node headNode = Presenter.findHeadNode (doc); + + Node metaNode = doc.createElement ("meta"); + + NamedNodeMap attrMap = metaNode.getAttributes(); + Node attrNode = doc.createAttribute("name"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(name); + + attrNode = doc.createAttribute("content"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(content); + headNode.insertBefore(metaNode, headNode.getFirstChild()); + } + + + /** + * Finds the node containing the <head> tag. + * + * @param node + * Document node. + * @return The head tag node + */ + static protected Node findHeadNode (Node node) + { + Node headNode = null; + + int type = node.getNodeType(); + switch (type) + { + // print document + case Node.DOCUMENT_NODE: + { + headNode = findHeadNode(((Document) node).getDocumentElement()); + break; + } + + case Node.ELEMENT_NODE: + { + String tag = node.getNodeName(); + + if ("head".equals(tag)) + { + headNode = node; + break; + } + + NodeList children = node.getChildNodes(); + int numChildren = 0; + + if (children != null) + numChildren = children.getLength(); + + for (int i = 0; i < numChildren; i++) + { + headNode = findHeadNode(children.item(i)); + if (headNode != null) + break; + } + break; + } + } + return headNode; + } + + + /** + * Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text + * nodes get read in as symbols. This method converts them back to entities. + * + * @param s String that is to have the entities restored.. + * @return The processed string. + */ + static public String restoreEntities (StringBuffer s) + { + String result; + + if (s == null) + { + result = null; + } + else + { + StringBuffer str = new StringBuffer(); + + int len = (s != null) ? s.length() : 0; + for (int i = 0; i < len; i++) + { + char ch = s.charAt(i); + switch (ch) + { + case '<': + { + str.append("<"); + break; + } + + case '>': + { + str.append(">"); + break; + } + + case '&': + { + str.append("&"); + break; + } + + default: + { + str.append(ch); + } + } + } + result = str.toString (); + } + + + // + return (result); + } + + + /** + * Get the text for an element. Converts new lines to spaces. + * + * @param node + */ + static protected String getElementText (Node node) + { + String result; + result = ""; // Grrrr, Java ... + + NodeList children = node.getChildNodes(); + if (children == null) + { + result = ""; + } + else + { + boolean ended = false; + int childCounter = 0; + int childCount = children.getLength (); + while (!ended) + { + if (childCounter >= childCount) + { + ended = true; + result = ""; + } + else + { + Node child = children.item (childCounter); + if (child.getNodeType () == Node.TEXT_NODE) + { + result = newLinesToSpaces (child.getNodeValue ()); // STU (+=, newLines...) + ended = true; + } + else + { + childCounter += 1; + } + } + } + } + + // + return (result); + } + + + /** + * Converts New Line characters to spaces. This is used when for example + * the text in a div tag goes over serveral lines. + * + * @param text String + * @return String + */ + static protected String newLinesToSpaces (String text) + { + StringBuffer result = new StringBuffer (text); + + for (int i = 0; i < result.length(); i++) + { + if (result.charAt (i) == '\n') + { + result.setCharAt (i,' '); + } + } + + // + return (result.toString()); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, Attributes namedDataAttributes, String suffix) + { + StringBuffer result; + + result = processAttributes (attrs, mergeAttributes (dataAttributes, namedDataAttributes), suffix); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes) + { + StringBuffer result; + + result = processAttributes (attrs, dataAttributes, ""); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs) + { + StringBuffer result; + + result = processAttributes (attrs, null, null, ""); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, String suffix) + { + StringBuffer result; + + result = new StringBuffer (); + + // Build the original attributes list. + HashMap mergedAttributes; + mergedAttributes = new HashMap (); + for (int attributeCounter = 0; attributeCounter < attrs.getLength(); attributeCounter++) + { + Attr attr = (Attr) attrs.item (attributeCounter); + mergedAttributes.put (attr.getNodeName(), attr.getNodeValue ()); + } + + + // Put model attributes in the merged attributes list. + if (dataAttributes != null) + { + Iterator iterator = dataAttributes.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry attribute = (Map.Entry) iterator.next(); + + if (mergedAttributes.containsKey (attribute.getKey ())) + { + if (attribute.getKey ().equalsIgnoreCase ("style")) + { + mergedAttributes.put (attribute.getKey (), mergedAttributes.get (attribute.getKey ()) + attribute.getValue ()); + } + else + { + mergedAttributes.put (attribute.getKey (), attribute.getValue ()); + } + } + else + { + mergedAttributes.put (attribute.getKey (), attribute.getValue ()); + } + } + } + + // Display the attributes + Iterator iterator = mergedAttributes.entrySet().iterator(); + while (iterator.hasNext ()) + { + Map.Entry attribute = (Map.Entry) iterator.next(); + + if ((attribute.getKey ().equals ("id")) && (suffix.length () != 0)) + { + result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + Presenter.INDEX_SEPARATOR + suffix + "\""); + } + else + { + result.append(" " + attribute.getKey () + "=\"" + attribute.getValue ()+ "\""); + } + } + + // + return (result); + } + + + /* + * + */ + static public String extractBodyContent (StringBuffer data) + { + String result = null; + + // Extract the body content. + String dataLowerCase = data.toString ().toLowerCase (); + + int startBody = dataLowerCase.indexOf (""); + int endBody = dataLowerCase.indexOf (""); + + // Note: as failed search is improbable, no care about complexity + // in failed search case. + if ((startBody == -1) || (endBody == -1)) + { + result = null; + } + else + { + result = data.substring (startBody + 6, endBody).trim (); + } + + // + return (result); + } + + + /* + * Define in Presnter cause needs this possibility. + */ + static protected Document fileToTree (String fileName, StringBuffer errorOutput) + { + Document result; + + try + { + result = buildTree (new FileInputStream (new File (fileName)), errorOutput); + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage (); + errorOutput.append (errorMessage); + logger.error (errorMessage); + result = null; + } + + // + return (result); + } +} diff --git a/src/fr/devinsy/xid/StringPresenter.java b/src/fr/devinsy/xid/StringPresenter.java new file mode 100644 index 0000000..42ada00 --- /dev/null +++ b/src/fr/devinsy/xid/StringPresenter.java @@ -0,0 +1,195 @@ +package fr.devinsy.xid; + + +import java.io.*; + + +/** + * + */ +public class StringPresenter extends DomPresenter +{ + static protected org.apache.log4j.Logger logger; + static + { + logger = org.apache.log4j.Logger.getLogger (StringPresenter.class); + } + + protected String html; + + /* + * + */ + public StringPresenter () + { + super (); + this.webappPath = Presenter.staticRootPath; + this.doc = null; + this.html = null; + } + + + /* + * + */ + public StringPresenter (String html) + { + this.webappPath = Presenter.staticRootPath; + this.doc = null; + this.html = html; + } + + + /* + * + */ + public StringPresenter (String webappPath, String html) + { + if ((webappPath == null) || (webappPath.equals (""))) + { + this.webappPath = Presenter.staticRootPath; + } + else + { + this.webappPath = webappPath; + } + this.doc = null; + this.html = html; + } + + + /* + * + */ + public void setSource (String html) + { + this.html = html; + this.doc = null; + } + + + /* + * + */ + public String getSource () + { + String result; + + result = this.html; + + // + return (result); + } + + + /* + * + */ + public StringBuffer doXid (Data datas, StringBuffer errorOutput) + { + return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); + } + + /* + * + */ + public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput) + { + StringBuffer result; + + if (this.doc == null) + { + // Build doc from this.html. + String htmlSource; + if ((this.html.startsWith ("")) || + (this.html.startsWith (""))) + { + htmlSource = html; + } + else + { + htmlSource = "\n" + html + ""; + } + + // StringBufferInputStream is deprecated so we use another solution. + // (see http://www.developpez.net/forums/archive/index.php/t-14101.html). + doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()), errorOutput); + } + + StringBuffer htmlTarget; + htmlTarget = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput); + + if (htmlTarget == null) + { + result = null; + } + else if ((this.html.startsWith ("")) || + (this.html.startsWith (""))) + { + result = htmlTarget; + } + else + { + String bodyContent = extractBodyContent (htmlTarget); + + if (bodyContent == null) + { + result = null; + } + else + { + result = new StringBuffer (bodyContent); + } + } + + // + return (result); + } + + + /* + * + */ + static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput) + { + return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), "", errorOutput)); + } + + + /* + * + */ + static public StringBuffer doXid (String html, Data datas, String webappPath, StringBuffer errorOutput) + { + return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), webappPath, errorOutput)); + } + + + /* + * 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); + + // + return (result); + } +} diff --git a/src/fr/devinsy/xid/TagData.java b/src/fr/devinsy/xid/TagData.java new file mode 100644 index 0000000..7a102b4 --- /dev/null +++ b/src/fr/devinsy/xid/TagData.java @@ -0,0 +1,39 @@ +package fr.devinsy.xid; + +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 TagData extends IdData implements Serializable +{ + private static final long serialVersionUID = 2857526344702056757L; + + + /* + * + */ + public TagData () + { + super (); + } + + + /* + * + */ + public TagData (String text) + { + super (text); + } +} diff --git a/src/fr/devinsy/xid/TagsDataById.java b/src/fr/devinsy/xid/TagsDataById.java new file mode 100644 index 0000000..1d1b9c4 --- /dev/null +++ b/src/fr/devinsy/xid/TagsDataById.java @@ -0,0 +1,43 @@ +package fr.devinsy.xid; + +import java.util.*; + + +/* + * + */ +public class TagsDataById extends HashMap +{ + + 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); + } + +} diff --git a/src/fr/devinsy/xid/testXid.html b/src/fr/devinsy/xid/testXid.html new file mode 100644 index 0000000..78a308e --- /dev/null +++ b/src/fr/devinsy/xid/testXid.html @@ -0,0 +1,79 @@ + + + + test + + + Test 01: No id attribute + XHTML: Hello world. + no Java code + Result: Hello world. + + Test 02: id attribute with empty model + XHTML: Hello world. + no Java code + Result: Hello world. + + + Test 03: model changing the text + XHTML: Hello world. + // Populate attributes of Test 03. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "totoClass"); + text.setText ("mummy"); + datas.put ("test03", text); + Result: Hello world. + + + Test 04: model changing title + XHTML: Hello world. + // Populate attributes of Test 04. + text = new TextModel (); + text.getAttributes ().setAttribute ("title", "another title"); + datas.put ("test04", text); + Result: Hello world. + + + Test 05: model adding style attributes + XHTML: Hello world. + // Populate attributes of Test 05. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test05", text); + Result: Hello world. + + + Test 06: model appending style attributes + XHTML: Hello world. + // Populate attributes of Test 06. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test06", text); + Result: Hello world. + + + Test 07: image + XHTML: A picture pinguoin flottant. + // Populate attributes of Test 07. + text = new TextModel (); + text.getAttributes ().setAttribute ("width", "50%"); + datas.put ("test07", text); + Result: A picture pinguoin flottant. + + + Test 08: xhtml source contains no display order in a tag. + XHTML: Hello you there. + Result: Hello you there. + + + Test 09: dynamic addition of the nodisplay order. + XHTML: Hello you there. + Result: Hello you there. + + + \ No newline at end of file diff --git a/src/fr/devinsy/xid/testXid.t b/src/fr/devinsy/xid/testXid.t new file mode 100644 index 0000000..9037424 --- /dev/null +++ b/src/fr/devinsy/xid/testXid.t @@ -0,0 +1,69 @@ + + + + test + + + Test 01: No id attribute + XHTML: Hello world. + no Java code + Result: Hello world. + + Test 02: id attribute with empty model + XHTML: Hello world. + no Java code + Result: Hello world. + + + Test 03: model changing the text + XHTML: Hello world. + // Populate attributes of Test 03. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "totoClass"); + text.setText ("mummy"); + datas.put ("test03", text); + Result: Hello world. + + + Test 04: model changing title + XHTML: Hello world. + // Populate attributes of Test 04. + text = new TextModel (); + text.getAttributes ().setAttribute ("title", "another title"); + datas.put ("test04", text); + Result: Hello world. + + + Test 05: model adding style attributes + XHTML: Hello world. + // Populate attributes of Test 05. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "background: blue;"); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test05", text); + Result: Hello world. + + + Test 06: model appending style attributes + XHTML: Hello world. + // Populate attributes of Test 06. + text = new TextModel (); + text.getAttributes ().appendAttribute ("style", "foreground: red;"); + text.getAttributes ().setAttribute ("class", "aClass"); + datas.put ("test06", text); + Result: Hello world. + + + Test 07: image + XHTML: A picture pinguoin flottant. + // Populate attributes of Test 07. + text = new TextModel (); + text.getAttributes ().setAttribute ("width", "50%"); + datas.put ("test07", text); + Result: A picture pinguoin flottant. + + + \ No newline at end of file diff --git a/src/fr/devinsy/xid/xhtml-lat1.ent b/src/fr/devinsy/xid/xhtml-lat1.ent new file mode 100644 index 0000000..ffee223 --- /dev/null +++ b/src/fr/devinsy/xid/xhtml-lat1.ent @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/xid/xhtml-special.ent b/src/fr/devinsy/xid/xhtml-special.ent new file mode 100644 index 0000000..cead4e8 --- /dev/null +++ b/src/fr/devinsy/xid/xhtml-special.ent @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/xid/xhtml-symbol.ent b/src/fr/devinsy/xid/xhtml-symbol.ent new file mode 100644 index 0000000..63c2abf --- /dev/null +++ b/src/fr/devinsy/xid/xhtml-symbol.ent @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/xid/xhtml1-frameset.dtd b/src/fr/devinsy/xid/xhtml1-frameset.dtd new file mode 100644 index 0000000..1a00936 --- /dev/null +++ b/src/fr/devinsy/xid/xhtml1-frameset.dtd @@ -0,0 +1,1235 @@ + + + + + +%HTMLlat1; + + +%HTMLsymbol; + + +%HTMLspecial; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/xid/xhtml1-transitional.dtd b/src/fr/devinsy/xid/xhtml1-transitional.dtd new file mode 100644 index 0000000..e22581b --- /dev/null +++ b/src/fr/devinsy/xid/xhtml1-transitional.dtd @@ -0,0 +1,1210 @@ + + + + + +%HTMLlat1; + + +%HTMLsymbol; + + +%HTMLspecial; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/XidTest.java b/tests/XidTest.java new file mode 100644 index 0000000..abab2c0 --- /dev/null +++ b/tests/XidTest.java @@ -0,0 +1,238 @@ +/** + * XidTest. + */ + + +import fr.devinsy.xid.*; + +/** + * + */ +class XidTest +{ + static private org.apache.log4j.Logger logger; + + static + { + // Initialize logger. + org.apache.log4j.Logger log = null; + + org.apache.log4j.BasicConfigurator.configure (); + + + log = org.apache.log4j.Logger.getRootLogger (); + //logger.setLevel (org.apache.log4j.Level.INFO); + logger.setLevel (org.apache.log4j.Level.INFO); + + logger.info ("Enter"); + + // + logger.info ("Set the log file format..."); + + + // log = org.apache.log4j.Category.getInstance(Application.class.getName()); + logger.info ("... done."); + + logger.debug ("Exit"); + log = org.apache.log4j.Logger.getLogger (XidTest.class.getName ()); + } + + + + /** + * + */ + public static String check (String title, StringBuffer source, String model) + { + String result; + + if (source.indexOf (model) == -1) + { + result = String.format ("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; + + } + else + { + result = String.format ("%-40s [ OK ] ", title); + } + + + // + return (result); + } + + public enum MONTHS {JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE}; + + /** + * + */ + public static void main(String[] args) + { + System.out.println("Automatic test action for Xid!"); + + + Data datas; + IdData tag; + + + String htmlSource; + StringBuffer html; + StringBuffer errorMessage; + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + datas.setContent ("name", "Superman"); + errorMessage = new StringBuffer (); + + html = StringPresenter.doXid ("
a name
", datas, errorMessage); + + System.out.println (check ("only content change", html, "
Superman
")); + + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + datas.setContent ("lastname", "Spiderman"); + datas.appendAttribute ("lastname", "style", "background: blue;"); + datas.appendAttribute ("lastname", "style", "foreground: red;"); + datas.setAttribute ("lastname", "class", "nameClass"); + + errorMessage = new StringBuffer (); + html = StringPresenter.doXid ("
a last name
", datas, errorMessage); + System.out.println (check ("content and attributes", html, "
Spiderman
")); + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + datas.setContent ("words", 0, "alpha"); + datas.setContent ("words", 1, "bravo"); + datas.setContent ("words", 2, "charlie"); + datas.setContent ("words", 3, "delta"); + datas.setContent ("words", 4, "echo"); + datas.setContent ("words", 5, "fox"); + + + errorMessage = new StringBuffer (); + html = StringPresenter.doXid ("
    \n
  • a word
  • \n
", datas, errorMessage); + + System.out.println (check ("list assertion 1", html, "
  • alpha
  • ")); + System.out.println (check ("list assertion 2", html, "
  • bravo
  • ")); + System.out.println (check ("list assertion 3", html, "
  • charlie
  • ")); + System.out.println (check ("list assertion 4", html, "
  • delta
  • ")); + System.out.println (check ("list assertion 5", html, "
  • echo
  • ")); + System.out.println (check ("list assertion 6", html, "
  • fox
  • ")); + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + 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"); + + + errorMessage = new StringBuffer (); + StringBuffer source = new StringBuffer (); + source.append ("\n"); + source.append (" \n"); + source.append ("
    noidun nomun prenom
    "); + htmlSource = source.toString (); + html = StringPresenter.doXid (htmlSource, datas, errorMessage); + + System.out.println (check ("table 1 assertion 1", html, "noidJembaEpo")); + System.out.println (check ("table 1 assertion 2", html, "noidMomonChristian")); + System.out.println (check ("table 1 assertion 3", html, "noidTroncheChristophe")); + + /* + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + 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", 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 (); + source = new StringBuffer (); + source.append ("\n"); + source.append (" \n"); + source.append (" \n"); + source.append (" \n"); + source.append ("
    noidun nomun prenom
    noidun nomun prenom
    noidun nomun prenom
    "); + htmlSource = source.toString (); + + System.out.println ("datas = new Data ();"); + 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\");"); + System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + + System.out.println ("+"); + System.out.println (htmlSource); + System.out.println ("=>"); + + + 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", 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", 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", IdsDataByIndex.IterationStrategy.ALL_ROWS); + System.out.println ("ALL_ROWS:"); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + System.out.println (html); + + + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new Data (); + datas.setAttribute ("
    ", "class", "aDivClass"); + datas.setAttribute ("
    ", "style", "background-color: #000000;"); + datas.setAttribute ("number", "style", "background-color: #0000FF;"); + + errorMessage = new StringBuffer (); + source = new StringBuffer (); + source.append ("
    \n"); + source.append ("

    one

    \n"); + source.append ("
    \n"); + source.append ("
    \n"); + source.append ("

    three

    \n"); + source.append ("
    "); + htmlSource = source.toString (); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + + System.out.println (htmlSource); + System.out.println ("+"); + System.out.println ("datas = new Data ();"); + 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/webapp-examples/META-INF/MANIFEST.MF b/webapp-examples/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/webapp-examples/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: +