Search in sources :

Example 6 with Rule

use of org.geotoolkit.sld.xml.v100.Rule in project opencms-core by alkacon.

the class CmsModuleImportExportHandler method readModuleFromManifest.

/**
 * Reads a module object from an external file source.<p>
 *
 * @param manifest the manifest data
 *
 * @return the imported module
 *
 * @throws CmsConfigurationException if the module could not be imported
 */
public static CmsModule readModuleFromManifest(byte[] manifest) throws CmsConfigurationException {
    // instantiate Digester and enable XML validation
    Digester digester = new Digester();
    digester.setUseContextClassLoader(true);
    digester.setValidating(false);
    digester.setRuleNamespaceURI(null);
    digester.setErrorHandler(new CmsXmlErrorHandler("manifest data"));
    // add this class to the Digester
    CmsModuleImportExportHandler handler = new CmsModuleImportExportHandler();
    final String[] version = new String[] { null };
    digester.push(handler);
    digester.addRule("*/export_version", new Rule() {

        @Override
        public void body(String namespace, String name, String text) throws Exception {
            version[0] = text.trim();
        }
    });
    CmsModuleXmlHandler.addXmlDigesterRules(digester);
    InputStream stream = new ByteArrayInputStream(manifest);
    try {
        digester.parse(stream);
    } catch (IOException e) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_IO_MODULE_IMPORT_1, "manifest data");
        LOG.error(message.key(), e);
        throw new CmsConfigurationException(message, e);
    } catch (SAXException e) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_SAX_MODULE_IMPORT_1, "manifest data");
        LOG.error(message.key(), e);
        throw new CmsConfigurationException(message, e);
    }
    CmsModule importedModule = handler.getModule();
    // the digester must have set the module now
    if (importedModule == null) {
        throw new CmsConfigurationException(Messages.get().container(Messages.ERR_IMPORT_MOD_ALREADY_INSTALLED_1, "manifest data"));
    } else {
        importedModule.setExportVersion(version[0]);
    }
    return importedModule;
}
Also used : CmsConfigurationException(org.opencms.configuration.CmsConfigurationException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) CmsConfigurationException(org.opencms.configuration.CmsConfigurationException) CmsXmlException(org.opencms.xml.CmsXmlException) CmsSecurityException(org.opencms.security.CmsSecurityException) CmsException(org.opencms.main.CmsException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) CmsImportExportException(org.opencms.importexport.CmsImportExportException) SAXException(org.xml.sax.SAXException) CmsMessageContainer(org.opencms.i18n.CmsMessageContainer) ByteArrayInputStream(java.io.ByteArrayInputStream) Digester(org.apache.commons.digester3.Digester) Rule(org.apache.commons.digester3.Rule) CmsXmlErrorHandler(org.opencms.xml.CmsXmlErrorHandler)

Example 7 with Rule

use of org.geotoolkit.sld.xml.v100.Rule in project geotoolkit by Geomatys.

the class SEforSLD100Test method testRule.

@Test
public void testRule() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_RULE);
    assertNotNull(obj);
    Rule jax = (Rule) obj;
    MutableRule rule = TRANSFORMER_GT.visitRule(jax);
    assertNotNull(rule);
    assertEquals(rule.getName(), valueName);
    assertEquals(rule.getDescription().getTitle().toString(), valueTitle);
    assertEquals(rule.getDescription().getAbstract().toString(), valueAbstract);
    assertEquals(rule.getMinScaleDenominator(), 500d, DELTA);
    assertEquals(rule.getMaxScaleDenominator(), 1000d, DELTA);
    assertNull(rule.getLegend());
    assertNotNull(rule.getFilter());
    assertEquals(rule.symbolizers().size(), 4);
    // Write test
    Rule pvt = TRANSFORMER_OGC.visit(rule, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), valueName);
    assertEquals(pvt.getTitle(), valueTitle);
    assertEquals(pvt.getAbstract(), valueAbstract);
    assertEquals(pvt.getMinScaleDenominator(), 500d, DELTA);
    assertEquals(pvt.getMaxScaleDenominator(), 1000d, DELTA);
    assertNull(pvt.getLegendGraphic());
    assertEquals(pvt.getSymbolizer().size(), 4);
    MARSHALLER.marshal(pvt, TEST_FILE_SE_RULE);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) Marshaller(javax.xml.bind.Marshaller) MutableRule(org.geotoolkit.style.MutableRule) Rule(org.geotoolkit.sld.xml.v100.Rule) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 8 with Rule

use of org.geotoolkit.sld.xml.v100.Rule in project umple by umple.

the class M5P method graph.

/**
 * Return a dot style String describing the tree.
 *
 * @return a <code>String</code> value
 * @throws Exception if an error occurs
 */
@Override
public String graph() throws Exception {
    StringBuffer text = new StringBuffer();
    text.append("digraph M5Tree {\n");
    Rule temp = m_ruleSet.get(0);
    temp.topOfTree().graph(text);
    text.append("}\n");
    return text.toString();
}
Also used : Rule(weka.classifiers.trees.m5.Rule)

Example 9 with Rule

