();
- 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-client-okhttp/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-client-okhttp/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 60105c1b951..00000000000
--- a/hapi-fhir-client-okhttp/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/hapi-fhir-jacoco/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-jacoco/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 60105c1b951..00000000000
--- a/hapi-fhir-jacoco/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/hapi-fhir-jaxrsserver-base/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-jaxrsserver-base/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 60105c1b951..00000000000
--- a/hapi-fhir-jaxrsserver-base/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/hapi-fhir-jaxrsserver-example/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-jaxrsserver-example/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 60105c1b951..00000000000
--- a/hapi-fhir-jaxrsserver-example/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java
index b51da9436a3..03771b9ebfd 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java
@@ -38,7 +38,8 @@ import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
-import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
+import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
+import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
@Configuration
@EnableScheduling
@@ -59,13 +60,13 @@ public class BaseConfig implements SchedulingConfigurer {
@Bean(autowire = Autowire.BY_TYPE)
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
- DatabaseBackedPagingProvider retVal = new DatabaseBackedPagingProvider(10);
+ DatabaseBackedPagingProvider retVal = new DatabaseBackedPagingProvider();
return retVal;
}
@Bean(autowire=Autowire.BY_TYPE)
- public StaleSearchDeletingSvc staleSearchDeletingSvc() {
- return new StaleSearchDeletingSvc();
+ public IStaleSearchDeletingSvc staleSearchDeletingSvc() {
+ return new StaleSearchDeletingSvcImpl();
}
@Bean()
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
index 22e67de435f..08a66c15be1 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
@@ -1087,7 +1087,7 @@ public abstract class BaseHapiFhirDao implements IDao {
b.append(" (pid ");
b.append(theEntity.getId());
b.append(", version ");
- b.append(myContext.getVersion().getVersion());
+ b.append(theEntity.getFhirVersion().name());
b.append("): ");
b.append(e.getMessage());
String msg = b.toString();
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java
index 446534ad694..880cd96e91e 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java
@@ -192,7 +192,7 @@ public abstract class BaseHapiFhirResourceDao extends B
validateOkToDelete(deleteConflicts, entity);
- preDelete(resourceToDelete);
+ preDelete(resourceToDelete, entity);
// Notify interceptors
if (theRequestDetails != null) {
@@ -722,7 +722,8 @@ public abstract class BaseHapiFhirResourceDao extends B
* Subclasses may override to provide behaviour. Invoked within a delete
* transaction with the resource that is about to be deleted.
*/
- protected void preDelete(T theResourceToDelete) {
+ @SuppressWarnings("unused")
+ protected void preDelete(T theResourceToDelete, ResourceTable theEntityToDelete) {
// nothing by default
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
index c1770e5cb03..051ee0bdeb7 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
@@ -21,12 +21,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
* limitations under the License.
* #L%
*/
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import javax.persistence.Query;
@@ -59,7 +54,6 @@ import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
-import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao implements IFhirSystemDao {
@@ -278,9 +272,9 @@ public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao
* The bundle type
+ * @param
+ * The Meta datatype type
*/
public interface IFhirSystemDao extends IDao {
/**
* Use with caution! This deletes everything!!
- * @param theRequestDetails TODO
+ *
+ * @param theRequestDetails
+ * TODO
*/
void deleteAllTagsOnServer(RequestDetails theRequestDetails);
@@ -58,11 +62,13 @@ public interface IFhirSystemDao extends IDao {
/**
* Not supported for DSTU1
- * @param theRequestDetails TODO
+ *
+ * @param theRequestDetails
+ * TODO
*/
MT metaGetOperation(RequestDetails theRequestDetails);
- int performReindexingPass(Integer theCount);
+ Integer performReindexingPass(Integer theCount);
T transaction(RequestDetails theRequestDetails, T theResources);
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java
index 549be9ed979..344fa4b83c1 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java
@@ -73,8 +73,8 @@ public class FhirResourceDaoSearchParameterDstu3 extends FhirResourceDaoDstu3 toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
- if (toDelete.isEmpty()) {
- return;
+ @Override
+ public synchronized void schedulePollForStaleSearches() {
+ if (!myDaoConfig.isSchedulingDisabled()) {
+ if (myDaoConfig.isExpireSearchResults()) {
+ pollForStaleSearchesAndDeleteThem();
}
+ }
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
+ public void pollForStaleSearchesAndDeleteThem() {
+ Date cutoff = new Date(System.currentTimeMillis() - myDaoConfig.getExpireSearchResultsAfterMillis());
+ ourLog.debug("Searching for searches which are before {}", cutoff);
+
+ Collection toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
+ if (!toDelete.isEmpty()) {
for (final Search next : toDelete) {
deleteSearch(next);
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java
index 85dfffa3558..699f62a96f5 100644
--- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java
@@ -36,7 +36,7 @@ import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
-import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
+import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
import ca.uhn.fhir.parser.IParser;
@@ -162,7 +162,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
@Autowired
protected IFulltextSearchSvc mySearchDao;
@Autowired
- protected StaleSearchDeletingSvc myStaleSearchDeletingSvc;
+ protected IStaleSearchDeletingSvc myStaleSearchDeletingSvc;
@Autowired
@Qualifier("myStructureDefinitionDaoDstu3")
protected IFhirResourceDao myStructureDefinitionDao;
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java
index 43a5c30aeed..61ee037b116 100644
--- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java
@@ -49,7 +49,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.jpa.entity.*;
-import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
+import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
@@ -1510,7 +1510,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
}
@Autowired
- protected StaleSearchDeletingSvc myStaleSearchDeletingSvc;
+ protected IStaleSearchDeletingSvc myStaleSearchDeletingSvc;
@Test
@@ -1539,7 +1539,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
assertThat(toUnqualifiedVersionlessIds(bundleProvider), containsInAnyOrder(pid1, pid2));
myDaoConfig.setExpireSearchResults(false);
- myStaleSearchDeletingSvc.pollForStaleSearches();
+ myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
Thread.sleep(1500);
assertThat(toUnqualifiedVersionlessIds(bundleProvider), (containsInAnyOrder(pid1, pid2)));
@@ -1572,7 +1572,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Thread.sleep(1500);
myDaoConfig.setExpireSearchResultsAfterMillis(500);
- myStaleSearchDeletingSvc.pollForStaleSearches();
+ myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
assertThat(toUnqualifiedVersionlessIds(bundleProvider), not(containsInAnyOrder(pid1, pid2)));
}
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java
index 05196ad1ce6..ce4d2d04c75 100644
--- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java
@@ -17,7 +17,6 @@ import org.junit.Test;
import ca.uhn.fhir.rest.gclient.IClientExecutable;
import ca.uhn.fhir.rest.gclient.IQuery;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
-import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.TestUtil;
public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Test {
@@ -69,13 +68,13 @@ public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Te
Bundle resp2 = ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp2));
- myStaleSearchDeletingSvc.pollForStaleSearches();
+ myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
Thread.sleep(20);
myDaoConfig.setExpireSearchResultsAfterMillis(10);
- myStaleSearchDeletingSvc.pollForStaleSearches();
+ myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
try {
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
index 4d5b7bc5b01..6056b717e85 100644
--- a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
+++ b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
@@ -177,8 +177,14 @@
org.apache.maven.plugins
maven-compiler-plugin
-
- 1.7
+
+
+ 1.8
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-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java
index 61c060cb7c0..f081a99a6ac 100644
--- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java
+++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java
@@ -1,30 +1,24 @@
package ca.uhn.fhir.rest.client;
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.util.List;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicStatusLine;
-import org.hl7.fhir.dstu3.model.Binary;
-import org.hl7.fhir.dstu3.model.Conformance;
-import org.hl7.fhir.dstu3.model.OperationOutcome;
-import org.hl7.fhir.dstu3.model.Patient;
+import org.hl7.fhir.dstu3.model.Bundle;
+import org.hl7.fhir.dstu3.model.Organization;
+import org.hl7.fhir.instance.model.api.IAnyResource;
+import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -36,65 +30,53 @@ import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
+import ca.uhn.fhir.rest.param.DateParam;
+import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.util.TestUtil;
-import ca.uhn.fhir.util.VersionUtil;
public class ClientWithCustomTypeDstu3Test {
- private static FhirContext ourCtx;
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ClientWithCustomTypeDstu3Test.class);
- private HttpClient myHttpClient;
- private HttpResponse myHttpResponse;
+ private static FhirContext ourCtx;
+ private HttpClient myHttpClient;
+ private HttpResponse myHttpResponse;
- @AfterClass
- public static void afterClassClearContext() {
- TestUtil.clearAllStaticFieldsForUnitTest();
- }
+ @AfterClass
+ public static void afterClassClearContext() {
+ TestUtil.clearAllStaticFieldsForUnitTest();
+ }
+ @Before
+ public void before() {
+ myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
+ ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
+ ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
+ myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
+ }
- @Before
- public void before() {
- myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
- ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
- ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
- myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
- }
+ @Test
+ public void testReadCustomType() throws Exception {
+ IParser p = ourCtx.newXmlParser();
- private byte[] extractBodyAsByteArray(ArgumentCaptor capt) throws IOException {
- byte[] body = IOUtils.toByteArray(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(0)).getEntity().getContent());
- return body;
- }
+ MyPatientWithExtensions response = new MyPatientWithExtensions();
+ response.addName().setFamily("FAMILY");
+ response.getStringExt().setValue("STRINGVAL");
+ response.getDateExt().setValueAsString("2011-01-02");
+ final String respString = p.encodeResourceToString(response);
- private String extractBodyAsString(ArgumentCaptor capt) throws IOException {
- String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(0)).getEntity().getContent(), "UTF-8");
- return body;
- }
+ ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
+ when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
+ when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
+ when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
+ when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() {
+ @Override
+ public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
+ return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
+ }
+ });
+ IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
- @Test
- public void testReadCustomType() throws Exception {
- IParser p = ourCtx.newXmlParser();
-
- MyPatientWithExtensions response = new MyPatientWithExtensions();
- response.addName().setFamily("FAMILY");
- response.getStringExt().setValue("STRINGVAL");
- response.getDateExt().setValueAsString("2011-01-02");
- final String respString = p.encodeResourceToString(response);
-
- ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
- when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
- when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
- when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
- when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() {
- @Override
- public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
- return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
- }
- });
-
- IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
-
- //@formatter:off
+ //@formatter:off
MyPatientWithExtensions value = client
.read()
.resource(MyPatientWithExtensions.class)
@@ -102,23 +84,97 @@ public class ClientWithCustomTypeDstu3Test {
.execute();
//@formatter:on
- HttpUriRequest request = capt.getAllValues().get(0);
+ HttpUriRequest request = capt.getAllValues().get(0);
- assertEquals("http://example.com/fhir/Patient/123", request.getURI().toASCIIString());
- assertEquals("GET", request.getMethod());
+ assertEquals("http://example.com/fhir/Patient/123", request.getURI().toASCIIString());
+ assertEquals("GET", request.getMethod());
- assertEquals(1, value.getName().size());
- assertEquals("FAMILY", value.getName().get(0).getFamily());
- assertEquals("STRINGVAL", value.getStringExt().getValue());
- assertEquals("2011-01-02", value.getDateExt().getValueAsString());
-
- }
+ assertEquals(1, value.getName().size());
+ assertEquals("FAMILY", value.getName().get(0).getFamily());
+ assertEquals("STRINGVAL", value.getStringExt().getValue());
+ assertEquals("2011-01-02", value.getDateExt().getValueAsString());
+ }
+ @Test
+ public void testSearchWithGenericReturnType() throws Exception {
- @BeforeClass
- public static void beforeClass() {
- ourCtx = FhirContext.forDstu3();
- }
+ final Bundle bundle = new Bundle();
+
+ final ExtendedPatient patient = new ExtendedPatient();
+ patient.addIdentifier().setValue("PRP1660");
+ bundle.addEntry().setResource(patient);
+
+ final Organization org = new Organization();
+ org.setName("FOO");
+ patient.getManagingOrganization().setResource(org);
+
+ final FhirContext ctx = FhirContext.forDstu3();
+ ctx.setDefaultTypeForProfile(ExtendedPatient.HTTP_FOO_PROFILES_PROFILE, ExtendedPatient.class);
+ ctx.getRestfulClientFactory().setHttpClient(myHttpClient);
+ ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
+
+ String msg = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle);
+
+ ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
+
+ when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
+ when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
+ when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
+
+ // httpResponse = new BasicHttpResponse(statusline, catalog, locale)
+ when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
+
+ ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
+ List response = client.getPatientByDobWithGenericResourceReturnType(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
+
+ assertEquals("http://foo/Patient?birthdate=ge2011-01-02", capt.getValue().getURI().toString());
+ ExtendedPatient patientResp = (ExtendedPatient) response.get(0);
+ assertEquals("PRP1660", patientResp.getIdentifier().get(0).getValue());
+
+ }
+
+ @Test
+ public void testSearchWithGenericReturnType2() throws Exception {
+
+ final Bundle bundle = new Bundle();
+
+ final ExtendedPatient patient = new ExtendedPatient();
+ patient.addIdentifier().setValue("PRP1660");
+ bundle.addEntry().setResource(patient);
+
+ final Organization org = new Organization();
+ org.setName("FOO");
+ patient.getManagingOrganization().setResource(org);
+
+ final FhirContext ctx = FhirContext.forDstu3();
+ ctx.setDefaultTypeForProfile(ExtendedPatient.HTTP_FOO_PROFILES_PROFILE, ExtendedPatient.class);
+ ctx.getRestfulClientFactory().setHttpClient(myHttpClient);
+ ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
+
+ String msg = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle);
+
+ ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
+
+ when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
+ when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
+ when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
+
+ // httpResponse = new BasicHttpResponse(statusline, catalog, locale)
+ when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
+
+ ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
+ List response = client.getPatientByDobWithGenericResourceReturnType2(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
+
+ assertEquals("http://foo/Patient?birthdate=ge2011-01-02", capt.getValue().getURI().toString());
+ ExtendedPatient patientResp = (ExtendedPatient) response.get(0);
+ assertEquals("PRP1660", patientResp.getIdentifier().get(0).getValue());
+
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ ourCtx = FhirContext.forDstu3();
+ }
}
diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ExtendedPatient.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ExtendedPatient.java
new file mode 100644
index 00000000000..fc6ed596489
--- /dev/null
+++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ExtendedPatient.java
@@ -0,0 +1,41 @@
+package ca.uhn.fhir.rest.client;
+
+import org.hl7.fhir.dstu3.model.Patient;
+import org.hl7.fhir.dstu3.model.StringType;
+
+import ca.uhn.fhir.model.api.annotation.Child;
+import ca.uhn.fhir.model.api.annotation.Description;
+import ca.uhn.fhir.model.api.annotation.Extension;
+import ca.uhn.fhir.model.api.annotation.ResourceDef;
+
+@ResourceDef(name = "Patient", profile = ExtendedPatient.HTTP_FOO_PROFILES_PROFILE)
+public class ExtendedPatient extends Patient {
+
+ static final String HTTP_FOO_PROFILES_PROFILE = "http://foo/profiles/Profile";
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ /**
+ * Each extension is defined in a field. Any valid HAPI Data Type
+ * can be used for the field type. Note that the [name=""] attribute
+ * in the @Child annotation needs to match the name for the bean accessor
+ * and mutator methods.
+ */
+ @Child(name = "petName")
+ @Extension(url = "http://example.com/dontuse#petname", definedLocally = false, isModifier = false)
+ @Description(shortDefinition = "The name of the patient's favourite pet")
+ private StringType myPetName;
+
+ public StringType getPetName() {
+ if (myPetName == null) {
+ myPetName = new StringType();
+ }
+ return myPetName;
+ }
+
+ public void setPetName(StringType thePetName) {
+ myPetName = thePetName;
+ }
+
+}
\ No newline at end of file
diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ITestClient.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ITestClient.java
new file mode 100644
index 00000000000..1fa7b935d01
--- /dev/null
+++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ITestClient.java
@@ -0,0 +1,22 @@
+package ca.uhn.fhir.rest.client;
+
+import java.util.List;
+
+import org.hl7.fhir.dstu3.model.Patient;
+import org.hl7.fhir.instance.model.api.IAnyResource;
+import org.hl7.fhir.instance.model.api.IBaseResource;
+
+import ca.uhn.fhir.rest.annotation.RequiredParam;
+import ca.uhn.fhir.rest.annotation.Search;
+import ca.uhn.fhir.rest.client.api.IBasicClient;
+import ca.uhn.fhir.rest.param.DateParam;
+
+public interface ITestClient extends IBasicClient {
+
+ @Search(type=ExtendedPatient.class)
+ public List getPatientByDobWithGenericResourceReturnType(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
+
+ @Search(type=ExtendedPatient.class)
+ public List getPatientByDobWithGenericResourceReturnType2(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
+
+}
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
diff --git a/hapi-fhir-validation-resources-dstu2.1/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-validation-resources-dstu2.1/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 60105c1b951..00000000000
--- a/hapi-fhir-validation-resources-dstu2.1/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/pom.xml b/pom.xml
index f47ee66a7b7..6418529d099 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,6 +95,11 @@
James Agnew
University Health Network
+
+ dmuylwyk
+ Diederik Muylwyk
+ Smile CDR
+
Dmitri Sotnikov
University Health Network
@@ -234,7 +239,7 @@
joelsch
- joelsch
+ Joel Schneider
euvitudo
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f98aedbab11..1921ee5e13c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -157,6 +157,11 @@
the resource ID was not present and required, or vice versa. Thanks to
Brian Postlethwaite for reporting!
+
+ When using an annotation based client, a ClassCastException would
+ occur under certain circumstances when the response contained
+ contained resources
+
diff --git a/src/site/fml/hapi-fhir-faq.fml b/src/site/fml/hapi-fhir-faq.fml
index 6122d411250..87d90f4013e 100644
--- a/src/site/fml/hapi-fhir-faq.fml
+++ b/src/site/fml/hapi-fhir-faq.fml
@@ -81,6 +81,23 @@
+
+ Using HAPI
+
+
+ What JDK version does HAPI support?
+
+
+
+ HAPI supports JDK 1.6 for the entire library, except for the CLI tool which is 1.8.
+
+
+ Note that the HAPI library itself also requires a 1.8 JDK to build, since the unit tests
+ have JDK 1.8 dependencies.
+
+
+
+
JPA Server
diff --git a/src/site/site.xml b/src/site/site.xml
index 8fbadbce93c..ad25cf7ad8d 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -57,6 +57,7 @@
+
@@ -141,7 +142,9 @@