1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
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 |
| |
42 |
| |
43 |
| |
44 |
| |
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 |
| |
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 |
| |
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><xupdate:modifications version=\"1.0\" \n" + |
123 |
| " xmlns:xupdate=\"http://www.xmldb.org/xupdate\"> \n\n" + |
124 |
| " <xupdate:insert-after select=\"/addresses/address[1]\" > \n" + |
125 |
| " <xupdate:element name=\"address\"> \n" + |
126 |
| " <xupdate:attribute name=\"id\">2</xupdate:attribute> \n" + |
127 |
| " <fullname>John Smith</fullname> \n" + |
128 |
| " <born day='2' month='12' year='1974'/> \n" + |
129 |
| " <country>Germany</country> \n" + |
130 |
| " </xupdate:element> \n\n" + |
131 |
| " </xupdate:insert-after> \n" + |
132 |
| "</xupdate:modifications> \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 |
| } |