From 8ecec43df2c636219ffe30b4d3c1e7ab15df31b1 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 20 Aug 2013 01:05:46 +0200 Subject: [PATCH] Fix index inc in findHeadNode. Improve FilePresenter code. --- .../xidyn/presenters/FilePresenter.java | 43 +++++++++---------- .../xidyn/presenters/URLPresenter.java | 2 + src/fr/devinsy/xidyn/utils/XidynUtils.java | 11 +++-- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/fr/devinsy/xidyn/presenters/FilePresenter.java b/src/fr/devinsy/xidyn/presenters/FilePresenter.java index b93cb54..5d6fcad 100644 --- a/src/fr/devinsy/xidyn/presenters/FilePresenter.java +++ b/src/fr/devinsy/xidyn/presenters/FilePresenter.java @@ -183,34 +183,33 @@ public class FilePresenter extends StringPresenter * */ @Override - public void setSource(final String filePathname) + public void setSource(final String source) { - if (filePathname == null) + // + File file; + if (source == null) { - setSource((File) null); + file = null; + } + else if (source.matches("file://.+")) + { + try + { + file = new File(new URI(source)); + } + catch (URISyntaxException exception) + { + exception.printStackTrace(); + throw new IllegalArgumentException("Bad URI argument.", exception); + } } else { - if (this.sourceFilePathname.matches("file://.+")) - { - try - { - this.source = new File(new URI(this.sourceFilePathname)); - } - catch (URISyntaxException exception) - { - exception.printStackTrace(); - throw new IllegalArgumentException("Bad URI argument.", exception); - } - } - else - { - this.source = new File(this.sourceFilePathname); - } - this.sourceFilePathname = filePathname; - this.sourceTime = 0; - super.setSource(null); + file = new File(source); } + + // + setSource(file); } /** diff --git a/src/fr/devinsy/xidyn/presenters/URLPresenter.java b/src/fr/devinsy/xidyn/presenters/URLPresenter.java index 874ae28..7e3325e 100644 --- a/src/fr/devinsy/xidyn/presenters/URLPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/URLPresenter.java @@ -142,6 +142,7 @@ public class URLPresenter extends StringPresenter @Override public void setSource(final String source) { + // URL url; if (source == null) { @@ -165,6 +166,7 @@ public class URLPresenter extends StringPresenter url = URLPresenter.class.getResource(source); } + // setSource(url); } diff --git a/src/fr/devinsy/xidyn/utils/XidynUtils.java b/src/fr/devinsy/xidyn/utils/XidynUtils.java index a6f5eb1..923007f 100644 --- a/src/fr/devinsy/xidyn/utils/XidynUtils.java +++ b/src/fr/devinsy/xidyn/utils/XidynUtils.java @@ -39,9 +39,9 @@ public class XidynUtils static public void addMetaTag(final Document doc, final String name, final String content) { // Find head tag. - Node headNode = findHeadNode(doc); logger.debug("headNode = [" + headNode + "]"); + if (headNode != null) { Node metaNode = doc.createElement("meta"); @@ -432,10 +432,15 @@ public class XidynUtils { if (childrenIndex < childrenCount) { - result = findNodeByName(children.item(childrenIndex), name); - if (result != null) + Node subResult = findNodeByName(children.item(childrenIndex), name); + if (subResult == null) + { + childrenIndex += 1; + } + else { ended = true; + result = subResult; } } else