Example usage for org.apache.commons.digester3.annotations FromAnnotationsRuleModule FromAnnotationsRuleModule

List of usage examples for org.apache.commons.digester3.annotations FromAnnotationsRuleModule FromAnnotationsRuleModule

Introduction

In this page you can find the example usage for org.apache.commons.digester3.annotations FromAnnotationsRuleModule FromAnnotationsRuleModule.

Prototype

FromAnnotationsRuleModule

Source Link

Usage

From source file:org.efaps.tests.ci.AbstractCIDataProvider.java

/**
 * Load ci.//from  w ww .  j  a  v a  2  s.com
 *
 * @param _context the context
 */
@BeforeSuite
public static void loadCI(final ITestContext _context) {
    final File xmlFile = new File(_context.getCurrentXmlTest().getSuite().getFileName());
    final String baseFolderRel = _context.getCurrentXmlTest().getParameter("baseFolder");
    final String baseFolder = FilenameUtils.concat(xmlFile.getPath(), baseFolderRel);
    AbstractCIDataProvider.LOG.debug("basefolder: '{}'", baseFolder);
    final Collection<File> files = FileUtils.listFiles(new File(baseFolder), new String[] { "xml" }, true);

    for (final File file : files) {
        AbstractCIDataProvider.LOG.debug("file added: '{}'", file);
        final DigesterLoader loader = DigesterLoader.newLoader(new FromAnnotationsRuleModule() {

            @Override
            protected void configureRules() {
                bindRulesFrom(CIForm.class);
                bindRulesFrom(CITable.class);
                bindRulesFrom(CICommand.class);
                bindRulesFrom(CISearch.class);
                bindRulesFrom(CIMenu.class);
                bindRulesFrom(CIType.class);
                bindRulesFrom(CIStatusGroup.class);
                bindRulesFrom(CINumberGenerator.class);
                bindRulesFrom(CIUIImage.class);
                bindRulesFrom(CIJasperImage.class);
                bindRulesFrom(CIAccessSet.class);
                bindRulesFrom(CISQLTable.class);
                bindRulesFrom(CIMsgPhrase.class);
            }
        });
        try {
            final Digester digester = loader.newDigester();
            final URLConnection connection = file.toURI().toURL().openConnection();
            connection.setUseCaches(false);
            final InputStream stream = connection.getInputStream();
            final InputSource source = new InputSource(stream);
            final Object item = digester.parse(source);
            stream.close();
            if (item instanceof ICIItem) {
                ((ICIItem) item).setFile(file.getPath());
            }

            if (item instanceof CIForm) {
                AbstractCIDataProvider.LOG.debug("Form added: '{}'", item);
                AbstractCIDataProvider.FORMS.add((CIForm) item);
            } else if (item instanceof CITable) {
                AbstractCIDataProvider.LOG.debug("Table added: '{}'", item);
                AbstractCIDataProvider.TABLES.add((CITable) item);
            } else if (item instanceof CICommand) {
                AbstractCIDataProvider.LOG.debug("Command added: '{}'", item);
                AbstractCIDataProvider.COMMANDS.add((CICommand) item);
            } else if (item instanceof CIType) {
                AbstractCIDataProvider.LOG.debug("Type added: '{}'", item);
                AbstractCIDataProvider.TYPES.add((CIType) item);
            } else if (item instanceof CIStatusGroup) {
                AbstractCIDataProvider.LOG.debug("CIStatusGroup added: '{}'", item);
                AbstractCIDataProvider.STATUSGRPS.add((CIStatusGroup) item);
            } else if (item instanceof CIMenu) {
                AbstractCIDataProvider.LOG.debug("CIMenu added: '{}'", item);
                AbstractCIDataProvider.MENUS.add((CIMenu) item);
            } else if (item instanceof CINumberGenerator) {
                AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item);
                AbstractCIDataProvider.NUMGENS.add((CINumberGenerator) item);
            } else if (item instanceof CIJasperImage) {
                AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item);
                AbstractCIDataProvider.JASPERIMG.add((CIJasperImage) item);
            } else if (item instanceof CIUIImage) {
                AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item);
                AbstractCIDataProvider.UIIMG.add((CIUIImage) item);
            } else if (item instanceof CIAccessSet) {
                AbstractCIDataProvider.LOG.debug("CIAccessSet added: '{}'", item);
                AbstractCIDataProvider.ACCESSSET.add((CIAccessSet) item);
            } else if (item instanceof CISearch) {
                AbstractCIDataProvider.LOG.debug("CISearch added: '{}'", item);
                AbstractCIDataProvider.SEARCHS.add((CISearch) item);
            } else if (item instanceof CISQLTable) {
                AbstractCIDataProvider.LOG.debug("CISearch added: '{}'", item);
                AbstractCIDataProvider.SQLTABLES.add((CISQLTable) item);
            } else if (item instanceof CIMsgPhrase) {
                AbstractCIDataProvider.LOG.debug("CIMsgPhrase added: '{}'", item);
                AbstractCIDataProvider.MSGPHRASES.add((CIMsgPhrase) item);
            }
        } catch (final MalformedURLException e) {
            AbstractCIDataProvider.LOG.error("MalformedURLException", e);
        } catch (final IOException e) {
            AbstractCIDataProvider.LOG.error("IOException", e);
        } catch (final SAXException e) {
            AbstractCIDataProvider.LOG.error("SAXException", e);
        }
    }

    final Collection<File> propFiles = FileUtils.listFiles(new File(baseFolder), new String[] { "properties" },
            true);
    for (final File file : propFiles) {
        final Properties props = new Properties();
        try {
            props.load(new FileInputStream(file));
            AbstractCIDataProvider.LOG.debug("properties loaded: '{}'", file);
        } catch (final IOException e) {
            AbstractCIDataProvider.LOG.error("IOException", e);
        }
        AbstractCIDataProvider.DBPROPERTIES.putAll(props);
    }

    try {
        final InputStream ignStream = AbstractCIDataProvider.class.getResourceAsStream("/Ignore.properties");
        if (ignStream != null) {
            final Properties ignoreProps = new Properties();
            ignoreProps.load(ignStream);
            AbstractCIDataProvider.DBPROPERTIES.putAll(ignoreProps);
        }
    } catch (final IOException e) {
        AbstractCIDataProvider.LOG.error("IOException", e);
    }
}

