Package net.n3.nanoxml

Examples of net.n3.nanoxml.IXMLElement


     *
     * @param xmlFile xml file associated with configuration info
     */
   public XmlConfig(String xmlFile, String tag) {
     file = xmlFile;
     XMLElement el = null;
     boolean fileMissing = false;
     try {
       try{
         try {
           IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
           // IXMLReader reader = StdXMLReader.fileReader(file); // fails on pc
           BufferedReader breader = new BufferedReader(new FileReader(file));
           IXMLReader reader = new StdXMLReader(breader);
           parser.setReader(reader);
           el = (XMLElement) parser.parse();
           if (el == null) {
             el = promptToOverwrite(xmlFile, tag);
           } else {
             LogBuffer.println("created xml config from file " + file);
           }
         } catch (java.io.FileNotFoundException e) {
           LogBuffer.println("File not found, will try from URL");
           fileMissing = true;
           url = new URL(xmlFile);
           el = getXMLElementFromURL();
         } catch (java.security.AccessControlException e) {
           LogBuffer.println("AccessControlException, will try from URL");
           url = new URL(xmlFile);
           el = getXMLElementFromURL();
         }
       } catch (java.net.MalformedURLException e) {
         if (!file.contains(":")) {
           url = new URL("file://" + xmlFile);
           el = getXMLElementFromURL();
         } else if (fileMissing) {
           // well, let's make our own...
           el = makeNewConfig(tag);
         } else {
       System.out.println("Invalid URL");
       System.out.println(e);
         }
       }
     } catch (XMLException ex) {
       try {
         el = promptToOverwrite(xmlFile, tag);
       } catch (Exception e) {
         System.out.println("Problem opening window: " + e.toString());
         System.out.println("Error parsing XML code in configuration file");
         System.out.println(file);
         System.out.println("Manually deleting file may fix, but you'll lose settings.");
         System.out.println("error was: " + ex);
         file = null;
         el = new XMLElement(tag);
       }
     } catch (java.io.FileNotFoundException e) {
       // well, let's make our own...
       el = makeNewConfig(tag);
     } catch (Exception ex) {
View Full Code Here


       System.out.println(ex);
     }
     root = new XmlConfigNode(el);
   }
  private XMLElement promptToOverwrite(String xmlFile, String tag) {
    XMLElement el;
    int response = JOptionPane.showConfirmDialog (null, "Problem Parsing Settings " + xmlFile + ", Should I replace?", "Replace Faulty Settings File?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
     if (response == JOptionPane.OK_OPTION) {
       el = makeNewConfig(tag);
     } else {
       LogBuffer.println("Using dummy config nodes");
       file = null;
       el = new XMLElement(tag);
     }
    return el;
  }
View Full Code Here

    return el;
  }
   private XMLElement makeNewConfig(String tag) {
       LogBuffer.println("Making new configuration file " + file);
       changed = true;
       return  new XMLElement(tag);
   }
View Full Code Here

     *
     * @param xmlUrl url from which the text came from, since nanoxml sucks so damn hard.
     */
   public XmlConfig(java.net.URL xmlUrl, String tag) {
     url = xmlUrl;
     XMLElement el = null;
     if (url != null) {
       try {
          el = getXMLElementFromURL();
       } catch (XMLException ex) {
         LogBuffer.println("Error parsing XML code in configuration url");
         LogBuffer.println(url.toString());
         ex.printStackTrace();
         url = null;
         el = new XMLElement(ex.toString());
       } catch (java.security.AccessControlException sec) {
         sec.printStackTrace();
         throw sec;
       } catch (Exception ex) {
         //      el = new XMLElement(ex.toString());
         LogBuffer.println(ex.toString());
         ex.printStackTrace();
       }
     }
    
     if (el == null) {
       el = new XMLElement(tag);
     }
    
     root = new XmlConfigNode(el);
   }
View Full Code Here

     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws XMLException
     */
    private XMLElement getXMLElementFromURL() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, XMLException {
      XMLElement el;
      String xmlText     = "";
      Reader st          = new InputStreamReader(url.openStream());
      int ch             = st.read();
      while (ch != -1) {
        char[] cbuf  = new char[1];
View Full Code Here

  public ConfigNode create(String name) {
    if (root == null) {
      LogBuffer.println("Warning: root is null, creating dummy config node");
      return new DummyConfigNode(name);
    }
      XMLElement kid = new XMLElement(name);
      root.addChild(kid);
      XmlConfig.this.changed = true;
      return new XmlConfigNode(kid);
   }
View Full Code Here

    public AutomatedInstallData() {
        availablePacks = new ArrayList();
        selectedPacks = new ArrayList();
        panels = new ArrayList<IzPanel>();
        panelsOrder = new ArrayList();
        xmlData = new XMLElement("AutomatedInstallation");
        variables = new Properties();
        attributes = new HashMap<String, Object>();
        customData = new HashMap<String, List>();
        self = this;
    }
View Full Code Here

     *
     * @param idata     The installation data.
     * @param panelRoot The tree to put the data in.
     */
    public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot) {
        XMLElement hostsElement;
        XMLElement hostElement;

        // ----------------------------------------------------
        // add the item that combines all entries
        // ----------------------------------------------------
        hostsElement = new XMLElement(ELEMENT_HOSTS_NAME);
        panelRoot.addChild(hostsElement);

        // ----------------------------------------------------
        // add all entries
        // ----------------------------------------------------
        Iterator<String> keys = this.entries.keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            String value = this.entries.get(key);

            hostElement = new XMLElement(ELENENT_HOST_NAME);
            hostElement.setAttribute(ATTRIBUTE_HOST_ID, key);
            hostElement.setAttribute(ATTRIBUTE_HOTS_ARGS, value);

            hostsElement.addChild(hostElement);
        }
    }
View Full Code Here

     * @param idata     The installation data.
     * @param panelRoot The XML tree to read the data from.
     * @return always true.
     */
    public boolean runAutomated(AutomatedInstallData idata, XMLElement panelRoot) {
        XMLElement hostsElement;
        XMLElement hostElement;
        String id;
        String arguments;

        // ----------------------------------------------------
        // get the section containing the user entries
        // ----------------------------------------------------
        hostsElement = panelRoot.getFirstChildNamed(ELEMENT_HOSTS_NAME);
        if (hostsElement == null) {
            return false;
        }

        Vector<XMLElement> hostElements = hostsElement.getChildrenNamed(ELENENT_HOST_NAME);
        if (hostElements == null) {
            return false;
        }

        // ----------------------------------------------------
        // retieve each entry and substitute the associated
        // variable
        // ----------------------------------------------------
        ArrayList<Host> allHosts = new ArrayList<Host>(hostElements.size());
        for (int i = 0; i < hostElements.size(); i++) {
            hostElement = hostElements.elementAt(i);

            id = hostElement.getAttribute(ATTRIBUTE_HOST_ID);
            arguments = hostElement.getAttribute(ATTRIBUTE_HOTS_ARGS);

            Debug.trace("Found host: '" + arguments + "'.");

            try {
                List<Host> hostsPart = Host.fromStringInstance(arguments);
View Full Code Here

    public ConfigureScript loadScript(String fileName) throws ConfigureException {
        configure.verbose("Loading configure script from " + fileName);
        final File file = new File(fileName);
        stack.add(new ParseContext(file));
        try {
            final XMLElement root = loadXML(file);
            configure.debug("Parsing script");
            return parseScript(root, file);
        } finally {
            stack.removeLast();
        }
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.