List of usage examples for org.apache.commons.digester Digester addRuleSet
public void addRuleSet(RuleSet ruleSet)
From source file:org.osjava.atom4j.reader.AtomReader.java
/** * Configure digester to parse Entries, based on the parent path. * /* ww w .ja va 2 s. c om*/ * @param digester * @param parent */ protected void configureEntryDigester(Digester digester, String parent) { String entryPath = parent + "entry"; digester.addObjectCreate(entryPath, Entry.class.getName()); digester.addRuleSet(new ContentRuleSet(entryPath + "/title", "setTitle")); digester.addCallMethod(entryPath + "/issued", "setIssued", 0); digester.addCallMethod(entryPath + "/created", "setCreated", 0); digester.addCallMethod(entryPath + "/modified", "setModified", 0); digester.addBeanPropertySetter(entryPath + "/id"); digester.addRuleSet(new LinkRuleSet(entryPath + "/link")); digester.addRuleSet(new PersonRuleSet(entryPath + "/author", "setAuthor")); digester.addRuleSet(new PersonRuleSet(entryPath + "/contributor", "addContributor")); digester.addRuleSet(new ContentRuleSet(entryPath + "/content", "setContent")); digester.addRuleSet(new ContentRuleSet(entryPath + "/content/content", "addContent")); digester.addRuleSet(new ContentRuleSet(entryPath + "/summary", "setSummary")); digester.addSetNext(entryPath, "addEntry", Entry.class.getName()); }
From source file:org.photovault.image.ChannelMapOperationFactory.java
/** Create a ChannelMapOperation object from XML data in database. This is intended mostly for Hibernate use./*from w w w.j av a 2 s . c o m*/ @param data The raw data from database field used for cunstruction the channel mapping. */ public static ChannelMapOperation createFromXmlData(byte[] data) { if (data == null) { return null; } String xmlStr = new String(data); Digester d = new Digester(); d.addRuleSet(new ChannelMapRuleSet()); ChannelMapOperationFactory f; try { f = (ChannelMapOperationFactory) d.parse(new StringReader(xmlStr)); } catch (IOException ex) { return null; } catch (SAXException ex) { return null; } return f.create(); }
From source file:org.photovault.image.Test_ChannelMapOperation.java
/** Test that converting ChannelMapOperation to its XML representation and back to java object creates an identical object. *///from ww w . j a v a 2 s .c om @Test public void testXmlConvert() { ChannelMapOperationFactory f = new ChannelMapOperationFactory(); ColorCurve r = new ColorCurve(); r.addPoint(0.0, 0.1); r.addPoint(0.2, 0.4); r.addPoint(1.0, 1.0); f.setChannelCurve("red", r); ColorCurve b = new ColorCurve(); b.addPoint(0.0, 0.2); b.addPoint(0.4, 0.4); b.addPoint(1.0, 0.9); f.setChannelCurve("blue", b); ChannelMapOperation o = f.create(); String xml = o.getAsXml(); ChannelMapOperation o2 = null; Digester d = new Digester(); d.addRuleSet(new ChannelMapRuleSet()); try { ChannelMapOperationFactory f2 = (ChannelMapOperationFactory) d.parse(new StringReader(xml)); o2 = f2.create(); } catch (SAXException ex) { fail(ex.getMessage()); } catch (IOException ex) { fail(ex.getMessage()); } assertEquals(o, o2); }
From source file:org.photovault.imginfo.xml.XmlImporter.java
/** Import data from XML file according to current settings in this object. *//*from w w w .j a v a2s .co m*/ public void importData() { Digester digester = new Digester(); digester.push(this); // Push controller servlet onto the stack digester.setValidating(false); digester.addFactoryCreate("*/folders/folder", new FolderFactory(true)); digester.addFactoryCreate("*/folder/folder", new FolderFactory(true)); digester.addCallMethod("*/folder/name", "setName", 0); digester.addCallMethod("*/folder/description", "setDescription", 0); // PhotoInfo mappings digester.addFactoryCreate("*/photos/photo", new PhotoFactory()); // After the photo is ready, inform listeners if a new photo was created. digester.addRule("*/photos/photo", new Rule() { @Override public void end(String namespace, String name) { Boolean isCreatingNew = (Boolean) digester.pop(STACK_CREATING_NEW); if (isCreatingNew.booleanValue()) { photoCount++; fireObjectImportedEvent(digester.peek()); } } }); digester.addCallMethod("*/photos/photo/shooting-place", "setShootingPlace", 0); digester.addCallMethod("*/photos/photo/photographer", "setPhotographer", 0); digester.addCallMethod("*/photos/photo/camera", "setCamera", 0); digester.addCallMethod("*/photos/photo/lens", "setLens", 0); digester.addCallMethod("*/photos/photo/film", "setFilm", 0); digester.addCallMethod("*/photos/photo/orig-fname", "setOrigFname", 0); digester.addCallMethod("*/photos/photo/description", "setDesc", 0); digester.addCallMethod("*/photos/photo/tech-notes", "setTechNotes", 0); digester.addCallMethod("*/photos/photo/f-stop", "setFStop", 0, new Class[] { Double.class }); digester.addCallMethod("*/photos/photo/shutter-speed", "setShutterSpeed", 0, new Class[] { Double.class }); digester.addCallMethod("*/photos/photo/focal-length", "setFocalLength", 0, new Class[] { Double.class }); digester.addCallMethod("*/photos/photo/quality", "setQuality", 0, new Class[] { Integer.class }); digester.addCallMethod("*/photos/photo/film-speed", "setFilmSpeed", 0, new Class[] { Integer.class }); digester.addFactoryCreate("*/photos/photo/shoot-time", new FuzzyDateFactory()); digester.addSetNext("*/photos/photo/shoot-time", "setFuzzyShootTime"); // Crop settings digester.addCallMethod("*/photos/photo/crop", "setPrefRotation", 1, new Class[] { Double.class }); digester.addCallParam("*/photos/photo/crop", 0, "rot"); digester.addFactoryCreate("*/photos/photo/crop", new RectangleFactory()); digester.addSetNext("*/photos/photo/crop", "setCropBounds"); /* Raw conversion setting mappings. All of these expect that a RawSettingsFactory is the topmost object in Digester stack. Note that in practice there must be and explicit rule for each raw setting field since the rule that instantates the raw setting object & assign it to the parent object will override this. */ digester.addObjectCreate("*/raw-conversion", RawSettingsFactory.class); digester.addCallMethod("*/raw-conversion/whitepoint", "setWhite", 0, new Class[] { Integer.class }); digester.addCallMethod("*/raw-conversion/blackpoint", "setBlack", 0, new Class[] { Integer.class }); digester.addCallMethod("*/raw-conversion/ev-corr", "setEvCorr", 0, new Class[] { Double.class }); digester.addCallMethod("*/raw-conversion/hlight-corr", "setHlightComp", 0, new Class[] { Double.class }); digester.addRule("*/raw-conversion/color-balance", new Rule() { @Override public void begin(String namespace, String name, Attributes attrs) { String rgStr = attrs.getValue("red-green-ratio"); String bgStr = attrs.getValue("blue-green-ratio"); double bg = 1.0; double rg = 1.0; try { bg = Double.parseDouble(bgStr); rg = Double.parseDouble(rgStr); } catch (NumberFormatException ex) { digester.createSAXException(ex); } RawSettingsFactory f = (RawSettingsFactory) digester.peek(); f.setRedGreenRation(rg); f.setBlueGreenRatio(bg); } }); digester.addRule("*/raw-conversion/daylight-color-balance", new Rule() { @Override public void begin(String namespace, String name, Attributes attrs) { String rgStr = attrs.getValue("red-green-ratio"); String bgStr = attrs.getValue("blue-green-ratio"); double bg = 1.0; double rg = 1.0; try { bg = Double.parseDouble(bgStr); rg = Double.parseDouble(rgStr); } catch (NumberFormatException ex) { digester.createSAXException(ex); } RawSettingsFactory f = (RawSettingsFactory) digester.peek(); f.setDaylightMultipliers(new double[] { rg, 1.0, bg }); } }); digester.addRuleSet(new ChannelMapRuleSet("*/photo/")); digester.addRule("*/photo/color-mapping", new Rule() { @Override public void end(String namespace, String name) { PhotoInfo p = (PhotoInfo) digester.peek(1); ChannelMapOperationFactory f = (ChannelMapOperationFactory) digester.peek(); p.setColorChannelMapping(f.create()); } }); digester.addObjectCreate("*/photo/raw-conversion", RawSettingsFactory.class); digester.addRule("*/photo/raw-conversion", new Rule() { @Override public void end(String namespace, String name) { PhotoInfo p = (PhotoInfo) digester.peek(1); RawSettingsFactory f = (RawSettingsFactory) digester.peek(); try { p.setRawSettings(f.create()); } catch (PhotovaultException ex) { digester.createSAXException(ex); } } }); // Instance mappings digester.addFactoryCreate("*/photo/instances/instance", new InstanceFactory()); digester.addCallMethod("*/instance/file-size", "setFileSize", 0, new Class[] { Long.class }); digester.addCallMethod("*/instance/width", "setWidth", 0, new Class[] { Integer.class }); digester.addCallMethod("*/instance/height", "setHeight", 0, new Class[] { Integer.class }); digester.addCallMethod("*/instance/crop", "setRotated", 1, new Class[] { Double.class }); digester.addCallParam("*/instance/crop", 0, "rot"); digester.addFactoryCreate("*/instance/crop", new RectangleFactory()); digester.addSetNext("*/instance/crop", "setCropBounds"); digester.addRule("*/instance/hash", new Rule() { @Override public void body(String namespace, String name, String text) { /* byte[] hash = Base64.decode( text ); ImageInstance i = (ImageInstance) digester.peek(); i.setHash( hash ); */ } }); digester.addRuleSet(new ChannelMapRuleSet("*/instance/")); digester.addRule("*/instance/color-mapping", new Rule() { @Override public void end(String namespace, String name) { /* ImageInstance i = (ImageInstance) digester.peek(1); ChannelMapOperationFactory f = (ChannelMapOperationFactory) digester.peek(); i.setColorChannelMapping( f.create() ); */ } }); // Raw conversion parsing was already specified earlier. We just need a // method for binding the RawConversionSettings object to instance digester.addObjectCreate("*/instance/raw-conversion", RawSettingsFactory.class); digester.addRule("*/instance/raw-conversion", new Rule() { @Override public void end(String namespace, String name) { /* ImageInstance i = (ImageInstance)digester.peek(1); RawSettingsFactory f = (RawSettingsFactory) digester.peek(); try { i.setRawSettings( f.create() ); } catch (PhotovaultException ex) { digester.createSAXException( ex ); } */ } }); /* TODO: import information about image locations. In first phase, this can be done by indexing images as an external volume... */ digester.addSetNext("*/photo/instances/instance", "addInstance"); // folder handling digester.addFactoryCreate("*/photos/photo/folders/folder-ref", new FolderFactory(false)); digester.addSetTop("*/photos/photo/folders/folder-ref", "addPhoto"); fireStatusChangeEvent(IMPORTING_STARTED); try { digester.parse(reader); } catch (SAXException ex) { fireErrorEvent(ex.getMessage()); ex.printStackTrace(); } catch (IOException ex) { fireErrorEvent(ex.getMessage()); ex.printStackTrace(); } fireStatusChangeEvent(IMPORTING_COMPLETED); }
From source file:org.quartz.xml.JobSchedulingDataProcessor.java
/** * Add the default set of digest rules/* w w w .j a v a 2s. c o m*/ */ protected void addDefaultDigesterRules(Digester digester) { digester.addSetProperties(TAG_QUARTZ, TAG_OVERWRITE_EXISTING_JOBS, "overWriteExistingJobs"); digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "jobListener", "class-name"); digester.addCallMethod(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "setName", 1); digester.addCallParam(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, 0, "name"); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "addListenerToSchedule"); digester.addRuleSet(new CalendarRuleSet(TAG_QUARTZ + "/" + TAG_CALENDAR, "addCalendarToSchedule")); digester.addRuleSet(new CalendarRuleSet("*/" + TAG_BASE_CALENDAR, "setBaseCalendar")); digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB, JobSchedulingBundle.class); digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL, JobDetail.class); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_NAME, "name"); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_GROUP, "group"); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_DESCRIPTION, "description"); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_CLASS, "jobClass"); digester.addCallMethod(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_LISTENER_REF, "addJobListener", 0); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_VOLATILITY, "volatility"); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_DURABILITY, "durability"); digester.addBeanPropertySetter(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_RECOVER, "requestsRecovery"); digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP, JobDataMap.class); digester.addCallMethod( TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY, "put", 2, new Class[] { Object.class, Object.class }); digester.addCallParam(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_KEY, 0); digester.addCallParam(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_VALUE, 1); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP, "setJobDataMap"); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL, "setJobDetail"); digester.addRuleSet(new TriggerRuleSet(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE, SimpleTrigger.class)); digester.addBeanPropertySetter( TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE + "/" + TAG_REPEAT_COUNT, "repeatCount"); digester.addBeanPropertySetter( TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE + "/" + TAG_REPEAT_INTERVAL, "repeatInterval"); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE, "addTrigger"); digester.addRuleSet(new TriggerRuleSet(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON, CronTrigger.class)); digester.addBeanPropertySetter( TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON + "/" + TAG_CRON_EXPRESSION, "cronExpression"); digester.addRule(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON + "/" + TAG_TIME_ZONE, new SimpleConverterRule("timeZone", new TimeZoneConverter(), TimeZone.class)); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON, "addTrigger"); digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB, "addJobToSchedule"); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
protected Digester initConfigDigester() throws ServletException { // Create a new Digester instance with standard capabilities Digester configDigester = new Digester(); configDigester.setNamespaceAware(true); configDigester.setValidating(this.isValidating()); configDigester.setUseContextClassLoader(true); configDigester.addRuleSet(new ConfigRuleSet()); for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i + 1]); if (url != null) { configDigester.register(registrations[i], url.toString()); }/* ww w. j a v a 2 s . c o m*/ } this.addRuleSets(configDigester); // Return the completely configured Digester instance return (configDigester); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
private void addRuleSets(Digester configDigester) throws ServletException { String rulesets = getServletConfig().getInitParameter("rulesets"); if (rulesets == null) { rulesets = ""; }//from w w w . j a v a 2s . co m rulesets = rulesets.trim(); String ruleset; while (rulesets.length() > 0) { int comma = rulesets.indexOf(","); if (comma < 0) { ruleset = rulesets.trim(); rulesets = ""; } else { ruleset = rulesets.substring(0, comma).trim(); rulesets = rulesets.substring(comma + 1).trim(); } if (log.isDebugEnabled()) { log.debug("Configuring custom Digester Ruleset of type " + ruleset); } try { RuleSet instance = (RuleSet) RequestUtils.applicationInstance(ruleset); configDigester.addRuleSet(instance); } catch (Exception e) { log.error("Exception configuring custom Digester RuleSet", e); throw new ServletException(e); } } }
From source file:org.sipfoundry.sipxconfig.setting.XmlModelBuilder.java
private SettingSet buildModel(InputStream is, File baseSystemId) throws IOException { Digester digester = new Digester(); // setting classloader ensures classes are searched for in this classloader // instead of parent's classloader is digister was loaded there. digester.setClassLoader(getClass().getClassLoader()); digester.setValidating(false);/*from w ww .j a v a 2 s .com*/ EntityResolver entityResolver = new ModelEntityResolver(m_configDirectory, baseSystemId); digester.setEntityResolver(entityResolver); digester.push(new ConditionalSet()); // keeps all types encountered during parsing SettingTypeIdRule typeIdRule = new SettingTypeIdRule(); addSettingTypes(digester, "model/type/", typeIdRule); CollectionRuleSet collectionRule = new CollectionRuleSet(); digester.addRuleSet(collectionRule); SettingRuleSet groupRule = new SettingRuleSet("*/group", ConditionalSet.class, typeIdRule); digester.addRuleSet(groupRule); SettingRuleSet settingRule = new SettingRuleSet("*/setting", ConditionalSettingImpl.class, typeIdRule); digester.addRuleSet(settingRule); try { return (SettingSet) digester.parse(is); } catch (SAXException se) { throw new RuntimeException("Could not parse model definition file", se); } }
From source file:org.sipfoundry.sipxconfig.setting.XmlModelBuilder.java
private static void addSettingTypes(Digester digester, String patternPrefix, SettingTypeIdRule typeIdRule) { digester.addRuleSet(new IntegerSettingRule(patternPrefix + "integer", typeIdRule)); digester.addRuleSet(new RealSettingRule(patternPrefix + "real", typeIdRule)); digester.addRuleSet(new StringSettingRule(patternPrefix + "string", typeIdRule)); digester.addRuleSet(new EnumSettingRule(patternPrefix + "enum", typeIdRule)); digester.addRuleSet(new MultiEnumSettingRule(patternPrefix + "multi-enum", typeIdRule)); digester.addRuleSet(new BooleanSettingRule(patternPrefix + "boolean", typeIdRule)); digester.addRuleSet(new FileSettingRule(patternPrefix + "file", typeIdRule)); digester.addRuleSet(//from ww w . ja v a 2 s. c o m new SpecializedStringSettingRule(patternPrefix + "sip-uri", typeIdRule, SipUriSetting.class)); digester.addRuleSet( new SpecializedStringSettingRule(patternPrefix + "ipaddr", typeIdRule, IpAddrSetting.class)); digester.addRuleSet(new SpecializedStringSettingRule(patternPrefix + "ipaddrwildcard", typeIdRule, IpAddrWildCardSetting.class)); digester.addRuleSet( new SpecializedStringSettingRule(patternPrefix + "hostname", typeIdRule, HostnameSetting.class)); digester.addRuleSet(new SpecializedStringSettingRule(patternPrefix + "phonepadpin", typeIdRule, PhonePadPinSetting.class)); digester.addRuleSet(new SpecializedStringSettingRule(patternPrefix + "username_sequence", typeIdRule, UsernameSequenceSetting.class)); }
From source file:org.squale.jraf.bootstrap.config.AbstractProviderConfigReader.java
/** * Lis le fichier de configuration d'un provider * @param in_fileName chemin du fichier de configuration * @return liste de configuration//from ww w . j a v a 2 s. c om */ public List readConfig(InputStream in_stream) throws JrafConfigException { // liste de configuration List lc_config = new ArrayList(); Digester lc_digester = new Digester(); lc_digester.setEntityResolver(new DTDEntityResolver(_dtdRegistration)); lc_digester.addRuleSet(this); lc_digester.push(lc_config); try { lc_digester.parse(in_stream); } catch (IOException ioe) { ioe.printStackTrace(); throw new JrafConfigException("Impossible de lire le fichier de configuration", ioe); } catch (SAXException saxe) { saxe.printStackTrace(); throw new JrafConfigException("Impossible de parser le fichier de configuration", saxe); } catch (FactoryConfigurationError e) { e.printStackTrace(); throw new JrafConfigException("Impossible de charger le parser xml", e); } finally { if (in_stream != null) { try { in_stream.close(); lc_digester.clear(); } catch (IOException ie) { // nothing to do } } } // retourne la liste de configuration return lc_config; }