From source file:org.efaps.update.version.Application.java

/**
 * <code>null</code> is returned, of the version file could not be opened
 * and read./*  w w  w.j a v  a 2 s  .co  m*/
 *
 * @param _versionUrl URL of the version file which defines the application
 * @param _rootUrl root URL where the source files are located (for local
 *            files); URL of the class file (if source is in a Jar file)
 * @param _classpathElements elements of the class path
 * @return application instance with all version information
 * @throws InstallationException if version XML file could not be parsed
 */
public static Application getApplication(final URL _versionUrl, final URL _rootUrl,
        final List<String> _classpathElements) throws InstallationException {
    Application appl = null;
    try {
        final DigesterLoader loader = DigesterLoader.newLoader(new FromAnnotationsRuleModule() {
            @Override
            protected void configureRules() {
                bindRulesFrom(Application.class);
            }
        });
        final Digester digester = loader.newDigester();
        appl = (Application) digester.parse(_versionUrl);
        appl.rootUrl = _rootUrl;
        appl.classpathElements = _classpathElements;
        for (final InstallFile installFile : appl.tmpElements) {
            appl.install.addFile(installFile.setURL(new URL(_rootUrl, installFile.getName())));
        }
        appl.tmpElements = null;
        Collections.sort(appl.dependencies, new Comparator<Dependency>() {

            @Override
            public int compare(final Dependency _dependency0, final Dependency _dependency1) {
                return _dependency0.getOrder().compareTo(_dependency1.getOrder());
            }
        });
        for (final ApplicationVersion applVers : appl.getVersions()) {
            applVers.setApplication(appl);
            appl.setMaxVersion(applVers.getNumber());
        }

    } catch (final IOException e) {
        if (e.getCause() instanceof InstallationException) {
            throw (InstallationException) e.getCause();
        } else {
            throw new InstallationException("Could not open / read version file '" + _versionUrl + "'");
        }
        //CHECKSTYLE:OFF
    } catch (final Exception e) {
        //CHECKSTYLE:ON
        throw new InstallationException("Error while parsing file '" + _versionUrl + "'", e);
    }
    return appl;
}

From source file:org.gbif.registry.metasync.protocols.BaseProtocolHandler.java

/**
 * Returns a new Digester which is configured with the annotation rules from the passed in class.
 */// w  w w.j ava 2s  . c om
protected Digester newDigester(final Class<?> clazz) {
    DigesterLoader loader = newLoader(new FromAnnotationsRuleModule() {

        @Override
        protected void configureRules() {
            bindRulesFrom(clazz);
        }
    });

    loader.setNamespaceAware(true);
    ConvertUtils.register(new DateTimeConverter(), DateTime.class);
    ConvertUtils.register(new LanguageConverter(), Language.class);
    ConvertUtils.register(new PeriodConverter(), Period.class);
    ConvertUtils.register(new UriConverter(), URI.class);
    return loader.newDigester();
}