Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.DataFormatException


    if (name == null) {
      if (myIgnoreMissingTemplates) {
        ourLog.debug("No narrative template available for profile: {}", theProfile);
        return new NarrativeDt(new XhtmlDt("<div>No narrative template available for resource profile: " + theProfile + "</div>"), NarrativeStatusEnum.EMPTY);
      } else {
        throw new DataFormatException("No narrative template for class " + theResource.getClass().getCanonicalName());
      }
    }

    try {
      Context context = new Context();
      context.setVariable("resource", theResource);

      String result = myProfileTemplateEngine.process(name, context);

      if (myCleanWhitespace) {
        ourLog.trace("Pre-whitespace cleaning: ", result);
        result = cleanWhitespace(result);
        ourLog.trace("Post-whitespace cleaning: ", result);
      }

      XhtmlDt div = new XhtmlDt(result);
      return new NarrativeDt(div, NarrativeStatusEnum.GENERATED);
    } catch (Exception e) {
      if (myIgnoreFailures) {
        ourLog.error("Failed to generate narrative", e);
        return new NarrativeDt(new XhtmlDt("<div>No narrative available - Error: " + e.getMessage() + "</div>"), NarrativeStatusEnum.EMPTY);
      } else {
        throw new DataFormatException(e);
      }
    }
  }
View Full Code Here


    if (name == null) {
      if (myIgnoreMissingTemplates) {
        ourLog.debug("No title template available for profile: {}", theProfile);
        return null;
      } else {
        throw new DataFormatException("No title template for class " + theResource.getClass().getCanonicalName());
      }
    }

    try {
      Context context = new Context();
      context.setVariable("resource", theResource);

      String result = myTitleTemplateEngine.process(name, context);

      ourLog.trace("Produced {}", result);

      StringBuilder b = new StringBuilder();
      boolean inTag = false;
      for (int i = 0; i < result.length(); i++) {
        char nextChar = result.charAt(i);
        char prevChar = i > 0 ? result.charAt(i - 1) : '\n';
        if (nextChar == '<') {
          inTag = true;
          continue;
        } else if (inTag) {
          if (nextChar == '>') {
            inTag = false;
          }
          continue;
        } else if (nextChar <= ' ') {
          if (prevChar <= ' ' || prevChar == '>') {
            continue;
          } else {
            b.append(' ');
          }
        } else {
          b.append(nextChar);
        }
      }

      while (b.length() > 0 && b.charAt(b.length() - 1) == ' ') {
        b.setLength(b.length() - 1);
      }

      result = b.toString();
      if (result.startsWith("<") && result.contains(">")) {
        result = result.substring(result.indexOf('>') + 1);
      }
      if (result.endsWith(">") && result.contains("<")) {
        result = result.substring(0, result.lastIndexOf('<'));
      }

      result = result.replace("&gt;", ">").replace("&lt;", "<").replace("&amp;", "&");

      return result;
    } catch (Exception e) {
      if (myIgnoreFailures) {
        ourLog.error("Failed to generate narrative", e);
        return "No title available - Error: " + e.getMessage();
      } else {
        throw new DataFormatException(e);
      }
    }
  }
View Full Code Here

      if (name == null) {
        if (myIgnoreMissingTemplates) {
          ourLog.debug("No narrative template available for type: {}", value.getClass());
          return ProcessorResult.ok();
        } else {
          throw new DataFormatException("No narrative template for class " + value.getClass());
        }
      }

      String result = myProfileTemplateEngine.process(name, context);
      String trim = result.trim();
