Examples of XUpdateQueryImpl


Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    document = builder.parse(file.getAbsolutePath());
                    System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory",
                            "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                    XPathQuery xpath = XPathQueryFactory.newInstance().newXPathQuery();
                    XUpdateQuery xq = new XUpdateQueryImpl();

                    String editSelect = null;
                    String insertSelect = null;
                    Enumeration params = request.getParameterNames();
                    while (params.hasMoreElements()) {
                        String pname = (String) params.nextElement();
                        getLogger().debug("Parameter: " + pname + " ("
                                + request.getParameter(pname) + ")");

                        // Extract the xpath to edit
                        if (editSelect == null && pname.indexOf("edit[") >= 0
                                && pname.endsWith("].x")) {
                            editSelect = pname.substring(5, pname.length() - 3);
                            getLogger().debug("Edit: " + editSelect);
                        }
                       
                        // Make sure we are dealing with an xupdate statement,
                        // else skip
                        if (pname.indexOf("<xupdate:") == 0) {
                            String select = pname.substring(pname.indexOf("select") + 8);
                            select = select.substring(0, select.indexOf("\""));
                            getLogger().debug(".act() Select Node: " + select);

                            // Check if node exists
                            xpath.setQString(select);
                            XObject result = xpath.execute(document);
                            NodeList selectionNodeList = result.nodeset();
                            if (selectionNodeList.getLength() == 0) {
                                getLogger()
                                        .debug(".act(): Node does not exist (might have been deleted during update): "
                                                + select);
                            } else {
                                String xupdateModifications = null;
                                // now check for the different xupdate
                                // statements, and handle appropriately
                                if (pname.indexOf("xupdate:update-parent") > 0) {
                                    getLogger().debug("UPDATE PARENT Node: " + pname);
                                    // CDATA updates need to be handled
                                    // seperately
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname, true);
                                    } else {
                                        xupdateModifications = update(request,
                                                pname,
                                                select,
                                                selectionNodeList,
                                                true);
                                    }
                                } else if (pname.indexOf("xupdate:update") > 0) {
                                    getLogger().debug("UPDATE Node: " + pname);
                                    // CDATA updates need to be handled
                                    // seperately
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname, false);
                                    } else {
                                        xupdateModifications = update(request,
                                                pname,
                                                select,
                                                selectionNodeList,
                                                false);
                                    }
                                } else if (pname.indexOf("xupdate:append") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = append(pname.substring(0,
                                            pname.length() - 2));
                                    // insert-before: in case of select/option
                                } else if (pname.indexOf("xupdate:insert-before") > 0
                                        && pname.endsWith("/>")) {
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertBefore(request
                                                .getParameter(pname));
                                        insertSelect = pname.substring(31,pname.length() - 3);
                                    }
                                    // insert-before: in case of image
                                } else if (pname.indexOf("xupdate:insert-before") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = insertBefore(pname.substring(0, pname
                                            .length() - 2));
                                    // insert-after: in case of select/option
                                } else if (pname.indexOf("xupdate:insert-after") > 0
                                        && pname.endsWith("/>")) {
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertAfter(request
                                                .getParameter(pname));
                                        insertSelect = pname.substring(30,pname.length() - 3);
                                    }
                                    // insert-after: in case of image
                                } else if (pname.indexOf("xupdate:insert-after") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = insertAfter(pname.substring(0, pname
                                            .length() - 2));
                                } else if (pname.indexOf("xupdate:remove") > 0
                                        && pname.endsWith("/>.x")) {
                                    xupdateModifications = remove(pname.substring(0,
                                            pname.length() - 2));
                                    insertSelect = pname.substring(24,pname.length() - 3);
                                } else if (pname.endsWith(">.y")) {
                                    getLogger().debug("Don't handle this: " + pname);
                                } else {
                                    getLogger().debug("Don't handle this either: " + pname);
                                }

                                // Get hidden namespaces
                                String namespaces = request.getParameter("namespaces");

                                // Add XML declaration
                                // NOTE: select/option is generating parameter
                                // which should be considered as null
                                if (xupdateModifications != null) {
                                    xupdateModifications = "<?xml version=\"1.0\"?>"
                                            + addHiddenNamespaces(namespaces, xupdateModifications);
                                }

                                // now run the assembled xupdate query
                                if (xupdateModifications != null) {
                                    getLogger().info("Execute XUpdate Modifications: "
                                            + xupdateModifications);
                                    xq.setQString(xupdateModifications);
                                    xq.execute(document);
                                } else {
                                    getLogger()
                                            .debug("Parameter did not match any xupdate command: "
                                                    + pname);
                                }
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    DocumentBuilder builder = parserFactory.newDocumentBuilder();
                    document = builder.parse(file.getAbsolutePath());
                    System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory", "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                    XPathQuery xpath = XPathQueryFactory.newInstance().newXPathQuery();
                    XUpdateQuery xq = new XUpdateQueryImpl();

                    String editSelect = null;
                    Enumeration params = request.getParameterNames();
                    while (params.hasMoreElements()) {
                        String pname = (String) params.nextElement();
                        log.debug("Parameter: " + pname + " (" + request.getParameter(pname+ ")");

                        if (editSelect == null && pname.indexOf("edit[") >= 0 && pname.endsWith("].x")) {
                            editSelect = pname.substring(5, pname.length() - 3);
                           log.debug("Edit: " + editSelect);
                        }

                        if (pname.indexOf("<xupdate:") == 0) {
                            String select = pname.substring(pname.indexOf("select") + 8);
                            select = select.substring(0, select.indexOf("\""));
                            log.debug(".act() Select Node: " + select);

                            // Check if node exists
                            xpath.setQString(select);
                            XObject result = xpath.execute(document);
                            NodeList selectionNodeList = result.nodeset();
                            if (selectionNodeList.getLength() == 0) {
                                log.warn(".act(): Node does not exist (might have been deleted during update): " + select);
                            } else {
                                String xupdateModifications = null;
                                if (pname.indexOf("xupdate:update") > 0) {
                                    log.debug(".act(): UPDATE Node: " + pname);
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname);
                                    } else {
                                        xupdateModifications = update(request, pname, select, selectionNodeList);
                                    }
                                } else if (pname.indexOf("xupdate:append") > 0 && pname.endsWith(">.x")) {
                                // FIXME: Internet Explorer does not send the name without the coordinates if input type is equals image. Mozilla does.
                                //} else if (pname.indexOf("xupdate:append") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = append(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = append(pname);
                                } else if (pname.indexOf("xupdate:insert-before") > 0 && pname.endsWith(">.x")) {
                                //} else if (pname.indexOf("xupdate:insert-before") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = insertBefore(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = insertBefore(pname);
                                } else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith("/>")) {
                                    // select:option
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertAfter(request.getParameter(pname));
                                    }
                                } else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith(">.x")) {
                                //} else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = insertAfter(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = insertAfter(pname);
                                } else if (pname.indexOf("xupdate:remove") > 0 && pname.endsWith("/>.x")) {
                                //} else if (pname.indexOf("xupdate:remove") > 0 && pname.endsWith("/>")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = remove(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = remove(pname);
                                }

                                if (xupdateModifications != null) {
                                    log.debug(".act(): MODIFICATIONS: " + xupdateModifications);
                                    xq.setQString(xupdateModifications);
                                    xq.execute(document);
                                } else {
                                    log.debug(".act(): Parameter did not match any xupdate command: " + pname);
                                }
                            } // Check select
                    } // Check <xupdate:
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

        Document document = builder.parse(xmlInputSource);
        System
                .setProperty(XPathQueryFactory.class.getName(), XPathQueryFactoryImpl.class
                        .getName());

        XUpdateQuery xUpdateQuery = new XUpdateQueryImpl();

        String editSelect = processElements(document, xUpdateQuery);
        setParameter("editSelect", editSelect);

        // validate against relax ng after the updates
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    DocumentBuilder builder = parserFactory.newDocumentBuilder();
                    document = builder.parse(file.getAbsolutePath());
                    System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory", "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                    XPathQuery xpath = XPathQueryFactory.newInstance().newXPathQuery();
                    XUpdateQuery xq = new XUpdateQueryImpl();

                    String editSelect = null;
                    Enumeration params = request.getParameterNames();
                    while (params.hasMoreElements()) {
                        String pname = (String) params.nextElement();
                        log.debug("Parameter: " + pname + " (" + request.getParameter(pname+ ")");

                        if (editSelect == null && pname.indexOf("edit[") >= 0 && pname.endsWith("].x")) {
                            editSelect = pname.substring(5, pname.length() - 3);
                           log.debug("Edit: " + editSelect);
                        }

                        if (pname.indexOf("<xupdate:") == 0) {
                            String select = pname.substring(pname.indexOf("select") + 8);
                            select = select.substring(0, select.indexOf("\""));
                            log.debug(".act() Select Node: " + select);

                            // Check if node exists
                            xpath.setQString(select);
                            XObject result = xpath.execute(document);
                            NodeList selectionNodeList = result.nodeset();
                            if (selectionNodeList.getLength() == 0) {
                                log.warn(".act(): Node does not exist (might have been deleted during update): " + select);
                            } else {
                                String xupdateModifications = null;
                                if (pname.indexOf("xupdate:update") > 0) {
                                    log.debug(".act(): UPDATE Node: " + pname);
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname);
                                    } else {
                                        xupdateModifications = update(request, pname, select, selectionNodeList);
                                    }
                                } else if (pname.indexOf("xupdate:append") > 0 && pname.endsWith(">.x")) {
                                // FIXME: Internet Explorer does not send the name without the coordinates if input type is equals image. Mozilla does.
                                //} else if (pname.indexOf("xupdate:append") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = append(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = append(pname);
                                } else if (pname.indexOf("xupdate:insert-before") > 0 && pname.endsWith(">.x")) {
                                //} else if (pname.indexOf("xupdate:insert-before") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = insertBefore(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = insertBefore(pname);
                                } else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith("/>")) {
                                    // select:option
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertAfter(request.getParameter(pname));
                                    }
                                } else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith(">.x")) {
                                //} else if (pname.indexOf("xupdate:insert-after") > 0 && pname.endsWith(">")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = insertAfter(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = insertAfter(pname);
                                } else if (pname.indexOf("xupdate:remove") > 0 && pname.endsWith("/>.x")) {
                                //} else if (pname.indexOf("xupdate:remove") > 0 && pname.endsWith("/>")) {
                                    // no .x and .y from input type="image"
                                    xupdateModifications = remove(pname.substring(0, pname.length()-2));
                                    //xupdateModifications = remove(pname);
                                }

                                if (xupdateModifications != null) {
                                    log.debug(".act(): MODIFICATIONS: " + xupdateModifications);
                                    xq.setQString(xupdateModifications);
                                    xq.execute(document);
                                } else {
                                    log.debug(".act(): Parameter did not match any xupdate command: " + pname);
                                }
                            } // Check select
                    } // Check <xupdate:
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

    Node xupdateQuery = XPathAPI.selectSingleNode(updates, "/tests/test[@name='" + test + "']/xupdate/*", updates);
    String query = serialize((Element) xupdateQuery);

    Document result = getDocument(updates, "/tests/input[@name=/tests/test[@name='" + test + "']/@input]/*");
    XUpdateQuery xupdate = new XUpdateQueryImpl();
    xupdate.setQString(query);
    System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory", XPATHQUERYFACTORY);
    xupdate.execute(result);

    removeWhiteSpace(result);
    Document expected = getDocument(updates, "/tests/test[@name='" + test + "']/result/*");
    removeWhiteSpace(expected);

