Package org.kxml2.kdom

Examples of org.kxml2.kdom.Node


          zin.close();
        } else {
          in = url.openStream();
        }
        Reader reader = new InputStreamReader(in);
        XmlPullParser parser = new KXmlParser();
        parser.setInput(reader);
        parseRepository(parser);
      } catch( MalformedURLException e ) {
        System.out.println("Cannot create connection to url");
      }
    }
View Full Code Here


    ByteArrayInputStream bais = new ByteArrayInputStream(xmlStr.getBytes());
    InputStreamReader isr = new InputStreamReader(bais);

    try {
        KXmlParser parser = new KXmlParser();
        parser.setInput(isr);
        while (parser.next() != XmlPullParser.END_DOCUMENT) {
      if (parser.getEventType() == XmlPullParser.START_TAG) {
          System.out.println("start tag: " + parser.getName());
      }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
View Full Code Here

        }

        in = container.openInputStream();

        try {
            KXmlParser parser = null;
            Document doc = null;
            Element root;
            Element kid;
            try {
                parser = new KXmlParser();
                parser.setInput(new AlbiteStreamReader(
                        in, Encodings.DEFAULT));

                doc = new Document();
                doc.parse(parser);
                parser = null;

                root = doc.getRootElement();

                Element rfile = root
                        .getElement(KXmlParser.NO_NAMESPACE, "rootfiles")
                        .getElement(KXmlParser.NO_NAMESPACE, "rootfile");

                opfFileName = rfile.getAttributeValue(
                        KXmlParser.NO_NAMESPACE, "full-path");

                if (opfFileName == null) {
                    throw new BookException("Missing opf file");
                }

                opfFilePath = RandomReadingFile.getPathFromURL(opfFileName);

                //#debug
                AlbiteMIDlet.LOGGER.log(opfFilePath);

            } catch (XmlPullParserException xppe) {
                parser = null;
                doc = null;
                throw new BookException(
                    "container.xml is invalid");
            }
        } finally {
            in.close();
        }

        /*
         * now the opf file
         */
        ArchiveEntry opfFile = bookArchive.getEntry(opfFileName);

        if (opfFile == null) {
            throw new BookException("Missing opf");
        }

        in = opfFile.openInputStream();

        try {
            KXmlParser parser = null;
            Document doc = null;
            Element root;
            Element kid;

            try {
                parser = new KXmlParser();

                try {
                    parser.setFeature(
                            KXmlParser.FEATURE_PROCESS_NAMESPACES, true);
                } catch (XmlPullParserException e) {}

                parser.setInput(new AlbiteStreamReader(
                        in, Encodings.DEFAULT));

                doc = new Document();
                doc.parse(parser);
                parser = null;
View Full Code Here

        /*
         * Loading bookmarks
         */
        InputStream in = bookmarksFile.openInputStream();

        KXmlParser parser = null;
        Document doc = null;
        Element root;
        Element kid;

        try {
            parser = new KXmlParser();
            parser.setInput(new InputStreamReader(in, "UTF-8"));

            doc = new Document();
            doc.parse(parser);
            parser = null;
        } catch (XmlPullParserException e) {
View Full Code Here

    // Obtain the data, build the DOM
    Element htmlElement;

    try {
      Element dummy = new Element(this, "");
      KXmlParser parser = new KXmlParser();
      if (encoding != null && encoding.trim().length() == 0) {
        encoding = "UTF-8";
      }
      parser.setInput(is, encoding);
      parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);

      for (int i = 0; i < HTML_ENTITY_TABLE.length; i += 2) {
        parser.defineEntityReplacementText(HTML_ENTITY_TABLE[i], HTML_ENTITY_TABLE[i + 1]);
      }

      dummy.parseContent(parser);

      htmlElement = dummy.getElement("html");
View Full Code Here

          }
        } else {
          in = url.openStream();
        }
        Reader reader = new InputStreamReader(in);
        XmlPullParser parser = new KXmlParser();
        parser.setInput(reader);
        parseRepository(parser);
      } catch( MalformedURLException e ) {
        System.out.println("Cannot create connection to url");
      }
    }
