Ejemplo n.º 1
0
  private void parseMetadata() throws ZipException, IOException, JAXBException, SAXException {
    ZipFile zipFile = null;
    try {
      // get the session.xml zip entry
      zipFile = new ZipFile(sessionFile);
      InputStream metadataStream =
          zipFile.getInputStream(zipFile.getEntry(UserSession.SESSION_DATA_FILENAME));

      // validate
      // ClientSession.getSchema().newValidator().validate(new StreamSource(metadataStream));

      // parse the metadata xml to java objects using jaxb
      Unmarshaller unmarshaller = UserSession.getPreviousJAXBContext().createUnmarshaller();
      unmarshaller.setSchema(UserSession.getPreviousSchema());
      NonStoppingValidationEventHandler validationEventHandler =
          new NonStoppingValidationEventHandler();
      unmarshaller.setEventHandler(validationEventHandler);
      this.sessionType =
          unmarshaller.unmarshal(new StreamSource(metadataStream), SessionType.class).getValue();

      if (validationEventHandler.hasEvents()) {
        throw new JAXBException(
            "Invalid session file:\n" + validationEventHandler.getValidationEventsAsString());
      }
    } finally {
      IOUtils.closeIfPossible(zipFile);
    }
  }