List of usage examples for org.apache.commons.digester Digester Digester
public Digester(XMLReader reader)
From source file:net.sibcolombia.sibsp.model.factory.VocabularyFactory.java
/** * Builds a Vocabulary from the supplied input stream * //www .j av a 2s . c o m * @param is For the XML * @return The extension */ public Vocabulary build(InputStream is) throws IOException, SAXException, ParserConfigurationException { Digester digester = new Digester(saxf.newSAXParser()); digester.setNamespaceAware(true); digester.setXIncludeAware(false); digester.setRuleNamespaceURI(VOCABULARY_NAMESPACE); Vocabulary tv = new Vocabulary(); digester.push(tv); // build the thesaurus digester.addCallMethod("*/thesaurus", "setTitle", 1); digester.addRule("*/thesaurus", new CallParamNoNSRule(0, "title")); digester.addCallMethod("*/thesaurus", "setDescription", 1); digester.addRule("*/thesaurus", new CallParamNoNSRule(0, "description")); digester.addCallMethod("*/thesaurus", "setLink", 1); digester.addRule("*/thesaurus", new CallParamNoNSRule(0, "relation")); digester.addCallMethod("*/thesaurus", "setUriString", 1); digester.addRule("*/thesaurus", new CallParamNoNSRule(0, "URI")); // build the concept digester.addObjectCreate("*/concept", VocabularyConcept.class); digester.addCallMethod("*/concept", "setLink", 1); digester.addRule("*/concept", new CallParamNoNSRule(0, "relation")); digester.addCallMethod("*/concept", "setDescription", 1); digester.addRule("*/concept", new CallParamNoNSRule(0, "description")); digester.addCallMethod("*/concept", "setUri", 1); digester.addRule("*/concept", new CallParamNoNSRule(0, "URI")); digester.addCallMethod("*/concept", "setIdentifier", 1); digester.addRule("*/concept", new CallParamNoNSRule(0, "identifier")); // build the terms digester.addObjectCreate("*/preferred/term", VocabularyTerm.class); digester.addCallMethod("*/preferred/term", "setLang", 1); digester.addRule("*/preferred/term", new CallParamNoNSRule(0, "lang")); digester.addCallMethod("*/preferred/term", "setTitle", 1); digester.addRule("*/preferred/term", new CallParamNoNSRule(0, "title")); digester.addSetNext("*/preferred/term", "addPreferredTerm"); // build alternative terms digester.addObjectCreate("*/alternative/term", VocabularyTerm.class); digester.addCallMethod("*/alternative/term", "setLang", 1); digester.addRule("*/alternative/term", new CallParamNoNSRule(0, "lang")); digester.addCallMethod("*/alternative/term", "setTitle", 1); digester.addRule("*/alternative/term", new CallParamNoNSRule(0, "title")); digester.addSetNext("*/alternative/term", "addAlternativeTerm"); // add concept digester.addSetNext("*/concept", "addConcept"); digester.parse(is); return tv; }
From source file:fitnesse.maven.io.ParentPomParser.java
private Digester createDigester() { try {/* ww w . j a va 2s. c om*/ Digester digester = new Digester(SAXParserFactory.newInstance().newSAXParser()); digester.addObjectCreate("project/parent", ParentPomBean.class.getName()); digester.addBeanPropertySetter("project/parent/groupId", "groupId"); digester.addBeanPropertySetter("project/parent/artifactId", "artifactId"); digester.addBeanPropertySetter("project/parent/version", "version"); return digester; } catch (ParserConfigurationException e) { throw new MavenException(e); } catch (SAXException e) { throw new MavenException(e); } }
From source file:net.sibcolombia.sibsp.model.factory.ExtensionFactory.java
/** * Builds an extension from the supplied input stream. * //from w w w. java 2s .c om * @param is For the XML * @return The extension */ public Extension build(InputStream is) throws IOException, SAXException, ParserConfigurationException { // in order to deal with arbitrary namespace prefixes we need to parse namespace aware! Digester digester = new Digester(saxf.newSAXParser()); digester.setRuleNamespaceURI(EXTENSION_NAMESPACE); Extension e = new Extension(); digester.push(e); digester.addCallMethod("*/extension", "setTitle", 1); digester.addRule("*/extension", new CallParamNoNSRule(0, "title")); digester.addCallMethod("*/extension", "setName", 1); digester.addCallParam("*/extension", 0, "name"); digester.addCallMethod("*/extension", "setNamespace", 1); digester.addCallParam("*/extension", 0, "namespace"); digester.addCallMethod("*/extension", "setRowType", 1); digester.addCallParam("*/extension", 0, "rowType"); digester.addCallMethod("*/extension", "setLink", 1); digester.addRule("*/extension", new CallParamNoNSRule(0, "relation")); digester.addCallMethod("*/extension", "setDescription", 1); digester.addRule("*/extension", new CallParamNoNSRule(0, "description")); digester.addCallMethod("*/extension", "setSubject", 1); digester.addRule("*/extension", new CallParamNoNSRule(0, "subject")); // build the properties digester.addObjectCreate("*/property", ExtensionProperty.class); digester.addCallMethod("*/property", "setQualname", 1); digester.addCallParam("*/property", 0, "qualName"); digester.addCallMethod("*/property", "setName", 1); digester.addCallParam("*/property", 0, "name"); digester.addCallMethod("*/property", "setNamespace", 1); digester.addCallParam("*/property", 0, "namespace"); digester.addCallMethod("*/property", "setGroup", 1); digester.addCallParam("*/property", 0, "group"); digester.addCallMethod("*/property", "setRequired", 1); digester.addCallParam("*/property", 0, "required"); digester.addCallMethod("*/property", "setLink", 1); digester.addRule("*/property", new CallParamNoNSRule(0, "relation")); digester.addCallMethod("*/property", "setDescription", 1); digester.addRule("*/property", new CallParamNoNSRule(0, "description")); digester.addCallMethod("*/property", "setExamples", 1); digester.addCallParam("*/property", 0, "examples"); digester.addCallMethod("*/property", "setType", 1); digester.addCallParam("*/property", 0, "type"); // This is a special rule that will use the url2ThesaurusMap // to set the Vocabulary based on the attribute "thesaurus" digester.addRule("*/property", thesaurusRule); digester.addSetNext("*/property", "addProperty"); digester.parse(is); return e; }
From source file:com.npower.cp.xmlinventory.OTAInventoryImpl.java
/** * Create Digester to parsing Template index file. * @return/*w w w . java2 s . c o m*/ * @throws SAXException * @throws ParserConfigurationException */ private Digester createDigester() throws ParserConfigurationException, SAXException { SAXParserFactory spf = SAXParserFactory.newInstance(); //spf.setNamespaceAware(true); //spf.setXIncludeAware(true); // Initialize the digester Digester currentDigester = new Digester(spf.newSAXParser()); currentDigester.setValidating(false); // Parsing template currentDigester.addSetProperties("ota-templates/import", "filename", "include"); // Parsing manufacturer currentDigester.addObjectCreate("ota-templates/manufacturer", ManufacturerItem.class); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/id", "ID"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/name", "name"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/description", "description"); currentDigester.addSetNext("ota-templates/manufacturer", "add"); // Parsing model currentDigester.addObjectCreate("ota-templates/manufacturer/model", ModelItem.class); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/id", "ID"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/name", "name"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/description", "description"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/compatible", "compatible"); currentDigester.addSetNext("ota-templates/manufacturer/model", "addModel"); // Parsing template currentDigester.addObjectCreate("ota-templates/manufacturer/model/template", OTATemplateItem.class); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/template/id", "externalID"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/template/name", "name"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/template/description", "description"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/template/content", "contentString"); currentDigester.addBeanPropertySetter("ota-templates/manufacturer/model/template/category", "categoryByName"); currentDigester.addSetProperties("ota-templates/manufacturer/model/template/content", "filename", "filename"); currentDigester.addSetNext("ota-templates/manufacturer/model/template", "addTemplate"); return currentDigester; }
From source file:ca.sqlpower.architect.ProjectLoader.java
protected Digester setupDigester() throws ParserConfigurationException, SAXException { Digester d = new Digester(new UnescapingSaxParser()); final ArchitectSession messageOwner = (siblingSession == null ? session : siblingSession); d.setValidating(false);/*from w w w. ja va 2 s . co m*/ d.push(session); d.addRule("architect-enterprise-project", new Rule() { @Override public void begin(String namespace, String name, Attributes attributes) throws Exception { UserPrompter loadingWarningPrompt = messageOwner.createUserPrompter( "This file contains an Enterprise project and can only\n" + "be opened in the Architect Enterprise Edition.", UserPromptType.BOOLEAN, UserPromptOptions.OK_CANCEL, UserPromptResponse.CANCEL, UserPromptResponse.CANCEL, "Get Enterprise", "Cancel"); UserPromptResponse upr = loadingWarningPrompt.promptUser(); if (upr == UserPromptResponse.OK) { try { BrowserUtil.launch("http://www.sqlpower.ca/page/architect-e"); } catch (IOException e) { throw new DigesterCancelledException(); } } throw new DigesterCancelledException(); } }); //app version number d.addRule("architect-project", new Rule() { @Override public void begin(String namespace, String name, Attributes attributes) throws Exception { fileVersion = attributes.getValue("appversion"); String loadingMessage; try { if (fileVersion == null) { loadingMessage = "The version of the file cannot be found."; fileVersion = "0"; } else if (ArchitectVersion.APP_FULL_VERSION.compareTo(new ArchitectVersion(fileVersion)) < 0) { loadingMessage = "This file was last saved with a newer version.\n" + "Loading with an older version may cause data loss."; } else { return; } } catch (Exception e) { loadingMessage = "The version of the file cannot be understood."; } UserPrompter loadingWarningPrompt = messageOwner.createUserPrompter( loadingMessage + "\nDo you wish to try and open the file?", UserPromptType.BOOLEAN, UserPromptOptions.OK_NOTOK_CANCEL, UserPromptResponse.OK, UserPromptResponse.OK, "Try loading", "Upgrade...", "Cancel"); UserPromptResponse response = loadingWarningPrompt.promptUser(); if (response == UserPromptResponse.OK) { //continue to try loading } else if (response == UserPromptResponse.NOT_OK) { BrowserUtil.launch(SPSUtils.SQLP_ARCHITECT_URL); throw new DigesterCancelledException(); } else if (response == UserPromptResponse.CANCEL) { throw new DigesterCancelledException(); } } }); // project name d.addCallMethod("architect-project/project-name", "setName", 0); // argument is element body text // source DB connection specs (deprecated in favour of project-data-sources; this is only here for backward compatibility) DBCSFactory dbcsFactory = new DBCSFactory(); d.addFactoryCreate("architect-project/project-connection-specs/dbcs", dbcsFactory); d.addSetProperties("architect-project/project-connection-specs/dbcs", new String[] { "connection-name", "driver-class", "jdbc-url", "user-name", "user-pass", "sequence-number", "single-login" }, new String[] { "displayName", "driverClass", "url", "user", "pass", "seqNo", "singleLogin" }); d.addCallMethod("architect-project/project-connection-specs/dbcs", "setName", 0); // these instances get picked out of the dbcsIdMap by the SQLDatabase factory // project data sources (replaces project connection specs) d.addFactoryCreate("architect-project/project-data-sources/data-source", dbcsFactory); d.addCallMethod("architect-project/project-data-sources/data-source/property", "put", 2); d.addCallParam("architect-project/project-data-sources/data-source/property", 0, "key"); d.addCallParam("architect-project/project-data-sources/data-source/property", 1, "value"); // for the project-data-sources, these instances get picked out of the dbcsIdMap by the SQLDatabase factory // but for the create kettle job settings, we add them explicitly // source database hierarchy d.addObjectCreate("architect-project/source-databases", LinkedList.class); d.addSetNext("architect-project/source-databases", "setSourceDatabaseList"); SQLDatabaseFactory dbFactory = new SQLDatabaseFactory(); d.addFactoryCreate("architect-project/source-databases/database", dbFactory); d.addSetProperties("architect-project/source-databases/database"); d.addSetNext("architect-project/source-databases/database", "add"); d.addObjectCreate("architect-project/source-databases/database/catalog", SQLCatalog.class); d.addSetProperties("architect-project/source-databases/database/catalog"); d.addSetNext("architect-project/source-databases/database/catalog", "addChild"); SQLSchemaFactory schemaFactory = new SQLSchemaFactory(); d.addFactoryCreate("*/schema", schemaFactory); d.addSetProperties("*/schema"); d.addSetNext("*/schema", "addChild"); SQLTableFactory tableFactory = new SQLTableFactory(); d.addFactoryCreate("*/table", tableFactory); d.addSetProperties("*/table"); d.addCallMethod("*/remarks", "setRemarks", 0); d.addSetNext("*/table", "addChild"); d.addFactoryCreate("*/folder", new SQLFolderFactory()); SQLColumnFactory columnFactory = new SQLColumnFactory(); d.addFactoryCreate("*/column", columnFactory); d.addSetProperties("*/column"); d.addCallMethod("*/remarks", "setRemarks", 0); // this needs to be manually set last to prevent generic types // from overwriting database specific types // Old name (it has been updated to sourceDataTypeName) d.addCallMethod("*/column", "setSourceDataTypeName", 1); d.addCallParam("*/column", 0, "sourceDBTypeName"); // new name d.addCallMethod("*/column", "setSourceDataTypeName", 1); d.addCallParam("*/column", 0, "sourceDataTypeName"); d.addSetNext("*/column", "addChild"); SQLRelationshipFactory relationshipFactory = new SQLRelationshipFactory(); d.addFactoryCreate("*/relationship", relationshipFactory); d.addSetProperties("*/relationship"); // the factory adds the relationships to the correct PK and FK tables ColumnMappingFactory columnMappingFactory = new ColumnMappingFactory(); d.addFactoryCreate("*/column-mapping", columnMappingFactory); d.addSetProperties("*/column-mapping"); d.addSetNext("*/column-mapping", "addChild"); SQLIndexFactory indexFactory = new SQLIndexFactory(); d.addFactoryCreate("*/index", indexFactory); d.addSetProperties("*/index"); d.addSetNext("*/index", "addChild"); SQLIndexColumnFactory indexColumnFactory = new SQLIndexColumnFactory(); d.addFactoryCreate("*/index-column", indexColumnFactory); d.addSetProperties("*/index-column"); d.addSetNext("*/index-column", "addChild"); SQLExceptionFactory exceptionFactory = new SQLExceptionFactory(); d.addFactoryCreate("*/sql-exception", exceptionFactory); d.addSetProperties("*/sql-exception"); d.addSetNext("*/sql-exception", "setChildrenInaccessibleReason"); TargetDBFactory targetDBFactory = new TargetDBFactory(); // target database hierarchy d.addFactoryCreate("architect-project/target-database", targetDBFactory); d.addSetProperties("architect-project/target-database"); DDLGeneratorFactory ddlgFactory = new DDLGeneratorFactory(); d.addFactoryCreate("architect-project/ddl-generator", ddlgFactory); d.addSetProperties("architect-project/ddl-generator"); d.addSetNext("architect-project/ddl-generator", "setDDLGenerator"); LiquibaseSettingsFactory lbFactory = new LiquibaseSettingsFactory(); d.addFactoryCreate("architect-project/liquibase-settings", lbFactory); d.addSetProperties("architect-project/liquibase-settings"); d.addSetNext("architect-project/liquibase-settings", "setLiquibaseSettings"); ProfileManagerFactory profileManagerFactory = new ProfileManagerFactory(); d.addFactoryCreate("*/profiles", profileManagerFactory); d.addSetProperties("*/profiles"); /* * Backward compatibility: the table and column profiles used to be * stored as siblings to each other, with the parent of a column result * being the last table result that was read. */ ProfileResultFactory profileResultFactory = new ProfileResultFactory(); d.addFactoryCreate("*/profiles/profile-result", profileResultFactory); /* * backward compatibility: the exception property used to be a boolean, and now it's an actual exception. * this causes an IllegalArgumentException when parsing old files. * this workaround tells the digester not to auto-map the exception property. */ d.addRule("*/profiles/profile-result", new SetPropertiesRule(new String[] { "exception" }, new String[] {})); d.addSetNext("*/profiles/profile-result", "loadResult"); d.addFactoryCreate("*/profiles/table-profile-result", new TableProfileResultFactory()); d.addRule("*/profiles/table-profile-result", new SetPropertiesRule(new String[] { "exception" }, new String[] {})); d.addSetNext("*/profiles/table-profile-result", "addTableProfileResult"); d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result", new ColumnProfileResultFactory()); d.addRule("*/profiles/table-profile-result/column-profile-result", new SetPropertiesRule(new String[] { "exception" }, new String[] {})); d.addSetNext("*/profiles/table-profile-result/column-profile-result", "addColumnProfileResult"); ProfileResultValueFactory profileResultValueFactory = new ProfileResultValueFactory(); d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/avgValue", profileResultValueFactory); d.addSetNext("*/profiles/table-profile-result/column-profile-result/avgValue", "setAvgValue"); d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/minValue", profileResultValueFactory); d.addSetNext("*/profiles/table-profile-result/column-profile-result/minValue", "setMinValue"); d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/maxValue", profileResultValueFactory); d.addSetNext("*/profiles/table-profile-result/column-profile-result/maxValue", "setMaxValue"); ProfileResultTopNValueFactory topNValueFactory = new ProfileResultTopNValueFactory(); d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/topNvalue", topNValueFactory); d.addSetNext("*/profiles/table-profile-result/column-profile-result/topNvalue", "addValueCount"); FileFactory fileFactory = new FileFactory(); d.addFactoryCreate("*/file", fileFactory); d.addSetNext("*/file", "setFile"); return d; }
From source file:org.apache.lucene.gdata.server.administration.AccountBuilder.java
/** * Reads the xml from the provided reader and binds the values to the * @param reader - the reader to read the xml from * @return - the GDataAccount /*from www . ja va2 s . com*/ * @throws IOException - if an IOException occurs * @throws SAXException - if the xml can not be parsed by the sax reader */ public static GDataAccount buildAccount(final Reader reader) throws IOException, SAXException { if (reader == null) throw new IllegalArgumentException("Reader must not be null"); URL resource = AccountBuilder.class.getResource("/gdata-account.xsd"); if (resource == null) throw new RuntimeException( "can not find xml schema file 'gdata-account.xsd' -- file must be present on the classpath"); String schemaFile = resource.getFile(); GDataAccount account = null; /* * Force using apache xerces parser for digester */ SAXParser parser = new SAXParser(); parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schemaFile); Digester digester = new Digester(parser); digester.setValidating(true); digester.setErrorHandler(new SimpleSaxErrorHandler()); digester.setSchema(schemaFile); digester.addObjectCreate("account", GDataAccount.class); digester.addBeanPropertySetter("account/account-name", "name"); digester.addBeanPropertySetter("account/password", "password"); digester.addBeanPropertySetter("account/account-role", "rolesAsInt"); digester.addBeanPropertySetter("account/account-owner/name", "authorname"); digester.addBeanPropertySetter("account/account-owner/email-address", "authorMail"); digester.addBeanPropertySetter("account/account-owner/url", "authorLink"); account = (GDataAccount) digester.parse(reader); return account; }
From source file:org.apache.lucene.gdata.server.registry.RegistryBuilder.java
/** * builds the {@link GDataServerRegistry} accessible via the * {@link GDataServerRegistry#getRegistry()} method * /*from w w w. j a v a 2s . c o m*/ * @throws IOException - * if an IOException occurs while reading the config file * @throws SAXException - * if the config file can not be parsed */ static void buildRegistry() throws IOException, SAXException { String schemaFile = RegistryBuilder.class.getResource("/gdata-config.xsd").getFile(); /* * Force using apache xerces parser for digester */ SAXParser parser = new SAXParser(); parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schemaFile); Digester digester = new Digester(parser); buildFromConfiguration(digester, GDataServerRegistry.getRegistry(), schemaFile); }
From source file:org.apache.myfaces.custom.skin.config.ConfigParser.java
/** * */// w ww.ja v a 2s . c o m static public RequestContextBean parseConfigFile(ExternalContext externalContext) { RequestContextBean bean = new RequestContextBean(); InputStream in = externalContext.getResourceAsStream(_SKINS_CONFIG_FILE); if (in == null) { in = externalContext.getResourceAsStream(_TRINIDAD_CONFIG_FILE); } if (in != null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); Digester digester = new Digester(factory.newSAXParser()); digester.setValidating(false); digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); RequestContextBean.addXmlRules(digester); InputSource input = new InputSource(); input.setByteStream(in); input.setPublicId(_SKINS_CONFIG_FILE); digester.parse(input); bean = (RequestContextBean) digester.getRoot(); } catch (IOException ioe) { _LOG.warning(ioe); } catch (ParserConfigurationException pce) { _LOG.warning(pce); } catch (SAXException saxe) { _LOG.warning(saxe); } finally { try { in.close(); } catch (IOException ioe) { // Ignore ; } } } return bean; }
From source file:org.apache.myfaces.trinidadbuild.plugin.faces.AbstractFacesMojo.java
protected URL[] readIndex(MavenProject project) throws MojoExecutionException { try {/* w w w .j a va 2 s.c o m*/ // 1. read master faces-config.xml resources List masters = getMasterConfigs(project); if (masters.isEmpty()) { getLog().warn("Master faces-config.xml not found"); return new URL[0]; } else { List entries = new LinkedList(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); // requires JAXP 1.3, in JavaSE 5.0 // spf.setXIncludeAware(false); for (Iterator<URL> i = masters.iterator(); i.hasNext();) { URL url = i.next(); Digester digester = new Digester(spf.newSAXParser()); digester.setNamespaceAware(true); // XInclude digester.setRuleNamespaceURI(XIncludeFilter.XINCLUDE_NAMESPACE); digester.addCallMethod("faces-config/include", "add", 1); digester.addFactoryCreate("faces-config/include", URLCreationFactory.class); digester.addCallParam("faces-config/include", 0, 0); digester.push(url); digester.push(entries); digester.parse(url.openStream()); } return (URL[]) entries.toArray(new URL[0]); } } catch (ParserConfigurationException e) { throw new MojoExecutionException("Failed to parse master config", e); } catch (SAXException e) { throw new MojoExecutionException("Failed to parse master config", e); } catch (IOException e) { throw new MojoExecutionException("Failed to parse master config", e); } }
From source file:org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacesConfigParser.java
static protected Digester createEmptyDigester() throws ParserConfigurationException, SAXException { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true);//from www. java2 s.co m // requires JAXP 1.3, in JavaSE 5.0 // spf.setXIncludeAware(true); Digester digester = new Digester(spf.newSAXParser()); digester.setNamespaceAware(true); return digester; }