Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.DataFormatException


  }

  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


    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

  }

  @Override
  public void setValueAsQueryToken(String theQualifier, String theValue) {
    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 (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() == 7) {
        // 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) {
        //Eg. 19840101 (allow this just to be lenient)
        if (isPrecisionAllowed(DAY)) {
          setValue((ourYearMonthDayNoDashesFormat).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() == 10) {
        // 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

  private void validateAndThrowDataFormatExceptionIfInvalid() {
    boolean haveLowerBound = haveLowerBound();
    boolean haveUpperBound = haveUpperBound();
    if (haveLowerBound && haveUpperBound) {
      if (myLowerBound.getValue().after(myUpperBound.getValue())) {
        throw new DataFormatException("Lower bound of " + myLowerBound.getValueAsString() + " is after upper bound of " + myUpperBound.getValueAsString());
      }
    }

    if (haveLowerBound) {
      if (myLowerBound.getComparator() == null) {
        myLowerBound.setComparator(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS);
      }
      switch (myLowerBound.getComparator()) {
      case GREATERTHAN:
      case GREATERTHAN_OR_EQUALS:
      default:
        break;
      case LESSTHAN:
      case LESSTHAN_OR_EQUALS:
        throw new DataFormatException("Lower bound comparator must be > or >=, can not be " + myLowerBound.getComparator().getCode());
      }
    }

    if (haveUpperBound) {
      if (myUpperBound.getComparator() == null) {
        myUpperBound.setComparator(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS);
      }
      switch (myUpperBound.getComparator()) {
      case LESSTHAN:
      case LESSTHAN_OR_EQUALS:
      default:
        break;
      case GREATERTHAN:
      case GREATERTHAN_OR_EQUALS:
        throw new DataFormatException("Upper bound comparator must be < or <=, can not be " + myUpperBound.getComparator().getCode());
      }
    }

  }
View Full Code Here

        }
      }
      setValue(value);
     
    } catch (XMLStreamException e) {
      throw new DataFormatException("String does not appear to be valid XML/XHTML (error is \""+e.getMessage() + "\"): " + theValue, e);
    } catch (FactoryConfigurationError e) {
      throw new ConfigurationException(e);
    }
  }
View Full Code Here

        ew.add(next);
      }
      ew.close();
      return w.toString();
    } catch (XMLStreamException e) {
      throw new DataFormatException("Problem with the contained XML events", e);
    } catch (FactoryConfigurationError e) {
      throw new ConfigurationException(e);
    }
  }
View Full Code Here

      myValue = null;
    } else {
      try {
        myValue = Integer.parseInt(theValue);
      } catch (NumberFormatException e) {
        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.