Return-Path: Delivered-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Received: (qmail 60094 invoked from network); 28 Jun 2010 17:36:25 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Jun 2010 17:36:25 -0000 Received: (qmail 36778 invoked by uid 500); 28 Jun 2010 17:36:25 -0000 Delivered-To: apmail-incubator-connectors-commits-archive@incubator.apache.org Received: (qmail 36728 invoked by uid 500); 28 Jun 2010 17:36:25 -0000 Mailing-List: contact connectors-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: connectors-dev@incubator.apache.org Delivered-To: mailing list connectors-commits@incubator.apache.org Received: (qmail 36721 invoked by uid 99); 28 Jun 2010 17:36:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Jun 2010 17:36:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED,WEIRD_QUOTING X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Jun 2010 17:36:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B556623889BB; Mon, 28 Jun 2010 17:34:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r958651 [2/2] - in /incubator/lcf/branches/CONNECTORS-40/modules/connectors/sharepoint: build.xml connector/org/apache/lcf/crawler/connectors/sharepoint/SharePointRepository.java crawler-ui/connectors/ Date: Mon, 28 Jun 2010 17:34:52 -0000 To: connectors-commits@incubator.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100628173452.B556623889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/lcf/branches/CONNECTORS-40/modules/connectors/sharepoint/connector/org/apache/lcf/crawler/connectors/sharepoint/SharePointRepository.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-40/modules/connectors/sharepoint/connector/org/apache/lcf/crawler/connectors/sharepoint/SharePointRepository.java?rev=958651&r1=958650&r2=958651&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-40/modules/connectors/sharepoint/connector/org/apache/lcf/crawler/connectors/sharepoint/SharePointRepository.java (original) +++ incubator/lcf/branches/CONNECTORS-40/modules/connectors/sharepoint/connector/org/apache/lcf/crawler/connectors/sharepoint/SharePointRepository.java Mon Jun 28 17:34:52 2010 @@ -689,48 +689,7 @@ public class SharePointRepository extend return rval; } - protected static class ExecuteMethodThread extends Thread - { - protected HttpClient client; - protected HostConfiguration hostConfiguration; - protected HttpMethodBase executeMethod; - protected Throwable exception = null; - protected int rval = 0; - - public ExecuteMethodThread(HttpClient client, HostConfiguration hostConfiguration, HttpMethodBase executeMethod) - { - super(); - setDaemon(true); - this.client = client; - this.hostConfiguration = hostConfiguration; - this.executeMethod = executeMethod; - } - - public void run() - { - try - { - // Call the execute method appropriately - rval = client.executeMethod(hostConfiguration,executeMethod,null); - } - catch (Throwable e) - { - this.exception = e; - } - } - - public Throwable getException() - { - return exception; - } - - public int getResponse() - { - return rval; - } - } - - /** Process a set of documents. + /** Process a set of documents. * This is the method that should cause each document to be fetched, processed, and the results either added * to the queue of documents for the current job, and/or entered into the incremental ingestion manager. * The document specification allows this class to filter what is done based on the job. @@ -1264,6 +1223,2864 @@ public class SharePointRepository extend } } + // UI support methods. + // + // These support methods come in two varieties. The first bunch is involved in setting up connection configuration information. The second bunch + // is involved in presenting and editing document specification information for a job. The two kinds of methods are accordingly treated differently, + // in that the first bunch cannot assume that the current connector object is connected, while the second bunch can. That is why the first bunch + // receives a thread context argument for all UI methods, while the second bunch does not need one (since it has already been applied via the connect() + // method, above). + + /** Output the configuration header section. + * This method is called in the head section of the connector's configuration page. Its purpose is to add the required tabs to the list, and to output any + * javascript methods that might be needed by the configuration editing HTML. + *@param threadContext is the local thread context. + *@param out is the output to which any HTML should be sent. + *@param parameters are the configuration parameters, as they currently exist, for this connection being configured. + *@param tabsArray is an array of tab names. Add to this array any tab names that are specific to the connector. + */ + public void outputConfigurationHeader(IThreadContext threadContext, IHTTPOutput out, ConfigParams parameters, ArrayList tabsArray) + throws LCFException, IOException + { + tabsArray.add("Server"); + out.print( +"\n" + ); + } + + /** Output the configuration body section. + * This method is called in the body section of the connector's configuration page. Its purpose is to present the required form elements for editing. + * The coder can presume that the HTML that is output from this configuration will be within appropriate , , and
tags. The name of the + * form is "editconnection". + *@param threadContext is the local thread context. + *@param out is the output to which any HTML should be sent. + *@param parameters are the configuration parameters, as they currently exist, for this connection being configured. + *@param tabName is the current tab name. + */ + public void outputConfigurationBody(IThreadContext threadContext, IHTTPOutput out, ConfigParams parameters, String tabName) + throws LCFException, IOException + { + String serverVersion = parameters.getParameter("serverVersion"); + if (serverVersion == null) + serverVersion = "2.0"; + + String serverProtocol = parameters.getParameter("serverProtocol"); + if (serverProtocol == null) + serverProtocol = "http"; + + String serverName = parameters.getParameter("serverName"); + if (serverName == null) + serverName = "localhost"; + + String serverPort = parameters.getParameter("serverPort"); + if (serverPort == null) + serverPort = ""; + + String serverLocation = parameters.getParameter("serverLocation"); + if (serverLocation == null) + serverLocation = ""; + + String userName = parameters.getParameter("userName"); + if (userName == null) + userName = ""; + + String password = parameters.getObfuscatedParameter("password"); + if (password == null) + password = ""; + + String keystore = parameters.getParameter("keystore"); + IKeystoreManager localKeystore; + if (keystore == null) + localKeystore = KeystoreManagerFactory.make(""); + else + localKeystore = KeystoreManagerFactory.make("",keystore); + + // "Server" tab + // Always send along the keystore. + if (keystore != null) + { + out.print( +"\n" + ); + } + + if (tabName.equals("Server")) + { + out.print( +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
Server SharePoint version:\n"+ +" \n"+ +"
Server protocol:\n"+ +" \n"+ +"
Server name:
Server port:
Site path:
User name:
Password:
SSL certificate list:\n"+ +" \n"+ +" \n"+ +" \n" + ); + // List the individual certificates in the store, with a delete button for each + String[] contents = localKeystore.getContents(); + if (contents.length == 0) + { + out.print( +" \n" + ); + } + else + { + int i = 0; + while (i < contents.length) + { + String alias = contents[i]; + String description = localKeystore.getDescription(alias); + if (description.length() > 128) + description = description.substring(0,125) + "..."; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + + i++; + } + } + out.print( +"
No certificates present
\n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(description)+"
\n"+ +"  \n"+ +" Certificate: \n"+ +"
\n" + ); + } + else + { + // Server tab hiddens + out.print( +"\n"+ +"\n"+ +"\n"+ +"\n"+ +"\n"+ +"\n" + ); + } + } + + /** Process a configuration post. + * This method is called at the start of the connector's configuration page, whenever there is a possibility that form data for a connection has been + * posted. Its purpose is to gather form information and modify the configuration parameters accordingly. + * The name of the posted form is "editconnection". + *@param threadContext is the local thread context. + *@param variableContext is the set of variables available from the post, including binary file post information. + *@param parameters are the configuration parameters, as they currently exist, for this connection being configured. + *@return null if all is well, or a string error message if there is an error that should prevent saving of the connection (and cause a redirection to an error page). + */ + public String processConfigurationPost(IThreadContext threadContext, IPostParameters variableContext, ConfigParams parameters) + throws LCFException + { + String serverVersion = variableContext.getParameter("serverVersion"); + if (serverVersion != null) + parameters.setParameter("serverVersion",serverVersion); + + String serverProtocol = variableContext.getParameter("serverProtocol"); + if (serverProtocol != null) + parameters.setParameter("serverProtocol",serverProtocol); + + String serverName = variableContext.getParameter("serverName"); + if (serverName != null) + parameters.setParameter("serverName",serverName); + + String serverPort = variableContext.getParameter("serverPort"); + if (serverPort != null) + parameters.setParameter("serverPort",serverPort); + + String serverLocation = variableContext.getParameter("serverLocation"); + if (serverLocation != null) + parameters.setParameter("serverLocation",serverLocation); + + String userName = variableContext.getParameter("userName"); + if (userName != null) + parameters.setParameter("userName",userName); + + String password = variableContext.getParameter("password"); + if (password != null) + parameters.setObfuscatedParameter("password",password); + + String keystoreValue = variableContext.getParameter("keystoredata"); + if (keystoreValue != null) + parameters.setParameter("keystore",keystoreValue); + + String configOp = variableContext.getParameter("configop"); + if (configOp != null) + { + if (configOp.equals("Delete")) + { + String alias = variableContext.getParameter("shpkeystorealias"); + keystoreValue = parameters.getParameter("keystore"); + IKeystoreManager mgr; + if (keystoreValue != null) + mgr = KeystoreManagerFactory.make("",keystoreValue); + else + mgr = KeystoreManagerFactory.make(""); + mgr.remove(alias); + parameters.setParameter("keystore",mgr.getString()); + } + else if (configOp.equals("Add")) + { + String alias = IDFactory.make(threadContext); + byte[] certificateValue = variableContext.getBinaryBytes("shpcertificate"); + keystoreValue = parameters.getParameter("keystore"); + IKeystoreManager mgr; + if (keystoreValue != null) + mgr = KeystoreManagerFactory.make("",keystoreValue); + else + mgr = KeystoreManagerFactory.make(""); + java.io.InputStream is = new java.io.ByteArrayInputStream(certificateValue); + String certError = null; + try + { + mgr.importCertificate(alias,is); + } + catch (Throwable e) + { + certError = e.getMessage(); + } + finally + { + try + { + is.close(); + } + catch (IOException e) + { + // Don't report anything + } + } + + if (certError != null) + { + // Redirect to error page + return "Illegal certificate: "+certError; + } + parameters.setParameter("keystore",mgr.getString()); + } + } + return null; + } + + /** View configuration. + * This method is called in the body section of the connector's view configuration page. Its purpose is to present the connection information to the user. + * The coder can presume that the HTML that is output from this configuration will be within appropriate and tags. + *@param threadContext is the local thread context. + *@param out is the output to which any HTML should be sent. + *@param parameters are the configuration parameters, as they currently exist, for this connection being configured. + */ + public void viewConfiguration(IThreadContext threadContext, IHTTPOutput out, ConfigParams parameters) + throws LCFException, IOException + { + out.print( +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
Parameters:\n" + ); + Iterator iter = parameters.listParameters(); + while (iter.hasNext()) + { + String param = (String)iter.next(); + String value = parameters.getParameter(param); + if (param.length() >= "password".length() && param.substring(param.length()-"password".length()).equalsIgnoreCase("password")) + { + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(param)+"=********
\n" + ); + } + else if (param.length() >="keystore".length() && param.substring(param.length()-"keystore".length()).equalsIgnoreCase("keystore")) + { + IKeystoreManager kmanager = KeystoreManagerFactory.make("",value); + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(param)+"=<"+Integer.toString(kmanager.getContents().length)+" certificate(s)>
\n" + ); + } + else + { + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(param)+"="+org.apache.lcf.ui.util.Encoder.bodyEscape(value)+"
\n" + ); + } + } + out.print( +"
\n" + ); + } + + /** Output the specification header section. + * This method is called in the head section of a job page which has selected a repository connection of the current type. Its purpose is to add the required tabs + * to the list, and to output any javascript methods that might be needed by the job editing HTML. + *@param out is the output to which any HTML should be sent. + *@param ds is the current document specification for this job. + *@param tabsArray is an array of tab names. Add to this array any tab names that are specific to the connector. + */ + public void outputSpecificationHeader(IHTTPOutput out, DocumentSpecification ds, ArrayList tabsArray) + throws LCFException, IOException + { + tabsArray.add("Paths"); + tabsArray.add("Security"); + tabsArray.add("Metadata"); + out.print( +"\n" + ); + } + + /** Output the specification body section. + * This method is called in the body section of a job page which has selected a repository connection of the current type. Its purpose is to present the required form elements for editing. + * The coder can presume that the HTML that is output from this configuration will be within appropriate , , and tags. The name of the + * form is "editjob". + *@param out is the output to which any HTML should be sent. + *@param ds is the current document specification for this job. + *@param tabName is the current tab name. + */ + public void outputSpecificationBody(IHTTPOutput out, DocumentSpecification ds, String tabName) + throws LCFException, IOException + { + int i; + int k; + int l; + + // Paths tab + + + if (tabName.equals("Paths")) + { + out.print( +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

Path rules:\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + i = 0; + l = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("startpoint")) + { + String site = sn.getAttributeValue("site"); + String lib = sn.getAttributeValue("lib"); + String siteLib = site + "/" + lib + "/"; + + // Go through all the file/folder rules for the startpoint, and generate new "rules" corresponding to each. + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("include") || node.getType().equals("exclude")) + { + String matchPart = node.getAttributeValue("match"); + String ruleType = node.getAttributeValue("type"); + + String theFlavor = node.getType(); + + String pathDescription = "_"+Integer.toString(k); + String pathOpName = "specop"+pathDescription; + String thePath = siteLib + matchPart; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + k++; + if (ruleType.equals("file") && !matchPart.startsWith("*")) + { + // Generate another rule corresponding to all matching paths. + pathDescription = "_"+Integer.toString(k); + pathOpName = "specop"+pathDescription; + + thePath = siteLib + "*/" + matchPart; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + + k++; + } + } + } + } + else if (sn.getType().equals("pathrule")) + { + String match = sn.getAttributeValue("match"); + String type = sn.getAttributeValue("type"); + String action = sn.getAttributeValue("action"); + + String pathDescription = "_"+Integer.toString(k); + String pathOpName = "specop"+pathDescription; + + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + k++; + } + } + if (k == 0) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + if (message != null) + { + // Display the error message, with no widgets + out.print( +" \n" + ); + } + else + { + // What we display depends on the determined state of the path. If the path is a library or is unknown, all we can do is allow a type-in to append + // to it, or allow a reset. If the path is a site, then we can optionally display libraries, sites, OR allow a type-in. + // The path buttons are on the left; they consist of "Reset" (to reset the path), "+" (to add to the path), and "-" (to remove from the path). + out.print( +" \n"+ +" \n" + ); + } + out.print( +" \n"+ +"
Path matchTypeAction
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(thePath)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" file\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+theFlavor+"\n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(thePath)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" file\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+theFlavor+"\n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(match)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+type+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+action+"\n"+ +" \n"+ +"
No documents currently included
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

\n"+ +" New rule:\n" + ); + + // The following variables may be in the thread context because postspec.jsp put them there: + // (1) "specpath", which contains the rule path as it currently stands; + // (2) "specpathstate", which describes what the current path represents. Values are "unknown", "site", "library". + // Once the widget is in the state "unknown", it can only be reset, and cannot be further modified + // specsitepath may be in the thread context, put there by postspec.jsp + String pathSoFar = (String)currentContext.get("specpath"); + String pathState = (String)currentContext.get("specpathstate"); + String pathLibrary = (String)currentContext.get("specpathlibrary"); + if (pathState == null) + { + pathState = "unknown"; + pathLibrary = null; + } + if (pathSoFar == null) + { + pathSoFar = "/"; + pathState = "site"; + pathLibrary = null; + } + + // Grab next site list and lib list + ArrayList childSiteList = null; + ArrayList childLibList = null; + String message = null; + if (pathState.equals("site")) + { + try + { + String queryPath = pathSoFar; + if (queryPath.equals("/")) + queryPath = ""; + childSiteList = getSites(queryPath); + if (childSiteList == null) + { + // Illegal path - state becomes "unknown". + pathState = "unknown"; + pathLibrary = null; + } + childLibList = getDocLibsBySite(queryPath); + if (childLibList == null) + { + // Illegal path - state becomes "unknown" + pathState = "unknown"; + pathLibrary = null; + } + } + catch (LCFException e) + { + e.printStackTrace(); + message = e.getMessage(); + } + catch (ServiceInterruption e) + { + message = "SharePoint unavailable: "+e.getMessage(); + } + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + if (pathLibrary != null) + { + out.print( +" \n" + ); + } + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(pathSoFar)+"\n"+ +" \n"+ +" \n"+ +" \n" + ); + if (pathState.equals("unknown")) + { + if (pathLibrary == null) + { + out.print( +" \n" + ); + } + else + { + out.print( +" \n"+ +" file\n" + ); + } + } + else + { + out.print( +" \n"+ +" "+pathState+"\n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

"+org.apache.lcf.ui.util.Encoder.bodyEscape(message)+"\n"+ +" \n"+ +" \n"+ +" \n" + ); + if (pathSoFar.length() > 1 && (pathState.equals("site") || pathState.equals("library"))) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n" + ); + if (pathState.equals("site") && childSiteList != null && childSiteList.size() > 0) + { + out.print( +" \n"+ +" \n" + ); + } + + if (pathState.equals("site") && childLibList != null && childLibList.size() > 0) + { + out.print( +" \n"+ +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +"
\n" + ); + } + else + { + // Hiddens for path rules + i = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("startpoint")) + { + String site = sn.getAttributeValue("site"); + String lib = sn.getAttributeValue("lib"); + String siteLib = site + "/" + lib + "/"; + + // Go through all the file/folder rules for the startpoint, and generate new "rules" corresponding to each. + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("include") || node.getType().equals("exclude")) + { + String matchPart = node.getAttributeValue("match"); + String ruleType = node.getAttributeValue("type"); + + String theFlavor = node.getType(); + + String pathDescription = "_"+Integer.toString(k); + + String thePath = siteLib + matchPart; + out.print( +"\n"+ +"\n"+ +"\n" + ); + k++; + + if (ruleType.equals("file") && !matchPart.startsWith("*")) + { + // Generate another rule corresponding to all matching paths. + pathDescription = "_"+Integer.toString(k); + + thePath = siteLib + "*/" + matchPart; + out.print( +"\n"+ +"\n"+ +"\n" + ); + k++; + } + } + } + } + else if (sn.getType().equals("pathrule")) + { + String match = sn.getAttributeValue("match"); + String type = sn.getAttributeValue("type"); + String action = sn.getAttributeValue("action"); + + String pathDescription = "_"+Integer.toString(k); + out.print( +"\n"+ +"\n"+ +"\n" + ); + k++; + } + } + out.print( +"\n" + ); + } + + // Security tab + + // Find whether security is on or off + i = 0; + boolean securityOn = true; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("security")) + { + String securityValue = sn.getAttributeValue("value"); + if (securityValue.equals("off")) + securityOn = false; + else if (securityValue.equals("on")) + securityOn = true; + } + } + + if (tabName.equals("Security")) + { + out.print( +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"\n"+ +" \n" + ); + // Finally, go through forced ACL + i = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("access")) + { + String accessDescription = "_"+Integer.toString(k); + String accessOpName = "accessop"+accessDescription; + String token = sn.getAttributeValue("token"); + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + k++; + } + } + if (k == 0) + { + out.print( +" \n"+ +" \n"+ +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

Security:\n"+ +" \n"+ +" Enabled \n"+ +" Disabled\n"+ +" \n"+ +"

\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(token)+"\n"+ +"
No access tokens present

\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n" + ); + } + else + { + out.print( +"\n" + ); + // Finally, go through forced ACL + i = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("access")) + { + String accessDescription = "_"+Integer.toString(k); + String token = sn.getAttributeValue("token"); + out.print( +"\n" + ); + k++; + } + } + out.print( +"\n" + ); + } + + // Metadata tab + + // Find the path-value metadata attribute name + i = 0; + String pathNameAttribute = ""; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("pathnameattribute")) + { + pathNameAttribute = sn.getAttributeValue("value"); + } + } + + // Find the path-value mapping data + i = 0; + org.apache.lcf.crawler.connectors.sharepoint.MatchMap matchMap = new org.apache.lcf.crawler.connectors.sharepoint.MatchMap(); + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("pathmap")) + { + String pathMatch = sn.getAttributeValue("match"); + String pathReplace = sn.getAttributeValue("replace"); + matchMap.appendMatchPair(pathMatch,pathReplace); + } + } + + if (tabName.equals("Metadata")) + { + out.print( +"\n"+ +"\n"+ +"\n"+ +"\n"+ +"\n"+ +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

Metadata rules:\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + i = 0; + l = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("startpoint")) + { + String site = sn.getAttributeValue("site"); + String lib = sn.getAttributeValue("lib"); + String path = site + "/" + lib + "/*"; + String allmetadata = sn.getAttributeValue("allmetadata"); + StringBuffer metadataFieldList = new StringBuffer(); + ArrayList metadataFieldArray = new ArrayList(); + if (allmetadata == null || !allmetadata.equals("true")) + { + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("metafield")) + { + if (metadataFieldList.length() > 0) + metadataFieldList.append(", "); + String val = node.getAttributeValue("value"); + metadataFieldList.append(val); + metadataFieldArray.add(val); + } + } + allmetadata = "false"; + } + + if (allmetadata.equals("true") || metadataFieldList.length() > 0) + { + String pathDescription = "_"+Integer.toString(k); + String pathOpName = "metaop"+pathDescription; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + k++; + } + } + else if (sn.getType().equals("metadatarule")) + { + String path = sn.getAttributeValue("match"); + String action = sn.getAttributeValue("action"); + String allmetadata = sn.getAttributeValue("allmetadata"); + StringBuffer metadataFieldList = new StringBuffer(); + ArrayList metadataFieldArray = new ArrayList(); + if (action.equals("include")) + { + if (allmetadata == null || !allmetadata.equals("true")) + { + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("metafield")) + { + String val = node.getAttributeValue("value"); + if (metadataFieldList.length() > 0) + metadataFieldList.append(", "); + metadataFieldList.append(val); + metadataFieldArray.add(val); + } + } + allmetadata="false"; + } + } + else + allmetadata = ""; + + String pathDescription = "_"+Integer.toString(k); + String pathOpName = "metaop"+pathDescription; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + l++; + k++; + + } + } + + if (k == 0) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + if (message != null) + { + out.print( +" \n" + ); + } + else + { + // What we display depends on the determined state of the path. If the path is a library or is unknown, all we can do is allow a type-in to append + // to it, or allow a reset. If the path is a site, then we can optionally display libraries, sites, OR allow a type-in. + // The path buttons are on the left; they consist of "Reset" (to reset the path), "+" (to add to the path), and "-" (to remove from the path). + out.print( +" \n"+ +" \n" + ); + } + out.print( +" \n"+ +"
Path matchActionAll metadata?Fields
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(path)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" include\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+allmetadata+"\n"+ +" \n"+ +" \n" + ); + int q = 0; + while (q < metadataFieldArray.size()) + { + String field = (String)metadataFieldArray.get(q++); + out.print( +" \n" + ); + } + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(metadataFieldList.toString())+"\n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(path)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+action+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+allmetadata+"\n"+ +" \n"+ +" \n" + ); + int q = 0; + while (q < metadataFieldArray.size()) + { + String field = (String)metadataFieldArray.get(q++); + out.print( +" \n" + ); + } + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(metadataFieldList.toString())+"\n"+ +"
No metadata included
\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"