View Full Code Here

        if (isPrecisionAllowed(YEAR)) {
          setValue((ourYearFormat).parse(theValue));
          setPrecision(YEAR);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support YEAR precision): " + theValue);
        }
      } else if (theValue.length() == 6 && ourYearMonthPattern.matcher(theValue).matches()) {
        // Eg. 198401 (allow this just to be lenient)
        if (isPrecisionAllowed(MONTH)) {
          setValue((ourYearMonthNoDashesFormat).parse(theValue));
          setPrecision(MONTH);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support DAY precision): " + theValue);
        }
      } else if (theValue.length() == 7 && ourYearDashMonthPattern.matcher(theValue).matches()) {
        // E.g. 1984-01 (this is valid according to the spec)
        if (isPrecisionAllowed(MONTH)) {
          setValue((ourYearMonthFormat).parse(theValue));
          setPrecision(MONTH);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support MONTH precision): " + theValue);
        }
      } else if (theValue.length() == 8 && ourYearMonthDayPattern.matcher(theValue).matches()) {
        // Eg. 19840101 (allow this just to be lenient)
        if (isPrecisionAllowed(DAY)) {
          setValue((ourYearMonthDayNoDashesFormat).parse(theValue));
          setPrecision(DAY);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support DAY precision): " + theValue);
        }
      } else if (theValue.length() == 10 && ourYearDashMonthDashDayPattern.matcher(theValue).matches()) {
        // E.g. 1984-01-01 (this is valid according to the spec)
        if (isPrecisionAllowed(DAY)) {
          setValue((ourYearMonthDayFormat).parse(theValue));
          setPrecision(DAY);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support DAY precision): " + theValue);
        }
      } else if (theValue.length() >= 18) {
        int dotIndex = theValue.indexOf('.', 18);
        if (dotIndex == -1 && !isPrecisionAllowed(SECOND)) {
          throw new DataFormatException("Invalid date/time string (data type does not support SECONDS precision): " + theValue);
        } else if (dotIndex > -1 && !isPrecisionAllowed(MILLI)) {
          throw new DataFormatException("Invalid date/time string (data type " + getClass().getSimpleName() + " does not support MILLIS precision):" + theValue);
        }

        Calendar cal;
        try {
          cal = DatatypeConverter.parseDateTime(theValue);
        } catch (IllegalArgumentException e) {
          throw new DataFormatException("Invalid data/time string (" + e.getMessage() + "): " + theValue);
        }
        myValue = cal.getTime();
        if (dotIndex == -1) {
          setPrecision(TemporalPrecisionEnum.SECOND);
        } else {
          setPrecision(TemporalPrecisionEnum.MILLI);
        }

        clearTimeZone();
        if (theValue.endsWith("Z")) {
          myTimeZoneZulu = true;
        } else if (theValue.indexOf('+', 19) != -1 || theValue.indexOf('-', 19) != -1) {
          myTimeZone = cal.getTimeZone();
        }

      } else {
        throw new DataFormatException("Invalid date/time string (invalid length): " + theValue);
      }
    } catch (ParseException e) {
      throw new DataFormatException("Invalid date string (" + e.getMessage() + "): " + theValue);
    }
  }
View Full Code Here

  }

  public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName) throws DataFormatException {
    BaseRuntimeChildDefinition retVal = myNameToChild.get(theName);
    if (retVal == null) {
      throw new DataFormatException("Unknown child name '" + theName + "' in element " + getName() + " - Valid names are: " + new TreeSet<String>(myNameToChild.keySet()));
    }
    return retVal;
  }
View Full Code Here

      myComparator=null;
      return;
    }

    if (theValue.length() < 2) {
      throw new DataFormatException("Invalid qualified date parameter: " + theValue);
    }

    char char0 = theValue.charAt(0);
    char char1 = theValue.charAt(1);
    if (Character.isDigit(char0)) {
      setValueAsString(theValue);
    } else {
      int dateStart = 2;
      if (Character.isDigit(char1)) {
        dateStart = 1;
      }

      String comparatorString = theValue.substring(0, dateStart);
      QuantityCompararatorEnum comparator = QuantityCompararatorEnum.VALUESET_BINDER.fromCodeString(comparatorString);
      if (comparator == null) {
        throw new DataFormatException("Invalid date qualifier: " + comparatorString);
      }

      String dateString = theValue.substring(dateStart);
      setValueAsString(dateString);
      setComparator(comparator);
View Full Code Here

    if (retVal == null) {
      try {
        String className = myNameToResourceType.get(resourceName.toLowerCase());
        if (className == null) {
          throw new DataFormatException("Unknown resource name[" + resourceName + "]");
        }
        Class<?> clazz = Class.forName(className);
        if (IResource.class.isAssignableFrom(clazz)) {
          retVal = scanResourceType((Class<? extends IResource>) clazz);
        }
      } catch (ClassNotFoundException e) {
        throw new DataFormatException("Unknown resource name[" + resourceName + "]");
      }
    }

    return retVal;
  }
