Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 164   Methods: 3
NCLOC: 119   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XUpdateCollectionViewer.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: XUpdateCollectionViewer.java 711958 2008-11-06 20:12:54Z natalia $
 18    */
 19   
 20    package org.apache.xindice.webadmin.viewer.components;
 21   
 22    import java.io.IOException;
 23    import java.io.Writer;
 24   
 25    import javax.servlet.ServletException;
 26    import javax.servlet.http.HttpServletRequest;
 27    import javax.servlet.http.HttpServletResponse;
 28   
 29    import org.w3c.dom.Node;
 30   
 31    import org.apache.xindice.core.Collection;
 32    import org.apache.xindice.core.DBException;
 33    import org.apache.xindice.core.data.NodeSet;
 34    import org.apache.xindice.webadmin.viewer.*;
 35    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 36    import org.apache.xindice.xml.NamespaceMap;
 37    import org.apache.commons.logging.Log;
 38    import org.apache.commons.logging.LogFactory;
 39   
 40    /**
 41    * Xindice Html Viewer for collection xupdate searches.
 42    *
 43    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 44    * @version $Revision: 711958 $, $Date: 2008-11-06 20:12:54 +0000 (Thu, 06 Nov 2008) $
 45    */
 46    public class XUpdateCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 47   
 48    private static final Log log = LogFactory.getLog(XUpdateCollectionViewer.class);
 49   
 50  0 public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
 51    throws ServletException, IOException {
 52   
 53  0 String path = col.getCanonicalName();
 54  0 String title = "XUpdate for " + path;
 55   
 56  0 Writer output = startViewer(title, path, res);
 57   
 58  0 String xupdate = req.getParameter("xupdate");
 59  0 if(xupdate == null) {
 60  0 xupdate = "";
 61  0 } else if(xupdate.length() > 0) {
 62    // do xupdate
 63  0 try {
 64  0 NodeSet result = col.queryCollection("XUpdate", xupdate, new NamespaceMap());
 65  0 printResult(result, output);
 66    } catch (DBException e) {
 67  0 log.error(e);
 68    }
 69    }
 70   
 71  0 printStartTable(title, output);
 72  0 printStartSingleTableBox(output);
 73  0 output.write(XUPDATE_FORM_START);
 74  0 output.write(xupdate);
 75  0 output.write(XUPDATE_FORM_END);
 76  0 printEndSingleTableBox(output);
 77  0 printEndTable(output);
 78   
 79  0 output.write("<br />\n");
 80  0 printStartTable("Examples", output);
 81  0 printStartSingleTableBox(output);
 82  0 output.write(XUPDATE_EXAMPLES);
 83  0 printEndSingleTableBox(output);
 84  0 printEndTable(output);
 85   
 86  0 finishViewer(output);
 87    }
 88   
 89  0 private void printResult(NodeSet result, Writer output) throws IOException {
 90  0 if(result != null && result.hasMoreNodes()) {
 91  0 Object node = result.getNextNode();
 92  0 String modified;
 93  0 if(node instanceof Node) {
 94  0 modified = ((Node)node).getFirstChild().getNodeValue();
 95    } else {
 96    // TODO print something, that makes sense
 97  0 modified = "Sorry something went wrong!";
 98    }
 99  0 printStartTable("XUpdate Result", output);
 100  0 printStartSingleTableBox(output);
 101  0 output.write("Modified <b>"+modified+"</b> Nodes!\n");
 102  0 printEndSingleTableBox(output);
 103  0 printEndTable(output);
 104  0 output.write("<br />\n");
 105    }
 106    }
 107   
 108    private static final String XUPDATE_FORM_START =
 109    "<form action=\"\" method=\"post\"> \n" +
 110    "<table class=\"upload-form\"> \n" +
 111    "<tr><td> \n" +
 112    "<textarea name=\"xupdate\" cols=\"80\" rows=\"15\">\n" ;
 113   
 114    private static final String XUPDATE_FORM_END =
 115    "</textarea> \n" +
 116    "</td></tr><tr><td> \n" +
 117    "<input type=\"submit\" name=\"submit\" value=\"xupdate\" /> \n" +
 118    "</td></tr></table></form> \n";
 119   
 120    private static final String XUPDATE_EXAMPLES =
 121    "<b>Basic XUpdate Insert Command</b>" +
 122    "<pre>&lt;xupdate:modifications version=\"1.0\" \n" +
 123    " xmlns:xupdate=\"http://www.xmldb.org/xupdate\"&gt; \n\n" +
 124    " &lt;xupdate:insert-after select=\"/addresses/address[1]\" &gt; \n" +
 125    " &lt;xupdate:element name=\"address\"&gt; \n" +
 126    " &lt;xupdate:attribute name=\"id\"&gt;2&lt;/xupdate:attribute&gt; \n" +
 127    " &lt;fullname&gt;John Smith&lt;/fullname&gt; \n" +
 128    " &lt;born day='2' month='12' year='1974'/&gt; \n" +
 129    " &lt;country&gt;Germany&lt;/country&gt; \n" +
 130    " &lt;/xupdate:element&gt; \n\n" +
 131    " &lt;/xupdate:insert-after&gt; \n" +
 132    "&lt;/xupdate:modifications&gt; \n" +
 133    " </pre>" +
 134    "<b>XUpdate Commands</b><ul>" +
 135    "<li><code>xupdate:insert-before</code> " +
 136    " - Inserts a new node in document order before the selected node.</li> \n" +
 137    "<li><code>xupdate:insert-after</code>" +
 138    " - Inserts a new node in document order after the selected node.</li> \n" +
 139    "<li><code>xupdate:update</code>" +
 140    " - Replaces all child nodes of the selected node with the specified nodes.</li> \n" +
 141    "<li><code>xupdate:append</code>" +
 142    " - Appends the specified node to the content of the selected node.</li> \n" +
 143    "<li><code>xupdate:remove</code>" +
 144    " - Remove the selected node</li> \n" +
 145    "<li><code>xupdate:rename</code>" +
 146    " - Renames the selected node</li> \n" +
 147    "<li><code>xupdate:variable</code>" +
 148    " - Defines a variable containing a node list that can be reused in later operations.</li> \n" +
 149    "</ul><b>XUpdate Node Construction</b><ul>" +
 150    "<li><code>xupdate:element</code>" +
 151    " - Creates a new element in the document.</li> \n" +
 152    "<li><code>xupdate:attribute</code>" +
 153    " - Creates a new attribute node associated with an <code>xupdate:element</code>.</li> \n" +
 154    "<li><code>xupdate:text</code>" +
 155    " - Creates a text content node in the document.</li> \n" +
 156    "<li><code>xupdate:processing-instruction</code>" +
 157    " - Creates a processing instruction node in the document.</li> \n" +
 158    "<li><code>xupdate:comment</code>" +
 159    " - Creates a new comment node in the document.</li> </ul>\n";
 160   
 161  0 protected String getName() {
 162  0 return "xupdate";
 163    }
 164    }