/** * Extracts (constructs) resource cache key validator/transmogrifier parameters. * <p/> * Per default, the key equals to the resource location. * * @param params validator/transmogrifier parameters. * @return cache key as a String. */ protected String resourceCacheKey(Object... params) { return resourceLocation(params); }
synchronized S get() { if (loaded == null) loaded = load(); return loaded; } }
@Override protected T load() throws RuntimeException { return createResource(params); } });
public void validate(String message, CombinedXmlValidationProfile profile) throws ValidationException { requireNonNull(profile, "validation profile must be not null"); // check whether the root element name is valid String rootElementName = rootElementName(requireNonNull(message, "message must be not null")); if (! profile.isValidRootElement(rootElementName)) { throw new ValidationException("Invalid root element '" + rootElementName + "'"); } // XSD validation String xsdPath = profile.getXsdPath(rootElementName); if (xsdPath != null) { XSD_VALIDATOR.validate(source(message), xsdPath); } // Schematron validation String schematronPath = profile.getSchematronPath(rootElementName); if (schematronPath != null) { SchematronProfile schematronProfile = new SchematronProfile( schematronPath, profile.getCustomSchematronParameters(rootElementName)); SCHEMATRON_VALIDATOR.validate(source(message), schematronProfile); } } }
@SuppressWarnings("unchecked") public static <T> ResultHolder<T> create(Class<T> clazz) { if (String.class == clazz) { return (ResultHolder<T>) new StringResultHolder(); } else if (InputStream.class == clazz) { return (ResultHolder<T>) new InputStreamResultHolder(); } else if (OutputStream.class == clazz) { return (ResultHolder<T>) new OutputStreamResultHolder(); } else if (Writer.class == clazz) { return (ResultHolder<T>) new WriterResultHolder(); } else if (DOMResult.class == clazz) { return (ResultHolder<T>) new DOMResultHolder(); } else if (SchematronOutput.class == clazz) { return (ResultHolder<T>) new SvrlResultHolder(); } else { return null; } }
/** * Converts a Source into a Result using a XSL processor. * <p> * The XSL stylesheet resource location is mandatory in the first extra parameter. * XSL Parameters may be passed as a Map in the second parameter. * * @see Transmogrifier#zap(java.lang.Object, java.lang.Object[]) */ @Override public T zap(Source source, Object... params) { ResultHolder<T> accessor = ResultHolderFactory.create(outputFormat); if (accessor == null) throw new IllegalArgumentException("Format " + outputFormat.getClass() + " is not supported"); Result result = accessor.createResult(); doZap(source, result, params); return accessor.getResult(); }
/** * Converts a Source into a typed result using a XQuery processor. * <p> * The XQ resource location is mandatory in the first extra parameter. Other * parameters may be passed as a Map in the second parameter. * * @see Transmogrifier#zap(java.lang.Object, java.lang.Object[]) */ @Override public T zap(Source source, Object... params) { ResultHolder<T> accessor = ResultHolderFactory.create(outputFormat); if (accessor == null) throw new IllegalArgumentException("Format " + outputFormat.getClass() + " is not supported"); Result result = accessor.createResult(); doZap(source, result, params); return accessor.getResult(); }
@Before public void setUp() throws Exception { parameters = new HashMap<>(); parameters.put("service", new XsltTestService()); transformer = new XsltTransmogrifier<>(String.class); }
public SchematronTransmogrifier(Class<T> outputFormat) { this(new XsltTransmogrifier<>(String.class), outputFormat); }
@Override protected String resourceCacheKey(Object... params) { String phase = null; if (params[0] instanceof SchematronProfile) { SchematronProfile schematronProfile = (SchematronProfile) params[0]; Map<String, Object> parameters = schematronProfile.getParameters(); if (parameters != null) { phase = (String) parameters.get("phase"); } } return (phase != null) ? resourceLocation(params) + '\n' + phase : resourceLocation(params); }
/** * This method had to be overridden because {@link XQPreparedExpression} objects * are not thread-safe, thus an additional replication step is necessary. */ @Override protected XQPreparedExpression resource(Object... params) throws Exception { XQPreparedExpression expression = super.resource(params); return getConnection().copyPreparedExpression(expression); }
@Before public void setUp() throws Exception { svi = new SchematronTransmogrifier<>(String.class); }
@Before public void setUp() throws Exception { transformer = new XqjTransmogrifier<>(String.class); }
@Before public void setUp() throws Exception { v = new SchematronValidator(); }
@Override public void fatalError(SAXParseException exception) throws SAXException { add(exception); }
/** * Extracts (constructs) resource creation/application parameters from * validator/transmogrifier parameters. * * @param params validator/transmogrifier parameters. * @return resource creation/application parameters as a Map, * or <code>null</code> if not found. */ protected Map<String, Object> resourceParameters(Object... params) { if (params[0] instanceof Map) { return (Map<String, Object>) params[0]; } else if (params[0] instanceof SchematronProfile) { SchematronProfile p = (SchematronProfile) params[0]; return p.getParameters(); } else if (params.length > 1 && params[1] instanceof Map) { return (Map<String, Object>) params[1]; } return null; }
public SchematronTransmogrifier(Class<T> outputFormat, Map<String, Object> staticParams) { this(new XsltTransmogrifier<>(String.class), outputFormat, staticParams); }
@Override public void error(SAXParseException exception) throws SAXException { add(exception); }