Package net.n3.nanoxml

Examples of net.n3.nanoxml.IXMLElement


        if (baseDirName.length() > 0) {
            File baseDir = new File(stack.getLast().getBaseDir(), baseDirName);
            stack.getLast().setBaseDir(baseDir);
        }
        for (Enumeration<?> en = root.enumerateChildren(); en.hasMoreElements(); /**/) {
            XMLElement element = (XMLElement) en.nextElement();
            String elementName = element.getName();
            if (elementName.equals(TYPE)) {
                parseType(element, script);
            } else if (elementName.equals(CONTROL_PROPS)) {
                parseControlProps(element, script);
            } else if (elementName.equals(PROP_FILE)) {
View Full Code Here


        if (includeFileName == null) {
            error("A '" + SCRIPT_FILE + "' attribute is required for an '" + INCLUDE + "' element",
                    element);
        }
        File includeFile = resolvePath(includeFileName);
        XMLElement includeRoot = loadXML(includeFile);
        stack.getLast().setElement(element);
        stack.add(new ParseContext(includeFile));
        try {
            parseScript(includeRoot, script);
        } finally {
View Full Code Here

        String name = element.getAttribute(NAME, null);
        checkName(name, NAME, TYPE, element);
        String patternString = element.getAttribute(PATTERN, null);
        List<EnumeratedType.Alternate> alternates = new LinkedList<EnumeratedType.Alternate>();
        for (Enumeration<?> en = element.enumerateChildren(); en.hasMoreElements(); /**/) {
            XMLElement child = (XMLElement) en.nextElement();
            if (!child.getName().equals(ALT)) {
                error("A '" + TYPE + "' element can only contain '" + ALT + "' elements", child);
            }
            String value = child.getAttribute(VALUE, null);
            String token = child.getAttribute(TOKEN, value);
            if (value == null) {
                error("A '" + VALUE + "' attribute is required for an '" + ALT + "' element", child);
            }
            if (token.length() == 0) {
                // An empty token is problematic because and empty input line is
View Full Code Here

    }

    private PropertySet parseProperties(XMLElement element, PropertySet propSet,
            ConfigureScript script) throws ConfigureException {
        for (Enumeration<?> en = element.enumerateChildren(); en.hasMoreElements(); /**/) {
            XMLElement child = (XMLElement) en.nextElement();
            if (child.getName().equals(PROPERTY)) {
                String name = child.getAttribute(NAME, null);
                checkName(name, NAME, PROPERTY, child);
                String typeName = child.getAttribute(TYPE, null);
                if (name == null) {
                    error("A '" + PROPERTY + "' element requires a '" + TYPE + "' attribute", child);
                }
                String description = child.getAttribute(DESCRIPTION, null);
                if (name == null) {
                    error("A '" + PROPERTY + "' element requires a '" + DESCRIPTION +
                            "' attribute", child);
                }
                String defaultText = child.getAttribute(DEFAULT, "");
                PropertyType type = script.getTypes().get(typeName);
                if (type == null) {
                    error("Use of undeclared type '" + typeName + "'", child);
                }
                Value defaultValue = type.fromValue(defaultText);
View Full Code Here

            }
        }
        Screen screen = new Screen(title, guardPropName, valueIs, valueIsNot);
        script.addScreen(screen);
        for (Enumeration<?> en = element.enumerateChildren(); en.hasMoreElements(); /**/) {
            XMLElement child = (XMLElement) en.nextElement();
            if (!child.getName().equals(ITEM)) {
                error("Expected an '" + ITEM + "' element", child);
            }
            String propName = child.getAttribute(PROPERTY, null);
            if (propName == null) {
                error("The '" + PROPERTY + "' attribute is required for an '" + ITEM + "' element",
                        child);
            }
            String changed = child.getAttribute(CHANGED, null);
            if (script.getProperty(propName) == null) {
                error("Use of undeclared property '" + propName + "'", child);
            }
            screen.addItem(new Item(script, propName, unindent(child.getContent()), changed));
        }
    }
View Full Code Here

        // ----------------------------------------------------
        Vector fields = spec.getChildrenNamed(FIELD_NODE_ID);

        for (int i = 0; i < fields.size(); i++)
        {
            XMLElement field = (XMLElement) fields.elementAt(i);
            String attribute = field.getAttribute(TYPE);

            if (attribute != null)
            {
                if (attribute.equals(RULE_FIELD))
                {
View Full Code Here

     */
    /*--------------------------------------------------------------------------*/
    private void readSpec() throws Exception
    {
        InputStream input = null;
        XMLElement data;
        Vector specElements;
        String attribute;
        String instance = Integer.toString(instanceNumber);

        try
        {
            input = parentFrame.getResource(SPEC_FILE_NAME);
        }
        catch (Exception exception)
        {
            haveSpec = false;
            return;
        }
        if (input == null)
        {
            haveSpec = false;
            return;
        }

        // initialize the parser
        StdXMLParser parser = new StdXMLParser();
        parser.setBuilder(new StdXMLBuilder());
        parser.setValidator(new NonValidator());
        parser.setReader(new StdXMLReader(input));

        // get the data
        data = (XMLElement) parser.parse();

        // extract the spec to this specific panel instance
        if (data.hasChildren())
        {
            specElements = data.getChildrenNamed(NODE_ID);
            for (int i = 0; i < specElements.size(); i++)
            {
                data = (XMLElement) specElements.elementAt(i);
                attribute = data.getAttribute(INSTANCE_IDENTIFIER);

                if (instance.equals(attribute))
                {
                    // use the current element as spec
                    spec = data;
View Full Code Here

    /*--------------------------------------------------------------------------*/
    private void addRuleField(XMLElement spec)
    {
        Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
        Vector forOs = spec.getChildrenNamed(OS);
        XMLElement element = spec.getFirstChildNamed(SPEC);
        String variable = spec.getAttribute(VARIABLE);
        RuleInputField field = null;
        JLabel label;
        String layout;
        String set;
        String separator;
        String format;
        String validator = null;
        String message = null;
        boolean hasParams = false;
        String paramName = null;
        String paramValue = null;
        HashMap validateParamMap = null;
        Vector validateParams = null;
        String processor = null;
        int resultFormat = RuleInputField.DISPLAY_FORMAT;

        // ----------------------------------------------------
        // extract the specification details
        // ----------------------------------------------------
        if (element != null)
        {
            label = new JLabel(getText(element));
            layout = element.getAttribute(RULE_LAYOUT);
            set = element.getAttribute(SET);

            // retrieve value of variable if not specified
            // (does not work here because of special format for set attribute)
            // if (set == null)
            // {
            // set = idata.getVariable (variable);
            // }

            separator = element.getAttribute(RULE_SEPARATOR);
            format = element.getAttribute(RULE_RESULT_FORMAT);

            if (format != null)
            {
                if (format.equals(RULE_PLAIN_STRING))
                {
                    resultFormat = RuleInputField.PLAIN_STRING;
                }
                else if (format.equals(RULE_DISPLAY_FORMAT))
                {
                    resultFormat = RuleInputField.DISPLAY_FORMAT;
                }
                else if (format.equals(RULE_SPECIAL_SEPARATOR))
                {
                    resultFormat = RuleInputField.SPECIAL_SEPARATOR;
                }
                else if (format.equals(RULE_ENCRYPTED))
                {
                    resultFormat = RuleInputField.ENCRYPTED;
                }
            }
        }
        // ----------------------------------------------------
        // if there is no specification element, return without
        // doing anything.
        // ----------------------------------------------------
        else
        {
            return;
        }

        // ----------------------------------------------------
        // get the description and add it to the list of UI
        // elements if it exists.
        // ----------------------------------------------------
        element = spec.getFirstChildNamed(DESCRIPTION);
        addDescription(element, forPacks, forOs);

        // ----------------------------------------------------
        // get the validator and processor if they are defined
        // ----------------------------------------------------
        element = spec.getFirstChildNamed(VALIDATOR);
        if (element != null)
        {
            validator = element.getAttribute(CLASS);
            message = getText(element);
            // ----------------------------------------------------------
            // check and see if we have any parameters for this validator.
            // If so, then add them to validateParamMap.
            // ----------------------------------------------------------
            validateParams = element.getChildrenNamed(RULE_PARAM);
            if (validateParams != null && validateParams.size() > 0)
            {
                hasParams = true;
               
                if (validateParamMap == null)
                    validateParamMap = new HashMap();

                for (Iterator it = validateParams.iterator(); it.hasNext();)
                {
                    element = (XMLElement) it.next();
                    paramName = element.getAttribute(RULE_PARAM_NAME);
                    paramValue = element.getAttribute(RULE_PARAM_VALUE);
                    validateParamMap.put(paramName, paramValue);
                }
               
            }

        }

        element = spec.getFirstChildNamed(PROCESSOR);
        if (element != null)
        {
            processor = element.getAttribute(CLASS);
        }

        // ----------------------------------------------------
        // create an instance of RuleInputField based on the
        // extracted specifications, then add it to the list
View Full Code Here

    /*--------------------------------------------------------------------------*/
    private void addTextField(XMLElement spec)
    {
        Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
        Vector forOs = spec.getChildrenNamed(OS);
        XMLElement element = spec.getFirstChildNamed(SPEC);
        JLabel label;
        String set;
        int size;

        String variable = spec.getAttribute(VARIABLE);
        if ((variable == null) || (variable.length() == 0)) { return; }

        // ----------------------------------------------------
        // extract the specification details
        // ----------------------------------------------------
        if (element != null)
        {
            label = new JLabel(getText(element));
            set = element.getAttribute(SET);
            if (set == null)
            {
                set = idata.getVariable(variable);
                if (set == null)
                {
                    set = "";
                }
            }else{
                if (set != null && !"".equals(set)){
                    VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
                    set = vs.substitute(set, null);
                }
            }
               
            try
            {
                size = Integer.parseInt(element.getAttribute(TEXT_SIZE));
            }
            catch (Throwable exception)
            {
                size = 1;
            }
View Full Code Here

    /*--------------------------------------------------------------------------*/
    private void addComboBox(XMLElement spec)
    {
        Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
        Vector forOs = spec.getChildrenNamed(OS);
        XMLElement element = spec.getFirstChildNamed(SPEC);
        String variable = spec.getAttribute(VARIABLE);
        TextValuePair listItem = null;
        JComboBox field = new JComboBox();
        JLabel label;

  Vector variables = new Vector();
  Vector values = new Vector();
        // ----------------------------------------------------
        // extract the specification details
        // ----------------------------------------------------
        if (element != null)
        {
            label = new JLabel(getText(element));

            Vector choices = element.getChildrenNamed(COMBO_CHOICE);


            if (choices == null) { return; }


            for (int i = 0; i < choices.size(); i++)
            {

                String processorClass = ((XMLElement) choices.elementAt(i))
                        .getAttribute("processor");



                if (processorClass != null && !"".equals(processorClass))
                {


                    String choiceValues = "";
                    try
                    {
                        choiceValues = ((Processor) Class.forName(processorClass).newInstance())
                                .process(null);
                    }
                    catch (Throwable t)
                    {
                        t.printStackTrace();
                    }


   
                    String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
                    if (set == null)
                    {
                        set = "";
                    }
                    if (set != null && !"".equals(set)){
                        VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
                        set = vs.substitute(set, null);
                    }
                   
                    StringTokenizer tokenizer = new StringTokenizer(choiceValues, ":");
                    int counter = 0;
                    while (tokenizer.hasMoreTokens())
                    {
                        String token = tokenizer.nextToken();
                        listItem = new TextValuePair(token, token);
                        field.addItem(listItem);
                        if (set.equals(token))
                        {
                            field.setSelectedIndex(field.getItemCount() - 1);
                        }
                        counter++;
                    }
                }
                else
                {
                    listItem = new TextValuePair(getText((XMLElement) choices.elementAt(i)),
                            ((XMLElement) choices.elementAt(i)).getAttribute(COMBO_VALUE));
                    field.addItem(listItem);

        XMLElement choiceElement = (XMLElement) choices.elementAt(i);

        variables.add(spec.getAttribute(VARIABLE));
        values.add("combo");
       
        // handle additional variable-value assignments
        Vector assignments = choiceElement.getChildrenNamed(ASSIGN);

        for (int j = 0; j < assignments.size(); j++)
      {
          XMLElement assignmentElement = (XMLElement) assignments.get(j);
          String variable2 = assignmentElement.getAttribute(VARIABLE);
          if (variable2 != null)
        {
            variables.add(variable2);
            values.add(assignmentElement.getAttribute(VALUE));

            //values.add();
            //System.out.println(variable2);
            //idata.setVariable(variable2,assignmentElement.getAttribute(VALUE));
        }
View Full Code Here

TOP

Related Classes of net.n3.nanoxml.IXMLElement

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.