manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1186877 - in /incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki: WikiConfig.java WikiConnector.java
Date Thu, 20 Oct 2011 16:06:33 GMT
Author: kwright
Date: Thu Oct 20 16:06:32 2011
New Revision: 1186877

URL: http://svn.apache.org/viewvc?rev=1186877&view=rev
Log:
Add support for namespaces and title prefixes to the wiki connector UI.

Modified:
    incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConfig.java
    incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java

Modified: incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConfig.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConfig.java?rev=1186877&r1=1186876&r2=1186877&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConfig.java
(original)
+++ incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConfig.java
Thu Oct 20 16:06:32 2011
@@ -36,6 +36,13 @@ public class WikiConfig
   /** Path */
   public static final String PARAM_PATH = "Server path";
 	
-  // Output specification
+  // Document specification
 
+  /** Namespace and title prefix */
+  public static final String NODE_NAMESPACE_TITLE_PREFIX = "namespaceandprefix";
+  /** Namespace attribute */
+  public static final String ATTR_NAMESPACE = "namespace";
+  /** Title prefix attribute */
+  public static final String ATTR_TITLEPREFIX = "titleprefix";
+  
 }

Modified: incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java?rev=1186877&r1=1186876&r2=1186877&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java
(original)
+++ incubator/lcf/branches/CONNECTORS-277/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java
Thu Oct 20 16:06:32 2011
@@ -220,7 +220,21 @@ public class WikiConnector extends org.a
     long startTime, long endTime)
     throws ManifoldCFException, ServiceInterruption
   {
-    listAllPages(activities,null,null,startTime,endTime);
+    // Scan specification nodes and extract prefixes and namespaces
+    boolean seenAny = false;
+    for (int i = 0 ; i < spec.getChildCount() ; i++)
+    {
+      SpecificationNode sn = spec.getChild(i);
+      if (sn.getType().equals(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX))
+      {
+        String namespace = sn.getAttributeValue(WikiConfig.ATTR_NAMESPACE);
+        String titleprefix = sn.getAttributeValue(WikiConfig.ATTR_TITLEPREFIX);
+        listAllPages(activities,namespace,titleprefix,startTime,endTime);
+        seenAny = true;
+      }
+    }
+    if (!seenAny)
+      listAllPages(activities,null,null,startTime,endTime);
   }
 
   /** Get document versions given an array of document identifiers.
@@ -528,6 +542,8 @@ public class WikiConnector extends org.a
   public void outputSpecificationHeader(IHTTPOutput out, DocumentSpecification ds, List<String>
tabsArray)
     throws ManifoldCFException, IOException
   {
+    tabsArray.add("Namespace and Titles");
+    
     out.print(
 "<script type=\"text/javascript\">\n"+
 "<!--\n"+
@@ -536,6 +552,23 @@ public class WikiConnector extends org.a
 "  // Does nothing right now.\n"+
 "  return true;\n"+
 "}\n"+
+"\n"+
+"function NsDelete(k)\n"+
+"{\n"+
+"  SpecOp(\"nsop\"+k, \"Delete\", \"ns_\"+k);\n"+
+"}\n"+
+"\n"+
+"function NsAdd(k)\n"+
+"{\n"+
+"  SpecOp(\"nsop\", \"Add\", \"ns_\"+k);\n"+
+"}\n"+
+"\n"+
+"function SpecOp(n, opValue, anchorvalue)\n"+
+"{\n"+
+"  eval(\"editjob.\"+n+\".value = \\\"\"+opValue+\"\\\"\");\n"+
+"  postFormSetAnchor(anchorvalue);\n"+
+"}\n"+
+"\n"+
 "//-->\n"+
 "</script>\n"
     );
@@ -553,6 +586,167 @@ public class WikiConnector extends org.a
   public void outputSpecificationBody(IHTTPOutput out, DocumentSpecification ds, String tabName)
     throws ManifoldCFException, IOException
   {
+    if (tabName.equals("Namespace and Titles"))
+    {
+      boolean seenAny = false;
+      // Output table column headers
+      out.print(
+"<table class=\"displaytable\">\n"+
+"  <tr><td class=\"separator\" colspan=\"2\"><hr/></td></tr>\n"+
+"  <tr>\n"+
+"    <td class=\"description\"><nobr>Namespaces and titles:</nobr></td>\n"+
+"    <td class=\"boxcell\">\n"+
+"      <table class=\"formtable\">\n"+
+"        <tr class=\"formheaderrow\">\n"+
+"          <td class=\"formcolumnheader\"></td>\n"+
+"          <td class=\"formcolumnheader\"><nobr>Namespace</nobr></td>\n"+
+"          <td class=\"formcolumnheader\"><nobr>Title prefix</nobr></td>\n"+
+"        </tr>\n"
+      );
+
+      int k = 0;
+      for (int i = 0 ; i < ds.getChildCount() ; i++)
+      {
+        SpecificationNode sn = ds.getChild(i);
+        if (sn.getType().equals(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX))
+        {
+          String namespace = sn.getAttributeValue(WikiConfig.ATTR_NAMESPACE);
+          String titlePrefix = sn.getAttributeValue(WikiConfig.ATTR_TITLEPREFIX);
+          
+          String nsOpName = "nsop_"+k;
+          String nsNsName = "nsnsname_"+k;
+          String nsTitlePrefix = "nstitleprefix_"+k;
+          out.print(
+"        <tr class=\""+(((k % 2)==0)?"evenformrow":"oddformrow")+"\">\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              <a name=\""+"ns_"+Integer.toString(k)+"\"/>\n"+
+"              <input type=\"hidden\" name=\""+nsOpName+"\" value=\"\"/>\n"+
+"              <input type=\"hidden\" name=\""+nsNsName+"\" value=\""+((namespace==null)?"":org.apache.manifoldcf.ui.util.Encoder.attributeEscape(namespace))+"\"/>\n"+
+"              <input type=\"hidden\" name=\""+nsTitlePrefix+"\" value=\""+((titlePrefix==null)?"":org.apache.manifoldcf.ui.util.Encoder.attributeEscape(titlePrefix))+"\"/>\n"+
+"              <input type=\"button\" value=\"Delete\" onClick='Javascript:NsDelete("+Integer.toString(k)+")'
alt=\""+"Delete namespace/title #"+Integer.toString(k)+"\"/>\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              "+((namespace==null)?"(default)":org.apache.manifoldcf.ui.util.Encoder.bodyEscape(namespace))+"\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              "+((titlePrefix==null)?"(all titles)":org.apache.manifoldcf.ui.util.Encoder.bodyEscape(titlePrefix))+"\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"        </tr>\n"
+          );
+          k++;
+        }
+      }
+
+      if (k == 0)
+      {
+        out.print(
+"        <tr class=\"formrow\"><td colspan=\"3\" class=\"formmessage\">No specification;
all default namespace documents currently included</td></tr>\n"
+        );
+      }
+
+      // Add area
+      out.print(
+"        <tr class=\"formrow\"><td colspan=\"4\" class=\"formseparator\"><hr/></td></tr>\n"
+      );
+
+      // Obtain the list of namespaces
+      Map<String,String> namespaces = new HashMap<String,String>();
+      try
+      {
+        getNamespaces(namespaces);
+        // Extract and sort the names we're going to present
+        String[] nameSpaceNames = new String[namespaces.size()];
+        Iterator<String> keyIter = namespaces.keySet().iterator();
+        int j = 0;
+        while (keyIter.hasNext())
+        {
+          nameSpaceNames[j++] = keyIter.next();
+        }
+        java.util.Arrays.sort(nameSpaceNames);
+      
+        out.print(
+"        <tr class=\"formrow\">\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              <a name=\""+"ns_"+Integer.toString(k)+"\"/>\n"+
+"              <input type=\"hidden\" name=\"nsop\" value=\"\"/>\n"+
+"              <input type=\"hidden\" name=\"nscount\" value=\""+Integer.toString(k)+"\"/>\n"+
+"              <input type=\"button\" value=\"Add\" onClick='Javascript:NsAdd("+Integer.toString(k)+")'
alt=\"Add namespace/prefix\"/>\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              <select name=\"nsnsname\">\n"+
+"                <option value=\"\" selected=\"true\">-- Use default --</option>\n"
+        );
+        for (int l = 0 ; l < nameSpaceNames.length ; l++)
+        {
+          String prettyName = nameSpaceNames[l];
+          String canonicalName = namespaces.get(prettyName);
+          out.print(
+"                <option value=\""+org.apache.manifoldcf.ui.util.Encoder.attributeEscape(canonicalName)+"\">"+
+  org.apache.manifoldcf.ui.util.Encoder.bodyEscape(prettyName)+"</option>\n"
+          );
+        }
+        out.print(
+"              </select>\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              <input type=\"text\" name=\"nstitleprefix\" size=\"16\" value=\"\"/>\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"        </tr>\n"
+        );
+      }
+      catch (ServiceInterruption e)
+      {
+        out.print(
+"        <tr class=\"formrow\"><td colspan=\"3\" class=\"formmessage\">Transient
error: "+org.apache.manifoldcf.ui.util.Encoder.bodyEscape(e.getMessage())+"</td></tr>\n"
+        );
+      }
+
+      out.print(
+"      </table>\n"+
+"    </td>\n"+
+"  </tr>\n"+
+"</table>\n"
+      );
+
+    }
+    else
+    {
+      // Generate hiddens
+      int k = 0;
+      for (int i = 0 ; i < ds.getChildCount() ; i++)
+      {
+        SpecificationNode sn = ds.getChild(i);
+        if (sn.getType().equals(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX))
+        {
+          String namespace = sn.getAttributeValue(WikiConfig.ATTR_NAMESPACE);
+          String titlePrefix = sn.getAttributeValue(WikiConfig.ATTR_TITLEPREFIX);
+          
+          String nsNsName = "nsnsname_"+k;
+          String nsTitlePrefix = "nstitleprefix_"+k;
+
+          out.print(
+"<input type=\"hidden\" name=\""+nsNsName+"\" value=\""+((namespace == null)?"":org.apache.manifoldcf.ui.util.Encoder.attributeEscape(namespace))+"\"/>\n"+
+"<input type=\"hidden\" name=\""+titlePrefix+"\" value=\""+((namespace == null)?"":org.apache.manifoldcf.ui.util.Encoder.attributeEscape(titlePrefix))+"\"/>\n"
+          );
+          k++;
+        }
+      }
+      out.print(
+"<input type=\"hidden\" name=\"nscount\" value=\""+new Integer(k)+"\"/>\n"
+      );
+    }
   }
   
   /** Process a specification post.
@@ -567,6 +761,61 @@ public class WikiConnector extends org.a
   public String processSpecificationPost(IPostParameters variableContext, DocumentSpecification
ds)
     throws ManifoldCFException
   {
+    String countString = variableContext.getParameter("nscount");
+    if (countString != null)
+    {
+      for (int i = 0 ; i < ds.getChildCount() ; i++)
+      {
+        SpecificationNode sn = ds.getChild(i);
+        if (sn.getType().equals(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX))
+          ds.removeChild(i);
+        else
+          i++;
+      }
+      
+      int nsCount = Integer.parseInt(countString);
+      for (int i = 0 ; i < nsCount ; i++)
+      {
+        String nsOpName = "nsop_"+i;
+        String nsNsName = "nsnsname_"+i;
+        String nsTitlePrefix = "nstitleprefix_"+i;
+        
+        String nsOp = variableContext.getParameter(nsOpName);
+        if (nsOp != null && !nsOp.equals("Delete"))
+        {
+          String namespaceName = variableContext.getParameter(nsNsName);
+          if (namespaceName != null && namespaceName.length() == 0)
+            namespaceName = null;
+          String titlePrefix = variableContext.getParameter(nsTitlePrefix);
+          if (titlePrefix != null && titlePrefix.length() == 0)
+            titlePrefix = null;
+          SpecificationNode sn = new SpecificationNode(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX);
+          if (namespaceName != null)
+            sn.setAttribute(WikiConfig.ATTR_NAMESPACE,namespaceName);
+          if (titlePrefix != null)
+            sn.setAttribute(WikiConfig.ATTR_TITLEPREFIX,titlePrefix);
+          ds.addChild(ds.getChildCount(),sn);
+        }
+      }
+      
+      String newOp = variableContext.getParameter("nsop");
+      if (newOp != null && newOp.equals("Add"))
+      {
+        String namespaceName = variableContext.getParameter("nsnsname");
+        if (namespaceName != null && namespaceName.length() == 0)
+          namespaceName = null;
+        String titlePrefix = variableContext.getParameter("nstitleprefix");
+        if (titlePrefix != null && titlePrefix.length() == 0)
+          titlePrefix = null;
+        SpecificationNode sn = new SpecificationNode(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX);
+        if (namespaceName != null)
+          sn.setAttribute(WikiConfig.ATTR_NAMESPACE,namespaceName);
+        if (titlePrefix != null)
+          sn.setAttribute(WikiConfig.ATTR_TITLEPREFIX,titlePrefix);
+        ds.addChild(ds.getChildCount(),sn);
+      }
+    }
+
     return null;
   }
   
@@ -580,6 +829,60 @@ public class WikiConnector extends org.a
   public void viewSpecification(IHTTPOutput out, DocumentSpecification ds)
     throws ManifoldCFException, IOException
   {
+    out.print(
+"<table class=\"displaytable\">\n"+
+"  <tr>\n"
+    );
+    out.print(
+"    <td class=\"description\"><nobr>Namespace and title:</nobr></td>\n"+
+"    <td class=\"boxcell\">\n"+
+"      <table class=\"formtable\">\n"+
+"        <tr class=\"formheaderrow\">\n"+
+"          <td class=\"formcolumnheader\"><nobr>Namespace</nobr></td>\n"+
+"          <td class=\"formcolumnheader\"><nobr>Title prefix</nobr></td>\n"+
+"        </tr>\n"
+    );
+
+    int k = 0;
+    for (int i = 0 ; i < ds.getChildCount() ; i++)
+    {
+      SpecificationNode sn = ds.getChild(i);
+      if (sn.getType().equals(WikiConfig.NODE_NAMESPACE_TITLE_PREFIX))
+      {
+        String namespace = sn.getAttributeValue(WikiConfig.ATTR_NAMESPACE);
+        String titlePrefix = sn.getAttributeValue(WikiConfig.ATTR_TITLEPREFIX);
+        out.print(
+"        <tr class=\""+(((k % 2)==0)?"evenformrow":"oddformrow")+"\">\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              "+((namespace==null)?"(default)":org.apache.manifoldcf.ui.util.Encoder.bodyEscape(namespace))+"\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"          <td class=\"formcolumncell\">\n"+
+"            <nobr>\n"+
+"              "+((titlePrefix==null)?"(all documents)":org.apache.manifoldcf.ui.util.Encoder.bodyEscape(titlePrefix))+"\n"+
+"            </nobr>\n"+
+"          </td>\n"+
+"        </tr>\n"
+        );
+        k++;
+      }
+    }
+    
+    if (k == 0)
+      out.print(
+"        <tr class=\"formrow\"><td class=\"formmessage\" colspan=\"2\">All default
namespace documents included</td></tr>\n"
+      );
+    
+    out.print(
+"      </table>\n"+
+"    </td>\n"
+    );
+
+    out.print(
+"  </tr>\n"+
+"</table>\n"
+    );
   }
 
   // Protected static classes and methods
@@ -2133,6 +2436,7 @@ public class WikiConnector extends org.a
         {
           throw new ManifoldCFException("Unexpected response code "+rval+": "+executeMethod.getResponseBodyAsString());
         }
+
         // Read response and make sure it's valid
         InputStream is = executeMethod.getResponseBodyAsStream();
         try
@@ -2294,7 +2598,8 @@ public class WikiConnector extends org.a
       if (qName.equals("ns"))
       {
         canonical = atts.getValue("canonical");
-        return new XMLStringContext(theStream,namespaceURI,localName,qName,atts);
+        if (canonical != null)
+          return new XMLStringContext(theStream,namespaceURI,localName,qName,atts);
       }
       return super.beginTag(namespaceURI,localName,qName,atts);
     }
@@ -2306,9 +2611,14 @@ public class WikiConnector extends org.a
       String theTag = theContext.getQname();
       if (theTag.equals("ns"))
       {
-        // Pull down the data
-        XMLStringContext sc = (XMLStringContext)theContext;
-        namespaces.put(canonical,sc.getValue());
+        if (canonical != null)
+        {
+          // Pull down the data
+          XMLStringContext sc = (XMLStringContext)theContext;
+          namespaces.put(sc.getValue(),canonical);
+        }
+        else
+          super.endTag();
       }
       else
         super.endTag();



Mime
View raw message