();
- String[] paragraphs = html.replace("", "").split("<\\/p>|
");
- for (int i=0;i htmlFormattingToPieces(String html) {
- List myPieces = new ArrayList();
- //Todo: At least handle bold and italics and turn them into formatted spans. (Will need to handle nesting though)
- myPieces.add(new Piece(null, html, null));
-
- return myPieces;
- }
+// private List htmlToParagraphPieces(String html) {
+// List myPieces = new ArrayList();
+// String[] paragraphs = html.replace("", "").split("<\\/p>|
");
+// for (int i=0;i htmlFormattingToPieces(String html) {
+// List myPieces = new ArrayList();
+// //Todo: At least handle bold and italics and turn them into formatted spans. (Will need to handle nesting though)
+// myPieces.add(new Piece(null, html, null));
+//
+// return myPieces;
+// }
public void addStyle(String style) {
for (Piece p : pieces)
p.addStyle(style);
@@ -507,8 +507,8 @@ public class HierarchicalTableGenerator {
b.append(new String(Base64.encodeBase64(bytes)));
// files.put(filename, b.toString());
return b.toString();
- } else
- return corePrefix+filename;
+ }
+ return corePrefix+filename;
}
@@ -558,22 +558,22 @@ public class HierarchicalTableGenerator {
b.append(new String(encodeBase64));
files.put(filename, b.toString());
return b.toString();
- } else {
- b.append("tbl_bck");
- for (Boolean i : indents)
- b.append(i ? "0" : "1");
- if (hasChildren)
- b.append("1");
- else
- b.append("0");
- b.append(".png");
- String file = Utilities.path(dest, b.toString());
- if (!new File(file).exists()) {
- FileOutputStream stream = new FileOutputStream(file);
- genImage(indents, hasChildren, stream);
- }
- return b.toString();
}
+ b.append("tbl_bck");
+ for (Boolean i : indents)
+ b.append(i ? "0" : "1");
+ if (hasChildren)
+ b.append("1");
+ else
+ b.append("0");
+ b.append(".png");
+ String file = Utilities.path(dest, b.toString());
+ if (!new File(file).exists()) {
+ //FIXME resource leak
+ FileOutputStream stream = new FileOutputStream(file);
+ genImage(indents, hasChildren, stream);
+ }
+ return b.toString();
}
diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlDocument.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlDocument.java
index 114f187c296..a4c6b19fbdf 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlDocument.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlDocument.java
@@ -25,7 +25,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-*/
+ */
package org.hl7.fhir.utilities.xhtml;
/*
@@ -51,15 +51,17 @@ package org.hl7.fhir.utilities.xhtml;
public class XhtmlDocument extends XhtmlNode {
- public XhtmlDocument() {
- super(NodeType.Document);
- }
+ private static final long serialVersionUID = -5061185698841745693L;
- public XhtmlNode getDocumentElement() {
- for (XhtmlNode n : getChildNodes()) {
- if (n.getNodeType() == NodeType.Element)
- return n;
- }
- return null;
- }
+ public XhtmlDocument() {
+ super(NodeType.Document);
+ }
+
+ public XhtmlNode getDocumentElement() {
+ for (XhtmlNode n : getChildNodes()) {
+ if (n.getNodeType() == NodeType.Element)
+ return n;
+ }
+ return null;
+ }
}
diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
index 4dac3bc76d5..a263b3d945c 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
@@ -25,7 +25,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-*/
+ */
package org.hl7.fhir.utilities.xhtml;
/*
@@ -62,268 +62,268 @@ import ca.uhn.fhir.model.primitive.XhtmlDt;
@ca.uhn.fhir.model.api.annotation.DatatypeDef(name="xhtml")
public class XhtmlNode implements IBaseXhtml {
- private static final long serialVersionUID = -4362547161441436492L;
+ private static final long serialVersionUID = -4362547161441436492L;
- public static class Location {
- private int line;
- private int column;
- public Location(int line, int column) {
- super();
- this.line = line;
- this.column = column;
- }
- public int getLine() {
- return line;
- }
- public int getColumn() {
- return column;
- }
- @Override
- public String toString() {
- return "Line "+Integer.toString(line)+", column "+Integer.toString(column);
- }
- }
+ public static class Location {
+ private int line;
+ private int column;
+ public Location(int line, int column) {
+ super();
+ this.line = line;
+ this.column = column;
+ }
+ public int getLine() {
+ return line;
+ }
+ public int getColumn() {
+ return column;
+ }
+ @Override
+ public String toString() {
+ return "Line "+Integer.toString(line)+", column "+Integer.toString(column);
+ }
+ }
- public static final String NBSP = Character.toString((char)0xa0);
+ public static final String NBSP = Character.toString((char)0xa0);
private static final String DECL_XMLNS = " xmlns=\"http://www.w3.org/1999/xhtml\"";
-
- private Location location;
- private NodeType nodeType;
- private String name;
- private Map attributes = new HashMap();
- private List childNodes = new ArrayList();
- private String content;
- public XhtmlNode() {
- super();
- }
+ private Location location;
+ private NodeType nodeType;
+ private String name;
+ private Map attributes = new HashMap();
+ private List childNodes = new ArrayList();
+ private String content;
-
- public XhtmlNode(NodeType nodeType, String name) {
- super();
- this.nodeType = nodeType;
- this.name = name;
- }
+ public XhtmlNode() {
+ super();
+ }
- public XhtmlNode(NodeType nodeType) {
- super();
- this.nodeType = nodeType;
- }
- public NodeType getNodeType() {
- return nodeType;
- }
+ public XhtmlNode(NodeType nodeType, String name) {
+ super();
+ this.nodeType = nodeType;
+ this.name = name;
+ }
- public void setNodeType(NodeType nodeType) {
- this.nodeType = nodeType;
- }
+ public XhtmlNode(NodeType nodeType) {
+ super();
+ this.nodeType = nodeType;
+ }
- public String getName() {
- return name;
- }
+ public NodeType getNodeType() {
+ return nodeType;
+ }
- public void setName(String name) {
- assert name.contains(":") == false : "Name should not contain any : but was " + name;
- this.name = name;
- }
+ public void setNodeType(NodeType nodeType) {
+ this.nodeType = nodeType;
+ }
- public Map getAttributes() {
- return attributes;
- }
+ public String getName() {
+ return name;
+ }
- public List getChildNodes() {
- return childNodes;
- }
+ public void setName(String name) {
+ assert name.contains(":") == false : "Name should not contain any : but was " + name;
+ this.name = name;
+ }
- public String getContent() {
- return content;
- }
+ public Map getAttributes() {
+ return attributes;
+ }
- public XhtmlNode setContent(String content) {
- if (!(nodeType != NodeType.Text || nodeType != NodeType.Comment))
- throw new Error("Wrong node type");
- this.content = content;
- return this;
- }
+ public List getChildNodes() {
+ return childNodes;
+ }
- public XhtmlNode addTag(String name)
- {
+ public String getContent() {
+ return content;
+ }
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type. is "+nodeType.toString());
- XhtmlNode node = new XhtmlNode(NodeType.Element);
- node.setName(name);
- childNodes.add(node);
- return node;
- }
+ public XhtmlNode setContent(String content) {
+ if (!(nodeType != NodeType.Text || nodeType != NodeType.Comment))
+ throw new Error("Wrong node type");
+ this.content = content;
+ return this;
+ }
- public XhtmlNode addTag(int index, String name)
- {
+ public XhtmlNode addTag(String name)
+ {
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type. is "+nodeType.toString());
- XhtmlNode node = new XhtmlNode(NodeType.Element);
- node.setName(name);
- childNodes.add(index, node);
- return node;
- }
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type. is "+nodeType.toString());
+ XhtmlNode node = new XhtmlNode(NodeType.Element);
+ node.setName(name);
+ childNodes.add(node);
+ return node;
+ }
- public XhtmlNode addComment(String content)
- {
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- XhtmlNode node = new XhtmlNode(NodeType.Comment);
- node.setContent(content);
- childNodes.add(node);
- return node;
- }
+ public XhtmlNode addTag(int index, String name)
+ {
- public XhtmlNode addDocType(String content)
- {
- if (!(nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- XhtmlNode node = new XhtmlNode(NodeType.DocType);
- node.setContent(content);
- childNodes.add(node);
- return node;
- }
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type. is "+nodeType.toString());
+ XhtmlNode node = new XhtmlNode(NodeType.Element);
+ node.setName(name);
+ childNodes.add(index, node);
+ return node;
+ }
- public XhtmlNode addInstruction(String content)
- {
- if (!(nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- XhtmlNode node = new XhtmlNode(NodeType.Instruction);
- node.setContent(content);
- childNodes.add(node);
- return node;
- }
+ public XhtmlNode addComment(String content)
+ {
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ XhtmlNode node = new XhtmlNode(NodeType.Comment);
+ node.setContent(content);
+ childNodes.add(node);
+ return node;
+ }
+
+ public XhtmlNode addDocType(String content)
+ {
+ if (!(nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ XhtmlNode node = new XhtmlNode(NodeType.DocType);
+ node.setContent(content);
+ childNodes.add(node);
+ return node;
+ }
+
+ public XhtmlNode addInstruction(String content)
+ {
+ if (!(nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ XhtmlNode node = new XhtmlNode(NodeType.Instruction);
+ node.setContent(content);
+ childNodes.add(node);
+ return node;
+ }
- public XhtmlNode addText(String content)
- {
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- if (content != null) {
- XhtmlNode node = new XhtmlNode(NodeType.Text);
- node.setContent(content);
- childNodes.add(node);
- return node;
- } else
- return null;
- }
+ public XhtmlNode addText(String content)
+ {
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ if (content != null) {
+ XhtmlNode node = new XhtmlNode(NodeType.Text);
+ node.setContent(content);
+ childNodes.add(node);
+ return node;
+ }
+ return null;
+ }
- public XhtmlNode addText(int index, String content)
- {
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- if (content == null)
- throw new Error("Content cannot be null");
-
- XhtmlNode node = new XhtmlNode(NodeType.Text);
- node.setContent(content);
- childNodes.add(index, node);
- return node;
- }
+ public XhtmlNode addText(int index, String content)
+ {
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ if (content == null)
+ throw new Error("Content cannot be null");
- public boolean allChildrenAreText()
- {
- boolean res = true;
- for (XhtmlNode n : childNodes)
- res = res && n.getNodeType() == NodeType.Text;
- return res;
- }
+ XhtmlNode node = new XhtmlNode(NodeType.Text);
+ node.setContent(content);
+ childNodes.add(index, node);
+ return node;
+ }
- public XhtmlNode getElement(String name)
- {
- for (XhtmlNode n : childNodes)
- if (n.getNodeType() == NodeType.Element && name.equals(n.getName()))
- return n;
- return null;
- }
+ public boolean allChildrenAreText()
+ {
+ boolean res = true;
+ for (XhtmlNode n : childNodes)
+ res = res && n.getNodeType() == NodeType.Text;
+ return res;
+ }
- public XhtmlNode getFirstElement()
- {
- for (XhtmlNode n : childNodes)
- if (n.getNodeType() == NodeType.Element)
- return n;
- return null;
- }
+ public XhtmlNode getElement(String name)
+ {
+ for (XhtmlNode n : childNodes)
+ if (n.getNodeType() == NodeType.Element && name.equals(n.getName()))
+ return n;
+ return null;
+ }
- public String allText() {
- StringBuilder b = new StringBuilder();
- for (XhtmlNode n : childNodes)
- if (n.getNodeType() == NodeType.Text)
- b.append(n.getContent());
- else if (n.getNodeType() == NodeType.Element)
- b.append(n.allText());
- return b.toString();
- }
+ public XhtmlNode getFirstElement()
+ {
+ for (XhtmlNode n : childNodes)
+ if (n.getNodeType() == NodeType.Element)
+ return n;
+ return null;
+ }
- public XhtmlNode attribute(String name, String value) {
- if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
- throw new Error("Wrong node type");
- if (name == null)
- throw new Error("name is null");
- if (value == null)
- throw new Error("value is null");
- attributes.put(name, value);
- return this;
- }
+ public String allText() {
+ StringBuilder b = new StringBuilder();
+ for (XhtmlNode n : childNodes)
+ if (n.getNodeType() == NodeType.Text)
+ b.append(n.getContent());
+ else if (n.getNodeType() == NodeType.Element)
+ b.append(n.allText());
+ return b.toString();
+ }
- public boolean hasAttribute(String name) {
- return getAttributes().containsKey(name);
- }
+ public XhtmlNode attribute(String name, String value) {
+ if (!(nodeType == NodeType.Element || nodeType == NodeType.Document))
+ throw new Error("Wrong node type");
+ if (name == null)
+ throw new Error("name is null");
+ if (value == null)
+ throw new Error("value is null");
+ attributes.put(name, value);
+ return this;
+ }
- public String getAttribute(String name) {
- return getAttributes().get(name);
- }
+ public boolean hasAttribute(String name) {
+ return getAttributes().containsKey(name);
+ }
- public XhtmlNode setAttribute(String name, String value) {
- getAttributes().put(name, value);
- return this;
- }
-
- public XhtmlNode copy() {
- XhtmlNode dst = new XhtmlNode(nodeType);
- dst.name = name;
- for (String n : attributes.keySet()) {
- dst.attributes.put(n, attributes.get(n));
- }
- for (XhtmlNode n : childNodes)
- dst.childNodes.add(n.copy());
- dst.content = content;
- return dst;
- }
+ public String getAttribute(String name) {
+ return getAttributes().get(name);
+ }
+
+ public XhtmlNode setAttribute(String name, String value) {
+ getAttributes().put(name, value);
+ return this;
+ }
+
+ public XhtmlNode copy() {
+ XhtmlNode dst = new XhtmlNode(nodeType);
+ dst.name = name;
+ for (String n : attributes.keySet()) {
+ dst.attributes.put(n, attributes.get(n));
+ }
+ for (XhtmlNode n : childNodes)
+ dst.childNodes.add(n.copy());
+ dst.content = content;
+ return dst;
+ }
@Override
public boolean isEmpty() {
- return (childNodes == null || childNodes.isEmpty()) && content == null;
- }
+ return (childNodes == null || childNodes.isEmpty()) && content == null;
+ }
public boolean equalsDeep(XhtmlNode other) {
- if (other == null) {
- return false;
- }
+ if (other == null) {
+ return false;
+ }
- if (!(nodeType == other.nodeType) || !compare(name, other.name) || !compare(content, other.content))
- return false;
- if (attributes.size() != other.attributes.size())
- return false;
- for (String an : attributes.keySet())
- if (!attributes.get(an).equals(other.attributes.get(an)))
- return false;
- if (childNodes.size() != other.childNodes.size())
- return false;
+ if (!(nodeType == other.nodeType) || !compare(name, other.name) || !compare(content, other.content))
+ return false;
+ if (attributes.size() != other.attributes.size())
+ return false;
+ for (String an : attributes.keySet())
+ if (!attributes.get(an).equals(other.attributes.get(an)))
+ return false;
+ if (childNodes.size() != other.childNodes.size())
+ return false;
for (int i = 0; i < childNodes.size(); i++) {
if (!compareDeep(childNodes.get(i), other.childNodes.get(i)))
return false;
}
return true;
- }
+ }
private boolean compare(String s1, String s2) {
if (s1 == null && s2 == null)
@@ -331,7 +331,7 @@ public class XhtmlNode implements IBaseXhtml {
if (s1 == null || s2 == null)
return false;
return s1.equals(s2);
- }
+ }
private static boolean compareDeep(XhtmlNode e1, XhtmlNode e2) {
if (e1 == null && e2 == null)
@@ -339,18 +339,18 @@ public class XhtmlNode implements IBaseXhtml {
if (e1 == null || e2 == null)
return false;
return e1.equalsDeep(e2);
- }
-
- public String getNsDecl() {
- for (String an : attributes.keySet()) {
- if (an.equals("xmlns")) {
- return attributes.get(an);
- }
- }
- return null;
- }
-
-
+ }
+
+ public String getNsDecl() {
+ for (String an : attributes.keySet()) {
+ if (an.equals("xmlns")) {
+ return attributes.get(an);
+ }
+ }
+ return null;
+ }
+
+
@Override
public String getValueAsString() {
if (isEmpty()) {
@@ -376,9 +376,9 @@ public class XhtmlNode implements IBaseXhtml {
if (isBlank(theValue)) {
return;
}
-
+
String val = theValue.trim();
-
+
if (!val.startsWith("<")) {
val = "" + val + "
";
}
@@ -387,7 +387,7 @@ public class XhtmlNode implements IBaseXhtml {
}
val = XhtmlDt.preprocessXhtmlNamespaceDeclaration(val);
-
+
try {
// TODO: this is ugly
XhtmlNode fragment = new XhtmlParser().parseFragment(val);
@@ -400,61 +400,64 @@ public class XhtmlNode implements IBaseXhtml {
// TODO: composer shouldn't throw exception like this
throw new RuntimeException(e);
}
-
+
}
- public XhtmlNode getElementByIndex(int i) {
- int c = 0;
- for (XhtmlNode n : childNodes)
- if (n.getNodeType() == NodeType.Element) {
- if (c == i)
- return n;
- else
- c++;
- }
- return null;
- }
+ public XhtmlNode getElementByIndex(int i) {
+ int c = 0;
+ for (XhtmlNode n : childNodes)
+ if (n.getNodeType() == NodeType.Element) {
+ if (c == i){
+ return n;
+ }
+ c++;
+ }
+ return null;
+ }
-@Override
-public String getValue() {
- return getValueAsString();
-}
+ @Override
+ public String getValue() {
+ return getValueAsString();
+ }
-@Override
-public XhtmlNode setValue(String theValue) throws IllegalArgumentException {
- setValueAsString(theValue);
- return this;
-}
+ @Override
+ public XhtmlNode setValue(String theValue) throws IllegalArgumentException {
+ setValueAsString(theValue);
+ return this;
+ }
-/**
- * Returns false
- */
-public boolean hasFormatComment() {
- return false;
-}
+ /**
+ * Returns false
+ */
+ @Override
+ public boolean hasFormatComment() {
+ return false;
+ }
-/**
- * NOT SUPPORTED - Throws {@link UnsupportedOperationException}
- */
-public List getFormatCommentsPre() {
- throw new UnsupportedOperationException();
-}
+ /**
+ * NOT SUPPORTED - Throws {@link UnsupportedOperationException}
+ */
+ @Override
+ public List getFormatCommentsPre() {
+ throw new UnsupportedOperationException();
+ }
-/**
- * NOT SUPPORTED - Throws {@link UnsupportedOperationException}
- */
-public List getFormatCommentsPost() {
- throw new UnsupportedOperationException();
-}
+ /**
+ * NOT SUPPORTED - Throws {@link UnsupportedOperationException}
+ */
+ @Override
+ public List getFormatCommentsPost() {
+ throw new UnsupportedOperationException();
+ }
-public Location getLocation() {
- return location;
-}
+ public Location getLocation() {
+ return location;
+ }
-public void setLocation(Location location) {
- this.location = location;
-}
+ public void setLocation(Location location) {
+ this.location = location;
+ }
}
diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java
index 1a54dc7db73..dda22dde031 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java
@@ -227,17 +227,17 @@ public class XhtmlParser {
if (validatorMode)
return true;
boolean ok = attributes.contains(attr) || attributes.contains(elem + "." + attr);
- if (ok)
+ if (ok) {
return true;
- else
- switch (policy) {
- case Accept:
- return true;
- case Drop:
- return false;
- case Reject:
- throw new FHIRFormatError("Illegal HTML attribute " + elem + "." + attr);
- }
+ }
+ switch (policy) {
+ case Accept:
+ return true;
+ case Drop:
+ return false;
+ case Reject:
+ throw new FHIRFormatError("Illegal HTML attribute " + elem + "." + attr);
+ }
if ((elem + "." + attr).equals("img.src") && !(value.startsWith("#") || value.startsWith("http:") || value.startsWith("https:"))) {
switch (policy) {
@@ -306,17 +306,17 @@ public class XhtmlParser {
if (validatorMode)
return true;
boolean ok = elements.contains(name);
- if (ok)
+ if (ok){
return true;
- else
- switch (policy) {
- case Accept:
- return true;
- case Drop:
- return false;
- case Reject:
- throw new FHIRFormatError("Illegal HTML element " + name);
- }
+ }
+ switch (policy) {
+ case Accept:
+ return true;
+ case Drop:
+ return false;
+ case Reject:
+ throw new FHIRFormatError("Illegal HTML element " + name);
+ }
return false;
}
@@ -458,26 +458,25 @@ public class XhtmlParser {
else if (peekChar() == '/') {
readChar();
QName n = new QName(readToTagEnd());
- if (node.getName().equals(n.getName()))
+ if (node.getName().equals(n.getName())){
return;
- else {
- if (mustBeWellFormed)
- throw new FHIRFormatError("Malformed XHTML: Found \"" + n.getName() + ">\" expecting \"" + node.getName() + ">\"" + descLoc());
- for (int i = parents.size() - 1; i >= 0; i--) {
- if (parents.get(i).getName().equals(n))
- unwindPoint = parents.get(i);
- }
- if (unwindPoint != null) {
- for (int i = parents.size(); i > 0; i--) {
- if (i < parents.size() && parents.get(i) == unwindPoint)
- return;
- if (i == parents.size()) {
- parents.get(i - 1).getChildNodes().addAll(node.getChildNodes());
- node.getChildNodes().clear();
- } else {
- parents.get(i - 1).getChildNodes().addAll(parents.get(i).getChildNodes());
- parents.get(i).getChildNodes().clear();
- }
+ }
+ if (mustBeWellFormed)
+ throw new FHIRFormatError("Malformed XHTML: Found \"" + n.getName() + ">\" expecting \"" + node.getName() + ">\"" + descLoc());
+ for (int i = parents.size() - 1; i >= 0; i--) {
+ if (parents.get(i).getName().equals(n))
+ unwindPoint = parents.get(i);
+ }
+ if (unwindPoint != null) {
+ for (int i = parents.size(); i > 0; i--) {
+ if (i < parents.size() && parents.get(i) == unwindPoint)
+ return;
+ if (i == parents.size()) {
+ parents.get(i - 1).getChildNodes().addAll(node.getChildNodes());
+ node.getChildNodes().clear();
+ } else {
+ parents.get(i - 1).getChildNodes().addAll(parents.get(i).getChildNodes());
+ parents.get(i).getChildNodes().clear();
}
}
}
diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java
index c943109b184..b36b8d0d704 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java
@@ -275,38 +275,37 @@ public class XMLUtil {
* @return escape string
*/
public static String escapeXML(String rawContent, String charset, boolean isNoLines) {
- if (rawContent == null)
+ if (rawContent == null){
return "";
- else {
- StringBuffer sb = new StringBuffer();
+ }
+ StringBuffer sb = new StringBuffer();
- for (int i = 0; i < rawContent.length(); i++) {
- char ch = rawContent.charAt(i);
- if (ch == '\'')
- sb.append("'");
- else if (ch == '&')
- sb.append("&");
- else if (ch == '"')
- sb.append(""");
- else if (ch == '<')
- sb.append("<");
- else if (ch == '>')
- sb.append(">");
- else if (ch > '~' && charset != null && charSetImpliesAscii(charset))
- // TODO - why is hashcode the only way to get the unicode number for the character
- // in jre 5.0?
- sb.append(""+Integer.toHexString(new Character(ch).hashCode()).toUpperCase()+";");
- else if (isNoLines) {
- if (ch == '\r')
- sb.append("
");
- else if (ch != '\n')
- sb.append(ch);
- }
- else
+ for (int i = 0; i < rawContent.length(); i++) {
+ char ch = rawContent.charAt(i);
+ if (ch == '\'')
+ sb.append("'");
+ else if (ch == '&')
+ sb.append("&");
+ else if (ch == '"')
+ sb.append(""");
+ else if (ch == '<')
+ sb.append("<");
+ else if (ch == '>')
+ sb.append(">");
+ else if (ch > '~' && charset != null && charSetImpliesAscii(charset))
+ // TODO - why is hashcode the only way to get the unicode number for the character
+ // in jre 5.0?
+ sb.append(""+Integer.toHexString(new Character(ch).hashCode()).toUpperCase()+";");
+ else if (isNoLines) {
+ if (ch == '\r')
+ sb.append("
");
+ else if (ch != '\n')
sb.append(ch);
}
- return sb.toString();
+ else
+ sb.append(ch);
}
+ return sb.toString();
}
public static Element getFirstChild(Element e) {
@@ -435,6 +434,7 @@ public class XMLUtil {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
+ //FIXME resource leak
return builder.parse(new FileInputStream(filename));
}
diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java
index f66a0915b2c..ab739b9390d 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java
@@ -401,10 +401,10 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
@Override
public String getDefaultNamespace() {
XMLNamespace ns = findDefaultNamespace();
- if (ns == null)
+ if (ns == null) {
return null;
- else
- return ns.getNamespace();
+ }
+ return ns.getNamespace();
}
/* (non-Javadoc)
@@ -519,10 +519,10 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
writePendingComment();
pendingClose = false;
}
-
- if (name == null) {
- throw new IOException("name is null");
- }
+//death code
+// if (name == null) {
+// throw new IOException("name is null");
+// }
newLevelIfRequired();
levels.current().setName(name);
levels.current().setNamespace(namespace);
@@ -615,23 +615,22 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
checkStarted();
if (levels.empty()) {
throw new IOException("Called exit one too many times");
+ }
+ if (pendingClose) {
+ write("/>");
+ writePendingComment();
+ pendingClose = false;
} else {
- if (pendingClose) {
- write("/>");
- writePendingComment();
- pendingClose = false;
- } else {
- if (levels.current().hasChildren())
- writePretty();
- write("");
- if (levels.current().getNamespace() == null)
- write(levels.current().getName());
- else
- write(getNSAbbreviation(levels.current().getNamespace())+levels.current().getName());
- write('>');
- }
- levels.pop();
+ if (levels.current().hasChildren())
+ writePretty();
+ write("");
+ if (levels.current().getNamespace() == null)
+ write(levels.current().getName());
+ else
+ write(getNSAbbreviation(levels.current().getNamespace())+levels.current().getName());
+ write('>');
}
+ levels.pop();
}
/* (non-Javadoc)
@@ -830,8 +829,8 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
for (int i = 0; i < levels.size() - 1; i++)
write(" ");
return (levels.size() - 1) * 2;
- } else
- return 0;
+ }
+ return 0;
}
public int getLineType() {
diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java
index 925340ac1b8..bc120a0e2c6 100644
--- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java
+++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java
@@ -7,11 +7,9 @@ import java.io.StringReader;
import org.junit.Test;
-import ca.uhn.fhir.context.FhirContext;
-
public class JsonLikeStructureTest {
- private static FhirContext ourCtx;
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonLikeStructureTest.class);
+// private static FhirContext ourCtx;
+// private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonLikeStructureTest.class);
private static final String TEST_STRUCTURELOADING_DATA =
"{" +
diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java
index f3b689e29ea..d55b7a9a1cc 100644
--- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java
+++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java
@@ -1,11 +1,11 @@
package ca.uhn.fhir.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import ca.uhn.fhir.util.UrlUtil.UrlParts;
-
public class UrlUtilTest {
@Test
diff --git a/hapi-fhir-structures-dstu2/pom.xml b/hapi-fhir-structures-dstu2/pom.xml
index f5cd1d325aa..53a0dadd33a 100644
--- a/hapi-fhir-structures-dstu2/pom.xml
+++ b/hapi-fhir-structures-dstu2/pom.xml
@@ -99,7 +99,7 @@
net.sf.json-lib
json-lib
- 2.4
+
jdk15
test
@@ -116,7 +116,7 @@
net.sf.json-lib
json-lib
- 2.4
+
jdk15-sources
test
@@ -139,7 +139,7 @@
directory-naming
naming-java
- 0.8
+
test
diff --git a/hapi-fhir-structures-hl7org-dstu2/pom.xml b/hapi-fhir-structures-hl7org-dstu2/pom.xml
index c04497c465c..95a218e25ac 100644
--- a/hapi-fhir-structures-hl7org-dstu2/pom.xml
+++ b/hapi-fhir-structures-hl7org-dstu2/pom.xml
@@ -121,7 +121,7 @@
net.sf.json-lib
json-lib
- 2.4
+
jdk15
test
@@ -142,7 +142,7 @@
net.sf.json-lib
json-lib
- 2.4
+
jdk15-sources
test
@@ -165,7 +165,7 @@
directory-naming
naming-java
- 0.8
+
test