List of usage examples for org.apache.commons.digester Digester setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
From source file:eu.planets_project.pp.plato.services.action.PreservationActionRegistryFactory.java
/** * //from ww w . j av a 2s. c o m * @return a list of all in PreservationActionRegistries.xml defined registries. * @throws IllegalArgumentException */ static public List<PreservationActionRegistryDefinition> getAvailableRegistries() throws IllegalArgumentException { ArrayList<PreservationActionRegistryDefinition> allRegistries = new ArrayList<PreservationActionRegistryDefinition>(); String configFile = "data/services/PreservationActionRegistries.xml"; InputStream config = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile); Digester digester = new Digester(); digester.setValidating(false); digester.setErrorHandler(new StrictErrorHandler()); digester.push(allRegistries); digester.addObjectCreate("*/registry", PreservationActionRegistryDefinition.class); digester.addBeanPropertySetter("*/registry/shortname", "shortname"); digester.addBeanPropertySetter("*/registry/logo", "logo"); digester.addBeanPropertySetter("*/registry/url", "url"); digester.addBeanPropertySetter("*/registry/type", "type"); digester.addBeanPropertySetter("*/registry/active", "active"); digester.addSetNext("*/registry", "add"); try { digester.setUseContextClassLoader(true); digester.parse(config); } catch (Exception e) { log.error("Error in config file: " + configFile, e); } return allRegistries; }
From source file:eu.planets_project.pp.plato.services.characterisation.xcl.ComparatorUtils.java
/** * parses a cpResponse and generates a list of {@link CompareResult compare results}, one per * sent target XCDL.// www . j ava2 s. com */ public List<CompareResult> parseResponse(String response) throws PlatoServiceException { compResult = new ArrayList<CompareResult>(); error = null; File validResult = new File(response); if (!validResult.exists()) { return compResult; } Digester d = new Digester(); d.setValidating(false); StrictErrorHandler errorHandler = new StrictErrorHandler(); d.setErrorHandler(errorHandler); d.setUseContextClassLoader(true); d.push(this); d.addCallMethod("copra/error", "setError", 0); d.addObjectCreate("*/set", CompareResult.class); d.addSetNext("*/set", "addResult"); d.addObjectCreate("*/set/property", CprProperty.class); d.addSetProperties("*/set/property"); d.addBeanPropertySetter("*/set/property/data/src/value", "source"); d.addBeanPropertySetter("*/set/property/data/tar/value", "target"); d.addObjectCreate("*/metrics/metric", CprMetricResult.class); d.addSetProperties("*/metrics/metric/result"); d.addBeanPropertySetter("*/metrics/metric/state"); CallMethodRule metricRule = new CallMethodRule(1, "addMetric", 2); d.addRule("*/metrics/metric", metricRule); d.addCallParam("*/metrics/metric", 0, "name"); d.addCallParam("*/metrics/metric", 1, true); // <metric id="121" name="valueSetMatch_1"> // <result state="ok">true</result> // </metric> CallMethodRule r = new CallMethodRule(1, "addProperty", 2); d.addRule("*/set/property", r); d.addCallParam("*/set/property", 0, "name"); d.addCallParam("*/set/property", 1, true); try { d.parse(validResult); if (error != null) { throw new PlatoServiceException("XCL tool:comparator failed: " + error); } return compResult; } catch (PlatoServiceException e) { throw e; } catch (Exception e) { throw new PlatoServiceException("The response of the XCL tool:comparator is invalid.", e); } catch (Error e) { throw new PlatoServiceException("The response of the XCL tool:comparator is invalid.", e); } }
From source file:at.tuwien.minimee.registry.MiniMeeRegistry.java
/** * Trashes current registry information and loads the information of the XML file, which is provided * by the input stream <param>config</config>. * /*from ww w .ja v a2s . com*/ * @throws PlatoServiceException if the stream can't be parsed. */ public void reloadFrom(String configFile) throws PlatoServiceException { Digester d = new Digester(); d.setValidating(false); StrictErrorHandler errorHandler = new StrictErrorHandler(); d.setErrorHandler(errorHandler); d.setClassLoader(PreservationActionServiceFactory.class.getClassLoader()); services.clear(); d.push(services); d.addFactoryCreate("*/preservationActionService", PreservationActionServiceFactory.class); d.addSetNext("*/preservationActionService", "add"); d.addCallMethod("*/preservationActionService/name", "setName", 0); d.addCallMethod("*/preservationActionService/description", "setDescription", 0); d.addCallMethod("*/preservationActionService/descriptor", "setDescriptor", 0); d.addObjectCreate("*/preservationActionService/sourceFormats", ArrayList.class); d.addSetNext("*/preservationActionService/sourceFormats", "setSourceFormats"); d.addObjectCreate("*/preservationActionService/sourceFormats/format", FormatInfo.class); d.addBeanPropertySetter("*/format/puid", "puid"); d.addBeanPropertySetter("*/format/name", "name"); d.addBeanPropertySetter("*/format/extension", "defaultExtension"); d.addSetNext("*/preservationActionService/sourceFormats/format", "add"); d.addObjectCreate("*/preservationActionService/targetFormat", FormatInfo.class); d.addBeanPropertySetter("*/targetFormat/puid", "puid"); d.addBeanPropertySetter("*/targetFormat/name", "name"); d.addBeanPropertySetter("*/targetFormat/extension", "defaultExtension"); d.addSetNext("*/preservationActionService/targetFormat", "setTargetFormat"); d.addCallMethod("*/preservationActionService/url", "setUrl", 0); d.addObjectCreate("*/preservationActionService/externalInfo", ArrayList.class); d.addSetNext("*/preservationActionService/externalInfo", "setExternalInfo"); d.addCallMethod("*/preservationActionService/externalInfo/url", "add", 0); try { InputStream config = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile); d.parse(config); } catch (IOException e) { throw new PlatoServiceException("Could not read registry data.", e); } catch (SAXException e) { throw new PlatoServiceException("Could not read registry data.", e); } }
From source file:eu.planets_project.pp.plato.services.characterisation.xcl.XclPropertiesExplorer.java
/** * @param PUIDs colon seperated list of "planets puids", i.e. pronom unique identifieres using an * underscore character instead of a forward slash. The list must end with a colon. * Example: fmt_10:fmt_13:/*from w w w . j av a 2 s . c om*/ */ public List<ObjectProperty> characterise(String PUIDs, List<String> warnings) throws PlatoServiceException { if (("".equals(PUIDs)) || (xclExplorerPath == null)) { return new ArrayList<ObjectProperty>(); } String xcelString; String tempDir = makeTempDir(); String command = xclExplorerPath + "XCLExplorer " + PUIDs + " -o " + tempDir; try { CommandExecutor cmdExecutor = new CommandExecutor(); cmdExecutor.setWorkingDirectory(xclExplorerPath); try { int exitStatus = cmdExecutor.runCommand(command); // r.setSuccess(exitStatus == 0); //r.setReport(cmdExecutor.getCommandError()); } catch (Exception e) { log.error(e.getMessage(), e); } String outputFile = tempDir + "fpm.fpm"; // we use a set as we don't want dublicate properties propertiesSet = new HashSet<ObjectProperty>(); this.warnings = warnings; status = null; format = null; error = null; Digester digester = new Digester(); digester.setValidating(false); digester.setErrorHandler(new StrictErrorHandler()); digester.push(this); digester.addCallMethod("*/XCLExplorer/fpmError", "setError", 0); // maybe there is a warning in the property "status" digester.addSetProperties("*/XCLExplorer/format"); digester.addCallMethod("*/XCLExplorer/format", "addWarning", 0); digester.addObjectCreate("*/XCLExplorer/format/property", XCLObjectProperty.class); digester.addBeanPropertySetter("*/XCLExplorer/format/property/id", "propertyId"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/name", "name"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/description", "description"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/unit", "unit"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/type", "type"); digester.addObjectCreate("*/XCLExplorer/format/property/metrics/m", Metric.class); digester.addBeanPropertySetter("*/XCLExplorer/format/property/metrics/m/mId", "metricId"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/metrics/m/mName", "name"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/metrics/m/mDescription", "description"); digester.addBeanPropertySetter("*/XCLExplorer/format/property/metrics/m/mType", "type"); digester.addSetNext("*/XCLExplorer/format/property/metrics/m", "addMetric"); digester.addSetNext("*/XCLExplorer/format/property", "addProperty"); try { digester.setUseContextClassLoader(true); digester.parse(new FileInputStream(outputFile)); if (error != null) { throw new PlatoServiceException("XCLExplorer failed: " + error); } return new ArrayList<ObjectProperty>(propertiesSet); } catch (IOException e) { throw new PlatoServiceException("The response of XCLExplorer is invalid.", e); } catch (SAXException e) { throw new PlatoServiceException("The response of XCLExplorer is invalid.", e); } finally { new File(tempDir + "fpm.fpm").delete(); new File(tempDir).delete(); } } catch (Exception e) { log.error(e.getMessage(), e); return new ArrayList<ObjectProperty>(); } }
From source file:at.tuwien.minimee.registry.ToolRegistry.java
private void load(InputStream config) throws IllegalArgumentException { Digester digester = new Digester(); digester.setValidating(true);// w ww .jav a2s . c o m digester.setErrorHandler(new StrictErrorHandler()); digester.push(this); digester.addObjectCreate("*/tool", Tool.class); digester.addSetProperties("*/tool"); digester.addObjectCreate("*/config", ToolConfig.class); digester.addSetProperties("*/config"); digester.addBeanPropertySetter("*/config/name", "name"); digester.addBeanPropertySetter("*/config/executablePath", "executablePath"); digester.addBeanPropertySetter("*/config/engineName", "engine"); digester.addBeanPropertySetter("*/config/params", "params"); digester.addBeanPropertySetter("*/config/inEnding", "inEnding"); digester.addBeanPropertySetter("*/config/outEnding", "outEnding"); digester.addBeanPropertySetter("*/config/noOutFile", "noOutFile"); digester.addBeanPropertySetter("*/config/initialisationDir", "initialisationDir"); digester.addCallMethod("*/config/evaluators/evaluator", "addEvaluator", 0); digester.addSetNext("*/config", "addConfig"); digester.addSetNext("*/tool", "addTool"); digester.addFactoryCreate("*/evaluators/evaluator", EvaluatorFactory.class); digester.addSetProperties("*/evaluators/evaluator"); digester.addSetNext("*/evaluators/evaluator", "addEvaluator"); //Digester engineDigester = new Digester(); // engineDigester.setValidating(true); // engineDigester.setErrorHandler(new StrictErrorHandler()); // engineDigester.push(this); digester.addFactoryCreate("*/engine", EngineFactory.class); digester.addSetProperties("*/engine"); digester.addObjectCreate("*/measurableProperties/property", MeasurableProperty.class); digester.addSetProperties("*/measurableProperties/property"); addCreateScale(digester, PositiveFloatScale.class); addCreateScale(digester, FreeStringScale.class); digester.addSetNext("*/measurableProperties/property", "addProperty"); digester.addCallMethod("*/includedEngine", "addEngineName", 0); digester.addCallMethod("*/nextEngine", "setNextEngineName", 0); digester.addSetNext("*/engine", "addEngine"); digester.addObjectCreate("*/machine", Machine.class); digester.addSetProperties("*/machine"); digester.addSetNext("*/machine", "addMachine"); try { digester.setUseContextClassLoader(true); digester.setValidating(false); digester.parse(config); // config = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile); // engineDigester.setValidating(false); // engineDigester.setUseContextClassLoader(true); // engineDigester.parse(config); } catch (Exception e) { log.error("Error in config file! ", e); } }
From source file:eu.planets_project.pp.plato.services.characterisation.jhove.JHove.java
/** * Extract the JHoveFileProperty from the String and returns a * {@link JHoveFileProperty} class./* w w w . j a v a 2s . c om*/ * * @param fileName * @return */ public JHoveFileProperty digestString(String stringToDigest) { Digester digester = null; try { digester = new Digester(); digester.setValidating(false); StrictErrorHandler errorHandler = new StrictErrorHandler(); digester.setErrorHandler(errorHandler); digester.setUseContextClassLoader(true); digester.addObjectCreate("jhove", JHoveFileProperty.class); // GENERAL INFOS digester.addBeanPropertySetter("jhove/date", "extractionDate"); digester.addSetProperties("jhove/repInfo/uri", "fileURI", "uri"); digester.addBeanPropertySetter("jhove/repInfo/size", "fileSize"); digester.addBeanPropertySetter("jhove/repInfo/format", "format"); digester.addBeanPropertySetter("jhove/repInfo/version", "version"); digester.addBeanPropertySetter("jhove/repInfo/status", "status"); digester.addBeanPropertySetter("jhove/repInfo/mimeType", "mimetype"); digester.addBeanPropertySetter("jhove/repInfo/sigMatch/module", "jhoveModuleName"); // OBJECT: MODULE - START digester.addObjectCreate("jhove/repInfo/reportingModule", Module.class); digester.addSetProperties("jhove/repInfo/reportingModule", "release", "release"); digester.addSetProperties("jhove/repInfo/reportingModule", "date", "date"); digester.addBeanPropertySetter("jhove/repInfo/reportingModule", "name"); digester.addSetNext("jhove/repInfo/reportingModule", "setModule"); // OBJECT: MODULE - END // OBJECT: PROFILES - START digester.addObjectCreate("jhove/repInfo/profiles", Vector.class); // OBJECT: PROFILE - START digester.addCallMethod("jhove/repInfo/profiles/profile", "add", 1); digester.addCallParam("jhove/repInfo/profiles/profile", 0); digester.addSetNext("jhove/repInfo/profiles", "setProfiles"); // OBJECT: PROFILES- END // OBJECT: PROPERTIES - START digester.addObjectCreate("jhove/repInfo/properties", Vector.class); // OBJECT: PROPERTY - START digester.addObjectCreate("*/property/", Property.class); digester.addBeanPropertySetter("*/property/name", "name"); digester.addSetProperties("*/property/values", "type", "type"); digester.addObjectCreate("*/property/values", Vector.class); digester.addCallMethod("*/property/values/value", "add", 1); digester.addCallParam("*/property/values/value", 0); digester.addSetNext("*/property/values", "setValues"); // OBJECT: PROPERTY - END digester.addSetNext("*/property/", "add"); digester.addSetNext("jhove/repInfo/properties", "setProperties"); Object jhoveFileProp = digester.parse(new StringReader(stringToDigest)); if (jhoveFileProp instanceof JHoveFileProperty) return (JHoveFileProperty) jhoveFileProp; else return null; } catch (Exception exc) { log.error("error happened while digesting the following jhove string \n====================\n" + stringToDigest); log.error("could not digest jhove results. error: " + exc.getMessage(), exc); return null; } finally { digester.clear(); } }
From source file:net.sf.jasperreports.engine.xml.JRXmlTemplateDigesterFactory.java
protected void configureDigester(JasperReportsContext jasperReportsContext, Digester digester) throws SAXException, ParserConfigurationException { digester.setNamespaceAware(true);/*from w w w . ja va2s . co m*/ digester.setRuleNamespaceURI(JRXmlConstants.JASPERTEMPLATE_NAMESPACE); boolean validating = JRPropertiesUtil.getInstance(jasperReportsContext) .getBooleanProperty(JRReportSaxParserFactory.COMPILER_XML_VALIDATION); digester.setErrorHandler(this); digester.setValidating(validating); digester.setFeature("http://xml.org/sax/features/validation", validating); digester.addRuleSet(rules); }
From source file:com.sun.faces.config.DigesterFactory.java
/** * <p>Configures the provided <code>Digester</code> instance appropriate * for use with JSF.</p>/*from ww w. j a v a2 s .co m*/ * @param digester - the <code>Digester</code> instance to configure */ private void configureDigester(Digester digester) { digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); digester.setEntityResolver(RESOLVER); digester.setErrorHandler(ERROR_HANDLER); // disable digester log messages digester.setLogger(new NoOpLog()); if (validating) { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "Attempting to configure Digester to perform" + " document validation."); } // In order to validate using *both* DTD and Schema, certain // Xerces specific features are required. Try to set these // features. If an exception is thrown trying to set these // features, then disable validation. try { digester.setFeature(XERCES_VALIDATION, true); digester.setFeature(XERCES_SCHEMA_VALIDATION, true); digester.setFeature(XERCES_SCHEMA_CONSTRAINT_VALIDATION, true); digester.setValidating(true); } catch (SAXNotSupportedException e) { if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Attempt to set supported feature on XMLReader, " + "but the value provided was not accepted. " + "Validation will be disabledb."); } digester.setValidating(false); } catch (SAXNotRecognizedException e) { if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Attempt to set unsupported feature on XMLReader" + " necessary for validation. Validation will be" + "disabled."); } digester.setValidating(false); } catch (ParserConfigurationException e) { if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Digester unable to configure underlying parser." + " Validation will be disabled."); } digester.setValidating(false); } } else { digester.setValidating(false); } }
From source file:it.jnrpe.server.config.CJNRPEConfiguration.java
private CJNRPEConfiguration(File fileName) { if (!fileName.exists() || !fileName.canRead()) { // TODO: throw an exception m_Logger.fatal("UNABLE TO READ CONFIGURATION FILE " + fileName.getAbsolutePath()); System.exit(-1);//from ww w.jav a 2 s . c o m } try { Digester digester = DigesterLoader.createDigester( new InputSource(System.class.getResourceAsStream("/it/jnrpe/server/config/digester.xml"))); // turn on XML schema validation digester.setFeature("http://xml.org/sax/features/validation", true); digester.setFeature("http://apache.org/xml/features/validation/schema", true); digester.setFeature("http://xml.org/sax/features/namespaces", true); digester.setEntityResolver(new CConfigValidationEntityResolver()); digester.setErrorHandler(new CConfigErrorHandler()); m_Configuration = (CConfiguration) digester.parse(fileName); } catch (Exception e) { // TODO: throw an exception m_Logger.fatal("UNABLE TO PARSE CONFIGURATION : " + e.getMessage()); System.exit(-1); } }
From source file:com.headstrong.fusion.statemachine.SCXMLStateMachine.java
/** * Initializes the state machine.//from ww w. j a v a2 s . c o m * * @throws StateMachineException */ public void init() throws StateMachineException { // Create a list of custom actions, add as many as are needed // currently only one custom action is exposed which internally would // execute action service registered by the component. // Need to take care of the parsing part. SCXML scxml = null; URL url = null; File tempConfigFile = null; try { tempConfigFile = this.persistConfiguration(this.definition); url = tempConfigFile.toURI().toURL(); } catch (MalformedURLException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + ".", e); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (IOException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + ".", e); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } try { Digester scxmlParser = SCXMLParser.newInstance(null, new URLResolver(url), getCustomActions()); scxmlParser.addObjectCreate("*/" + CUSTOM_ACTION_SERVICE + "/properties", HashMap.class); scxmlParser.addSetNext("*/" + CUSTOM_ACTION_SERVICE + "/properties", "setProperties"); // call the put method on the top object on the digester stack // passing the key attribute as the 0th parameter // and the element body text as the 1th parameter.. scxmlParser.addCallMethod("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", "put", 2); scxmlParser.addCallParam("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", 0, "name"); scxmlParser.addCallParam("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", 1, "value"); scxmlParser.setErrorHandler(new SimpleErrorHandler()); scxml = (SCXML) scxmlParser.parse(url.toString()); SCXMLParser.updateSCXML(scxml); } catch (IOException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (SAXException e) { logger.error("Error parsing the configuration for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (ModelException e) { logger.error("Error persisting the configuration for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } // Once done remove the file. tempConfigFile.delete(); // initialize the executor. scxmlExecutor = new SCXMLExecutor(); scxmlExecutor.setStateMachine(scxml); scxmlExecutor.setEvaluator(this.getEvaluator()); scxmlExecutor.setErrorReporter(this.getErrorReporter()); scxmlExecutor.setEventdispatcher(this.getEventDispatcher(scxmlExecutor)); scxmlExecutor.addListener(scxml, new SimpleSCXMLListener()); scxmlExecutor.registerInvokerClass("scxml", SimpleSCXMLInvoker.class); scxmlExecutor.setRootContext(scxmlExecutor.getEvaluator().newContext(null)); }