List of usage examples for org.apache.commons.digester Digester parse
public Object parse(URL url) throws IOException, SAXException
From source file:com.npower.dm.hibernate.management.ClientProvTemplateBeanImpl.java
/** * @param in//from w ww . jav a 2 s . c om * @return */ private List<ClientProvTemplate> parsingClientProvTemplates(InputStream in, String relativeBaseDir) throws DMException { // Create and execute our Digester Digester digester = createClientProvTemplateDigester(relativeBaseDir); try { // Push a ManagementBeanFactory into the stack. digester.push(this.getManagementBeanFactory()); List<ClientProvTemplate> result = new ArrayList<ClientProvTemplate>(); digester.push(result); digester.parse(in); return result; } catch (Exception e) { throw new DMException(e); } }
From source file:cucumber.templates.PerRepositoryTemplatesTest.java
/** * Parses given file.//www.ja va 2 s .c o m * @param file the file to parse. * @param digester the {@link Digester} instance. * @return the list of {@link BeanElement}s in the file. */ @NotNull protected List<BeanElement> parseFile(@NotNull final File file, @NotNull final Digester digester) { @NotNull final List<BeanElement> result = new ArrayList<BeanElement>( 1 /* jndi */ + 1 /* transaction manager */ + 2 * (getTableNames().size())); digester.push(result); try { digester.parse(file); } catch (@NotNull final IOException e) { Assert.fail(e.getMessage()); } catch (@NotNull final SAXException e) { Assert.fail(e.getMessage()); } return result; }
From source file:catalina.core.StandardHostDeployer.java
/** * <p>Install a new web application, whose context configuration file * (consisting of a <code><Context></code> element) and (optional) * web application archive are at the specified URLs.</p> * * If this application is successfully installed, a ContainerEvent of type * <code>PRE_INSTALL_EVENT</code> will be sent to registered listeners * before the associated Context is started, and a ContainerEvent of type * <code>INSTALL_EVENT</code> will be sent to all registered listeners * after the associated Context is started, with the newly created * <code>Context</code> as an argument. * * @param config A URL that points to the context configuration descriptor * to be used for configuring the new Context * @param war A URL of type "jar:" that points to a WAR file, or type * "file:" that points to an unpacked directory structure containing * the web application to be installed, or <code>null</code> to use * the <code>docBase</code> attribute from the configuration descriptor * * @exception IllegalArgumentException if one of the specified URLs is * null/*from ww w. j a va 2s. c o m*/ * @exception IllegalStateException if the context path specified in the * context configuration file is already attached to an existing web * application * @exception IOException if an input/output error was encountered * during installation */ public synchronized void install(URL config, URL war) throws IOException { // Validate the format and state of our arguments if (config == null) throw new IllegalArgumentException(sm.getString("standardHost.configRequired")); if (!host.isDeployXML()) throw new IllegalArgumentException(sm.getString("standardHost.configNotAllowed")); // Calculate the document base for the new web application (if needed) String docBase = null; // Optional override for value in config file if (war != null) { String url = war.toString(); host.log(sm.getString("standardHost.installingWAR", url)); // Calculate the WAR file absolute pathname if (url.startsWith("jar:")) { url = url.substring(4, url.length() - 2); } if (url.startsWith("file://")) docBase = url.substring(7); else if (url.startsWith("file:")) docBase = url.substring(5); else throw new IllegalArgumentException(sm.getString("standardHost.warURL", url)); } // Install the new web application this.context = null; this.overrideDocBase = docBase; InputStream stream = null; try { stream = config.openStream(); Digester digester = createDigester(); digester.setDebug(host.getDebug()); digester.clear(); digester.push(this); digester.parse(stream); stream.close(); stream = null; } catch (Exception e) { host.log(sm.getString("standardHost.installError", docBase), e); throw new IOException(e.toString()); } finally { if (stream != null) { try { stream.close(); } catch (Throwable t) { ; } } } }
From source file:catalina.realm.JAASMemoryLoginModule.java
/** * Load the contents of our configuration file. *//*from w w w .j a va2 s. c o m*/ protected void load() { // Validate the existence of our configuration file File file = new File(pathname); if (!file.isAbsolute()) file = new File(System.getProperty("catalina.base"), pathname); if (!file.exists() || !file.canRead()) { log("Cannot load configuration file " + file.getAbsolutePath()); return; } // Load the contents of our configuration file Digester digester = new Digester(); digester.setValidating(false); digester.addRuleSet(new MemoryRuleSet()); try { digester.push(this); digester.parse(file); } catch (Exception e) { log("Error processing configuration file " + file.getAbsolutePath(), e); return; } }
From source file:com.npower.dm.hibernate.management.ProfileMappingBeanImpl.java
public List<ProfileMapping> parsingProfileMapping(InputStream in, String defaultManufacturerExternalID, String defaultModelExternalID) throws DMException { // Create and execute our Digester Digester digester = createProfileMappingDigester(defaultManufacturerExternalID, defaultModelExternalID); try {// ww w. j av a 2 s . co m // Push a ManagementBeanFactory into the stack. digester.push(this.getManagementBeanFactory()); List<ProfileMapping> result = new ArrayList<ProfileMapping>(); digester.push(result); digester.parse(in); return result; } catch (Exception e) { throw new DMException(e); } }
From source file:fr.paris.lutece.plugins.document.modules.metadatadublincore.business.DublinCoreMetadata.java
/** * Load dublin core metadata from an XML stream * @param strXmlData The XML content to get the attributes from *//* www. j av a 2s . c o m*/ public void load(String strXmlData) { // Configure Digester from XML ruleset URL rules = getClass().getResource(FILE_RULES); Digester digester = DigesterLoader.createDigester(rules); // Push empty List onto Digester's Stack digester.push(this); try { if (strXmlData != null) { StringReader sr = new StringReader(strXmlData); digester.parse(sr); } } catch (FileNotFoundException e) { AppLogService.error(e.getMessage(), e); } catch (SAXException e) { AppLogService.error(e.getMessage(), e); } catch (IOException e) { AppLogService.error(e.getMessage(), e); } }
From source file:hudson.scm.CVSChangeLogSet.java
public static CVSChangeLogSet parse(final AbstractBuild<?, ?> build, final java.io.File f) throws IOException, SAXException { Digester digester = new Digester2(); ArrayList<CVSChangeLog> r = new ArrayList<CVSChangeLog>(); digester.push(r);//from w w w. jav a 2s . com digester.addObjectCreate("*/entry", CVSChangeLog.class); digester.addBeanPropertySetter("*/entry/changeDate", "changeDateString"); digester.addBeanPropertySetter("*/entry/date"); digester.addBeanPropertySetter("*/entry/time"); digester.addBeanPropertySetter("*/entry/author", "user"); digester.addBeanPropertySetter("*/entry/msg"); digester.addSetNext("*/entry", "add"); digester.addObjectCreate("*/entry/file", File.class); digester.addBeanPropertySetter("*/entry/file/name"); digester.addBeanPropertySetter("*/entry/file/fullName"); digester.addBeanPropertySetter("*/entry/file/revision"); digester.addBeanPropertySetter("*/entry/file/prevrevision"); digester.addCallMethod("*/entry/file/dead", "setDead"); digester.addSetNext("*/entry/file", "addFile"); try { digester.parse(f); } catch (IOException e) { throw new IOException2("Failed to parse " + f, e); } catch (SAXException e) { throw new IOException2("Failed to parse " + f, e); } // merge duplicate entries. Ant task somehow seems to report duplicate // entries. for (int i = r.size() - 1; i >= 0; i--) { CVSChangeLog log = r.get(i); boolean merged = false; if (!log.isComplete()) { r.remove(log); continue; } for (int j = 0; j < i; j++) { CVSChangeLog c = r.get(j); if (c.canBeMergedWith(log)) { c.merge(log); merged = true; break; } } if (merged) { r.remove(log); } } return new CVSChangeLogSet(build, r); }
From source file:com.npower.dm.hibernate.management.DDFTreeManagementBeanImpl.java
public DDFTree parseDDFTree(InputStream in) throws DMException { // Create and execute our Digester Digester digester = createDDFTreeDigester(); try {/*from w w w .jav a 2s . c o m*/ // Push a DDFTreeEntity into the stack. DDFTreeEntity tree = new DDFTreeEntity(); digester.push(tree); digester.parse(in); // Ignore the "." node in DDF file. testcase: SonyErricsson W900i_2.0.xml /* Set<DDFNode> rootNodes = tree.getRootDDFNodes(); if (rootNodes.size() == 1) { DDFNode rootNode = rootNodes.iterator().next(); String name = rootNode.getName(); if (name != null && name.equals(".")) { Set<DDFNode> children = rootNode.getChildren(); tree.getRootDDFNodes().clear(); tree.getRootDDFNodes().addAll(children); for (DDFNode child: children) { child.setParentDDFNode(null); } tree.getDdfNodes().remove(rootNode); tree.getDdfNodes().addAll(children); } } */ Set<DDFNode> rootNodes = tree.getRootDDFNodes(); boolean includeRootNode = false; for (DDFNode node : rootNodes) { String name = node.getName(); if (name != null && name.equals(".")) { includeRootNode = true; break; } } if (!includeRootNode) { DDFNodeEntity rootDDFNode = new DDFNodeEntity(); rootDDFNode.setDdfTree(tree); rootDDFNode.setName("."); rootDDFNode.setParentDDFNode(null); rootDDFNode.getChildren().addAll(rootNodes); tree.add(rootDDFNode); tree.getRootDDFNodes().clear(); tree.getRootDDFNodes().add(rootDDFNode); for (DDFNode child : rootNodes) { child.setParentDDFNode(rootDDFNode); tree.getDdfNodes().removeAll(rootNodes); } } return tree; } catch (Exception e) { throw new DMException(e); } }
From source file:eu.planets_project.pp.plato.xml.TreeLoader.java
/** * This method imports a FreeMind MindMap defined in an XML file into the * objective tree structure defined by Plato. * @param in an InputStream which contains a FreeMind XML mindmap * @return {@link ObjectiveTree} created from the xml file, * or <code>null</code> if there was an error. * @param hasUnits If this is set to <code>true</code>, we assume * that every leaf node is a measurement unit, and the objective tree * leaves are one level higher. So we stop one level earlier, * the units are not imported at the moment. *//*from w ww . j a v a 2 s.c om*/ public ObjectiveTree loadFreeMindStream(InputStream in, boolean hasUnits, boolean hasLeaves) { MindMap map = new MindMap(); // load content into temporary structure Digester digester = new Digester(); digester.setSchema("/data/schemas/freemind.xsd"); digester.setValidating(true); digester.push(map); digester.addObjectCreate("*/node", "eu.planets_project.pp.plato.xml.freemind.Node"); digester.addSetProperties("*/node"); digester.addCallMethod("*/node/hook/text", "setDESCRIPTION", 0); digester.addSetNext("*/node", "addChild"); try { //InputStream s = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); digester.setUseContextClassLoader(true); digester.parse(in); } catch (IOException e) { log.error("Error loading Freemind file. Cause: " + e.getMessage()); return null; } catch (SAXException e) { log.error("Document is not a valid Freemind file. Cause: " + e.getMessage()); return null; } // traverse temp structure of map and nodes and create ObjectiveTree ObjectiveTree tree = new ObjectiveTree(); tree.setRoot(map.getObjectiveTreeRoot(hasUnits, hasLeaves)); if (tree.getRoot().isLeaf()) { return null; } return tree; }
From source file:com.alibaba.antx.config.descriptor.ConfigDescriptorLoader.java
/** ?validators.xmlvalidator */ private Digester loadValidatorPlugins() { Digester digester = new Digester(); digester.setRules(new PluginRules()); digester.addObjectCreate("config-property-validators", HashMap.class); digester.addCallMethod("config-property-validators/validator", "put", 2); digester.addCallParam("config-property-validators/validator", 0, "id"); digester.addCallParam("config-property-validators/validator", 1, "class"); digester.addRule("config-property-validators/validator", new PluginDeclarationRule()); InputStream istream = getClass().getResourceAsStream("validators.xml"); try {/*from w w w . j a va 2 s . co m*/ digester.push(digester.parse(istream)); } catch (Exception e) { throw new ConfigException("Failed to load validators", e); } finally { if (istream != null) { try { istream.close(); } catch (IOException e) { } } } digester.getRules().clear(); return digester; }