Java Code Examples for org.hl7.fhir.utilities.xhtml.XhtmlNode#hasAttribute()

The following examples show how to use org.hl7.fhir.utilities.xhtml.XhtmlNode#hasAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceRenderer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (r.hasLanguage()) {
    // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
    x.setAttribute("lang", r.getLanguage());
    x.setAttribute("xml:lang", r.getLanguage());
  }
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.clear();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example 2
Source File: BundleRenderer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void scanNodesForInternalLinks(Bundle b, List<XhtmlNode> nodes) {
  for (XhtmlNode n : nodes) {
    if ("a".equals(n.getName()) && n.hasAttribute("href")) {
      scanInternalLink(b, n);
    }
    scanNodesForInternalLinks(b, n.getChildNodes());
  }
}
 
Example 3
Source File: ElementWrappers.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public void injectNarrative(XhtmlNode x, NarrativeStatus status) throws IOException {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  String l = wrapped.getChildValue("language");
  if (!Utilities.noString(l)) {
    // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
    x.setAttribute("lang", l);
    x.setAttribute("xml:lang", l);
  }
  org.hl7.fhir.r5.elementmodel.Element txt = wrapped.getNamedChild("text");
  if (txt == null) {
    txt = new org.hl7.fhir.r5.elementmodel.Element("text", wrapped.getProperty().getChild(null, "text"));
    int i = 0;
    while (i < wrapped.getChildren().size() && (wrapped.getChildren().get(i).getName().equals("id") || wrapped.getChildren().get(i).getName().equals("meta") || wrapped.getChildren().get(i).getName().equals("implicitRules") || wrapped.getChildren().get(i).getName().equals("language")))
      i++;
    if (i >= wrapped.getChildren().size())
      wrapped.getChildren().add(txt);
    else
      wrapped.getChildren().add(i, txt);
  }
  org.hl7.fhir.r5.elementmodel.Element st = txt.getNamedChild("status");
  if (st == null) {
    st = new org.hl7.fhir.r5.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
    txt.getChildren().add(0, st);
  }
  st.setValue(status.toCode());
  org.hl7.fhir.r5.elementmodel.Element div = txt.getNamedChild("div");
  if (div == null) {
    div = new org.hl7.fhir.r5.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
    txt.getChildren().add(div);
    div.setValue(new XhtmlComposer(XhtmlComposer.XML, context.isPretty()).compose(x));
  }
  div.setValue(x.toString());
  div.setXhtml(x);

}
 
Example 4
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.hr();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example 5
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(org.hl7.fhir.r4.elementmodel.Element er, XhtmlNode x, NarrativeStatus status) throws IOException, FHIRException {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  org.hl7.fhir.r4.elementmodel.Element txt = er.getNamedChild("text");
  if (txt == null) {
    txt = new org.hl7.fhir.r4.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
    int i = 0;
    while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language")))
      i++;
    if (i >= er.getChildren().size())
      er.getChildren().add(txt);
    else
      er.getChildren().add(i, txt);
  }
  org.hl7.fhir.r4.elementmodel.Element st = txt.getNamedChild("status");
  if (st == null) {
    st = new org.hl7.fhir.r4.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
    txt.getChildren().add(0, st);
  }
  st.setValue(status.toCode());
  org.hl7.fhir.r4.elementmodel.Element div = txt.getNamedChild("div");
  if (div == null) {
    div = new org.hl7.fhir.r4.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
    txt.getChildren().add(div);
    div.setValue(new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x));
  }
  div.setXhtml(x);
}
 
Example 6
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.hr();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example 7
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(org.hl7.fhir.dstu3.elementmodel.Element er, XhtmlNode x, NarrativeStatus status) throws DefinitionException, IOException {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  org.hl7.fhir.dstu3.elementmodel.Element txt = er.getNamedChild("text");
  if (txt == null) {
    txt = new org.hl7.fhir.dstu3.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
    int i = 0;
    while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language")))
      i++;
    if (i >= er.getChildren().size())
      er.getChildren().add(txt);
    else
      er.getChildren().add(i, txt);
  }
  org.hl7.fhir.dstu3.elementmodel.Element st = txt.getNamedChild("status");
  if (st == null) {
    st = new org.hl7.fhir.dstu3.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
    txt.getChildren().add(0, st);
  }
  st.setValue(status.toCode());
  org.hl7.fhir.dstu3.elementmodel.Element div = txt.getNamedChild("div");
  if (div == null) {
    div = new org.hl7.fhir.dstu3.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
    txt.getChildren().add(div);
    div.setValue(new XhtmlComposer(XhtmlComposer.XML).compose(x));
  }
  div.setXhtml(x);
}