Package org.kxml2.kdom

Examples of org.kxml2.kdom.Element


        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;

                root = doc.getRootElement();

                try {
                    /*
                     * try to get the metadata
                     */
 
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) {
            parser = null;
            doc = null;
            throw new BookException("Wrong XML data.");
        }

        try {

            /*
             * root element
             */
            root = doc.getRootElement();

            int childCount = root.getChildCount();

            for (int i = 0; i < childCount ; i++ ) {
                if (root.getType(i) != Node.ELEMENT) {
View Full Code Here

    }
  }

  public void addWsseHeader(String userName, String userPassword)
  {
    Element usernameTag = new Element();

    usernameTag.setName("wsse:Username");
    usernameTag.addChild(Element.TEXT, userName);

    Element passwordTag = new Element();

    passwordTag.setName("wsse:Password");
    passwordTag.addChild(Element.TEXT, userPassword);

    Element tokenTag = new Element();

    tokenTag.setName("wsse:UsernameToken");
    tokenTag.addChild(Element.ELEMENT, usernameTag);
    tokenTag.addChild(Element.ELEMENT, passwordTag);

    Element securityHeader = new Element();

    securityHeader.setName("wsse:Security");
    securityHeader.setPrefix("wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
    securityHeader.addChild(Element.ELEMENT, tokenTag);

    addHeader(securityHeader);
  }
View Full Code Here

    }
  }

  public void addWsseHeader(String userName, String userPassword)
  {
    Element usernameTag = new Element();
    usernameTag.setName("wsse:Username");
    usernameTag.addChild(Element.TEXT, userName);

    Element passwordTag = new Element();
    passwordTag.setName("wsse:Password");
    passwordTag.addChild(Element.TEXT, userPassword);

    Element tokenTag = new Element();
    tokenTag.setName("wsse:UsernameToken");
    tokenTag.addChild(Element.ELEMENT, usernameTag);
    tokenTag.addChild(Element.ELEMENT, passwordTag);

    Element securityHeader = new Element();
    securityHeader.setName("wsse:Security");
    securityHeader.setPrefix("wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
    securityHeader.addChild(Element.ELEMENT, tokenTag);

    addHeader(securityHeader);
  }
View Full Code Here

        for (int i = 0; i < node.getChildCount(); i++) {
            if (node.getType(i) != Node.ELEMENT) {
                continue;
            }

            Element element = node.getElement(i);
            if (name.equalsIgnoreCase(element.getName())) {
                return element;
            }
        }

        return null;
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;

                root = doc.getRootElement();

                try {
                    /*
                     * try to get the metadata
                     */
//                    meta = new Hashtable(10);

                    Element metadata = getElement(root, "metadata");
                   
                    Element dcmetadata = getElement(metadata, "dc-metadata");
                   
                    if (dcmetadata != null) {
                        metadata = dcmetadata;
                    }

                    if (metadata != null) {
                        for (int i = 0; i < metadata.getChildCount(); i++) {
                            if (metadata.getType(i) != Node.ELEMENT) {
                                continue;
                            }

                            kid = metadata.getElement(i);

                            if (kid.getName().equalsIgnoreCase("title")) {
                                title = text(kid);
                                continue;
                            }

                            if (kid.getName().equalsIgnoreCase("creator")) {
                                author = text(kid);
                                continue;
                            }

                            if (kid.getName().equalsIgnoreCase("language")) {
                                language = text(kid);
                                /*
                                 * squash it to a 2-letter tag
                                 */
                                if (language.length() > 2) {
                                    language = language.substring(0, 2);
                                }

                                /*
                                 * set currentLanguage to the default value
                                 * afterward (in loadUserFile) it will
                                 * be overwritten
                                 */
                                currentLanguage = language;

                                continue;
                            }

//                            if (kid.getName().equalsIgnoreCase("meta")) {
//                                String metaname = kid.getAttributeValue(parser.NO_NAMESPACE, "name");
//                                String metavalue = kid.getAttributeValue(parser.NO_NAMESPACE, "content");
//                                if (metaname != null && metavalue != null
//                                        && !metaname.startsWith("calibre")) {
//                                    /*
//                                     * Ignore Calibre-specific tags,
//                                     * as they are not informative for the
//                                     * reader, but only for Calibre
//                                     */
//                                    meta.put(metaname, metavalue);
//                                }
//
//                                continue;
//                            }
//
//                            /*
//                             * It's a metadata then
//                             */
//                            {
//                                String metaname = kid.getName();
//                                String metavalue = text(kid);
//
//                                if (metaname != null && metavalue != null
//                                        && !metaname.startsWith("calibre")) {
//                                    meta.put(metaname, metavalue);
//                                }
//                            }
                        }
                    }
                } catch (Exception e) {
                    /*
                     * If there is a problem with the metadata,
                     * it's not worth bothering
                     */
                    //#debug
                    AlbiteMIDlet.LOGGER.log(e);
                }

                Hashtable manifest = new Hashtable(200);

                try {
                    /*
                     * Parse the manifest list
                     */
                    Element manifestEl = getElement(root, "manifest");

                    if (manifestEl == null) {
                        throw new BookException("No manifest tag in OPF");
                    }
                   
                    for (int i = 0; i < manifestEl.getChildCount(); i++) {
                        if (manifestEl.getType(i) != Node.ELEMENT) {
                            continue;
                        }

                        kid = manifestEl.getElement(i);

                        if (kid.getName().equalsIgnoreCase("item")) {
                            String id = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "id");
                            String href = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "href");

                            if (id != null && href != null) {
                                /*
                                 * Item is OK
                                 */
                                manifest.put(id, href);
                            }
                        }
                    }
                } catch (Exception e) {
                    //#debug
                    AlbiteMIDlet.LOGGER.log(e);
                    throw new BookException("couldn't parse manifest");
                }

                try {
                    /*
                     * Parse the spine and create the chapters
                     */
                    Vector chaps = new Vector(40);

                    Element spine = getElement(root, "spine");

                    if (spine == null) {
                        throw new BookException("No spine tag in OPF");
                    }

                    for (int i = 0; i < spine.getChildCount(); i++) {
                        if (spine.getType(i) != Node.ELEMENT) {
                            continue;
                        }

                        kid = spine.getElement(i);

                        if (kid.getName().equalsIgnoreCase("itemref")) {
                            String idref = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "idref");
                            if (idref != null) {
View Full Code Here

         */
        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) {
            parser = null;
            doc = null;
            throw new BookException("Wrong XML data.");
        }

        try {

            /*
             * root element
             */
            root = doc.getRootElement();

            int childCount = root.getChildCount();

            for (int i = 0; i < childCount ; i++ ) {
                if (root.getType(i) != Node.ELEMENT) {
                    continue;
                }

                kid = root.getElement(i);

                final int chapter =
                        readIntFromXML(kid, USERDATA_CHAPTER_ATTRIB);

                int position =
                        readIntFromXML(kid, USERDATA_POSITION_ATTRIB);

                if (position < 0) {
                    position = 0;
                }

                if (kid.getName().equals(USERDATA_BOOKMARK_TAG)) {

                    String text = kid.getText(0);

                    if (text == null) {
                        text = "Untitled";
                    }

View Full Code Here

TOP

Related Classes of org.kxml2.kdom.Element

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.