\n"+ +" New rule:\n" + ); + // The following variables may be in the thread context because postspec.jsp put them there: + // (1) "metapath", which contains the rule path as it currently stands; + // (2) "metapathstate", which describes what the current path represents. Values are "unknown", "site", "library". + // (3) "metapathlibrary" is the library path (if this is known yet). + // Once the widget is in the state "unknown", it can only be reset, and cannot be further modified + String metaPathSoFar = (String)currentContext.get("metapath"); + String metaPathState = (String)currentContext.get("metapathstate"); + String metaPathLibrary = (String)currentContext.get("metapathlibrary"); + if (metaPathState == null) + metaPathState = "unknown"; + if (metaPathSoFar == null) + { + metaPathSoFar = "/"; + metaPathState = "site"; + } + + String message = null; + String[] fields = null; + if (metaPathLibrary != null) + { + // Look up metadata fields + int index = metaPathLibrary.lastIndexOf("/"); + String site = metaPathLibrary.substring(0,index); + String lib = metaPathLibrary.substring(index+1); + Map metaFieldList = null; + try + { + metaFieldList = getFieldList(site,lib); + } + catch (LCFException e) + { + e.printStackTrace(); + message = e.getMessage(); + } + catch (ServiceInterruption e) + { + message = "SharePoint unavailable: "+e.getMessage(); + } + if (metaFieldList != null) + { + fields = new String[metaFieldList.size()]; + int j = 0; + Iterator iter = metaFieldList.keySet().iterator(); + while (iter.hasNext()) + { + fields[j++] = (String)iter.next(); + } + java.util.Arrays.sort(fields); + } + } + + // Grab next site list and lib list + ArrayList childSiteList = null; + ArrayList childLibList = null; + + if (message == null && metaPathState.equals("site")) + { + try + { + String queryPath = metaPathSoFar; + if (queryPath.equals("/")) + queryPath = ""; + childSiteList = getSites(queryPath); + if (childSiteList == null) + { + // Illegal path - state becomes "unknown". + metaPathState = "unknown"; + } + childLibList = getDocLibsBySite(queryPath); + if (childLibList == null) + { + // Illegal path - state becomes "unknown" + metaPathState = "unknown"; + } + } + catch (LCFException e) + { + e.printStackTrace(); + message = e.getMessage(); + } + catch (ServiceInterruption e) + { + message = "SharePoint unavailable: "+e.getMessage(); + } + } + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + if (metaPathLibrary != null) + { + out.print( +" \n" + ); + } + out.print( +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(metaPathSoFar)+"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" Include all metadata\n"+ +" \n"+ +" \n"+ +" \n" + ); + if (fields != null && fields.length > 0) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +"

