svn commit: r541504 [4/7] - in /xml/xindice/trunk: ./ config/ java/scratchpad/webadmin/ java/src/org/apache/xindice/client/xmldb/embed/ java/src/org/apache/xindice/core/ java/src/org/apache/xindice/core/data/ java/src/org/apache/xindice/core/filer/ jav...

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/DeleteResourceViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/DeleteResourceViewer.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/DeleteResourceViewer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/DeleteResourceViewer.java Thu May 24 18:43:39 2007
@@ -16,7 +16,7 @@
  *
  * $Id$
  */
- 
+
 package org.apache.xindice.webadmin.viewer.components;
 
 import java.io.IOException;
@@ -28,97 +28,92 @@
 
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
-import org.apache.xindice.webadmin.viewer.*;
 import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
+import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
 
 /**
  * Xindice Html Viewer for deleting resources.
- * 
- * @avalon.component
- * @avalon.service type=HtmlResourceViewer
- * @x-avalon.info name=delete-resource
- * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$
  */
-public class DeleteResourceViewer
-	extends HtmlViewerComponent
-	implements HtmlResourceViewer {
-		
-	String ROLE = HtmlResourceViewer.ROLE+"/DeleteResourceViewer";
-
-	public void execute(
-		HttpServletRequest req,
-		HttpServletResponse res,
-		Collection parentCol,
-		String resourceName)
-		throws ServletException, IOException {
-		
-		String path = parentCol.getCanonicalName()+"/"+resourceName;
-		String title = "Delete Document "+path;
-		
-		String action = req.getParameter("action");
-		String redirect = req.getParameter("redirect");
-		if(redirect == null) {
-			redirect = "";
-		}
-		if(action == null || !action.equals("yes")) {
-			ServletOutputStream output = startViewer(title, path, res);
-			printStartTable(title, output);
-			printStartSingleTableBox(output);
-			output.print("<a href=\"./?viewer=default\">up to parent collection</a>" );
-			printEndSingleTableBox(output);
-			printStartSingleTableBox(output);
-			output.print("Do you really want to delete ");
-			output.print(resourceName);
-			output.print("? <a href=\"javascript:history.back()\">no</a> ");
-			output.print("<a href=\"?viewer=delete-resource&action=yes&redirect=");
-			output.print(redirect);
-			output.print("\">yes</a>" );
-			printEndSingleTableBox(output);
-			printEndTable(output);
-			finishViewer(output);
-		} else {
-			try {
-				// delete resource
-				parentCol.remove(resourceName);
-				
-				// display output or redirect
-				if(redirect.length() > 0) {
-					res.sendRedirect(redirect);
-				} else {
-					ServletOutputStream output = startViewer(title, path, res);
-					printStartTable(title, output);
-					printStartSingleTableBox(output);
-					output.print("<a href=\"./?viewer=default\">up to parent collection</a>" );
-					printEndSingleTableBox(output);
-					printStartSingleTableBox(output);
-					output.print("<b>Document ");
-					output.print(resourceName);
-					output.print(" deleted! </b>");
-					printEndSingleTableBox(output);
-					printEndTable(output);
-					finishViewer(output);
-				}
-			} catch (DBException e) {
-				e.printStackTrace();
-				ServletOutputStream output = startViewer(title, path, res);
-				printStartTable(title, output);
-				printStartSingleTableBox(output);
-				output.print("<a href=\"./?viewer=default\">up to parent collection</a>" );
-				printEndSingleTableBox(output);
-				printStartSingleTableBox(output);
-				output.print("<b>Cannot delete ");
-				output.print(resourceName);
-				output.print(": ");
-				output.print(e.getMessage());
-				printEndSingleTableBox(output);
-				printEndTable(output);
-				finishViewer(output);	
-			}
-		}
+public class DeleteResourceViewer extends HtmlViewerComponent implements HtmlResourceViewer {
+    private static final Log log = LogFactory.getLog(DeleteResourceViewer.class);
+
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col, String resourceName)
+            throws ServletException, IOException {
+
+        String path = col.getCanonicalName() + "/" + resourceName;
+        String title = "Delete Document " + path;
 
-	} 
+        String action = req.getParameter("action");
+        String redirect = req.getParameter("redirect");
+        if (redirect == null) {
+            redirect = "";
+        }
+
+        if (!"yes".equals(action)) { // ask confirmation
+            ServletOutputStream output = startViewer(title, path, res);
+            printStartTable(title, output);
+            printStartSingleTableBox(output);
+            output.print("<a href=\"./?viewer=default\">up to parent collection</a>");
+            printEndSingleTableBox(output);
+            printStartSingleTableBox(output);
+            output.print("Do you really want to delete ");
+            output.print(resourceName);
+            output.print("? <a href=\"javascript:history.back()\">no</a> ");
+            output.print("<a href=\"?viewer=delete&action=yes&redirect=");
+            output.print(redirect);
+            output.print("\">yes</a>");
+            printEndSingleTableBox(output);
+            printEndTable(output);
+            finishViewer(output);
+        } else {
+            try {
+                // delete resource
+                col.remove(resourceName);
+
+                // display output or redirect
+                if (redirect.length() > 0) {
+                    res.sendRedirect(redirect);
+                } else {
+                    ServletOutputStream output = startViewer(title, path, res);
+                    printStartTable(title, output);
+                    printStartSingleTableBox(output);
+                    output.print("<a href=\"./?viewer=default\">up to parent collection</a>");
+                    printEndSingleTableBox(output);
+                    printStartSingleTableBox(output);
+                    output.print("<b>Document ");
+                    output.print(resourceName);
+                    output.print(" deleted! </b>");
+                    printEndSingleTableBox(output);
+                    printEndTable(output);
+                    finishViewer(output);
+                }
+            } catch (DBException e) {
+                log.error(e);
+                ServletOutputStream output = startViewer(title, path, res);
+                printStartTable(title, output);
+                printStartSingleTableBox(output);
+                output.print("<a href=\"./?viewer=default\">up to parent collection</a>");
+                printEndSingleTableBox(output);
+                printStartSingleTableBox(output);
+                output.print("<b>Cannot delete ");
+                output.print(resourceName);
+                output.print(": ");
+                output.print(e.getMessage());
+                printEndSingleTableBox(output);
+                printEndTable(output);
+                finishViewer(output);
+            }
+        }
+
+    }
+
+    protected String getName() {
+        return "delete";
+    }
 
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/DeleteResourceViewer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListCollectionViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListCollectionViewer.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListCollectionViewer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListCollectionViewer.java Thu May 24 18:43:39 2007
@@ -32,167 +32,128 @@
 
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
-import org.apache.xindice.core.data.Key;
-import org.apache.xindice.core.data.Record;
-import org.apache.xindice.core.filer.Filer;
 import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
 import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 
 /**
  * Xindice Html Viewer for collection listings.
- * 
- * @avalon.component
- * @avalon.service type=HtmlCollectionViewer
- * @x-avalon.info name=list
- * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$
  */
-public class ListCollectionViewer
-  extends HtmlViewerComponent 
-  implements HtmlCollectionViewer {
-  	
-  /**
-   * Simple date format for the modification date representation.
-   */
-  protected static final SimpleDateFormat modificationDateFormat =
-          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
-          
-
-  static {
-    modificationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
-  }
-
-  public void execute(HttpServletRequest req,
-    HttpServletResponse res,
-    Collection col)
-    throws ServletException, IOException {
-    	    
-	String requestPath = req.getPathInfo(); 
-	String path = "/";
-	boolean isDatabase = true;
-	if(requestPath != null && !requestPath.equals("/")) {
-		isDatabase = false;
-		path = col.getCanonicalName();
-	}
-	String title = "List contents for "+path;
-    
-    TableRow row = new TableRow();
-	ServletOutputStream output = startViewer(title, path, res);    
-	printStartTable(row.getTitles(), output);
-       
-    if(!isDatabase) {
-      // write parent
-      printTableRow(row.getParentCollection(), output);
-      // write child collections
-      String[] childCol = null;
-      try {
-        childCol = col.listCollections();
-      } catch(DBException e) {
-        childCol = new String[0];
-      }
-      for(int i = 0; i < childCol.length; i++) {
-		printTableRow(row.getCollection(childCol[i]), output);
-      }
-      // write child resources
-      String[] childRes = null;
-      Filer filer = null;
-      try { // get names
-        childRes = col.listDocuments(); // TODO binaries are also listed!
-      } catch(Exception e) {
-        childRes = new String[0];
-      }      
-      try { // get filer
-        filer = col.getFiler();
-      } catch(Exception e) {
-        filer = null;
-      }
-      for(int i = 0; i < childRes.length; i++) {
-        String date = null;
-        if(filer != null) {
-          try { // get date
-            Record record = filer.readRecord(new Key(childRes[i]));
-            long modificationDate = 
-              ((Long)record.getMetaData(Record.MODIFIED)).longValue();
-            date = (new StringBuffer(modificationDateFormat
-                      .format(new Date(modificationDate)))).toString();    
-          } catch(DBException e) {
-            date = null;
-          }
-        }
-		printTableRow(row.getResource(childRes[i], date), output);
-      }
-	  path = col.getCanonicalName();
-    } else { // write database
-	  printTableRow(row.getDatabase(col.getName()), output);
-    }
-	printEndTable(output);
-	finishViewer(output);
-  }
-
-  // TableRow Inner Class
-  protected class TableRow {
-
-    protected final String[] titles = { "Name", "Type", "Last Modification", "Source", "Delete" };
-  
-    protected String[] content;
-
-    TableRow() {
-      content = new String[titles.length];
-       reset();
-    }
+public class ListCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 
-    protected String[] getTitles() {
-      return titles;
-    }
+    /**
+     * Simple date format for the modification date representation.
+     */
+    public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
+
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
+            throws ServletException, IOException {
+
+        String path = col.getCanonicalName();
+        String title = "List contents for " + path;
+
+        TableRow row = new TableRow();
+        ServletOutputStream output = startViewer(title, path, res);
+        printStartTable(row.getTitles(), output);
+
+        // write parent
+        printTableRow(row.getParentCollection(), output);
+
+        // write child collections
+        String[] childCol;
+        try {
+            childCol = col.listCollections();
+        } catch (DBException e) {
+            childCol = new String[0];
+        }
+        for (int i = 0; i < childCol.length; i++) {
+            printTableRow(row.getCollection(childCol[i]), output);
+        }
 
-    protected void reset() {
-      for(int i = 0; i < content.length; i++) {
-        content[i] = null;
-      }
-    }
-  
-    protected String[] getCollection(String name) {
-      reset();
-      content[0] = createLink(name+"/?viewer=list", name);
-      content[1] = "collection";
-	  content[3] = "&nbsp;";
-	  content[4] = createLink(name+"/?viewer=delete&redirect=../?viewer=list", "delete");
-      return content;      
-    }
+        // write child resources
+        String[] childRes;
+        try { // get names
+            childRes = col.listDocuments();
+        } catch (Exception e) {
+            childRes = new String[0];
+        }
 
-    protected String[] getResource(String name, String date) {
-      reset();
-      content[0] = createLink(name+"?viewer=default", name);
-      content[1] = "resource";
-      content[2] = date;
-	  content[3] = createLink(name, "src");
-	  content[4] = createLink(name+"?viewer=delete-resource&redirect=./?viewer=list", "delete");
-      return content;      
+        for (int i = 0; i < childRes.length; i++) {
+            String date;
+            try { // get date
+                long modificationDate = col.getEntryMeta(childRes[i]).getModificationTime();
+                if (modificationDate != 0) {
+                    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+                    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
+                    date = formatter.format(new Date(modificationDate));
+                } else {
+                    date = "";
+                }
+            } catch (DBException e) {
+                date = "";
+            }
+            printTableRow(row.getResource(childRes[i], date), output);
+        }
+        printEndTable(output);
+        finishViewer(output);
     }
 
-    protected String[] getDatabase(String name) {
-      reset();
-      content[0] = createLink(name+"/?viewer=list", name);
-      content[1] = "database";
-      return content;      
+    protected String getName() {
+        return "list";
     }
 
-    protected String[] getParentCollection() {
-      reset();
-      content[0] = createLink("../?viewer=list", "up to parent collection");
-      content[1] = "collection";
-      return content;      
-    }
-    
-    protected String createLink(String link, String name) {
-    	return "<a href=\""+link+"\">"+name+"</a>";
-    }
+    // TableRow Inner Class
+    protected class TableRow {
+
+        protected final String[] titles = {"Name", "Type", "Last Modification", "Source", "Delete"};
 
+        protected String[] content;
 
-  }
+        TableRow() {
+            content = new String[titles.length];
+            reset();
+        }
 
-  
-  
+        protected String[] getTitles() {
+            return titles;
+        }
+
+        protected void reset() {
+            for (int i = 0; i < content.length; i++) {
+                content[i] = null;
+            }
+        }
+
+        protected String[] getCollection(String name) {
+            reset();
+            content[0] = createLink(name + "/?viewer=list", name);
+            content[1] = "collection";
+            content[3] = "&nbsp;";
+            content[4] = createLink(name + "/?viewer=delete&redirect=../?viewer=list", "delete");
+            return content;
+        }
+
+        protected String[] getResource(String name, String date) {
+            reset();
+            content[0] = createLink(name + "?viewer=default", name);
+            content[1] = "resource";
+            content[2] = date;
+            content[3] = createLink(name, "src");
+            content[4] = createLink(name + "?viewer=delete&redirect=./?viewer=list", "delete");
+            return content;
+        }
+
+        protected String[] getParentCollection() {
+            reset();
+            content[0] = createLink("../?viewer=list", "up to parent collection");
+            content[1] = "collection";
+            return content;
+        }
+
+        protected String createLink(String link, String name) {
+            return "<a href=\"" + link + "\">" + name + "</a>";
+        }
+    }
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListCollectionViewer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java Thu May 24 18:43:39 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xindice.webadmin.viewer.components;
+
+import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
+import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
+import org.apache.xindice.core.Database;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import java.io.IOException;
+
+/**
+ * Xindice Html Viewer for database listings.
+ */
+public class ListDatabaseViewer extends HtmlViewerComponent implements HtmlDatabaseViewer {
+
+    public void execute(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+
+        String[] databases = Database.listDatabases();
+
+        String path = "/";
+        String title = "List databases";
+
+        ListDatabaseViewer.TableRow row = new ListDatabaseViewer.TableRow();
+        ServletOutputStream output = startViewer(title, path, res);
+        printStartTable(row.getTitles(), output);
+
+        for (int i = 0; i < databases.length; i++) {
+            boolean metaEnabled = Database.getDatabase(databases[i]).isMetaEnabled();
+            String dbRoot = Database.getDatabase(databases[i]).getCollectionRoot().getCanonicalPath();
+            printTableRow(row.getDatabase(databases[i], metaEnabled, dbRoot), output);
+        }
+
+        printEndTable(output);
+        finishViewer(output);
+    }
+
+    protected String getName() {
+        return "list";
+    }
+
+    // TableRow Inner Class
+    protected class TableRow {
+
+        protected final String[] titles = {"Name", "Type", "Meta-enabled", "DB root"};
+
+        protected String[] content;
+
+        TableRow() {
+            content = new String[titles.length];
+            reset();
+        }
+
+        protected String[] getTitles() {
+            return titles;
+        }
+
+        protected void reset() {
+            for (int i = 0; i < content.length; i++) {
+                content[i] = null;
+            }
+        }
+
+        protected String[] getDatabase(String name, boolean metaEnabled, String dbRoot) {
+            reset();
+            content[0] = createLink(name + "/?viewer=list", name);
+            content[1] = "database";
+            content[2] = Boolean.toString(metaEnabled);
+            content[3] = dbRoot;
+            return content;
+        }
+
+        protected String createLink(String link, String name) {
+            return "<a href=\"" + link + "\">" + name + "</a>";
+        }
+    }
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/ListDatabaseViewer.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataCollectionViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataCollectionViewer.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataCollectionViewer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataCollectionViewer.java Thu May 24 18:43:39 2007
@@ -30,10 +30,11 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.framework.context.ContextException;
 import org.apache.commons.fileupload.DiskFileUpload;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
 import org.apache.xindice.core.meta.MetaData;
@@ -49,335 +50,304 @@
 
 /**
  * Xindice Html Viewer for Collection Metadata.
- * 
- * @avalon.component
- * @avalon.service type=HtmlCollectionViewer
- * @x-avalon.info name=meta
- * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$
  */
-public class MetadataCollectionViewer
-	extends HtmlViewerComponent
-	implements HtmlCollectionViewer {
-	
-	public void execute(HttpServletRequest req, HttpServletResponse res,
-		Collection col) throws ServletException, IOException {
-    	
-		String path = col.getCanonicalName();
-		String title = "Collection Metadata for "+path;
-		
-		ServletOutputStream output = startViewer(title, path, res);
-		
-		String attrName = req.getParameter("attrname");
-		if(attrName == null) {
-			attrName = "";
-		}
-		String attrValue = req.getParameter("attrvalue");
-		if(attrValue == null) {
-			attrValue = "";
-		}
-		String updateAttr = req.getParameter("updateattr");
-		String deleteAttr = req.getParameter("deleteattr");
-		String custom = req.getParameter("custom");
-		String deleteCustom = 	req.getParameter("deleteCustom");
-		
-		//	add attribute
-		if(attrName.length() > 0 && col.isMetaEnabled() && updateAttr == null) {
-			try {
-				MetaData newMeta = col.getCollectionMeta();
-				newMeta.setAttribute(attrName, attrValue);
-				col.setCollectionMeta(newMeta);
-				attrName = "";
-				attrValue = "";
-			} catch (DBException e1) {
-				e1.printStackTrace();
-				printError("Cannot add Attribute "+attrName+": "+e1.getMessage(),
-									output);
-			}
-		} else if(updateAttr != null && updateAttr.length() > 0 
-			&& col.isMetaEnabled()) {
-			attrName = updateAttr;
-			try {
-				attrValue = (String) col.getCollectionMeta().getAttribute(attrName);
-			} catch (DBException e) {
-				e.printStackTrace();
-				attrValue = "";
-			}
-		} else if(deleteAttr != null && deleteAttr.length() > 0 
-			&& col.isMetaEnabled()) {
-			try {
-				MetaData delMeta = col.getCollectionMeta();
-				delMeta.removeAttribute(deleteAttr);
-				col.setCollectionMeta(delMeta);
-			} catch (DBException e) {
-				e.printStackTrace();
-				printError("Cannot delete Attribute "+deleteAttr+": "+e.getMessage(),
-					output);
-			}
-		} else if(custom != null && custom.length() > 0 
-			&& col.isMetaEnabled()) {
-			try {
-				MetaData customMeta = col.getCollectionMeta();
-				Document customDoc = DOMParser.toDocument(custom);
-				customMeta.setCustomDocument(customDoc);
-				col.setCollectionMeta(customMeta);
-			} catch (DBException e) {
-				e.printStackTrace();
-				printError("Cannot add/update Custom: "+e.getMessage(), output);
-			} catch (XindiceException e) {
-				e.printStackTrace();
-				printError("Cannot add/update Custom: "+e.getMessage(), output);
-			}
-		} else if(deleteCustom != null && deleteCustom.length() > 0 
-			&& col.isMetaEnabled()) {
-			try {
-				MetaData customMeta = col.getCollectionMeta();
-				Document newCustom = new DocumentImpl();
-				newCustom.appendChild(newCustom.createElement("custom"));
-				customMeta.setCustomDocument(newCustom);
-				col.setCollectionMeta(customMeta);
-			} catch (DBException e) {
-				e.printStackTrace();
-				printError("Cannot delete Custom: "+e.getMessage(),	output);
-			}
-		} else if(req.getMethod().equalsIgnoreCase("POST")) {
-			byte[] content = new byte[0];
-			try {
-				//	Create a new file upload handler
-				DiskFileUpload upload = new DiskFileUpload();
-				// Set upload parameters
-				upload.setSizeMax(-1);
-				if(m_context != null) {
-					try {
-						File tmpdir = (File) m_context.get(org.apache.avalon.fortress
-							.ContainerConstants.WORK_DIRECTORY);
-						if(tmpdir != null) {
-							upload.setRepositoryPath(tmpdir.getCanonicalPath());		
-						}
-					} catch (ContextException e1) {
-						e1.printStackTrace();
-					} catch (IOException e1) {
-						e1.printStackTrace();
-					}
-				}
-				List items = upload.parseRequest(req);
-				// Process the uploaded fields
-				Iterator iter = items.iterator();
-				while (iter.hasNext()) {
-					FileItem item = (FileItem) iter.next();
-					FileItem uploadFile = null;
-					if (!item.isFormField()) {
-						if (item.getFieldName().equals("customfile") && uploadFile == null) {
-							uploadFile = item;
-							content = uploadFile.get();
-						} else {
-							item.delete();
-						}
-					} else {
-						item.delete();
-					}
-				}
-			} catch (FileUploadException e) {
-				e.printStackTrace();
-			}
-			if(content.length > 0) {
-				Document customDoc = null;
-				try {
-					customDoc = DOMParser.toDocument(content);
-				} catch (XindiceException e1) { // document fragment ?
-					e1.printStackTrace();
-					StringBuffer newContent = new StringBuffer();
-					newContent.append("<custom>").append(new String(content))
-						.append("</custom>");
-					try {
-						customDoc = DOMParser.toDocument(newContent.toString());
-					} catch (XindiceException e2) { // no xml content
-						e2.printStackTrace();
-						printError("Cannot parse Custom: "+e2.getMessage(), output);
-						customDoc = null;
-					}
-				}
-				if(customDoc != null) {
-					if(!customDoc.getDocumentElement()
-						.getNodeName().equals("custom")) {
-						Document newCustomDoc = new DocumentImpl();
-						Element customEle = newCustomDoc.createElement("custom");
-						customEle.appendChild(customDoc.getDocumentElement());
-						newCustomDoc.appendChild(customEle);
-						customDoc = newCustomDoc;
-					}
-					try {
-						MetaData customMeta = col.getCollectionMeta();
-						customMeta.setCustomDocument(customDoc);
-						col.setCollectionMeta(customMeta);
-					} catch (DBException e2) {
-						e2.printStackTrace();
-						printError("Cannot create Custom: "+e2.getMessage(), output);
-					}
-				}
-			}
-		}
-		
-		printStartTable("Add/Update Metadata Attribute", output);
-		printStartSingleTableBox(output);
-		output.print(META_ATTR_UPDATE_FORM_START);
-		output.print(attrName);
-		output.print(META_ATTR_UPDATE_FORM_MIDDLE);
-		output.print(attrValue);
-		output.print(META_ATTR_UPDATE_FORM_END);
-		printEndSingleTableBox(output);
-		printEndTable(output);
-		output.println("<br />\n");
-		
-		if(col.isMetaEnabled()) {
-			MetaData metaData;
-			try {
-				metaData = col.getCollectionMeta();
-			} catch (DBException e) {
-				e.printStackTrace();
-				metaData = null;
-			}
-			if(metaData != null) {
-				printAttributes(metaData, output);
-				output.println("<br />\n");
-				printCustom(metaData, output);
-			} 
-		}
-
-		finishViewer(output);
-	}
-	
-	protected void printAttributes(MetaData meta, 
-		ServletOutputStream output) throws IOException {
-		
-		String[] attrTitle = { "Attribute Name", "Attribute Value", "delete Attribute" };
-		if(meta.getAttributeKeys().hasMoreElements()) {
-			printStartTable(attrTitle, output);
-			for(Enumeration e = meta.getAttributeKeys(); e.hasMoreElements();) {
-				String name = (String) e.nextElement();
-				String value = (String) meta.getAttribute(name);
-				String[] contents = { 
-					"<a href=\"?viewer="+thisViewer+"&updateattr="+name+"\">"
-						+name+"</a>",
-					value, 
-					"<a href=\"?viewer="+thisViewer+"&deleteattr="+name+"\">"
-						+"delete</a>" };
-				printTableRow(contents, output);
-			}
-			printEndTable(output);
-		} else {
-			String message = "No Attributes available!";
-			printStartTable(message, output);
-			printStartSingleTableBox(output);
-			output.println(message);
-			printEndSingleTableBox(output);
-			printEndTable(output);
-		}
-	}
-	
-	protected void printReadonlyAttributes(MetaData meta, 
-		ServletOutputStream output) throws IOException {
-		output.println("<b>Additional Attributes: </b><br />");
-		output.println("Creation Time: "+meta.getCreatedTime()+"<br />");		
-		output.println("Last Modified Time: "+meta.getLastModifiedTime()+"<br />");
-		output.println("Link Target URI: "+meta.getLinkTargetURI()+"<br />");
-		output.println("Owner: "+meta.getOwner()+"<br />");
-		output.println("Type: "+MetaData.getTypeString(meta.getType())+"<br />");
-		output.println("Has Context: "+meta.hasContext()+"<br />");
-		output.println("Is Dirty: "+meta.isDirty()+"<br />");
-	}
-	
-	protected void printCustom(MetaData meta, 
-		ServletOutputStream output) throws IOException {
-		Document custom = meta.getCustomDocument();
-		printStartTable("Add/Update MetaData Custom", output);
-		printStartSingleTableBox(output);
-		output.println(META_CUSTOM_UPDATE_FORM_START);
-		if(custom != null && custom.getDocumentElement() != null) {
-			Element customEle = custom.getDocumentElement();
-			if(!customEle.hasChildNodes()) {
-				Document helper = new DocumentImpl();
-				/*customEle = (Element) */customEle
-					.appendChild(helper.createTextNode("\n\n"));
-			}
-			TextWriter.write(custom.getDocumentElement(), output);
-		}
-		output.println(META_CUSTOM_UPDATE_FORM_END);
-		printEndSingleTableBox(output);
-		printStartSingleTableBox(output);
-		output.println("<a href=\"?viewer="+thisViewer+"&deleteCustom=true\">");
-		output.println("delete Custom</a>");
-		printEndSingleTableBox(output);
-		printStartSingleTableBox(output);
-		output.println(META_CUSTOM_UPLOAD_FORM);
-		printEndSingleTableBox(output);
-		printEndTable(output);
-		output.println("<br />");		
-		printStartTable("MetaData Custom", output);
-		printStartSingleTableBox(output);
-		if(custom != null && custom.getDocumentElement() != null) {
-			// print custom ontent (children)
-			/*NodeList customChilds = custom.getDocumentElement().getChildNodes();
-			for(int i = 0; i < customChilds.getLength(); i++) {
-				Xml2HtmlWriter.write(customChilds.item(i), output);
-			}*/
-			Xml2HtmlWriter.write(custom.getDocumentElement(), output);
-		} else {
-			output.println("No Custom Document!");
-		}
-		printEndSingleTableBox(output);
-		printEndTable(output);
-	}
-	
-	protected void printError(String message, 
-		ServletOutputStream output) throws IOException {
-		printStartTable("Error", output);
-		printStartSingleTableBox(output);
-		output.println(message);
-		printEndSingleTableBox(output);
-		printEndTable(output);
-		output.println("<br />\n");
-	}
-		
-	protected static final String META_ATTR_UPDATE_FORM_START =	
-		"<form action=\"\" method=\"get\"> \n" +
-		"<input name=\"viewer\" value=\"meta\" type=\"hidden\" /> \n" +	
-		"<table class=\"upload-form\"> \n" +
-		"<tr><td> name: </td><td><input name=\"attrname\" type=\"text\" value=\"";
-	
-	protected static final String META_ATTR_UPDATE_FORM_MIDDLE =
-		"\"/></td></tr> \n" +
-		"<tr><td> value: </td><td><input name=\"attrvalue\" type=\"text\" value=\"";
-	
-	protected static final String META_ATTR_UPDATE_FORM_END =
-		"\"/></td></tr><tr><td>\n" +
-		"<input type=\"submit\" name=\"submit\" value=\"add/update\" /> \n" +
-		"</td></tr></table></form> \n";
-		
-	protected static final String META_CUSTOM_UPDATE_FORM_START = 
-		"<form action=\"\" method=\"get\"> \n" +	
-		"<input name=\"viewer\" value=\"meta\" type=\"hidden\" /> \n" +
-		"<table class=\"upload-form\"> \n" +
-		"<tr><td> \n" +
-		"<textarea name=\"custom\" cols=\"80\" rows=\"8\">" ;
-	
-	protected static final String META_CUSTOM_UPDATE_FORM_END =
-		"</textarea> \n" +
-		"</td></tr><tr><td> \n" +
-		"<input type=\"submit\" name=\"submit\" value=\"add/update\" /> \n" +
-		"</td></tr></table></form> \n";
-	
-	protected static final String META_CUSTOM_UPLOAD_FORM =
-		"<form action=\"?viewer=meta\" method=\"post\" "+
-		"enctype=\"multipart/form-data\"> \n" +
-		"<table class=\"upload-form\"> \n" +
-		"<tr><td>Upload Custom file: </td> \n" +
-		"<td><input name=\"customfile\" type=\"file\" /></td> \n" +
-		"<td><input type=\"submit\" name=\"submit\" value=\"upload\" /> \n" +
-		"</td></tr> " +
-		"</table> \n" +
-		"</form> \n";	
+public class MetadataCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 
+    private static final Log log = LogFactory.getLog(MetadataCollectionViewer.class);
+
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
+            throws ServletException, IOException {
+
+        String path = col.getCanonicalName();
+        String title = "Collection Metadata for " + path;
+
+        ServletOutputStream output = startViewer(title, path, res);
+
+        String attrName = req.getParameter("attrname");
+        if (attrName == null) {
+            attrName = "";
+        }
+        String attrValue = req.getParameter("attrvalue");
+        if (attrValue == null) {
+            attrValue = "";
+        }
+        String updateAttr = req.getParameter("updateattr");
+        String deleteAttr = req.getParameter("deleteattr");
+        String custom = req.getParameter("custom");
+        String deleteCustom = req.getParameter("deleteCustom");
+
+        //	add attribute
+        if (attrName.length() > 0 && col.isMetaEnabled() && updateAttr == null) {
+            try {
+                MetaData newMeta = col.getCollectionMeta();
+                newMeta.setAttribute(attrName, attrValue);
+                col.setCollectionMeta(newMeta);
+                attrName = "";
+                attrValue = "";
+            } catch (DBException e1) {
+                log.error(e1);
+                printError("Cannot add Attribute " + attrName + ": " + e1.getMessage(), output);
+            }
+        } else if (updateAttr != null && updateAttr.length() > 0 && col.isMetaEnabled()) {
+            attrName = updateAttr;
+            try {
+                attrValue = (String) col.getCollectionMeta().getAttribute(attrName);
+            } catch (DBException e) {
+                log.error(e);
+                attrValue = "";
+            }
+        } else if (deleteAttr != null && deleteAttr.length() > 0 && col.isMetaEnabled()) {
+            try {
+                MetaData delMeta = col.getCollectionMeta();
+                delMeta.removeAttribute(deleteAttr);
+                col.setCollectionMeta(delMeta);
+            } catch (DBException e) {
+                log.error(e);
+                printError("Cannot delete Attribute " + deleteAttr + ": " + e.getMessage(), output);
+            }
+        } else if (custom != null && custom.length() > 0 && col.isMetaEnabled()) {
+            try {
+                MetaData customMeta = col.getCollectionMeta();
+                Document customDoc = DOMParser.toDocument(custom);
+                customMeta.setCustomDocument(customDoc);
+                col.setCollectionMeta(customMeta);
+            } catch (DBException e) {
+                log.error(e);
+                printError("Cannot add/update Custom: " + e.getMessage(), output);
+            } catch (XindiceException e) {
+                log.error(e);
+                printError("Cannot add/update Custom: " + e.getMessage(), output);
+            }
+        } else if (deleteCustom != null && deleteCustom.length() > 0 && col.isMetaEnabled()) {
+            try {
+                MetaData customMeta = col.getCollectionMeta();
+                if (customMeta != null) {
+                    customMeta.setCustomDocument(null);
+                    col.setCollectionMeta(customMeta);
+                }
+            } catch (DBException e) {
+                log.error(e);
+                printError("Cannot delete Custom: " + e.getMessage(), output);
+            }
+        } else if (req.getMethod().equalsIgnoreCase("POST")) {
+            byte[] content = new byte[0];
+            try {
+                //	Create a new file upload handler
+                DiskFileUpload upload = new DiskFileUpload();
+                // Set upload parameters
+                upload.setSizeMax(-1);
+
+                try {
+                    File tmpdir = new File(System.getProperty("java.io.tmpdir"));
+                    upload.setRepositoryPath(tmpdir.getCanonicalPath());
+                } catch (IOException e1) {
+                    log.error(e1);
+                }
+                List items = upload.parseRequest(req);
+                // Process the uploaded fields
+                Iterator iter = items.iterator();
+                while (iter.hasNext()) {
+                    FileItem item = (FileItem) iter.next();
+                    if (!item.isFormField()) {
+                        FileItem uploadFile = null;
+                        if (item.getFieldName().equals("customfile") && uploadFile == null) {
+                            uploadFile = item;
+                            content = uploadFile.get();
+                        } else {
+                            item.delete();
+                        }
+                    } else {
+                        item.delete();
+                    }
+                }
+            } catch (FileUploadException e) {
+                log.error(e);
+            }
+            if (content.length > 0) {
+                Document customDoc;
+                try {
+                    customDoc = DOMParser.toDocument(content);
+                } catch (XindiceException e1) { // document fragment ?
+                    log.error(e1);
+                    StringBuffer newContent = new StringBuffer();
+                    newContent.append("<custom>").append(new String(content)).append("</custom>");
+                    try {
+                        customDoc = DOMParser.toDocument(newContent.toString());
+                    } catch (XindiceException e2) { // no xml content
+                        log.error(e2);
+                        printError("Cannot parse Custom: " + e2.getMessage(), output);
+                        customDoc = null;
+                    }
+                }
+                if (customDoc != null) {
+                    if (!customDoc.getDocumentElement().getNodeName().equals("custom")) {
+                        Document newCustomDoc = new DocumentImpl();
+                        Element customEle = newCustomDoc.createElement("custom");
+                        customEle.appendChild(customDoc.getDocumentElement());
+                        newCustomDoc.appendChild(customEle);
+                        customDoc = newCustomDoc;
+                    }
+                    try {
+                        MetaData customMeta = col.getCollectionMeta();
+                        customMeta.setCustomDocument(customDoc);
+                        col.setCollectionMeta(customMeta);
+                    } catch (DBException e2) {
+                        log.error(e2);
+                        printError("Cannot create Custom: " + e2.getMessage(), output);
+                    }
+                }
+            }
+        }
+
+        printStartTable("Add/Update Metadata Attribute", output);
+        printStartSingleTableBox(output);
+        output.print(META_ATTR_UPDATE_FORM_START);
+        output.print(attrName);
+        output.print(META_ATTR_UPDATE_FORM_MIDDLE);
+        output.print(attrValue);
+        output.print(META_ATTR_UPDATE_FORM_END);
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        output.println("<br />\n");
+
+        if (col.isMetaEnabled()) {
+            MetaData metaData;
+            try {
+                metaData = col.getCollectionMeta();
+            } catch (DBException e) {
+                log.error(e);
+                metaData = null;
+            }
+            if (metaData != null) {
+                printAttributes(metaData, output);
+                output.println("<br />\n");
+                printCustom(metaData, output);
+            }
+        }
+
+        finishViewer(output);
+    }
+
+    private void printAttributes(MetaData meta, ServletOutputStream output) throws IOException {
+
+        String[] attrTitle = {"Attribute Name", "Attribute Value", "delete Attribute"};
+        if (meta.getAttributeKeys().hasMoreElements()) {
+            printStartTable(attrTitle, output);
+            for (Enumeration e = meta.getAttributeKeys(); e.hasMoreElements();) {
+                String name = (String) e.nextElement();
+                String value = (String) meta.getAttribute(name);
+                String[] contents = {
+                        "<a href=\"?viewer=" + getName() + "&updateattr=" + name + "\">"
+                        + name + "</a>",
+                        value,
+                        "<a href=\"?viewer=" + getName() + "&deleteattr=" + name + "\">"
+                        + "delete</a>"};
+                printTableRow(contents, output);
+            }
+            printEndTable(output);
+        } else {
+            String message = "No Attributes available!";
+            printStartTable(message, output);
+            printStartSingleTableBox(output);
+            output.println(message);
+            printEndSingleTableBox(output);
+            printEndTable(output);
+        }
+    }
+
+    private void printCustom(MetaData meta, ServletOutputStream output) throws IOException {
+        Document custom = meta.getCustomDocument();
+        printStartTable("Add/Update MetaData Custom", output);
+        printStartSingleTableBox(output);
+        output.println(META_CUSTOM_UPDATE_FORM_START);
+        if (custom != null && custom.getDocumentElement() != null) {
+            Element customEle = custom.getDocumentElement();
+            if (!customEle.hasChildNodes()) {
+                Document helper = new DocumentImpl();
+                /*customEle = (Element) */customEle
+                    .appendChild(helper.createTextNode("\n\n"));
+            }
+            TextWriter.write(custom.getDocumentElement(), output);
+        }
+        output.println(META_CUSTOM_UPDATE_FORM_END);
+        printEndSingleTableBox(output);
+        printStartSingleTableBox(output);
+        output.println("<a href=\"?viewer=" + getName() + "&deleteCustom=true\">");
+        output.println("delete Custom</a>");
+        printEndSingleTableBox(output);
+        printStartSingleTableBox(output);
+        output.println(META_CUSTOM_UPLOAD_FORM);
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        output.println("<br />");
+        printStartTable("MetaData Custom", output);
+        printStartSingleTableBox(output);
+        if (custom != null && custom.getDocumentElement() != null) {
+            // print custom ontent (children)
+            /*NodeList customChilds = custom.getDocumentElement().getChildNodes();
+               for(int i = 0; i < customChilds.getLength(); i++) {
+                   Xml2HtmlWriter.write(customChilds.item(i), output);
+               }*/
+            Xml2HtmlWriter.write(custom.getDocumentElement(), output);
+        } else {
+            output.println("No Custom Document!");
+        }
+        printEndSingleTableBox(output);
+        printEndTable(output);
+    }
+
+    private void printError(String message, ServletOutputStream output) throws IOException {
+        printStartTable("Error", output);
+        printStartSingleTableBox(output);
+        output.println(message);
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        output.println("<br />\n");
+    }
+
+    private static final String META_ATTR_UPDATE_FORM_START =
+            "<form action=\"\" method=\"get\"> \n" +
+            "<input name=\"viewer\" value=\"meta\" type=\"hidden\" /> \n" +
+            "<table class=\"upload-form\"> \n" +
+            "<tr><td> name: </td><td><input name=\"attrname\" type=\"text\" value=\"";
+
+    private static final String META_ATTR_UPDATE_FORM_MIDDLE =
+            "\"/></td></tr> \n" +
+            "<tr><td> value: </td><td><input name=\"attrvalue\" type=\"text\" value=\"";
+
+    private static final String META_ATTR_UPDATE_FORM_END =
+            "\"/></td></tr><tr><td>\n" +
+            "<input type=\"submit\" name=\"submit\" value=\"add/update\" /> \n" +
+            "</td></tr></table></form> \n";
+
+    private static final String META_CUSTOM_UPDATE_FORM_START =
+            "<form action=\"\" method=\"get\"> \n" +
+            "<input name=\"viewer\" value=\"meta\" type=\"hidden\" /> \n" +
+            "<table class=\"upload-form\"> \n" +
+            "<tr><td> \n" +
+            "<textarea name=\"custom\" cols=\"80\" rows=\"8\">";
+
+    private static final String META_CUSTOM_UPDATE_FORM_END =
+            "</textarea> \n" +
+            "</td></tr><tr><td> \n" +
+            "<input type=\"submit\" name=\"submit\" value=\"add/update\" /> \n" +
+            "</td></tr></table></form> \n";
+
+    private static final String META_CUSTOM_UPLOAD_FORM =
+            "<form action=\"?viewer=meta\" method=\"post\" " +
+            "enctype=\"multipart/form-data\"> \n" +
+            "<table class=\"upload-form\"> \n" +
+            "<tr><td>Upload Custom file: </td> \n" +
+            "<td><input name=\"customfile\" type=\"file\" /></td> \n" +
+            "<td><input type=\"submit\" name=\"submit\" value=\"upload\" /> \n" +
+            "</td></tr> " +
+            "</table> \n" +
+            "</form> \n";
+
+    protected String getName() {
+        return "meta";
+    }
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataCollectionViewer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java Thu May 24 18:43:39 2007
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.xindice.webadmin.viewer.components;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.fileupload.DiskFileUpload;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.DBException;
+import org.apache.xindice.core.meta.MetaData;
+import org.apache.xindice.util.XindiceException;
+import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
+import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
+import org.apache.xindice.xml.TextWriter;
+import org.apache.xindice.xml.Xml2HtmlWriter;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.xml.dom.DocumentImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Xindice Html Viewer for Resource Metadata.
+ */
+public class MetadataResourceViewer extends HtmlViewerComponent implements HtmlResourceViewer {
+
+    private static final Log log = LogFactory.getLog(MetadataCollectionViewer.class);
+
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col, String name)
+            throws ServletException, IOException {
+
+        String path = col.getCanonicalDocumentName(name);
+        String title = "Resource Metadata for " + path;
+
+        ServletOutputStream output = startViewer(title, path, res);
+
+        String custom = req.getParameter("custom");
+        String deleteCustom = req.getParameter("deleteCustom");
+
+        if (custom != null && custom.length() > 0 && col.isMetaEnabled()) {
+            try {
+                MetaData customMeta = col.getDocumentMeta(name);
+                Document customDoc = DOMParser.toDocument(custom);
+                customMeta.setCustomDocument(customDoc);
+                col.setDocumentMeta(name, customMeta);
+            } catch (DBException e) {
+                log.error(e);
+                printError("Cannot add/update Custom: " + e.getMessage(), output);
+            } catch (XindiceException e) {
+                log.error(e);
+                printError("Cannot add/update Custom: " + e.getMessage(), output);
+            }
+        } else if (deleteCustom != null && deleteCustom.length() > 0 && col.isMetaEnabled()) {
+            try {
+                MetaData customMeta = col.getDocumentMeta(name);
+                if (customMeta != null) {
+                    customMeta.setCustomDocument(null);
+                    col.setDocumentMeta(name, customMeta);
+                }
+            } catch (DBException e) {
+                log.error(e);
+                printError("Cannot delete Custom: " + e.getMessage(), output);
+            }
+        } else if (req.getMethod().equalsIgnoreCase("POST")) {
+            byte[] content = new byte[0];
+            try {
+                //	Create a new file upload handler
+                DiskFileUpload upload = new DiskFileUpload();
+                // Set upload parameters
+                upload.setSizeMax(-1);
+
+                try {
+                    File tmpdir = new File(System.getProperty("java.io.tmpdir"));
+                    upload.setRepositoryPath(tmpdir.getCanonicalPath());
+                } catch (IOException e1) {
+                    log.error(e1);
+                }
+                List items = upload.parseRequest(req);
+                // Process the uploaded fields
+                Iterator iter = items.iterator();
+                while (iter.hasNext()) {
+                    FileItem item = (FileItem) iter.next();
+                    if (!item.isFormField()) {
+                        FileItem uploadFile = null;
+                        if (item.getFieldName().equals("customfile") && uploadFile == null) {
+                            uploadFile = item;
+                            content = uploadFile.get();
+                        } else {
+                            item.delete();
+                        }
+                    } else {
+                        item.delete();
+                    }
+                }
+            } catch (FileUploadException e) {
+                log.error(e);
+            }
+            if (content.length > 0) {
+                Document customDoc;
+                try {
+                    customDoc = DOMParser.toDocument(content);
+                } catch (XindiceException e1) { // document fragment ?
+                    log.error(e1);
+                    StringBuffer newContent = new StringBuffer();
+                    newContent.append("<custom>").append(new String(content)).append("</custom>");
+                    try {
+                        customDoc = DOMParser.toDocument(newContent.toString());
+                    } catch (XindiceException e2) { // no xml content
+                        log.error(e2);
+                        printError("Cannot parse Custom: " + e2.getMessage(), output);
+                        customDoc = null;
+                    }
+                }
+                if (customDoc != null) {
+                    if (!customDoc.getDocumentElement().getNodeName().equals("custom")) {
+                        Document newCustomDoc = new DocumentImpl();
+                        Element customEle = newCustomDoc.createElement("custom");
+                        customEle.appendChild(customDoc.getDocumentElement());
+                        newCustomDoc.appendChild(customEle);
+                        customDoc = newCustomDoc;
+                    }
+                    try {
+                        MetaData customMeta = col.getDocumentMeta(name);
+                        customMeta.setCustomDocument(customDoc);
+                        col.setDocumentMeta(name, customMeta);
+                    } catch (DBException e2) {
+                        log.error(e2);
+                        printError("Cannot create Custom: " + e2.getMessage(), output);
+                    }
+                }
+            }
+        }
+
+        if (col.isMetaEnabled()) {
+            MetaData metaData;
+            try {
+                metaData = col.getDocumentMeta(name);
+            } catch (DBException e) {
+                log.error(e);
+                metaData = null;
+            }
+            if (metaData != null) {
+                printCustom(metaData, output);
+            }
+        }
+
+        finishViewer(output);
+    }
+
+    private void printCustom(MetaData meta, ServletOutputStream output) throws IOException {
+        Document custom = meta.getCustomDocument();
+        printStartTable("Add/Update MetaData Custom", output);
+        printStartSingleTableBox(output);
+        output.print("<a href=\"./?viewer=default\">up to parent collection</a>");
+        printEndSingleTableBox(output);
+        printStartSingleTableBox(output);
+        output.println(META_CUSTOM_UPDATE_FORM_START);
+        if (custom != null && custom.getDocumentElement() != null) {
+            Element customEle = custom.getDocumentElement();
+            if (!customEle.hasChildNodes()) {
+                Document helper = new DocumentImpl();
+                customEle.appendChild(helper.createTextNode("\n\n"));
+            }
+            TextWriter.write(custom.getDocumentElement(), output);
+        }
+        output.println(META_CUSTOM_UPDATE_FORM_END);
+        printEndSingleTableBox(output);
+        printStartSingleTableBox(output);
+        output.println("<a href=\"?viewer=" + getName() + "&deleteCustom=true\">");
+        output.println("delete Custom</a>");
+        printEndSingleTableBox(output);
+        printStartSingleTableBox(output);
+        output.println(META_CUSTOM_UPLOAD_FORM);
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        output.println("<br />");
+        printStartTable("MetaData Custom", output);
+        printStartSingleTableBox(output);
+        if (custom != null && custom.getDocumentElement() != null) {
+            Xml2HtmlWriter.write(custom.getDocumentElement(), output);
+        } else {
+            output.println("No Custom Document!");
+        }
+        printEndSingleTableBox(output);
+        printEndTable(output);
+    }
+
+    private void printError(String message, ServletOutputStream output) throws IOException {
+        printStartTable("Error", output);
+        printStartSingleTableBox(output);
+        output.println(message);
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        output.println("<br />\n");
+    }
+
+    private static final String META_CUSTOM_UPDATE_FORM_START =
+            "<form action=\"\" method=\"get\"> \n" +
+            "<input name=\"viewer\" value=\"meta\" type=\"hidden\" /> \n" +
+            "<table class=\"upload-form\"> \n" +
+            "<tr><td> \n" +
+            "<textarea name=\"custom\" cols=\"80\" rows=\"8\">";
+
+    private static final String META_CUSTOM_UPDATE_FORM_END =
+            "</textarea> \n" +
+            "</td></tr><tr><td> \n" +
+            "<input type=\"submit\" name=\"submit\" value=\"add/update\" /> \n" +
+            "</td></tr></table></form> \n";
+
+    private static final String META_CUSTOM_UPLOAD_FORM =
+            "<form action=\"?viewer=meta\" method=\"post\" " +
+            "enctype=\"multipart/form-data\"> \n" +
+            "<table class=\"upload-form\"> \n" +
+            "<tr><td>Upload Custom file: </td> \n" +
+            "<td><input name=\"customfile\" type=\"file\" /></td> \n" +
+            "<td><input type=\"submit\" name=\"submit\" value=\"upload\" /> \n" +
+            "</td></tr> " +
+            "</table> \n" +
+            "</form> \n";
+
+    protected String getName() {
+        return "meta";
+    }
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/MetadataResourceViewer.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/UploadCollectionViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/UploadCollectionViewer.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/UploadCollectionViewer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/UploadCollectionViewer.java Thu May 24 18:43:39 2007
@@ -29,17 +29,15 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.commons.fileupload.DiskFileUpload;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
-import org.apache.xindice.core.data.Key;
+import org.apache.xindice.core.FaultCodes;
 import org.apache.xindice.util.XindiceException;
-import org.apache.xindice.webadmin.util.CollectionConfigurationHelper;
 import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
 import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 import org.apache.xindice.xml.dom.DOMParser;
@@ -47,26 +45,17 @@
 
 /**
  * Xindice Html Viewer for uploading documents to this collection.
- * 
- * @avalon.component
- * @avalon.service type=HtmlCollectionViewer
- * @x-avalon.info name=upload
- * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$
  */
-public class UploadCollectionViewer
-    extends HtmlViewerComponent
-    implements HtmlCollectionViewer {
+public class UploadCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 
     protected static final String INLINE_METADATA = "inline-metadata";
+    private static final Log log = LogFactory.getLog(UploadCollectionViewer.class);
 
-    public void execute(
-        HttpServletRequest req,
-        HttpServletResponse res,
-        Collection col)
-        throws ServletException, IOException {
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
+            throws ServletException, IOException {
 
         String path = col.getCanonicalName();
         String title = "Upload Document to Collection " + path;
@@ -79,180 +68,104 @@
         if (!method.equalsIgnoreCase("POST")) {
             output.print(UPLOAD_FORM);
         } else {
-
-            boolean inlineMetaSupported =
-                col.getConfig().getBooleanAttribute(INLINE_METADATA, false);
-            String name = "";
-            byte[] content = new byte[0];
-            boolean overwrite = false;
-            char type = 'd';
-
             // Create a new file upload handler
             DiskFileUpload upload = new DiskFileUpload();
             // Set upload parameters
             upload.setSizeMax(-1);
-            if (m_context != null) {
-                try {
-                    File tmpdir =
-                        (File)m_context.get(
-                            org
-                                .apache
-                                .avalon
-                                .fortress
-                                .ContainerConstants
-                                .WORK_DIRECTORY);
-                    if (tmpdir != null) {
-                        upload.setRepositoryPath(tmpdir.getCanonicalPath());
-                    }
-                } catch (ContextException e1) {
-                    e1.printStackTrace();
-                } catch (IOException e1) {
-                    e1.printStackTrace();
-                }
-            }
             try {
-                List items = upload.parseRequest(req);
-                // Process the uploaded fields
-                Iterator iter = items.iterator();
-                while (iter.hasNext()) {
-                    FileItem item = (FileItem)iter.next();
-                    FileItem uploadFile = null;
-                    if (!item.isFormField()) {
-                        if (item.getFieldName().equals("file")
-                            && uploadFile == null) {
-                            uploadFile = item;
-                            name = uploadFile.getName();
-                            //	Get the filename if uploaded name includes a path
-                            if (name.lastIndexOf('\\') >= 0) {
-                                name =
-                                    name.substring(name.lastIndexOf('\\') + 1);
-                            }
-                            if (name.lastIndexOf('/') >= 0) {
-                                name =
-                                    name.substring(name.lastIndexOf('/') + 1);
-                            }
-                            content = uploadFile.get();
-                        } else {
-                            output.print(item.getFieldName());
-                            item.delete();
-                        }
-                    } else {
-                        if (item.getFieldName().equals("overwrite")) {
-                            if (item.getString().equalsIgnoreCase("true")) {
-                                overwrite = true;
-                            }
-                        } else if (item.getFieldName().equals("type")) {
-                            type = item.getString().charAt(0);
-                        } else {
-                            item.delete();
-                        }
-                    }
-                    if (uploadFile != null) {
-                        uploadFile.delete();
-                    }
-                }
+                File tmpdir = new File(System.getProperty("java.io.tmpdir"));
+                upload.setRepositoryPath(tmpdir.getCanonicalPath());
+            } catch (IOException e) {
+                log.error(e);
+            }
 
+            Form form;
+            try {
+                form = parseUpload(req, upload);
             } catch (FileUploadException e) {
-                e.printStackTrace();
+                log.error(e);
                 throw new ServletException(e);
             }
 
-            if (content.length == 0) {
+            if (form.content == null && form.content.length == 0) {
                 throw new ServletException("empty upload file");
             }
 
-            try {
-                if (type != 'b') { // xml or detect
-                    Document resource = null;
-                    byte[] binary = null;
-                    if (name != null && name.length() > 0) {
-                        try {
-                            resource = col.getDocument(name);
-                        } catch (DBException e) { // get binary
-                            e.printStackTrace();
-                            resource = null;
-                        }
-                        if (resource == null
-                            && type == 'd'
-                            && inlineMetaSupported) {
-                            binary = col.getBinary(name);
-                        }
-                    }
+            if (form.type != 'b') { // xml or detect
+                handleXML(col, form, output);
+            } else {
+                handleBinary(col, form, output);
+            }
 
-                    if (resource == null && binary == null) {
-                        try {
-                            insertXML(col, name, content, output);
-                        } catch (XindiceException e) {
-                            if (type == 'd') {
-                                try {
-                                    insertBinary(col, name, content, output);
-                                } catch (Exception e1) {
-                                    e1.printStackTrace();
-                                    printError(
-                                        "Could not create Binary!",
-                                        e1.getMessage(),
-                                        output);
-                                }
-                            } else {
-                                printError(
-                                    "no valid xml?",
-                                    e.getMessage(),
-                                    output);
-                            }
-                        }
-                    } else if (overwrite && resource != null) {
-                        setXML(col, name, content, output);
-                    } else if (overwrite && binary != null) {
-                        setBinary(col, name, content, output);
-                    } else {
-                        printError(
-                            "Could not create/update Resource/Binary!",
-                            name + " already exists!",
-                            output);
-                    }
+        }
+        printEndSingleTableBox(output);
+        printEndTable(output);
+        finishViewer(output);
+    }
+
+    private Form parseUpload(HttpServletRequest req, DiskFileUpload upload) throws FileUploadException {
+        List items = upload.parseRequest(req);
+        Form form = new Form();
+
+        // Process the uploaded fields
+        Iterator iter = items.iterator();
+        while (iter.hasNext()) {
+            FileItem item = (FileItem) iter.next();
+
+            if (!item.isFormField()) {
+                if (item.getFieldName().equals("file")) {
+                    form.content = item.get();
+                    item.delete();
                 } else {
-                    byte[] binary = null;
-                    if (name != null
-                        && name.length() > 0
-                        && inlineMetaSupported) {
-                        binary = col.getBinary(name);
-                    }
+                    item.delete();
+                }
+            } else {
+                if (item.getFieldName().equals("overwrite")) {
+                    form.overwrite = (Boolean.getBoolean(item.getString()));
+                } else if (item.getFieldName().equals("type")) {
+                    form.type = item.getString().charAt(0);
+                } else if (item.getFieldName().equals("name")) {
+                    form.name = item.getString();
+                } else {
+                    item.delete();
+                }
+            }
+        }
 
-                    if (binary == null) {
-                        try {
-                            insertBinary(col, name, content, output);
-                        } catch (Exception e1) {
-                            e1.printStackTrace();
-                            printError(
-                                "Could not create Binary!",
-                                e1.getMessage(),
-                                output);
-                        }
-                    } else if (overwrite) {
-                        setBinary(col, name, content, output);
-                    } else {
-                        printError(
-                            "Could not update Binary!",
-                            name + " already exists!",
-                            output);
-                    }
+        return form;
+    }
+
+    private void handleXML(Collection col, Form form, ServletOutputStream out) throws IOException {
+        try {
+            insertXML(col, form.name, form.content, form.overwrite, out);
+        } catch (XindiceException e) {
+            if (form.type == 'd') {
+                try {
+                    insertBinary(col, form.name, form.content, form.overwrite, out);
+                } catch (DBException e1) {
+                    log.error(e1);
+                    printError("Could not create Binary!", e1.getMessage(), out);
                 }
-            } catch (DBException e) {
-                e.printStackTrace();
-                printError(
-                    "Could not create/update Resource/Binary!",
-                    e.getMessage(),
-                    output);
+            } else {
+                printError("Not a valid xml", e.getMessage(), out);
             }
+        }
+    }
 
+    private void handleBinary(Collection col, Form form, ServletOutputStream out) throws IOException {
+        try {
+            insertBinary(col, form.name, form.content, form.overwrite, out);
+        } catch (DBException e) {
+            log.error(e);
+            printError("Could not create Binary!", e.getMessage(), out);
         }
-        printEndSingleTableBox(output);
-        printEndTable(output);
-        finishViewer(output);
     }
 
-    protected void printMetaError(ServletOutputStream output)
-        throws IOException {
+    protected String getName() {
+        return "upload";
+    }
+
+    private void printMetaError(ServletOutputStream output) throws IOException {
         output.print("<b>Metadata storage is not enabled!<br />");
         output.print("If you want to store binary content please ");
         output.print("enable metadata storage inside the server.xml");
@@ -260,128 +173,78 @@
         output.print("Collection Configuration!</b>");
     }
 
-    protected void printError(
-        String info,
-        String message,
-        ServletOutputStream output)
-        throws IOException {
+    private void printError(String info, String message, ServletOutputStream output) throws IOException {
         output.print("<b>");
         output.print(info);
         output.print("</b><br />");
         output.print(message);
     }
 
-    protected void insertXML(
-        Collection col,
-        String name,
-        byte[] content,
-        ServletOutputStream output)
-        throws XindiceException, IOException {
+    private void insertXML(Collection col, String name, byte[] content, boolean overwrite, ServletOutputStream out)
+            throws XindiceException, IOException {
         Document resource = DOMParser.toDocument(content);
-        if (name != null && name.length() > 0) {
-            col.insertDocument(name, resource);
-        } else {
-            Key key = col.insertDocument(resource);
-            name = key.toString();
+        if (name.trim().length() == 0) {
+            name = null;
         }
-        output.print("<b>Resource <a href=\"./");
-        output.print(name);
-        output.print("?viewer=default\">");
-        output.print(name);
-        output.print("</a> created!</b>");
-    }
 
-    protected void setXML(
-        Collection col,
-        String name,
-        byte[] content,
-        ServletOutputStream output)
-        throws DBException, IOException {
-        Document resource = null;
-        try {
-            resource = DOMParser.toDocument(content);
-        } catch (XindiceException e) {
-            printError("no valid xml?", e.getMessage(), output);
-            resource = null;
-        }
-        if (resource != null) {
+        if (!overwrite) {
+            try {
+                name = col.insertDocument(name, resource).toString();
+            } catch (DBException e) {
+                if (e.faultCode == FaultCodes.COL_DUPLICATE_RESOURCE) {
+                    printError("Could not create Resource!", name + " already exists!", out);
+                } else {
+                    throw e;
+                }
+            }
+        } else {
             col.setDocument(name, resource);
-            output.print("<b>Resource <a href=\"./");
-            output.print(name);
-            output.print("?viewer=default\">");
-            output.print(name);
-            output.print("</a> updated!</b>");
         }
+        out.print("<b>Resource <a href=\"./");
+        out.print(name);
+        out.print("?viewer=default\">");
+        out.print(name);
+        out.print("</a> created!</b>");
     }
 
-    protected void insertBinary(
-        Collection col,
-        String name,
-        byte[] content,
-        ServletOutputStream output)
-        throws DBException, IOException, ServiceException {
-        if (!col.isMetaEnabled()) {
-            printMetaError(output);
+    private void insertBinary(Collection col, String name, byte[] content, boolean overwrite, ServletOutputStream out)
+            throws DBException, IOException {
+
+        boolean inlineMetaSupported = col.getConfig().getBooleanAttribute(INLINE_METADATA, false);
+        if (!inlineMetaSupported) {
+            printMetaError(out);
         } else {
-            CollectionConfigurationHelper helper;
-            Object object =
-                m_serviceManager.lookup(CollectionConfigurationHelper.ROLE);
-            if (object instanceof ServiceSelector) {
-                helper =
-                    (CollectionConfigurationHelper)
-                        ((ServiceSelector)object).select(
-                        "col-config");
-            } else {
-                helper = (CollectionConfigurationHelper)object;
+            if (name.trim().length() == 0) {
+                name = null;
             }
 
-            if (!helper.isInlineMetaEnabled(col)
-                && helper.isAutoEnableInlineMeta()) {
-                // enable Metadata
+            if (!overwrite) {
                 try {
-                    helper.enableCollectionInlineMetadata(col);
-                } catch (XindiceException e) {
-                    e.printStackTrace();
-                    if (getLogger().isDebugEnabled()) {
-                        getLogger().debug(
-                            "Could not enable Collection Inline Metadata: "
-                                + e.getMessage());
+                    name = col.insertBinary(name, content).toString();
+                } catch (DBException e) {
+                    if (e.faultCode == FaultCodes.COL_DUPLICATE_RESOURCE) {
+                        printError("Could not update Binary!", name + " already exists!", out);
+                    } else {
+                        throw e;
                     }
-                    return;
                 }
-            }
-
-            if (!helper.isInlineMetaEnabled(col)) {
-                printMetaError(output);
-                return;
-            }
-
-            if (name != null && name.length() > 0) {
-                col.insertBinary(name, content);
             } else {
-                Key key = col.insertBinary(content);
-                name = key.toString();
+                col.setBinary(name, content);
             }
-            output.print("<b>Binary <a href=\"./");
-            output.print(name);
-            output.print("?viewer=default\">");
-            output.print(name);
-            output.print("</a> created!</b>");
+
+            out.print("<b>Binary <a href=\"./");
+            out.print(name);
+            out.print("?viewer=default\">");
+            out.print(name);
+            out.print("</a> created!</b>");
         }
     }
 
-    protected void setBinary(
-        Collection col,
-        String name,
-        byte[] content,
-        ServletOutputStream output)
-        throws DBException, IOException {
-        col.insertBinary(name, content);
-        output.print("<b>Binary <a href=\"./");
-        output.print(name);
-        output.print("?viewer=default\">");
-        output.print(name);
-        output.print("</a> updated!</b>");
+    private class Form {
+        public byte[] content = null;
+        public String name = null;
+        public boolean overwrite = false;
+        public char type = 'd';
     }
 
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/UploadCollectionViewer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/XPathSearchCollectionViewer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/XPathSearchCollectionViewer.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/XPathSearchCollectionViewer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/XPathSearchCollectionViewer.java Thu May 24 18:43:39 2007
@@ -35,122 +35,121 @@
 import org.apache.xindice.webadmin.viewer.*;
 import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 import org.apache.xindice.xml.Xml2HtmlWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Xindice Html Viewer for collection xpath searches.
- * 
- * @avalon.component
- * @avalon.service type=HtmlCollectionViewer
- * @x-avalon.info name=xpath
- * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$
  */
-public class XPathSearchCollectionViewer 
-  extends HtmlViewerComponent 
-  implements HtmlCollectionViewer {
-    
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection col)
-    throws ServletException, IOException {
-    
-    String query = req.getParameter("query");
-    if(query == null) {
-    	query = "";
+public class XPathSearchCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
+
+    private static final Log log = LogFactory.getLog(XPathSearchCollectionViewer.class);
+
+    public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
+            throws ServletException, IOException {
+
+        String query = req.getParameter("query");
+        if (query == null) {
+            query = "";
+        }
+
+        String path = col.getCanonicalName();
+        String title = "XPATH Query for " + path;
+        ServletOutputStream output = startViewer(title, path, res);
+
+        // get namespaces
+        String[] ns = {"", ""};
+        int nsSize = 1;
+        String rawNsSize = req.getParameter("nssize");
+        if (rawNsSize != null) {
+            nsSize = Integer.parseInt(rawNsSize);
+            ns = new String[nsSize * 2];
+            int index = 0;
+            for (int i = 1; i <= nsSize; i++) {
+                String prefix = req.getParameter("prefix" + i);
+                String uri = req.getParameter("uri" + i);
+                if (prefix != null) {
+                    ns[index] = prefix;
+                } else {
+                    ns[index] = "";
+                }
+                index++;
+                if (uri != null) {
+                    ns[index] = uri;
+                } else {
+                    ns[index] = "";
+                }
+                index++;
+            }
+        }
+
+        printQueryForm(output, query, path, ns);
+        output.print("<br />\n");
+        output.flush();
+
+        if (query.length() > 0) { // print result
+            NamespaceMap nsMap = new NamespaceMap();
+            int index = 0;
+            for (int i = 0; i < nsSize; i++) {
+                nsMap.setNamespace(ns[index++], ns[index++]);
+            }
+            try {
+                NodeSet result = col.queryCollection("XPath", query, nsMap);
+                printQuery(result, output, query, path);
+            } catch (DBException e) {
+                log.error(e);
+                printStartTable("Error while XPath Query", output);
+                printStartSingleTableBox(output);
+                output.print("<b>Error while XPath Query:</b><br />");
+                output.print(e.getMessage());
+                printEndSingleTableBox(output);
+                printEndTable(output);
+            }
+        }
+
+        finishViewer(output);
+    }
+
+    protected String getName() {
+        return "xpath";
     }
-	
-	String path = col.getCanonicalName();
-	String title = "XPATH Query for "+path;
-	ServletOutputStream output = startViewer(title, path, res);	
-	
-	// get namespaces
-	String[] ns = { "", "" };
-	int nsSize = 1;
-	String rawNsSize = req.getParameter("nssize");
-	if(rawNsSize != null) {
-		nsSize = Integer.parseInt(rawNsSize);
-		ns = new String[nsSize*2];
-		int index = 0;
-		String prefix;
-		String uri;
-		for(int i = 1; i <= nsSize; i++) {
-			prefix = req.getParameter("prefix"+i);
-			uri = req.getParameter("uri"+i);
-			if(prefix != null) {
-				ns[index] = prefix;
-			} else {
-				ns[index] = "";
-			}
-			index++;
-			if(uri != null) {
-				ns[index] = uri;
-			} else {
-				ns[index] = "";
-			}
-			index++;
-		}
-	}
-	    
-   	printQueryForm(output, query, path, ns);
-   	output.print("<br />\n");
-	output.flush();
-	
-	if(query.length() > 0) { // print result
-    	NamespaceMap nsMap = new NamespaceMap();
-    	int index = 0;
-    	for(int i = 0; i < nsSize; i++) {
-    		nsMap.setNamespace(ns[index++], ns[index++]);
-    	}
-		try {
-			NodeSet result = col.queryCollection("XPath", query, nsMap);
-			printQuery(result, output, query, path);
-		} catch (DBException e) {
-			e.printStackTrace();
-			printStartTable("Error while XPath Query", output);
-			printStartSingleTableBox(output);
-			output.print("<b>Error while XPath Query:</b><br />");
-			output.print(e.getMessage());
-			printEndSingleTableBox(output);
-			printEndTable(output);
-		}
+
+    private void printQuery(NodeSet result, ServletOutputStream output, String query, String path)
+            throws IOException {
+
+        String resultTitle = "Result for Query " + query;
+        printStartTable(resultTitle, output);
+
+        if (!result.hasMoreNodes()) {
+            printStartSingleTableBox(output);
+            output.print("No result for query " + query + "");
+            printEndSingleTableBox(output);
+        }
+
+        while (result.hasMoreNodes()) {
+            Object node = result.getNextNode();
+
+            printStartSingleTableBox(output);
+            if (node instanceof Node) {
+                Xml2HtmlWriter.write((Node) node, output);
+            } else {
+                //	TODO print something, that makes sense
+                output.print("Node is no Node");
+            }
+            printEndSingleTableBox(output);
+        }
+        printEndTable(output);
+    }
+
+    private void printQueryForm(ServletOutputStream output, String query, String path, String[] ns)
+            throws IOException {
+        String formTitle = "XPath Query for Collection " + path;
+        printStartTable(formTitle, output);
+        printSearchFromRow("xpath", query, ns, output);
+        printEndTable(output);
     }
-    
-    finishViewer(output);
-  }
-  
-  protected void printQuery(NodeSet result, ServletOutputStream output,
-  										String query, String path) throws IOException {
-	String resultTitle = "Result for Query "+query;
-	printStartTable(resultTitle, output);
-	
-	if(!result.hasMoreNodes()) {
-		printStartSingleTableBox(output);
-		output.print("No result for query "+query+"");
-		printEndSingleTableBox(output);
-	}
-	
-  	while(result.hasMoreNodes()) {
-  		Object node = result.getNextNode();
-		
-		printStartSingleTableBox(output);
-		if(node instanceof Node) {
-			Xml2HtmlWriter.write((Node)node, output);	
-		} else {
-			//	TODO print something, that makes sense
-			output.print("Node is no Node");
-		}
-		printEndSingleTableBox(output);		
-  	}
-	printEndTable(output);
-  }
-  
-  protected void printQueryForm(ServletOutputStream output, String query, 
-  									String path, String[] ns) throws IOException {
-	String formTitle = "XPath Query for Collection "+path;
-	printStartTable(formTitle, output);
-	printSearchFromRow("xpath", query, ns, output);
-	printEndTable(output);
-  }
-  
+
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/viewer/components/XPathSearchCollectionViewer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.