Example usage for org.apache.commons.digester Digester setSchema

List of usage examples for org.apache.commons.digester Digester setSchema

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester setSchema.

Prototype

@Deprecated
public void setSchema(String schemaLocation) 

Source Link

Document

Set the XML Schema URI used for validating the input XML.

Usage

From source file:com.liusoft.sc.startup.DigesterFactory.java

/**
 * Turn on DTD and/or validation (based on the parser implementation)
 *//*www . j  ava 2 s.c  om*/
protected static void configureSchema(Digester digester) {
    URL url = DigesterFactory.class.getResource(Constants.WebSchemaResourcePath_24);

    if (url == null) {
        log.error("Could not get url for " + Constants.WebSchemaResourcePath_24);
    } else {
        digester.setSchema(url.toString());
    }
}

From source file:eu.planets_project.pp.plato.xml.TreeLoader.java

public PolicyTree loadFreeMindPolicyTree(InputStream in) {
    MindMap map = new MindMap();

    // load content into temporary structure
    Digester digester = new Digester();
    digester.setSchema("/data/schemas/freemind.xsd");
    digester.setValidating(true);//from w  w w.  j ava2  s  . c  o m
    digester.push(map);

    digester.addObjectCreate("*/node", "eu.planets_project.pp.plato.xml.freemind.Node");
    digester.addSetProperties("*/node");
    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;
    }

    PolicyTree tree = new PolicyTree();
    tree.setRoot(map.getPolicyTreeRoot());
    return tree;
}

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   www  .j  a  va 2s. c o m
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:org.apache.catalina.startup.DigesterFactory.java

/**
 * Turn on DTD and/or validation (based on the parser implementation)
 *//*from www  .  ja  v  a2 s  . co  m*/
protected static void turnOnValidation(Digester digester) {
    URL url = DigesterFactory.class.getResource(Constants.WebSchemaResourcePath_24);
    digester.setSchema(url.toString());
}

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 //  w  w w.j a  v a 2  s. co  m
 * @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

private static void buildFromConfiguration(Digester digester, GDataServerRegistry registry, String schemaURL)
        throws IOException, SAXException {
    digester.setValidating(true);//ww w .  j a  v a  2  s.c o  m
    digester.setSchema(schemaURL);
    digester.setErrorHandler(new SimpleSaxErrorHandler());
    digester.push(registry);
    /*
     * register services
     */
    digester.addObjectCreate("gdata/service", ProvidedServiceConfig.class);
    digester.addSetProperties("gdata/service");
    digester.addSetNext("gdata/service", "registerService");
    digester.addBeanPropertySetter("gdata/service/feed-class", "feedType");
    digester.addBeanPropertySetter("gdata/service/entry-class", "entryType");
    digester.addBeanPropertySetter("gdata/service/extension-profile", "extensionProfileClass");
    digester.addBeanPropertySetter("gdata/service/previewStyleSheet", "xsltStylesheet");
    addIndexRule(digester);
    /*
     * load components and configurations
     */
    digester.addCallMethod("gdata/server-components/component", "registerComponent", 2,
            new Class[] { Class.class, ComponentConfiguration.class });
    digester.addCallParam("gdata/server-components/component/class", 0);
    digester.addObjectCreate("gdata/server-components/component/configuration", ComponentConfiguration.class);
    digester.addCallMethod("gdata/server-components/component/configuration/property", "set", 2,
            new Class[] { String.class, String.class });
    digester.addCallParam("gdata/server-components/component/configuration/property", 0, "name");
    digester.addCallParam("gdata/server-components/component/configuration/property", 1);
    //second parameter on registerComponent -- top of the stack (Component configuration)
    digester.addCallParam("gdata/server-components/component/configuration", 1, 0);
    digester.parse(RegistryBuilder.class.getResourceAsStream("/gdata-config.xml"));

}

From source file:org.kuali.kfs.module.ar.batch.CustomerInvoiceWriteoffBatchDigesterTest.java

/**
 * @return fully-initialized Digester used to process entry XML files
 *//*from w w  w .  ja v  a2  s.  c  o m*/
private Digester buildDigester(String schemaLocation, String digestorRulesFileName) {
    Digester digester = new Digester();
    digester.setNamespaceAware(false);
    digester.setValidating(true);
    digester.setErrorHandler(new XmlErrorHandler());
    digester.setSchema(schemaLocation);

    Rules rules = loadRules(digestorRulesFileName);

    digester.setRules(rules);

    return digester;
}

From source file:org.kuali.kfs.sys.batch.XmlBatchInputFileTypeBase.java

/**
 * @return fully-initialized Digester used to process entry XML files
 *//*  w ww  .j a v a  2s.  co m*/
protected Digester buildDigester(String schemaLocation, String digestorRulesFileName) {
    Digester digester = new Digester();
    digester.setNamespaceAware(false);
    digester.setValidating(true);
    digester.setErrorHandler(new XmlErrorHandler());
    digester.setSchema(schemaLocation);

    Rules rules = loadRules(digestorRulesFileName);

    digester.setRules(rules);

    return digester;
}

From source file:org.sipfoundry.fswitchtester.TesterConfigParser.java

public TesterConfig parse(String fileName) {
    Digester digester = new Digester();
    digester.setSchema("file:schema/tester.xsd");
    addRules(digester);/*from w  ww  .  j av  a  2  s . c  om*/
    // Process the input file.
    String url = "file:" + fileName;
    try {
        InputSource inputSource = new InputSource(url);
        digester.parse(inputSource);
        return (TesterConfig) digester.getRoot();

    } catch (Exception se) {
        se.printStackTrace(System.err);
        throw new FreeSwitchTesterException("exception parsing config file", se);
    }

}

From source file:org.sipfoundry.sipxbridge.ConfigurationParser.java

/**
 * Create an account manager structure and initialize it with the information pointed to by
 * the given URL.//from  ww w. j av a  2 s  .c  o  m
 *
 * @param url -- the rul from where to fetch the config file.
 *
 * @return
 */

public AccountManagerImpl createAccountManager(String url) {
    // Create a Digester instance
    Digester digester = new Digester();

    digester.setSchema("file:schema/sipxbridge.xsd");

    addRules(digester);

    // Process the input file.
    try {
        InputSource inputSource = new InputSource(url);
        digester.parse(inputSource);
        AccountManagerImpl accountManagerImpl = (AccountManagerImpl) digester.getRoot();
        BridgeConfiguration bridgeConfiguration = accountManagerImpl.getBridgeConfiguration();
        if (bridgeConfiguration.getStunServerAddress() == null) {
            for (ItspAccountInfo itspAccountInfo : accountManagerImpl.getItspAccounts()) {
                if (itspAccountInfo.isGlobalAddressingUsed() && bridgeConfiguration.getGlobalAddress() == null)
                    throw new SAXException(
                            "Need stun server address or public address to be specified in sipxbridge configuration.");

            }
        }
        return (AccountManagerImpl) digester.getRoot();
    } catch (java.io.IOException ioe) {
        // Note that we do not have a debug file here so we need to print to stderr.
        ioe.printStackTrace(System.err);
        throw new SipXbridgeException("Initialization exception", ioe);
    } catch (org.xml.sax.SAXException se) {
        se.printStackTrace(System.err);
        throw new SipXbridgeException("Initialization exception", se);
    }

}