use of org.geotoolkit.sld.xml.v100.Rule in project opencms-core by alkacon.

the class CmsModuleImportExportHandler method readModuleFromImport.

/**
 * Reads a module object from an external file source.<p>
 *
 * @param importResource the name of the input source
 *
 * @return the imported module
 *
 * @throws CmsConfigurationException if the module could not be imported
 */
public static CmsModule readModuleFromImport(String importResource) throws CmsConfigurationException {
    // instantiate Digester and enable XML validation
    Digester digester = new Digester();
    digester.setUseContextClassLoader(true);
    digester.setValidating(false);
    digester.setRuleNamespaceURI(null);
    digester.setErrorHandler(new CmsXmlErrorHandler(importResource));
    // add this class to the Digester
    CmsModuleImportExportHandler handler = new CmsModuleImportExportHandler();
    final String[] version = new String[] { null };
    digester.push(handler);
    digester.addRule("*/export_version", new Rule() {

        @Override
        public void body(String namespace, String name, String text) throws Exception {
            version[0] = text.trim();
        }
    });
    CmsModuleXmlHandler.addXmlDigesterRules(digester);
    InputStream stream = null;
    ZipFile importZip = null;
    try {
        File file = new File(importResource);
        if (!file.exists()) {
            throw new IOException("readModuleFromImport: Path '" + importResource + "' does not exist.");
        }
        if (file.isFile()) {
            importZip = new ZipFile(importResource);
            ZipEntry entry = importZip.getEntry(CmsImportExportManager.EXPORT_MANIFEST);
            if (entry != null) {
                stream = importZip.getInputStream(entry);
            } else {
                CmsMessageContainer message = Messages.get().container(Messages.ERR_NO_MANIFEST_MODULE_IMPORT_1, importResource);
                LOG.error(message.key());
                throw new CmsConfigurationException(message);
            }
        } else if (file.isDirectory()) {
            file = new File(file, CmsImportExportManager.EXPORT_MANIFEST);
            stream = new FileInputStream(file);
        }
        // start the parsing process
        digester.parse(stream);
    } catch (IOException e) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_IO_MODULE_IMPORT_1, importResource);
        LOG.error(message.key(), e);
        throw new CmsConfigurationException(message, e);
    } catch (SAXException e) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_SAX_MODULE_IMPORT_1, importResource);
        LOG.error(message.key(), e);
        throw new CmsConfigurationException(message, e);
    } finally {
        try {
            if (importZip != null) {
                importZip.close();
            }
            if (stream != null) {
                stream.close();
            }
        } catch (Exception e) {
        // noop
        }
    }
    CmsModule importedModule = handler.getModule();
    // the digester must have set the module now
    if (importedModule == null) {
        throw new CmsConfigurationException(Messages.get().container(Messages.ERR_IMPORT_MOD_ALREADY_INSTALLED_1, importResource));
    } else {
        importedModule.setExportVersion(version[0]);
    }
    return importedModule;
}
Also used : CmsConfigurationException(org.opencms.configuration.CmsConfigurationException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) CmsConfigurationException(org.opencms.configuration.CmsConfigurationException) CmsXmlException(org.opencms.xml.CmsXmlException) CmsSecurityException(org.opencms.security.CmsSecurityException) CmsException(org.opencms.main.CmsException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) CmsImportExportException(org.opencms.importexport.CmsImportExportException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) CmsMessageContainer(org.opencms.i18n.CmsMessageContainer) ZipFile(java.util.zip.ZipFile) Digester(org.apache.commons.digester3.Digester) Rule(org.apache.commons.digester3.Rule) ZipFile(java.util.zip.ZipFile) File(java.io.File) CmsXmlErrorHandler(org.opencms.xml.CmsXmlErrorHandler)

Example 10 with Rule

use of org.geotoolkit.sld.xml.v100.Rule in project opencms-core by alkacon.

the class CmsVfsConfiguration method addXmlDigesterRules.

/**
 * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester3.Digester)
 */