View Full Code Here

                b.append(nextChild.getChildByName(iter.next()).getImplementingClass().getSimpleName());
                if (iter.hasNext()) {
                  b.append(", ");
                }
              }
              throw new DataFormatException(b.toString());
            }
            visit(nextValue, nextChild, childElementDef, theCallback);
          }
        }
      }
View Full Code Here

    if (name == null) {
      if (myIgnoreMissingTemplates) {
        ourLog.debug("No narrative template available for profile: {}", theProfile);
        return new NarrativeDt(new XhtmlDt("<div>No narrative template available for resource profile: " + theProfile + "</div>"), NarrativeStatusEnum.EMPTY);
      } else {
        throw new DataFormatException("No narrative template for class " + theResource.getClass().getCanonicalName());
      }
    }

    try {
      Context context = new Context();
      context.setVariable("resource", theResource);

      String result = myProfileTemplateEngine.process(name, context);

      if (myCleanWhitespace) {
        ourLog.trace("Pre-whitespace cleaning: ", result);
        result = cleanWhitespace(result);
        ourLog.trace("Post-whitespace cleaning: ", result);
      }

      XhtmlDt div = new XhtmlDt(result);
      return new NarrativeDt(div, NarrativeStatusEnum.GENERATED);
    } catch (Exception e) {
      if (myIgnoreFailures) {
        ourLog.error("Failed to generate narrative", e);
        return new NarrativeDt(new XhtmlDt("<div>No narrative available - Error: " + e.getMessage() + "</div>"), NarrativeStatusEnum.EMPTY);
      } else {
        throw new DataFormatException(e);
      }
    }
  }
View Full Code Here

    if (name == null) {
      if (myIgnoreMissingTemplates) {
        ourLog.debug("No title template available for profile: {}", theProfile);
        return null;
      } else {
        throw new DataFormatException("No title template for class " + theResource.getClass().getCanonicalName());
      }
    }

    try {
      Context context = new Context();
      context.setVariable("resource", theResource);

      String result = myTitleTemplateEngine.process(name, context);

      ourLog.trace("Produced {}", result);

      StringBuilder b = new StringBuilder();
      boolean inTag = false;
      for (int i = 0; i < result.length(); i++) {
        char nextChar = result.charAt(i);
        char prevChar = i > 0 ? result.charAt(i - 1) : '\n';
        if (nextChar == '<') {
          inTag = true;
          continue;
        } else if (inTag) {
          if (nextChar == '>') {
            inTag = false;
          }
          continue;
        } else if (nextChar <= ' ') {
          if (prevChar <= ' ' || prevChar == '>') {
            continue;
          } else {
            b.append(' ');
          }
        } else {
          b.append(nextChar);
        }
      }

      while (b.length() > 0 && b.charAt(b.length() - 1) == ' ') {
        b.setLength(b.length() - 1);
      }

      result = b.toString();
      if (result.startsWith("<") && result.contains(">")) {
        result = result.substring(result.indexOf('>') + 1);
      }
      if (result.endsWith(">") && result.contains("<")) {
        result = result.substring(0, result.lastIndexOf('<'));
      }

      result = result.replace("&gt;", ">").replace("&lt;", "<").replace("&amp;", "&");

      return result;
    } catch (Exception e) {
      if (myIgnoreFailures) {
        ourLog.error("Failed to generate narrative", e);
        return "No title available - Error: " + e.getMessage();
      } else {
        throw new DataFormatException(e);
      }
    }
  }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.parser.DataFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.