Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.DataFormatException


      myValue=null;
    }else {
      try {
        myValue = new URI(theValue);
      } catch (URISyntaxException e) {
        throw new DataFormatException("Unable to parse URI value", e);
      }
    }
  }
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

    if (name == null) {
      if (myIgnoreMissingTemplates) {
        ourLog.debug("No narrative template available for profile: {}", theProfile);
        return new NarrativeDt(new XhtmlDt("<div>No narrative available</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</div>"), NarrativeStatusEnum.EMPTY);
      } 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);
      Document dom = DOMUtils.getXhtmlDOMFor(new StringReader(result));
View Full Code Here

    if ("true".equals(theValue)) {
      myValue = Boolean.TRUE;
    } else if ("false".equals(theValue)) {
      myValue = Boolean.FALSE;
    } else {
      throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
    }
  }
View Full Code Here

      myValue=null;
    }else {
      try {
        myValue = new URI(theValue);
      } catch (URISyntaxException e) {
        throw new DataFormatException("Unable to parse URI value", e);
      }
    }
  }
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

        }
      }
      setValue(value);
     
    } catch (XMLStreamException e) {
      throw new DataFormatException("String does not appear to be valid XML/XHTML: "+e.getMessage(), 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.