public void addXmlDigesterRules(Digester digester) {
    // add finish rule
    digester.addCallMethod("*/" + N_VFS, "initializeFinished");
    // creation of the resource manager
    digester.addObjectCreate("*/" + N_VFS + "/" + N_RESOURCES, CmsResourceManager.class);
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES, I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD);
    digester.addSetNext("*/" + N_VFS + "/" + N_RESOURCES, "setResourceManager");
    // add rules for resource loaders
    digester.addObjectCreate("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER, CmsConfigurationException.class.getName(), A_CLASS);
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER, I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD);
    digester.addSetNext("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER, "addLoader");
    // add rules for resource types
    addResourceTypeXmlRules(digester);
    // add rules for VFS content collectors
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR, "addContentCollector", 2);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR, 0, A_CLASS);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR, 1, A_ORDER);
    // add the name generator
    digester.addObjectCreate("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_NAMEGENERATOR, CmsDefaultFileNameGenerator.class.getName(), A_CLASS);
    digester.addSetNext("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_NAMEGENERATOR, "setNameGenerator");
    // add MIME type rules
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE, "addMimeType", 2);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE, 0, A_EXTENSION);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE, 1, A_TYPE);
    // add relation type rules
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RELATIONTYPES + "/" + N_RELATIONTYPE, "addRelationType", 2);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RELATIONTYPES + "/" + N_RELATIONTYPE, 0, A_NAME);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RELATIONTYPES + "/" + N_RELATIONTYPE, 1, A_TYPE);
    // add html converter rules
    digester.addCallMethod("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_HTML_CONVERTERS + "/" + N_HTML_CONVERTER, "addHtmlConverter", 2);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_HTML_CONVERTERS + "/" + N_HTML_CONVERTER, 0, A_NAME);
    digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_HTML_CONVERTERS + "/" + N_HTML_CONVERTER, 1, A_CLASS);
    // generic <param> parameter rules
    digester.addCallMethod("*/" + I_CmsXmlConfiguration.N_PARAM, I_CmsConfigurationParameterHandler.ADD_PARAMETER_METHOD, 2);
    digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 0, I_CmsXmlConfiguration.A_NAME);
    digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 1);
    // add rule for default files
    digester.addCallMethod("*/" + N_VFS + "/" + N_DEFAULTFILES + "/" + N_DEFAULTFILE, "addDefaultFile", 1);
    digester.addCallParam("*/" + N_VFS + "/" + N_DEFAULTFILES + "/" + N_DEFAULTFILE, 0, A_NAME);
    // add rules for file translations
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS + "/" + N_TRANSLATION, "addFileTranslation", 0);
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS, "setFileTranslationEnabled", 1);
    digester.addCallParam("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS, 0, A_ENABLED);
    // add rules for file translations
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS + "/" + N_TRANSLATION, "addFolderTranslation", 0);
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS, "setFolderTranslationEnabled", 1);
    digester.addCallParam("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS, 0, A_ENABLED);
    // add rules for file translations
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_XSDTRANSLATIONS + "/" + N_TRANSLATION, "addXsdTranslation", 0);
    digester.addCallMethod("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_XSDTRANSLATIONS, "setXsdTranslationEnabled", 1);
    digester.addCallParam("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_XSDTRANSLATIONS, 0, A_ENABLED);
    // XML content type manager creation rules
    digester.addObjectCreate("*/" + N_VFS + "/" + N_XMLCONTENT, CmsXmlContentTypeManager.class);
    digester.addSetNext("*/" + N_VFS + "/" + N_XMLCONTENT, "setXmlContentTypeManager");
    // XML content widgets add rules
    // Widget definitions.
    // 'aliases' list is used/reset by the rule for widgets, and filled by the rule for aliases.
    final List<String> aliases = new ArrayList<>();
    digester.addRule("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_WIDGETS + "/" + N_WIDGET, new Rule() {

        private String m_className;

        private String m_config;

        @Override
        public void begin(String namespace, String name, Attributes attributes) throws Exception {
            m_className = attributes.getValue(A_CLASS);
            m_config = attributes.getValue(A_CONFIGURATION);
            String alias = attributes.getValue(A_ALIAS);
            aliases.clear();
            if (alias != null) {
                aliases.add(alias.trim());
            }
        }

        @Override
        public void end(String namespace, String name) throws Exception {
            CmsXmlContentTypeManager manager = getDigester().peek();
            List<String> aliasesCopy = new ArrayList<>(aliases);
            manager.addWidget(m_className, aliasesCopy, m_config);
        }
    });
    digester.addRule("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_WIDGETS + "/" + N_WIDGET + "/" + N_WIDGET_ALIAS, new Rule() {

        @Override
        public void body(String namespace, String name, String text) throws Exception {
            aliases.add(text.trim());
        }
    });
    // XML content schema type add rules
    digester.addCallMethod("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE, "addSchemaType", 2);
    digester.addCallParam("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE, 0, A_CLASS);
    digester.addCallParam("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE, 1, A_DEFAULTWIDGET);
}
Also used : CmsXmlContentTypeManager(org.opencms.xml.CmsXmlContentTypeManager) ArrayList(java.util.ArrayList) Attributes(org.xml.sax.Attributes) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.apache.commons.digester3.Rule) CmsDefaultFileNameGenerator(org.opencms.loader.CmsDefaultFileNameGenerator)

Aggregations

Rule (org.apache.commons.digester3.Rule)9 Attributes (org.xml.sax.Attributes)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CallMethodRule (org.apache.commons.digester3.CallMethodRule)3 CmsException (org.opencms.main.CmsException)3 SAXException (org.xml.sax.SAXException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ParseException (java.text.ParseException)2 List (java.util.List)2 Digester (org.apache.commons.digester3.Digester)2 CmsConfigurationException (org.opencms.configuration.CmsConfigurationException)2 CmsMessageContainer (org.opencms.i18n.CmsMessageContainer)2 CmsImportExportException (org.opencms.importexport.CmsImportExportException)2 CmsRoleViolationException (org.opencms.security.CmsRoleViolationException)2 CmsSecurityException (org.opencms.security.CmsSecurityException)2 File (java.io.File)1 HashMap (java.util.HashMap)1