Package org.jconfig

Examples of org.jconfig.ExtensibleConfiguration


            }
            if ( braces != 0 ) {
              ErrorReporter.getErrorHandler().reportError("Unmatched brackets in script file");
                throw new ConfigurationManagerException("Unmatched brackets in script file");
            }
            Configuration cfg = new ExtensibleConfiguration(configurationName);
            boolean process = false;
            String currentCategoryName = null;
            for ( int i = 0; i < content.size();i++) {
                String tmp = (String)content.get(i);
                tmp = tmp.trim();
                if ( process ) {
                    if ( tmp.startsWith("}") ) {
                        process = false;                    
                    }
                    else {                                               
                        String left = tmp.substring(0,tmp.indexOf("=")-1);
                        left = left.trim();
                        String right = tmp.substring(tmp.indexOf("=")+1);
                        right = right.trim();                                               
                        cfg.setProperty(left,right,currentCategoryName);                       
                    }
                }
                if ( tmp.startsWith("category") && tmp.indexOf("{") != -1 ) {
                    process = true;
                    String name = tmp.substring(9);
                    name = name.substring(0,name.indexOf("{"));
                    name = name.trim();                   
                    String extend = null;
                    if ( tmp.indexOf(" extends ") != -1 ) {
                        extend = name.substring(name.indexOf(" extends ")+9);
                        extend = extend.trim();
                        name = name.substring(0,name.indexOf(" extends "));                           
                    }
                    Category ec = new DefaultCategory(name);
                    if ( extend != null ) {
                        ec.setExtendsCategory(extend);
                    }
                    cfg.setCategory(ec);
                    currentCategoryName = name;
                }
            }
            return cfg;
        }
View Full Code Here


            while ((line=nis.readLine()) != null ) {
                content.add(line);
            }
            nis.close();
            boolean addVar = false;
            Configuration cfg = new ExtensibleConfiguration(configurationName);
            String currentCategoryName = null;
            for ( int i = 0; i < content.size();i++) {
                String tmp = (String)content.get(i);
                if ( tmp != null && tmp.length() > 0 && !tmp.startsWith("#") ) {
                  if ( tmp.startsWith(" ") || tmp.startsWith("\t") ) {
                    if ( tmp.indexOf(":") != -1 ) {
                      String left = tmp.substring(0,tmp.indexOf(":"));
                        left = left.trim();
                        String right = tmp.substring(tmp.indexOf(":")+1);
                        right = right.trim();          
                        if ( addVar ) {
                          cfg.setVariable(left,right);
                        }
                        else {
                          cfg.setProperty(left,right,currentCategoryName);
                        }
                    }
                  }
                  else {
                    String name = tmp;
            name = name.trim();
                      if ( name.endsWith(":")) {
                        name = name.substring(0,name.length()-1);
                      }
                      if ( name.equalsIgnoreCase("variables")) {
                        addVar = true;
                      }
                      else {
                        addVar = false;
                        String extend = null;
                        if ( name.startsWith("extends")) {
                          int pos = name.indexOf(":");
                          if ( pos != -1 ) {
                            cfg.setBaseConfiguration(name.substring(pos+1).trim());
                          }
                        }
                        else {
                          if ( tmp.indexOf(" extends ") != -1 ) {
                              extend = name.substring(name.indexOf(" extends ")+9);
                              extend = extend.trim();
                              name = name.substring(0,name.indexOf(" extends "));                           
                          }
                          Category ec = new DefaultCategory(name);
                          if ( extend != null ) {
                              ec.setExtendsCategory(extend);
                          }
                          cfg.setCategory(ec);
                          currentCategoryName = name;
                        }
                      }
                  }
                }
View Full Code Here

     *  Description of the Method
     *
     *@param  doc  Description of the Parameter
     */
    public Configuration parse(Document doc,String configName) {       
        ExtensibleConfiguration configuration = new ExtensibleConfiguration(configName);
        String currentCategory;
        getVariables(doc,configuration);  
        getIncludeProperties(doc, configuration);
        getBaseConfigName(doc, configuration);
        // first we get all nodes where the element is category
        NodeList nl = doc.getElementsByTagName("category");
        for (int i = 0; i < nl.getLength(); i++) {
            // now we get every node from the list
            Node n = nl.item(i);
            // and get the name attribute for this category
            NamedNodeMap curAtt = n.getAttributes();
            Node curNode = curAtt.getNamedItem("name");
            currentCategory = curNode.getNodeValue();                       
            Category ec = new DefaultCategory(currentCategory);
            configuration.setCategory(ec);
            curNode = curAtt.getNamedItem("extends");
            if ( curNode != null ) {
                ec.setExtendsCategory(curNode.getNodeValue());
            }
            // now we process all children for this category
            for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
                // we take the tag name as property name               
                if ( child.getNodeType() == 1 && child.getFirstChild() != null ) {
                    String name = child.getNodeName();                                 
                    String value = child.getFirstChild().getNodeValue();                    
                    if (name != null && value != null) {
                        // the key is always category/name
                        // e.g. general/congig_file                                               
                        configuration.setProperty(name,value,currentCategory);
                    }               
                }
            }
        }
        return configuration;
View Full Code Here

TOP

Related Classes of org.jconfig.ExtensibleConfiguration

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.