"+org.apache.lcf.ui.util.Encoder.bodyEscape(message)+"
\n"+ +" \n"+ +" \n"+ +" \n" + ); + if (metaPathSoFar.length() > 1 && (metaPathState.equals("site") || metaPathState.equals("library"))) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n" + ); + if (metaPathState.equals("site") && childSiteList != null && childSiteList.size() > 0) + { + out.print( +" \n"+ +" \n" + ); + } + + if (metaPathState.equals("site") && childLibList != null && childLibList.size() > 0) + { + out.print( +" \n"+ +" \n" + ); + } + out.print( +" \n"+ +" \n"+ +" \n"+ +"
\n"+ +"

Path metadata:\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + i = 0; + while (i < matchMap.getMatchCount()) + { + String matchString = matchMap.getMatchString(i); + String replaceString = matchMap.getReplaceString(i); + out.print( +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n" + ); + i++; + } + if (i == 0) + { + out.print( +" \n" + ); + } + out.print( +" \n"+ +"\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +"
Attribute name:\n"+ +" \n"+ +" \n"+ +" \n"+ +"

\n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(matchString)+"\n"+ +" \n"+ +" ==>\n"+ +" \n"+ +" \n"+ +" "+org.apache.lcf.ui.util.Encoder.bodyEscape(replaceString)+"\n"+ +" \n"+ +"
No mappings specified

\n"+ +" \n"+ +" \n"+ +" \n"+ +" Match regexp: ==>Replace string: 
\n"+ +"
\n" + ); + } + else + { + // Hiddens for metadata rules + i = 0; + k = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i++); + if (sn.getType().equals("startpoint")) + { + String site = sn.getAttributeValue("site"); + String lib = sn.getAttributeValue("lib"); + String path = site + "/" + lib + "/*"; + + String allmetadata = sn.getAttributeValue("allmetadata"); + ArrayList metadataFieldArray = new ArrayList(); + if (allmetadata == null || !allmetadata.equals("true")) + { + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("metafield")) + { + String val = node.getAttributeValue("value"); + metadataFieldArray.add(val); + } + } + allmetadata = "false"; + } + + if (allmetadata.equals("true") || metadataFieldArray.size() > 0) + { + String pathDescription = "_"+Integer.toString(k); + out.print( +"\n"+ +"\n"+ +"\n" + ); + int q = 0; + while (q < metadataFieldArray.size()) + { + String field = (String)metadataFieldArray.get(q++); + out.print( +"\n" + ); + } + k++; + } + } + else if (sn.getType().equals("metadatarule")) + { + String match = sn.getAttributeValue("match"); + String action = sn.getAttributeValue("action"); + String allmetadata = sn.getAttributeValue("allmetadata"); + + String pathDescription = "_"+Integer.toString(k); + out.print( +"\n"+ +"\n" + ); + if (action.equals("include")) + { + if (allmetadata == null || allmetadata.length() == 0) + allmetadata = "false"; + out.print( +"\n" + ); + int j = 0; + while (j < sn.getChildCount()) + { + SpecificationNode node = sn.getChild(j++); + if (node.getType().equals("metafield")) + { + String value = node.getAttributeValue("value"); + out.print( +"\n" + ); + } + } + } + k++; + } + } + out.print( +"\n"+ +"\n"+ +"\n"+ +"\n" + ); + i = 0; + while (i < matchMap.getMatchCount()) + { + String matchString = matchMap.getMatchString(i); + String replaceString = matchMap.getReplaceString(i); + out.print( +"\n"+ +"\n" + ); + i++; + } + } + } + + /** Process a specification post. + * This method is called at the start of job's edit or view page, whenever there is a possibility that form data for a connection has been + * posted. Its purpose is to gather form information and modify the document specification accordingly. + * The name of the posted form is "editjob". + *@param variableContext contains the post data, including binary file-upload information. + *@param ds is the current document specification for this job. + *@return null if all is well, or a string error message if there is an error that should prevent saving of the job (and cause a redirection to an error page). + */ + public String processSpecificationPost(IPostParameters variableContext, DocumentSpecification ds) + throws LCFException + { + // Remove old-style rules, but only if the information would not be lost + if (variableContext.getParameter("specpathcount") != null && variableContext.getParameter("metapathcount") != null) + { + int i = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i); + if (sn.getType().equals("startpoint")) + ds.removeChild(i); + else + i++; + } + } + + String x = variableContext.getParameter("specpathcount"); + if (x != null) + { + // Delete all path rule entries first + int i = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i); + if (sn.getType().equals("pathrule")) + ds.removeChild(i); + else + i++; + } + + // Find out how many children were sent + int pathCount = Integer.parseInt(x); + // Gather up these + i = 0; + while (i < pathCount) + { + String pathDescription = "_"+Integer.toString(i); + String pathOpName = "specop"+pathDescription; + x = variableContext.getParameter(pathOpName); + if (x != null && x.equals("Delete")) + { + // Skip to the next + i++; + continue; + } + + // Get the stored information for this rule. + String path = variableContext.getParameter("specpath"+pathDescription); + String type = variableContext.getParameter("spectype"+pathDescription); + String action = variableContext.getParameter("specflav"+pathDescription); + + SpecificationNode node = new SpecificationNode("pathrule"); + node.setAttribute("match",path); + node.setAttribute("action",action); + node.setAttribute("type",type); + + // If there was an insert operation, do it now + if (x != null && x.equals("Insert Here")) + { + // The global parameters are what are used to create the rule + path = variableContext.getParameter("specpath"); + type = variableContext.getParameter("spectype"); + action = variableContext.getParameter("specflavor"); + + SpecificationNode sn = new SpecificationNode("pathrule"); + sn.setAttribute("match",path); + sn.setAttribute("action",action); + sn.setAttribute("type",type); + ds.addChild(ds.getChildCount(),sn); + } + + ds.addChild(ds.getChildCount(),node); + i++; + } + + // See if there's a global path rule operation + String op = variableContext.getParameter("specop"); + if (op != null) + { + if (op.equals("Add")) + { + String match = variableContext.getParameter("specpath"); + String action = variableContext.getParameter("specflavor"); + String type = variableContext.getParameter("spectype"); + SpecificationNode node = new SpecificationNode("pathrule"); + node.setAttribute("match",match); + node.setAttribute("action",action); + node.setAttribute("type",type); + ds.addChild(ds.getChildCount(),node); + } + } + + // See if there's a global pathbuilder operation + String pathop = variableContext.getParameter("specpathop"); + if (pathop != null) + { + if (pathop.equals("Reset")) + { + currentContext.save("specpath","/"); + currentContext.save("specpathstate","site"); + currentContext.save("specpathlibrary",null); + } + else if (pathop.equals("AppendSite")) + { + String path = variableContext.getParameter("specpath"); + String addon = variableContext.getParameter("specsite"); + if (addon != null && addon.length() > 0) + { + if (path.equals("/")) + path = path + addon; + else + path = path + "/" + addon; + } + currentContext.save("specpath",path); + currentContext.save("specpathstate","site"); + currentContext.save("specpathlibrary",null); + } + else if (pathop.equals("AppendLibrary")) + { + String path = variableContext.getParameter("specpath"); + String addon = variableContext.getParameter("speclibrary"); + if (addon != null && addon.length() > 0) + { + if (path.equals("/")) + path = path + addon; + else + path = path + "/" + addon; + currentContext.save("specpathstate","library"); + currentContext.save("specpathlibrary",path); + } + currentContext.save("specpath",path); + } + else if (pathop.equals("AppendText")) + { + String path = variableContext.getParameter("specpath"); + String library = variableContext.getParameter("specpathlibrary"); + String addon = variableContext.getParameter("specmatch"); + if (addon != null && addon.length() > 0) + { + if (path.equals("/")) + path = path + addon; + else + path = path + "/" + addon; + currentContext.save("specpathstate","unknown"); + } + currentContext.save("specpath",path); + currentContext.save("specpathlibrary",library); + } + else if (pathop.equals("Remove")) + { + // Strip off end + String path = variableContext.getParameter("specpath"); + int index = path.lastIndexOf("/"); + path = path.substring(0,index); + if (path.length() == 0) + path = "/"; + currentContext.save("specpath",path); + // Now, adjust state. + String pathState = variableContext.getParameter("specpathstate"); + if (pathState.equals("library")) + pathState = "site"; + currentContext.save("specpathstate",pathState); + } + } + + } + + x = variableContext.getParameter("metapathcount"); + if (x != null) + { + // Delete all metadata rule entries first + int i = 0; + while (i < ds.getChildCount()) + { + SpecificationNode sn = ds.getChild(i); + if (sn.getType().equals("metadatarule")) + ds.removeChild(i); + else + i++; + } + + // Find out how many children were sent + int pathCount = Integer.parseInt(x); + // Gather up these + i = 0; + while (i < pathCount) + { + String pathDescription = "_"+Integer.toString(i); + String pathOpName = "metaop"+pathDescription; + x = variableContext.getParameter(pathOpName); + if (x != null && x.equals("Delete")) + { + // Skip to the next + i++; + continue; + } + + // Get the stored information for this rule. + String path = variableContext.getParameter("metapath"+pathDescription); + String action = variableContext.getParameter("metaflav"+pathDescription); + String allmetadata = variableContext.getParameter("metaall"+pathDescription); + String[] metadataFields = variableContext.getParameterValues("metafields"+pathDescription); + + SpecificationNode node = new SpecificationNode("metadatarule"); + node.setAttribute("match",path); + node.setAttribute("action",action); + if (action.equals("include")) + { + if (allmetadata != null) + node.setAttribute("allmetadata",allmetadata); + if (metadataFields != null) + { + int j = 0; + while (j < metadataFields.length) + { + SpecificationNode sn = new SpecificationNode("metafield"); + sn.setAttribute("value",metadataFields[j]); + node.addChild(j++,sn); + } + } + } + + if (x != null && x.equals("Insert Here")) + { + // Insert the new global rule information now + path = variableContext.getParameter("metapath"); + action = variableContext.getParameter("metaflavor"); + allmetadata = variableContext.getParameter("metaall"); + metadataFields = variableContext.getParameterValues("metafields"); + + SpecificationNode sn = new SpecificationNode("metadatarule"); + sn.setAttribute("match",path); + sn.setAttribute("action",action); + if (action.equals("include")) + { + if (allmetadata != null) + node.setAttribute("allmetadata",allmetadata); + if (metadataFields != null) + { + int j = 0; + while (j < metadataFields.length) + { + SpecificationNode node2 = new SpecificationNode("metafield"); + node2.setAttribute("value",metadataFields[j]); + sn.addChild(j++,node2); + } + } + } + + ds.addChild(ds.getChildCount(),sn); + } + + ds.addChild(ds.getChildCount(),node); + i++; + } + + // See if there's a global path rule operation + String op = variableContext.getParameter("metaop"); + if (op != null) + { + if (op.equals("Add")) + { + String match = variableContext.getParameter("metapath"); + String action = variableContext.getParameter("metaflavor"); + SpecificationNode node = new SpecificationNode("metadatarule"); + node.setAttribute("match",match); + node.setAttribute("action",action); + if (action.equals("include")) + { + String allmetadata = variableContext.getParameter("metaall"); [... 693 lines stripped ...]