Package org.apache.avalon.framework.configuration

Examples of org.apache.avalon.framework.configuration.Configuration


    public void testSpaceTrimming()
        throws Exception
    {
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        InputStream in = new ByteArrayInputStream( spaceTrimmingCheckXML.getBytes() );
        Configuration conf = builder.build( in );
        assertEquals( "Value is trimmed by default",
                      "value",
                      conf.getChild( "trimmed-item" ).getValue() );
        assertEquals( "After trimming turned off value is preserved",
                      "\n a space\r a CR, then a trailing space ",
                      conf.getChild( "preserved-item" ).getValue() );
        assertEquals( "Trimming two levels deep works too",
                      " whitespace around ",
                      conf.getChild( "first-level-item" )
                      .getChild( "second-level-preserved" ).getValue() );
        assertEquals( "Trimming turned back on",
                      "value",
                      conf.getChild( "trimmed-again-item" ).getValue() );
    }
View Full Code Here


        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        MyEntityResolver customResolver = new MyEntityResolver();
        builder.setEntityResolver( new MyEntityResolver() );
        Configuration conf = builder.buildFromFile( TEST_PATH + EXTERNAL_FILE_NAME );
        simpleAssertions( conf );
    }
View Full Code Here

    }
   
    public void testAddRemoveChild()
    {
        final String childName = "child";
        final Configuration child = new DefaultConfiguration( childName, "child location" );
       
        m_configuration.addChild( child );
        assertEquals( child, m_configuration.getChild( childName ) );
       
        m_configuration.removeChild( child );
View Full Code Here

        try
        {
            final DefaultConfigurationBuilder builder =
                new DefaultConfigurationBuilder();
            final Configuration configuration = builder.build( confInput );

            final Parameters parameters =
                Parameters.fromConfiguration( configuration );

            assertEquals( "key1 should be value1", "value1", parameters.getParameter( "key1" ) );
View Full Code Here

   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    try
    {
      Configuration config = getConfiguration();
      java.util.List configPath = ModelTools.getDerivationPath(req, this);

      ModelResponse res = req.createResponse();
      ListingDescriptor listing = createListingFromConfig(config, configPath);
      Output output = res.createOutput("listing");
View Full Code Here

        try {

            sessionManager = (SessionManager)this.manager.lookup(SessionManager.ROLE);
            Session session = sessionManager.getSession(true);

            Configuration conf = (Configuration)session.getAttribute(
                                  req.getParameter(SessionConstants.SESSION_FORM_PARAMETER));

            String valstr = parameters.getParameter ("validate", (String) settings.get("validate",""));
            String valsetstr = parameters.getParameter ("validate-set", (String) settings.get("validate-set",""));

            Configuration valConf = (Configuration)session.getAttribute(
                                     req.getParameter(SessionConstants.SESSION_FORM_PARAMETER)+"validate-set");
            if (valConf != null) {
                valsetstr = valConf.getAttribute("name","");
            }

            Configuration[] desc = conf.getChildren ("parameter");
            Configuration[] csets = conf.getChildren ("constraint-set");

            HashMap actionMap = new HashMap ();
            HashMap resultMap = new HashMap ();
            boolean allOK = true;

            /*
             * old obsoleted method
             */
            if (!"".equals (valstr.trim ())) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug ("Validating parameters "
                                       + "as specified via 'validate' parameter");
                }

                /* get list of params to be validated */
                String[] rparams = null;
                if (!"*".equals(valstr.trim())) {
                    rparams = Tokenizer.tokenize (valstr, ",", false);
                } else {
                    // validate _all_ parameters
                    rparams = new String[desc.length];
                    for (int i=0; i<desc.length; i++) {
                        rparams[i] = desc[i].getAttribute("name","");
                        if ("".equals(rparams[i])) {
                            if (getLogger().isDebugEnabled()) {
                                getLogger().debug ("Wrong syntax of the 'validate' parameter");
                            }
                            return null;
                        }
                    }
                }
                /* perform actual validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (rparams.length);
                /* put required params into hash */
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i];
                    if (name == null || "".equals (name.trim ())) {
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug ("Wrong syntax of the 'validate' parameter");
                        }
                        return null;
                    }
                    name = name.trim ();
                    params.put (name, req.getParameter (name));
                }
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i].trim ();
                    result = validateParameter (name, null, desc,
                                                params, true);
                    if (!result.isOK()) {
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug ("Validation failed for parameter " + name);
                        }
                        allOK = false;
                    }
                    actionMap.put (name, result.getObject());
                    resultMap.put (name, result.getResult());
                }
            }
            /*
             * new set-based method
             */
            if (!"".equals (valsetstr.trim ())) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug ("Validating parameters "
                                       + "from given constraint-set " + valsetstr);
                }
                // go over all constraint sets
                // untill the requested set is found
                // set number will be in j
                Configuration cset = null;
                String setname = null;
                int j = 0;
                boolean found = false;
                for (j = 0; j < csets.length; j ++) {
                    setname = csets[j].getAttribute ("name", "");
                    if (valsetstr.trim().equals (setname.trim ())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug ("Given set "
                                           + valsetstr
                                           + " does not exist in a description file");
                    }
                    return null;
                }
                cset = csets[j];
                /* get the list of params to be validated */
                Configuration[] set = cset.getChildren ("validate");

                /* perform actuall validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (set.length);
View Full Code Here

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("BEGIN getRoles");
        }
        Document frag = null;

        Configuration conf = this.getAuthenticationManager().getModuleConfiguration("single-role-user-management");
        if (conf != null) {

            // get load-roles resource (optional)
            Configuration child = conf.getChild("load-roles", false);
            if (child != null) {
                String loadRolesResource = child.getAttribute("uri", null);
                SourceParameters loadRolesResourceParameters = SourceParameters.create(child);
                if (loadRolesResource != null) {
                    SourceParameters parameters = (loadRolesResourceParameters == null) ? new SourceParameters()
                                                                           : loadRolesResourceParameters;
                    if (this.getAuthenticationManager().getApplicationName() != null)
View Full Code Here

         *
         * @param  configuration               Cocoon factory configuration
         * @exception  ConfigurationException  thrown iff configuration fails
         */
        public void configure(Configuration configuration) throws ConfigurationException {
            Configuration child;

            // configure logLevel
            String logLevel = "WARN";
            child = configuration.getChild("log-level", false);
            if (child != null) {
                logLevel = child.getValue();
            } else {
                logLevel = "WARN";
            }

            // configure the logKitManager, either by using a logkit.xconf file,
            // or by a logger
            final org.apache.log.Priority priority = org.apache.log.Priority.getPriorityForName(logLevel);
            org.apache.log.Hierarchy.getDefaultHierarchy().setDefaultPriority(priority);
            logger = org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor("");

            child = configuration.getChild("logKit", false);
            if (child != null) {
                String logKit = child.getValue();
                String logKitLogCategory = child.getAttribute("category", "cocoon");

                if (logKit != null) {
                    try {
                        final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
                        final Configuration logKitConf = builder.buildFromFile(logKit);
                        logKitManager = new DefaultLogKitManager(org.apache.log.Hierarchy.getDefaultHierarchy());

                        final DefaultContext subcontext = new DefaultContext(this.ctx);
                        File contextDir = (File) this.ctx.get("context-root");
                        subcontext.put("context-root", contextDir);
View Full Code Here

    /**
     * Configure an application
     */
    public void configure(SourceResolver resolver, Configuration appconf)
    throws ProcessingException, SAXException, IOException, ConfigurationException {
        Configuration child = null;

        // test for loadondemand attribute
        this.loadOnDemand = appconf.getAttributeAsBoolean("loadondemand", false);

        // get load resource (optinal)
        child = appconf.getChild("load", false);
        if (child != null) {
            this.loadResource = child.getAttribute("uri");
            this.loadResourceParameters = SourceParameters.create(child);
        }

        // get save resource (optional)
        child =  appconf.getChild("save", false);
        if (child != null) {
            this.saveResource = child.getAttribute("uri");
            this.saveResourceParameters = SourceParameters.create(child);
        }

        // get configurations (optional)
        Configuration[] configurations = appconf.getChildren("configuration");
        if (configurations != null) {
            for(int i = 0; i < configurations.length; i++) {
                child = configurations[i];
                String value = child.getAttribute("name");
                if (this.getConfiguration(value) != null) {
                    throw new ConfigurationException("Configuration names must be unique for application " + this.name + ": " + value);
                }
                this.configurations.put(value, child);
            }
View Full Code Here

                                    this.resolverContext);

        // Read in any additional properties to pass to the VelocityEngine during initialization
        Configuration[] properties = configuration.getChildren("property");
        for (int i = 0; i < properties.length; ++i) {
            Configuration c = properties[i];
            String name = c.getAttribute("name");

            // Disallow setting of certain properties
            if (name.startsWith("runtime.log")
                    || name.indexOf(".resource.loader.") != -1) {
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("ignoring disallowed property '" + name + "'.");
                }
                continue;
            }
            this.tmplEngine.setProperty(name, c.getAttribute("value"));
        }

        // Now read in any additional Velocity resource loaders
        List resourceLoaders = new ArrayList();
        Configuration[] loaders = configuration.getChildren("resource-loader");
        for (int i = 0; i < loaders.length; ++i) {
            Configuration loader = loaders[i];
            String name = loader.getAttribute("name");
            if (name.equals("cocoon")) {
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("'cocoon' resource loader already defined.");
                }
                continue;
            }
            resourceLoaders.add(name);
            String prefix = name + ".resource.loader.";
            String type = loader.getAttribute("class");
            this.tmplEngine.setProperty(prefix + "class", type);
            Configuration[] loaderProperties = loader.getChildren("property");
            for (int j = 0; j < loaderProperties.length; j++) {
                Configuration c = loaderProperties[j];
                String propName = c.getAttribute("name");
                this.tmplEngine.setProperty(prefix + propName, c.getAttribute("value"));
            }
        }

        // Velocity expects resource loaders as CSV list
        //
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.configuration.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.