Package org.jnode.nanoxml

Examples of org.jnode.nanoxml.XMLElement


    }


    @Override
    public XMLElement toXML() {
        XMLElement element = basicElement("option");
        element.setAttribute("argLabel", getArgName());
        if (longOptName != null) {
            element.setAttribute("longName", longOptName.substring(2));
        }
        if (shortOptName != null) {
            element.setAttribute("shortName", shortOptName.substring(1));
        }
        return element;
    }
View Full Code Here


        return sb.toString();
    }

    @Override
    public XMLElement toXML() {
        XMLElement element = basicElement("optional");
        if (eager) {
            element.setAttribute("eager", eager);
        }
        return element;
    }
View Full Code Here

    }

    public abstract XMLElement toXML();

    protected XMLElement basicElement(String name) {
        XMLElement element = new XMLElement(new Hashtable<String, Object>(), false, false);
        element.setName(name);
        if (label != null) {
            element.setAttribute("label", label);
        }
        if (description != null) {
            element.setAttribute("description", description);
        }
        return element;
    }
View Full Code Here

                    dumpSyntax(alias, bundle, out);
                }
            } else if (argFile.isSet()) {
                alias = getAlias();
                File file = argFile.getValue();
                XMLElement xml = new XMLElement();
                FileReader reader = null;
                try {
                    reader = new FileReader(file);
                    xml.parseFromReader(new BufferedReader(reader));
                    xml.setAttribute("alias", alias);
                    SyntaxBundle bundle =
                        new SyntaxSpecLoader().loadSyntax(new XMLSyntaxSpecAdapter(xml));
                    synMgr.add(bundle);
                } catch (IOException ex) {
                    err.format(err_file_read, alias, ex.getLocalizedMessage());
View Full Code Here

        return argAlias.getValue();
    }

    private void dumpSyntax(String alias, SyntaxBundle bundle, PrintWriter out)
        throws IOException {
        XMLElement element = new XMLElement(new Hashtable<String, Object>(), false, false);
        element.setName("syntax");
        element.setAttribute("alias", alias);
        String description = bundle.getDescription();
        if (description != null) {
            element.setAttribute("description", description);
        }
        Syntax[] syntaxes = bundle.getSyntaxes();
        for (Syntax syntax : syntaxes) {
            element.addChild(syntax.toXML());
        }
        element.write(out);
        out.println();
    }
View Full Code Here

*/
public class NanoXmlTest {

    public static void main(String[] args)
        throws IOException {
        XMLElement xml = new XMLElement(new Hashtable(), true, false);
        xml.parseFromReader(new FileReader(args[0]));
        System.out.println(xml);
    }
View Full Code Here

            resources = loadResources(pluginIs);
        } catch (IOException ex) {
            throw new PluginException("Error loading jarfile", ex);
        }

        final XMLElement root;
        try {
            // Not find the plugin.xml
            final ByteBuffer buf = getResourceAsBuffer("plugin.xml");
            if (buf == null) {
                throw new PluginException(
                    "plugin.xml not found in jar file");
            }

            // Now parse plugin.xml
            root = new XMLElement(new Hashtable<Object, Object>(), true, false);
            final Reader r = new InputStreamReader(new ByteBufferInputStream(buf));
            try {
                root.parseFromReader(r);
            } finally {
                r.close();
            }
        } catch (IOException ex) {
            throw new PluginException("Plugin " + pluginUrl, ex);
View Full Code Here

    public PluginList(File file, File defaultDir, String targetArch)
        throws PluginException, MalformedURLException {
        this.defaultDir = defaultDir;
        descrList = new ArrayList<URL>();
        pluginList = new ArrayList<URL>();
        final XMLElement root = new XMLElement(new Hashtable<Object, Object>(), true, false);
        try {
            final FileReader r = new FileReader(file);
            try {
                root.parseFromReader(r);
            } finally {
                r.close();
            }
        } catch (IOException ex) {
            throw new PluginException(ex);
        }
        if (!root.getName().equals("plugin-list")) {
            throw new PluginException("plugin-list element expected");
        }

        this.name = (String) root.getAttribute("name");
        if (name == null) {
            throw new PluginException("name attribute is missing in " + file);
        }

        for (Iterator<?> i = root.getChildren().iterator(); i.hasNext();) {

            final XMLElement e = (XMLElement) i.next();
            if (e.getName().equals("plugin")) {
                final String id = e.getStringAttribute("id");

                if (id == null) {
                    throw new PluginException("id attribute expected on "
                        + e.getName());
                }
               
                // version attribute is optional
                // if not specified, then the latest version found will be used.
                final String version = e.getStringAttribute("version");

                addPlugin(descrList, pluginList, id, version);
            } else if (e.getName().equals("manifest")) {
                manifest = parseManifest(e);
            } else if (e.getName().equals("include")) {
                parseInclude(e, file.getParentFile(), defaultDir, targetArch,
                    descrList, pluginList);
            } else {
                throw new PluginException("Unknown element " + e.getName());
            }
        }
    }
View Full Code Here

        Manifest mf = this.manifest;
        if (mf == null) {
            mf = new Manifest();
        }
        for (Iterator<?> i = me.getChildren().iterator(); i.hasNext();) {
            final XMLElement e = (XMLElement) i.next();
            if (e.getName().equals("attribute")) {
                final String k = e.getStringAttribute("key");
                final String v = e.getStringAttribute("value");
                try {
                    mf.addConfiguredAttribute(new Manifest.Attribute(k, v));
                } catch (ManifestException ex) {
                    throw new PluginException("Error in manifest", ex);
                }
            } else {
                throw new PluginException("Unknown element " + e.getName());
            }
        }
        return mf;
    }
View Full Code Here

    }


    public static Plugin readPlugin(Reader in) throws Exception {

        final XMLElement root = new XMLElement(new Hashtable<Object, Object>(), true, false);
        root.parseFromReader(in);
        String rname = root.getName();
        if (rname.equals("plugin") || rname.equals("fragment")) {
            String id = (String) root.getAttribute("id");
            if (id == null) {
                throw new RuntimeException("Invalid plugin");
            }
            Plugin plug = new Plugin(id);
            String system = (String) root.getAttribute("system");
            if (system != null && "true".equals(system)) {
                plug.setSystem();
            }
            for (XMLElement obj : root.getChildren()) {
                String name = obj.getName();
                if (name.equals("requires")) {
                    for (XMLElement ch : obj.getChildren()) {
                        String xname = ch.getName();
                        if (xname.equals("import")) {
                            String pid = (String) ch.getAttribute("plugin");
                            if (pid != null) {
                                plug.addRecuiredId(pid);
                            }
                        }
                    }
                }
            }
            if (rname.equals("fragment")) {
                String pid = (String) root.getAttribute("plugin-id");
                if (pid == null) {
                    throw new RuntimeException("Invalid fragment");
                }
                plug.addRecuiredId(pid);
            }
View Full Code Here

TOP

Related Classes of org.jnode.nanoxml.XMLElement

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.