@Test public void executeMissingTheme() { sut = new UrlXmlValidator("http: boolean exceptionFired = false; try { sut.validate(getActionContext("src/test/resources/themes/noSuchTheme.xml")); } catch (ValidationException e) { exceptionFired = true; } assertTrue("Didn't get the validation exception that was expected from the missing theme", exceptionFired); }
@Override @SuppressWarnings("unchecked") public void validate(final ServiceActionContext inActionContext) throws ValidationException { InputStream schemaStream = null; Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); String galleryItemUrl = (String) fields.get(URL_KEY); try { schemaStream = this.getClass().getResourceAsStream(xsdPath); log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath); SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString); Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); Validator validator = schema.newValidator(); InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl); validator.validate(new StreamSource(galleryItemInputStream)); log.debug("Success validating xml at: " + galleryItemUrl); } catch (Exception e) { log.error("Validation for gadget definition failed.", e); ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Valid url is required"); throw ve; } finally { try { if(schemaStream != null) { schemaStream.close(); } } catch(IOException ex) { log.error("Error closing stream, already closed.", ex); } } }
UrlXmlValidator implements ValidationStrategy<ServiceActionContext> { @Override @SuppressWarnings("unchecked") public void validate(final ServiceActionContext inActionContext) throws ValidationException { InputStream schemaStream = null; Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); String galleryItemUrl = (String) fields.get(URL_KEY); try { schemaStream = this.getClass().getResourceAsStream(xsdPath); log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath); SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString); Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); Validator validator = schema.newValidator(); InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl); validator.validate(new StreamSource(galleryItemInputStream)); log.debug("Success validating xml at: " + galleryItemUrl); } catch (Exception e) { log.error("Validation for gadget definition failed.", e); ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Valid url is required"); throw ve; } finally { try { if(schemaStream != null) { schemaStream.close(); } } catch(IOException ex) { log.error("Error closing stream, already closed.", ex); } } } }
UrlXmlValidator implements ValidationStrategy<ServiceActionContext> { @Override @SuppressWarnings("unchecked") public void validate(final ServiceActionContext inActionContext) throws ValidationException { InputStream schemaStream = null; Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); String galleryItemUrl = (String) fields.get(URL_KEY); try { schemaStream = this.getClass().getResourceAsStream(xsdPath); log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath); SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString); Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); Validator validator = schema.newValidator(); InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl); validator.validate(new StreamSource(galleryItemInputStream)); log.debug("Success validating xml at: " + galleryItemUrl); } catch (Exception e) { log.error("Validation for gadget definition failed.", e); ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Valid url is required"); throw ve; } finally { try { if(schemaStream != null) { schemaStream.close(); } } catch(IOException ex) { log.error("Error closing stream, already closed.", ex); } } } UrlXmlValidator(final String inSchema, final String inXsdPath, final ResourceFetcher inResourceFetcher); }
UrlXmlValidator implements ValidationStrategy<ServiceActionContext> { @Override @SuppressWarnings("unchecked") public void validate(final ServiceActionContext inActionContext) throws ValidationException { InputStream schemaStream = null; Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); String galleryItemUrl = (String) fields.get(URL_KEY); try { schemaStream = this.getClass().getResourceAsStream(xsdPath); log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath); SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString); Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); Validator validator = schema.newValidator(); InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl); validator.validate(new StreamSource(galleryItemInputStream)); log.debug("Success validating xml at: " + galleryItemUrl); } catch (Exception e) { log.error("Validation for gadget definition failed.", e); ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Valid url is required"); throw ve; } finally { try { if(schemaStream != null) { schemaStream.close(); } } catch(IOException ex) { log.error("Error closing stream, already closed.", ex); } } } UrlXmlValidator(final String inSchema, final String inXsdPath, final ResourceFetcher inResourceFetcher); @Override @SuppressWarnings("unchecked") void validate(final ServiceActionContext inActionContext); }
UrlXmlValidator implements ValidationStrategy<ServiceActionContext> { @Override @SuppressWarnings("unchecked") public void validate(final ServiceActionContext inActionContext) throws ValidationException { InputStream schemaStream = null; Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); String galleryItemUrl = (String) fields.get(URL_KEY); try { schemaStream = this.getClass().getResourceAsStream(xsdPath); log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath); SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString); Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); Validator validator = schema.newValidator(); InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl); validator.validate(new StreamSource(galleryItemInputStream)); log.debug("Success validating xml at: " + galleryItemUrl); } catch (Exception e) { log.error("Validation for gadget definition failed.", e); ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Valid url is required"); throw ve; } finally { try { if(schemaStream != null) { schemaStream.close(); } } catch(IOException ex) { log.error("Error closing stream, already closed.", ex); } } } UrlXmlValidator(final String inSchema, final String inXsdPath, final ResourceFetcher inResourceFetcher); @Override @SuppressWarnings("unchecked") void validate(final ServiceActionContext inActionContext);  }