View Full Code Here

                // cannot happen
            }
            return false;
        }

        KXmlParser parser = new KXmlParser();
        try {
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

            if (input instanceof FileInputStream) {
                input = new BufferedInputStream(input);
            }
            parser.setInput(input, SdkConstants.UTF_8);

            return parse(path, parser);
        } catch (XmlPullParserException e) {
            String message = e.getMessage();

            // Strip off position description
            int index = message.indexOf("(position:"); //$NON-NLS-1$ (Hardcoded in KXml)
            if (index != -1) {
                message = message.substring(0, index);
            }

            String error = String.format("%1$s:%2$d: Error: %3$s", //$NON-NLS-1$
                    path, parser.getLineNumber(), message);
            mContext.addError(error);
            return false;
        } catch (RuntimeException e) {
            // Some exceptions are thrown by the KXmlParser that are not XmlPullParserExceptions,
            // such as this one:
            //    java.lang.RuntimeException: Undefined Prefix: w in org.kxml2.io.KXmlParser@...
            //        at org.kxml2.io.KXmlParser.adjustNsp(Unknown Source)
            //        at org.kxml2.io.KXmlParser.parseStartTag(Unknown Source)
            String message = e.getMessage();
            String error = String.format("%1$s:%2$d: Error: %3$s", //$NON-NLS-1$
                    path, parser.getLineNumber(), message);
            mContext.addError(error);
            return false;
        } finally {
            try {
                Closeables.close(input, true /* swallowIOException */);
 
View Full Code Here

     * This converts all the extensions into objects using information from their config.xml and returns an array.
     *
     * @return A list of extensions that are loaded or an empty list of no extension is loaded successfully.
     */
    public ArrayList loadExtensions() {
        KXmlParser parser = new KXmlParser();
        ArrayList extList = new ArrayList();
        File[] extensions = mDirectory.listFiles(new FileFilter() {
            public boolean accept(File file) {
                return file.isDirectory();
            }
        });
        int i;
        try {
            for (i = 0; i < extensions.length; i++) {
                File ext = extensions[i];
                KindleLauncher.LOG.info("Loading: " + ext.getAbsolutePath());
                File config = new File(ext, "config.xml");
                Extension extObj = new Extension();
                parser.setInput(new InputStreamReader(new FileInputStream(config)));
                parser.nextTag();
                parser.require(XmlPullParser.START_TAG, null, "extension");
                while (parser.nextTag() != XmlPullParser.END_TAG) {
                    parser.require(XmlPullParser.START_TAG, null, null);
                    String name = parser.getName();
                    if (name.equals("information"))
                        parseInformation(parser, extObj);
                    else if (name.equals("menus"))
                        parseMenus(parser, extObj, ext);
                    else //skip
                        while (parser.next() != XmlPullParser.END_TAG || !parser.getName().equals(name))
                            ; // this one line does magic to skip all unrelated events
                    parser.require(XmlPullParser.END_TAG, null, name);
                }
                parser.require(XmlPullParser.END_TAG, null, "extension");
                parser.next();
                parser.require(XmlPullParser.END_DOCUMENT, null, null);
                extList.add(extObj);
                KindleLauncher.LOG.info(LOADED_EXTENSION, new String[]{extObj.getName(), extObj.getVersion(), extObj.getAuthor(), extObj.getId()}, "");
            }
        } catch (IOException e) {
            KindleLauncher.LOG.error("Error reading extension config. " + e.getMessage());
View Full Code Here

        if (publicXmlFile.exists()) {
            Reader reader = null;
            try {
                reader = new BufferedReader(new InputStreamReader(publicXmlFile.getContents(),
                        Charsets.UTF_8));
                KXmlParser parser = new KXmlParser();
                parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
                parser.setInput(reader);

                ResourceType lastType = null;
                String lastTypeName = "";
                while (true) {
                    int event = parser.next();
                    if (event == XmlPullParser.START_TAG) {
                        // As of API 15 there are a number of "java-symbol" entries here
                        if (!parser.getName().equals("public")) { //$NON-NLS-1$
                            continue;
                        }

                        String name = null;
                        String typeName = null;
                        for (int i = 0, n = parser.getAttributeCount(); i < n; i++) {
                            String attribute = parser.getAttributeName(i);

                            if (attribute.equals("name")) { //$NON-NLS-1$
                                name = parser.getAttributeValue(i);
                                if (typeName != null) {
                                    // Skip id attribute processing
                                    break;
                                }
                            } else if (attribute.equals("type")) { //$NON-NLS-1$
                                typeName = parser.getAttributeValue(i);
                            }
                        }

                        if (name != null && typeName != null) {
                            ResourceType type = null;
View Full Code Here

    {
        boolean result=false;
        try
        {
            InputStream xmlIn =new ByteArrayInputStream(xmlResponse.getBytes());
            KXmlParser parser = new KXmlParser();
            parser.setInput(new InputStreamReader(xmlIn));
            GenericXmlParser gParser = new GenericXmlParser();
            xml = gParser.parseXML(parser, true);
            result=true;
        }
        catch(Exception e)
View Full Code Here

TOP

Related Classes of org.kxml2.kdom.Node

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.