View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    "org.xmldb.common.xml.queries.XPathQueryFactory",
                    "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                XPathQuery xpath =
                    XPathQueryFactory.newInstance().newXPathQuery();
                XUpdateQuery xq = new XUpdateQueryImpl();

                String editSelect = null;
                Enumeration params = request.getParameterNames();
                while (params.hasMoreElements()) {
                    String pname = (String) params.nextElement();
                    log.debug(
                        "Parameter: "
                            + pname
                            + " ("
                            + request.getParameter(pname)
                            + ")");

                    // Extract the xpath to edit
                    if (editSelect == null
                        && pname.indexOf("edit[") >= 0
                        && pname.endsWith("].x")) {
                        editSelect = pname.substring(5, pname.length() - 3);
                        log.debug("Edit: " + editSelect);
                    }

                    // Make sure we are dealing with an xupdate statement, else skip
                    if (pname.indexOf("<xupdate:") == 0) {
                        String select =
                            pname.substring(pname.indexOf("select") + 8);
                        select = select.substring(0, select.indexOf("\""));
                        log.debug(".act() Select Node: " + select);

                        // Check if node exists
                        xpath.setQString(select);
                        XObject result = xpath.execute(document);
                        NodeList selectionNodeList = result.nodeset();
                        if (selectionNodeList.getLength() == 0) {
                            log.debug(
                                ".act(): Node does not exist (might have been deleted during update): "
                                    + select);
                        } else {
                            String xupdateModifications = null;
                            // now check for the different xupdate statements, and handle appropriately
                            if (pname.indexOf("xupdate:update-parent") > 0) {
                                log.debug("UPDATE PARENT Node: " + pname);
                                // CDATA updates need to be handled seperately
                                if (pname.indexOf("<![CDATA[") > 0) {
                                    xupdateModifications =
                                        updateCDATA(request, pname, true);
                                } else {
                                    xupdateModifications =
                                        update(
                                            request,
                                            pname,
                                            select,
                                            selectionNodeList,
                                            true);
                                }
                            } else if (pname.indexOf("xupdate:update") > 0) {
                                log.debug("UPDATE Node: " + pname);
                                // CDATA updates need to be handled seperately
                                if (pname.indexOf("<![CDATA[") > 0) {
                                    xupdateModifications =
                                        updateCDATA(request, pname, false);
                                } else {
                                    xupdateModifications =
                                        update(
                                            request,
                                            pname,
                                            select,
                                            selectionNodeList,
                                            false);
                                }
                            } else if (
                                pname.indexOf("xupdate:append") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    append(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            // insert-before: in case of select/option
                            } else if (
                                pname.indexOf("xupdate:insert-before") > 0
                                    && pname.endsWith("/>")) {
                                if (!request
                                    .getParameter(pname)
                                    .equals("null")) {
                                    xupdateModifications =
                                        insertBefore(
                                            request.getParameter(pname));
                                }
                            // insert-before: in case of image
                            } else if (
                                pname.indexOf("xupdate:insert-before") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    insertBefore(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            // insert-after: in case of select/option
                            } else if (
                                pname.indexOf("xupdate:insert-after") > 0
                                    && pname.endsWith("/>")) {
                                if (!request
                                    .getParameter(pname)
                                    .equals("null")) {
                                    xupdateModifications =
                                        insertAfter(
                                            request.getParameter(pname));
                                }
                            // insert-after: in case of image
                            } else if (
                                pname.indexOf("xupdate:insert-after") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    insertAfter(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            } else if (
                                pname.indexOf("xupdate:remove") > 0
                                    && pname.endsWith("/>.x")) {
                                xupdateModifications =
                                    remove(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            } else if (pname.endsWith(">.y")) {
                                log.debug("Don't handle this: " + pname);
                            } else {
                                log.debug("Don't handle this either: " + pname);
                            }

                            // Get hidden namespaces
                            String namespaces = request.getParameter("namespaces");

                            // Add XML declaration
          // NOTE: select/option is generating parameter which should be considered as null
                            if (xupdateModifications != null) {
                                xupdateModifications = "<?xml version=\"1.0\"?>" + addHiddenNamespaces(namespaces, xupdateModifications);
                            }

                            // now run the assembled xupdate query
                            if (xupdateModifications != null) {
                                log.info("Execute XUpdate Modifications: " + xupdateModifications);
                                xq.setQString(xupdateModifications);
                                xq.execute(document);
                            } else {
                                log.debug("Parameter did not match any xupdate command: " + pname);
                            }
                        }
                    }
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    document = builder.parse(file.getAbsolutePath());
                    System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory",
                            "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                    XPathQuery xpath = XPathQueryFactory.newInstance().newXPathQuery();
                    XUpdateQuery xq = new XUpdateQueryImpl();

                    String editSelect = null;
                    Enumeration params = request.getParameterNames();
                    while (params.hasMoreElements()) {
                        String pname = (String) params.nextElement();
                        getLogger().debug("Parameter: " + pname + " ("
                                + request.getParameter(pname) + ")");

                        // Extract the xpath to edit
                        if (editSelect == null && pname.indexOf("edit[") >= 0
                                && pname.endsWith("].x")) {
                            editSelect = pname.substring(5, pname.length() - 3);
                            getLogger().debug("Edit: " + editSelect);
                        }

                        // Make sure we are dealing with an xupdate statement,
                        // else skip
                        if (pname.indexOf("<xupdate:") == 0) {
                            String select = pname.substring(pname.indexOf("select") + 8);
                            select = select.substring(0, select.indexOf("\""));
                            getLogger().debug(".act() Select Node: " + select);

                            // Check if node exists
                            xpath.setQString(select);
                            XObject result = xpath.execute(document);
                            NodeList selectionNodeList = result.nodeset();
                            if (selectionNodeList.getLength() == 0) {
                                getLogger()
                                        .debug(".act(): Node does not exist (might have been deleted during update): "
                                                + select);
                            } else {
                                String xupdateModifications = null;
                                // now check for the different xupdate
                                // statements, and handle appropriately
                                if (pname.indexOf("xupdate:update-parent") > 0) {
                                    getLogger().debug("UPDATE PARENT Node: " + pname);
                                    // CDATA updates need to be handled
                                    // seperately
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname, true);
                                    } else {
                                        xupdateModifications = update(request,
                                                pname,
                                                select,
                                                selectionNodeList,
                                                true);
                                    }
                                } else if (pname.indexOf("xupdate:update") > 0) {
                                    getLogger().debug("UPDATE Node: " + pname);
                                    // CDATA updates need to be handled
                                    // seperately
                                    if (pname.indexOf("<![CDATA[") > 0) {
                                        xupdateModifications = updateCDATA(request, pname, false);
                                    } else {
                                        xupdateModifications = update(request,
                                                pname,
                                                select,
                                                selectionNodeList,
                                                false);
                                    }
                                } else if (pname.indexOf("xupdate:append") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = append(pname.substring(0,
                                            pname.length() - 2));
                                    // insert-before: in case of select/option
                                } else if (pname.indexOf("xupdate:insert-before") > 0
                                        && pname.endsWith("/>")) {
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertBefore(request
                                                .getParameter(pname));
                                    }
                                    // insert-before: in case of image
                                } else if (pname.indexOf("xupdate:insert-before") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = insertBefore(pname.substring(0, pname
                                            .length() - 2));
                                    // insert-after: in case of select/option
                                } else if (pname.indexOf("xupdate:insert-after") > 0
                                        && pname.endsWith("/>")) {
                                    if (!request.getParameter(pname).equals("null")) {
                                        xupdateModifications = insertAfter(request
                                                .getParameter(pname));
                                    }
                                    // insert-after: in case of image
                                } else if (pname.indexOf("xupdate:insert-after") > 0
                                        && pname.endsWith(">.x")) {
                                    xupdateModifications = insertAfter(pname.substring(0, pname
                                            .length() - 2));
                                } else if (pname.indexOf("xupdate:remove") > 0
                                        && pname.endsWith("/>.x")) {
                                    xupdateModifications = remove(pname.substring(0,
                                            pname.length() - 2));
                                } else if (pname.endsWith(">.y")) {
                                    getLogger().debug("Don't handle this: " + pname);
                                } else {
                                    getLogger().debug("Don't handle this either: " + pname);
                                }

                                // Get hidden namespaces
                                String namespaces = request.getParameter("namespaces");

                                // Add XML declaration
                                // NOTE: select/option is generating parameter
                                // which should be considered as null
                                if (xupdateModifications != null) {
                                    xupdateModifications = "<?xml version=\"1.0\"?>"
                                            + addHiddenNamespaces(namespaces, xupdateModifications);
                                }

                                // now run the assembled xupdate query
                                if (xupdateModifications != null) {
                                    getLogger().info("Execute XUpdate Modifications: "
                                            + xupdateModifications);
                                    xq.setQString(xupdateModifications);
                                    xq.execute(document);
                                } else {
                                    getLogger()
                                            .debug("Parameter did not match any xupdate command: "
                                                    + pname);
                                }
View Full Code Here

Examples of org.xmldb.xupdate.lexus.XUpdateQueryImpl

                    "org.xmldb.common.xml.queries.XPathQueryFactory",
                    "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");

                XPathQuery xpath =
                    XPathQueryFactory.newInstance().newXPathQuery();
                XUpdateQuery xq = new XUpdateQueryImpl();

                String editSelect = null;
                Enumeration params = request.getParameterNames();
                while (params.hasMoreElements()) {
                    String pname = (String) params.nextElement();
                    log.debug(
                        "Parameter: "
                            + pname
                            + " ("
                            + request.getParameter(pname)
                            + ")");

                    // Extract the xpath to edit
                    if (editSelect == null
                        && pname.indexOf("edit[") >= 0
                        && pname.endsWith("].x")) {
                        editSelect = pname.substring(5, pname.length() - 3);
                        log.debug("Edit: " + editSelect);
                    }

                    // Make sure we are dealing with an xupdate statement, else skip
                    if (pname.indexOf("<xupdate:") == 0) {
                        String select =
                            pname.substring(pname.indexOf("select") + 8);
                        select = select.substring(0, select.indexOf("\""));
                        log.debug(".act() Select Node: " + select);

                        // Check if node exists
                        xpath.setQString(select);
                        XObject result = xpath.execute(document);
                        NodeList selectionNodeList = result.nodeset();
                        if (selectionNodeList.getLength() == 0) {
                            log.debug(
                                ".act(): Node does not exist (might have been deleted during update): "
                                    + select);
                        } else {
                            String xupdateModifications = null;
                            // now check for the different xupdate statements, and handle appropriately
                            if (pname.indexOf("xupdate:update-parent") > 0) {
                                log.debug("UPDATE PARENT Node: " + pname);
                                // CDATA updates need to be handled seperately
                                if (pname.indexOf("<![CDATA[") > 0) {
                                    xupdateModifications =
                                        updateCDATA(request, pname, true);
                                } else {
                                    xupdateModifications =
                                        update(
                                            request,
                                            pname,
                                            select,
                                            selectionNodeList,
                                            true);
                                }
                            } else if (pname.indexOf("xupdate:update") > 0) {
                                log.debug("UPDATE Node: " + pname);
                                // CDATA updates need to be handled seperately
                                if (pname.indexOf("<![CDATA[") > 0) {
                                    xupdateModifications =
                                        updateCDATA(request, pname, false);
                                } else {
                                    xupdateModifications =
                                        update(
                                            request,
                                            pname,
                                            select,
                                            selectionNodeList,
                                            false);
                                }
                            } else if (
                                pname.indexOf("xupdate:append") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    append(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            } else if (
                                pname.indexOf("xupdate:insert-before") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    insertBefore(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            } else if (
                                pname.indexOf("xupdate:insert-after") > 0
                                    && pname.endsWith("/>")) {
                                // FIXME: Not sure why this is here.
                                if (!request
                                    .getParameter(pname)
                                    .equals("null")) {
                                    xupdateModifications =
                                        insertAfter(
                                            request.getParameter(pname));
                                }
                            } else if (
                                pname.indexOf("xupdate:insert-after") > 0
                                    && pname.endsWith(">.x")) {
                                xupdateModifications =
                                    insertAfter(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            } else if (
                                pname.indexOf("xupdate:remove") > 0
                                    && pname.endsWith("/>.x")) {
                                xupdateModifications =
                                    remove(
                                        pname.substring(
                                            0,
                                            pname.length() - 2));
                            }

                            // now run the assembled xupdate query
                            if (xupdateModifications != null) {
                                log.debug(
                                    ".act(): MODIFICATIONS: "
                                        + xupdateModifications);
                                xq.setQString(xupdateModifications);
                                xq.execute(document);
                            } else {
                                log.debug(
                                    ".act(): Parameter did not match any xupdate command: "
                                        + pname);
                            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.