/** Add rules for digesting tool elements. */ protected void addToolRules(Digester digester) { digester.addObjectCreate("toolbox/tool", getToolInfoClass()); digester.addBeanPropertySetter("toolbox/tool/key", "key"); digester.addBeanPropertySetter("toolbox/tool/class", "classname"); digester.addRule("toolbox/tool/parameter", new ParameterRule()); digester.addSetNext("toolbox/tool", "addTool"); }
/** Add rules for digesting data elements. */ protected void addDataRules(Digester digester) { digester.addObjectCreate("toolbox/data", getDataInfoClass()); digester.addSetProperties("toolbox/data"); digester.addBeanPropertySetter("toolbox/data/key", "key"); digester.addBeanPropertySetter("toolbox/data/value", "value"); digester.addSetNext("toolbox/data", "addData"); }
public void addRuleInstances(Digester digester) { digester.addObjectCreate("*/Ciudad", Ciudad.class); digester.addBeanPropertySetter("*/Ciudad/Id", "id"); digester.addBeanPropertySetter("*/Ciudad/Codigo", "codigo"); digester.addBeanPropertySetter("*/Ciudad/Nombre", "nombre"); digester.addBeanPropertySetter("*/Ciudad/IdProvincia", "idProvincia"); }
/** * Process the xmlfile named <code>fileName</code> with the given system ID. * * @param fileName meta data file name. * @param systemId system ID. */ public void processFile(String fileName, String systemId) throws ValidationException, ParserConfigurationException, SAXException, IOException, SchedulerException, ClassNotFoundException, ParseException { clearValidationExceptions(); scheduledJobs.clear(); jobsToSchedule.clear(); calsToSchedule.clear(); getLog() .info( "Parsing XML file: " + fileName + " with systemId: " + systemId + " validating: " + digester.getValidating() + " validating schema: " + digester.getSchema()); InputSource is = new InputSource(getInputStream(fileName)); is.setSystemId(systemId); digester.push(this); digester.parse(is); maybeThrowValidationException(); }
public void addRuleInstances(Digester digester) { digester.addObjectCreate(prefix, CalendarBundle.class); digester.addSetProperties(prefix, TAG_CLASS_NAME, "className"); digester.addBeanPropertySetter(prefix + "/" + TAG_NAME, "calendarName"); digester.addBeanPropertySetter(prefix + "/" + TAG_DESCRIPTION, "description"); digester.addSetNext(prefix, setNextMethodName); }
/** * Load ManufacturerItems from DM setup data files. * * @param filename * @return */ protected List<ManufacturerItem> loadManufacturerItems(String filename) throws SetupException { List<ManufacturerItem> result = new ArrayList<ManufacturerItem>(); try { Digester digester = this.createManufacturerDigester(); digester.push(result); digester.parse(new FileInputStream(filename)); for (ManufacturerItem item : result) { List<String> includeFilenames4Model = item.getIncludedFiles4Models(); for (String includeFilename : includeFilenames4Model) { digester.push(item); File file = new File(includeFilename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), includeFilename); } // Trace definition file item.setCurrentModelDefinitionFilename(file.getAbsolutePath()); digester.parse(new FileInputStream(file)); } } return result; } catch (Exception e) { throw new SetupException(e); } }
@Override protected Digester getDigester() { Digester digester = super.getDigester(); digester.addBeanPropertySetter("eveapi/result/serverOpen"); digester.addBeanPropertySetter("eveapi/result/onlinePlayers"); return digester; }
private static Digester initDigester() throws SAXNotRecognizedException, SAXNotSupportedException { Digester digester = new Digester(); digester.setValidating(true); digester.setErrorHandler( new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { throw new SAXException( "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception); } @Override public void error(SAXParseException exception) throws SAXException { throw new SAXException( "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception); } @Override public void fatalError(SAXParseException exception) throws SAXException { throw new SAXException( "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception); } }); digester.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI); digester.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", GoPluginDescriptorParser.class.getResourceAsStream("/plugin-descriptor.xsd")); return digester; }
@Override protected Digester getDigester() { Digester digester = super.getDigester(); digester.addObjectCreate("*/rowset/row", ApiAsset.class); digester.addSetProperties("*/rowset/row"); digester.addSetNext("*/rowset/row", "addAsset"); return digester; }
@Override protected Digester getDigester() { Digester digester = super.getDigester(); digester.addSetProperties("eveapi/result/rowset/row"); digester.addObjectCreate("eveapi/result/rowset/row/rowset/row", ApiMemberCorporation.class); digester.addSetProperties("eveapi/result/rowset/row/rowset/row"); digester.addSetNext("eveapi/result/rowset/row/rowset/row", "add"); return digester; }
/** * Return a configured <code>Digester</code> to use for processing the XML input file, creating a * new one if necessary. */ protected synchronized Digester getDigester() { if (digester == null) { digester = new Digester(); digester.setDebug(this.debug); digester.setValidating(false); digester.addRuleSet(new MemoryRuleSet()); } return (digester); }
protected void configureDigester(Digester digester) throws SAXException, ParserConfigurationException { boolean validating = JRProperties.getBooleanProperty(JRProperties.COMPILER_XML_VALIDATION); digester.setErrorHandler(this); digester.setValidating(validating); digester.setFeature("http://xml.org/sax/features/validation", validating); digester.addRuleSet(rules); }
@SuppressWarnings("unchecked") public void parse(File file, Config cfg) { Digester d = createDigester(); try { cfg.setAccounts((List<Account>) d.parse(file)); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } }
protected List<SoftwareItem> loadSoftwareItems(String filename) throws SetupException { List<SoftwareItem> result = new ArrayList<SoftwareItem>(); try { Digester digester = this.createSoftwareDigester(); digester.push(result); digester.parse(new FileInputStream(filename)); return result; } catch (Exception e) { throw new SetupException(e); } }
/** * Configures a Digester * * @return Digester */ private Digester getDigester() { final SaxErrorHandler errorHandler = new SaxErrorHandler(); final Digester digester = new Digester(); digester.setErrorHandler(errorHandler); digester.setValidating(true); digester.setEntityResolver(new DtdEntityResolver()); return digester; }
/** * @param parent * @param digester */ public static void registerDigester(String parent, Digester digester) { final String myPath = parent + _SEP + _DBPROCEDURECALLER_TAG; final String[] properties = new String[] { "id", "dbMethodName", "connectionJndiName", "resourceFactoryId", "returnMapId" }; digester.addObjectCreate(myPath, DBProcedureCallerConfig.class); digester.addSetNext(myPath, ADD_DB_PROCEDURE_CALLER_CONFIG); digester.addSetProperties(myPath, properties, properties); DBResourceFactoryConfig.registerDigester(myPath, digester); DBReturnMapConfig.registerDigester(myPath, digester); }
/** * Process a single <code>faces-config.xml</code> file and add all beans found to the supplied * list of {@link FacesConfigEntry} objects. * * @param url The faces-config.xml file * @param facesConfigEntries list of entries to add the beans to */ private void processFacesConfig(URL url, List<FacesConfigEntry> facesConfigEntries) { // log name of current file if (log.isTraceEnabled()) { log.trace("Loading bean names from: " + url.toString()); } // setup digester Digester digester = new Digester(); /* * We use the context class loader to resolve classes. * This fixes ClassNotFoundExceptions on Geronimo. */ digester.setUseContextClassLoader(true); // prevent downloading of DTDs digester.setEntityResolver(new EmptyEntityResolver()); digester.setValidating(false); digester.push(facesConfigEntries); digester.addObjectCreate("faces-config/managed-bean", FacesConfigEntry.class); digester.addCallMethod("faces-config/managed-bean/managed-bean-name", "setName", 0); digester.addCallMethod("faces-config/managed-bean/managed-bean-class", "setBeanClass", 0); digester.addSetNext("faces-config/managed-bean", "add"); // stream used to read faces-config.xml file InputStream stream = null; try { // open the file and let digester pares it stream = url.openStream(); digester.parse(stream); } catch (IOException e) { // may be thrown when reading the file log.error("Failed to parse: " + url.toString(), e); } catch (SAXException e) { // parsing errors log.error("Failed to parse: " + url.toString(), e); } finally { // close stream if (stream != null) { try { stream.close(); } catch (IOException e) { // ignore IOExceptions on close } } } }
/** * Initializes the digester. * * @param useContextClassLoader whether or not to use the context class loader. * @param validating whether or not to validate XML. * @param validatingSchema whether or not to validate XML schema. */ protected void initDigester( boolean useContextClassLoader, boolean validating, boolean validatingSchema) { digester = new Digester(); digester.setNamespaceAware(true); digester.setUseContextClassLoader(useContextClassLoader); digester.setValidating(validating); initSchemaValidation(validatingSchema); digester.setEntityResolver(this); digester.setErrorHandler(this); if (addCustomDigesterRules(digester)) { addDefaultDigesterRules(digester); } }
/** * Parse input reader and add encountered definitions to definitions set. * * @param in Input stream. * @param definitions Xml Definitions set to which encountered definition are added. * @throws IOException On errors during file parsing. * @throws SAXException On errors parsing XML. */ public void parse(InputStream in, XmlDefinitionsSet definitions) throws IOException, SAXException { try { // set first object in stack // digester.clear(); digester.push(definitions); // parse digester.parse(in); in.close(); } catch (SAXException e) { // throw new ServletException( "Error while parsing " + mappingConfig, e); throw e; } }
/** Constructor. Creates a digester parser and initializes syntax rules. */ public XmlParser() { digester = new Digester(); digester.setValidating(validating); digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); // Register our local copy of the DTDs that we can find for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i + 1]); if (url != null) { digester.register(registrations[i], url.toString()); } } // Init syntax rules initDigester(digester); }
protected Digester createSoftwareCategoryDigester() { Digester digester = new Digester(); digester.addObjectCreate("*/SoftwareCategory", SoftwareCategoryItem.class); digester.addBeanPropertySetter("*/SoftwareCategory/Name", "name"); digester.addBeanPropertySetter("*/SoftwareCategory/Description", "description"); digester.addSetNext("*/SoftwareCategory", "add"); digester.addObjectCreate("*/SoftwareCategory/SoftwareCategory", SoftwareCategoryItem.class); digester.addBeanPropertySetter("*/SoftwareCategory/SoftwareCategory/Name", "name"); digester.addBeanPropertySetter( "*/SoftwareCategory/SoftwareCategory/Description", "description"); digester.addSetNext("*/SoftwareCategory/SoftwareCategory", "addSoftwareCategory"); return digester; }
private void parseConfigurationXML(InputSource inputSource) { // Create a digester. Digester digester = getDigester(); // add this object to the digesters stack digester.push(this); // parse the XML. try { digester.parse(inputSource); } catch (SAXException se) { throw new ApiException(se); } catch (IOException ie) { throw new ApiException(ie); } }
/** * Initialize a <code>Digester</code> and use it to parse a configuration file, resulting in a * root object which will be placed into the ServletContext. * * @param servlet ActionServlet that is managing all the modules in this web application * @param config ModuleConfig for the module with which this plug-in is associated * @throws ServletException if this <code>PlugIn</code> cannot be successfully initialized */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { this.servlet = servlet; this.moduleConfig = config; Object obj = null; Digester digester = this.initializeDigester(); if (this.push) { log.debug("push == true; pushing plugin onto digester stack"); digester.push(this); } try { log.debug( "XML data file: [path: " + this.configPath + ", source: " + this.configSource + "]"); URL configURL = this.getConfigURL(this.configPath, this.configSource); if (configURL == null) { throw new ServletException( "Unable to locate XML data file at [path: " + this.configPath + ", source: " + this.configSource + "]"); } URLConnection conn = configURL.openConnection(); conn.setUseCaches(false); conn.connect(); obj = digester.parse(conn.getInputStream()); } catch (IOException e) { // TODO Internationalize msg log.error("Exception processing config", e); throw new ServletException(e); } catch (SAXException e) { // TODO Internationalize msg log.error("Exception processing config", e); throw new ServletException(e); } this.storeGeneratedObject(obj); }
public static TreeNode build(InputSource inputSource) throws SAXException, IOException { Digester digester = new Digester(); Rule rule = new Rule(); final List rulesList = new ArrayList(1); rulesList.add(rule); RulesBase rulesBase = new RulesBase() { protected List lookup(String namespace, String name) { return rulesList; } }; digester.setRules(rulesBase); digester.setNamespaceAware(true); digester.parse(inputSource); return rule.treeNode; }
/** * Reading of the configuration * * @param pStream stream * @throws ConfigurationException exception if an error occurs */ public void parse(InputStream pStream) throws ConfigurationException { StringBuffer errors = new StringBuffer(); Digester digester = preSetupDigester( "-//Quartz Configuration DTD //EN", "/config/quartz-timer-config.dtd", errors); // Root directory treatment digester.addCallMethod( "quartz-timer-configuration/quartzKey", "setQuartzKey", 1, new Class[] {String.class}); digester.addCallParam("quartz-timer-configuration/quartzKey", 0); digester.push(this); // Parser call parse(digester, pStream, errors); if (errors.length() > 0) { throw new ConfigurationException( QuartzMessages.getString( "quartz.exception.configuration.parse", new Object[] {errors.toString()})); } }
/** * Validate the configurationXml. * * @param configurationXml String xml content to validate * @see "architecture-rules.dtd" */ @Override protected void validateConfiguration(final String configurationXml) { final Digester digester = getDigester(); final StringReader configurationReader = new StringReader(configurationXml); try { digester.parse(configurationReader); } catch (final IOException e) { throw new InvalidConfigurationException( "configuration xml file contains invalid configuration properties", e); } catch (final SAXException e) { throw new InvalidConfigurationException( "configuration xml file contains invalid configuration properties", e); } }
protected Digester getDigester() { Digester digester = new Digester(); ConvertUtils.register(DateUtils.getGMTConverter(), Date.class); ConvertUtils.register(new EveRaceConverter(), EveRace.class); ConvertUtils.register(new EveBloodlineConverter(), EveBloodline.class); ConvertUtils.register(new EveAncestryConverter(), EveAncestry.class); digester.setValidating(false); digester.addObjectCreate("eveapi", clazz); digester.addSetProperties("eveapi"); digester.addObjectCreate("eveapi/error", ApiError.class); digester.addSetProperties("eveapi/error"); digester.addBeanPropertySetter("eveapi/error"); digester.addSetNext("eveapi/error", "setError"); digester.addBeanPropertySetter("eveapi/currentTime"); digester.addBeanPropertySetter("eveapi/cachedUntil"); return digester; }
/** * Initializes the digester for XML Schema validation. * * @param validatingSchema whether or not to validate XML. */ protected void initSchemaValidation(boolean validatingSchema) { if (validatingSchema) { String schemaUri = null; URL url = getClass().getResource(QUARTZ_XSD); if (url != null) { schemaUri = url.toExternalForm(); } else { schemaUri = QUARTZ_SCHEMA; } digester.setSchema(schemaUri); } }
private Set<String> getListenerClassNames(final String xml, final String path) throws IOException, SAXException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.listeners, ArrayList.class); digester.addObjectCreate(path, StringBuffer.class); // TODO rather than StringBuffer can digester.addCallMethod(path, "append", 0); // TODO this be a String? digester.addSetRoot(path, "add"); final Set<String> classNames = new HashSet<String>(); final StringReader includeReader = new StringReader(xml); Object o = digester.parse(includeReader); if (o == null) { // return empty Set return classNames; } Collection<StringBuffer> classNamesAsStringBuffers = (Collection<StringBuffer>) o; /** When the configuration contains no listener settings, return the empty Set */ if (classNamesAsStringBuffers == null) { return classNames; } for (StringBuffer classNamesAsStringBuffer : classNamesAsStringBuffers) { classNames.add(classNamesAsStringBuffer.toString()); } return classNames; }
/** * Process XML sources <tt>not-found</tt> attribute to a <code>SourcesConfiguration</code> entity. * * <p> * * <p>package scope so that it could be individually tested * * @param configurationXml String xml to parse * @throws IOException when an input/output error occurs * @throws SAXException when given xml can not be parsed */ void processSourcesNotFoundConfiguration(final String configurationXml) throws IOException, SAXException { final Digester digester = getDigester(); final StringReader configurationReader = new StringReader(configurationXml); digester.addObjectCreate(XmlConfiguration.sources, SourcesConfiguration.class); digester.addSetProperties(XmlConfiguration.sources, "no-packages", "noPackages"); SourcesConfiguration configuration = (SourcesConfiguration) digester.parse(configurationReader); /** If no configuration was provided in the xml, then use the default value. */ if (configuration == null) { configuration = new SourcesConfiguration(); } final String value = configuration.getNoPackages(); final boolean isIgnore = value.equalsIgnoreCase("ignore"); final boolean isException = value.equalsIgnoreCase("exception"); if (isIgnore || isException) { boolean shouldThrowException = value.equalsIgnoreCase("exception"); setThrowExceptionWhenNoPackages(shouldThrowException); } else { throw new InvalidConfigurationException( "'" + value + "' is not a valid value for the " + "sources no-packages configuration. " + "Use <sources no-packages=\"ignore\">, " + "<sources no-packages=\"exception\"> or " + "leave the property unset."); } }