public PMML unmarshalPMML(File file) throws JAXBException, SAXException, IOException { Unmarshaller unmarshaller = createUnmarshaller(); try(InputStream is = new FileInputStream(file)){ Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return (PMML)unmarshaller.unmarshal(source); } }
/** * @see JAXBUtil#unmarshalPMML(Source) */ static public PMML unmarshal(InputStream is) throws SAXException, JAXBException { Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return JAXBUtil.unmarshalPMML(source); }
/** * @see JAXBUtil#unmarshalPMML(Source) */ static public PMML unmarshal(InputStream is) throws SAXException, JAXBException { Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return JAXBUtil.unmarshalPMML(source); }
static public PMML unmarshal(Class<?> clazz, XMLFilter... filters) throws IOException, SAXException, JAXBException { try(InputStream is = getStream(clazz)){ Source source = SAXUtil.createFilteredSource(is, filters); return JAXBUtil.unmarshalPMML(source); } }
public LoadingModelEvaluatorBuilder load(InputStream is, String modelName) throws SAXException, JAXBException { Schema schema = getSchema(); ValidationEventHandler validationEventHandler = getValidationEventHandler(); List<? extends XMLFilter> filters = getFilters(); boolean locatable = getLocatable(); VisitorBattery visitors = getVisitors(); Unmarshaller unmarshaller = JAXBUtil.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventHandler); if(filters == null){ filters = Collections.singletonList(new ImportFilter()); } Source source = SAXUtil.createFilteredSource(is, filters.toArray(new XMLFilter[filters.size()])); PMML pmml = (PMML)unmarshaller.unmarshal(source); Visitor locatorHandler = (locatable ? new LocatorTransformer() : new LocatorNullifier()); locatorHandler.applyTo(pmml); if(visitors != null && visitors.size() > 0){ visitors.applyTo(pmml); } Model model = PMMLUtil.findModel(pmml, modelName); setPMML(pmml); setModel(model); return this; }
@Test public void unmarshalSecurely() throws Exception { try(InputStream is = ResourceUtil.getStream(XXEAttackTest.class)){ Source source = SAXUtil.createFilteredSource(is); JAXBUtil.unmarshalPMML(source); fail(); } catch(UnmarshalException ue){ Throwable cause = ue.getCause(); assertTrue(cause instanceof SAXParseException); } } }