home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / create-index.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  5.1 KB  |  152 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17.  
  18. <xsp:page language="java"
  19.           xmlns:xsp="http://apache.org/xsp"
  20.           xmlns:xsp-request="http://apache.org/xsp/request/2.0">
  21.  
  22.   <xsp:structure>
  23.    <xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
  24.    <xsp:include>org.apache.avalon.framework.component.ComponentException</xsp:include>
  25.    <xsp:include>org.apache.cocoon.ProcessingException</xsp:include>
  26.    <xsp:include>java.net.URL</xsp:include>
  27.    <xsp:include>java.net.MalformedURLException</xsp:include>
  28.    <xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
  29.    <xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
  30.    <xsp:include>org.apache.cocoon.components.search.*</xsp:include>
  31.    <xsp:include>org.apache.lucene.store.Directory</xsp:include>
  32.    <xsp:include>org.apache.lucene.analysis.Analyzer</xsp:include>
  33.   </xsp:structure>
  34.  
  35.   <xsp:logic>
  36.   File workDir = null;
  37.   /** Contextualize this class */
  38.   public void contextualize(Context context) throws ContextException {
  39.     super.contextualize( context );
  40.     workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
  41.   }
  42.   
  43.   LuceneCocoonIndexer lcii;
  44.   Analyzer analyzer = LuceneCocoonHelper.getAnalyzer( "org.apache.lucene.analysis.standard.StandardAnalyzer" );
  45.   
  46.   void createIndex(String baseURL, boolean create) throws ProcessingException {
  47.     try {
  48.       
  49.       lcii = (LuceneCocoonIndexer)this.manager.lookup( LuceneCocoonIndexer.ROLE );
  50.       Directory directory = LuceneCocoonHelper.getDirectory( new File( workDir, "index" ), create );
  51.       lcii.setAnalyzer( analyzer );
  52.       URL base_url = new URL( baseURL );
  53.       lcii.index( directory, create, base_url );
  54.     } catch (MalformedURLException mue) {
  55.       throw new ProcessingException( "MalformedURLException in createIndex()!", mue );
  56.     } catch (IOException ioe) {
  57.       // ignore ??
  58.       throw new ProcessingException( "IOException in createIndex()!", ioe );
  59.     } catch (ComponentException ce) {
  60.       // ignore ??
  61.       throw new ProcessingException( "ComponentException in createIndex()!", ce );
  62.     } finally {
  63.       if (lcii != null) {
  64.         this.manager.release( lcii );
  65.       }
  66.       lcii = null;
  67.     }
  68.   }
  69.  
  70.   </xsp:logic>
  71.  
  72.   <page>
  73.     <xsp:logic>
  74.       boolean create;
  75.       String createParam = <xsp-request:get-parameter name="create" />;
  76.       if (createParam == null) {
  77.         create = false;
  78.       } else {
  79.         create = true;
  80.       }
  81.       
  82.       String baseURL = <xsp-request:get-parameter name="baseURL" />;
  83.       if (baseURL != null && baseURL.length() > 0) {
  84.         createIndex(baseURL, create );
  85.       }
  86.       if (baseURL == null || baseURL.length() < 1) {
  87.         baseURL = 
  88.           "http://" + 
  89.           <xsp-request:get-server-name/> +
  90.           ":" + <xsp-request:get-server-port/> +
  91.           <xsp-request:get-context-path/> + "/" + "docs/index.html";
  92.       }
  93.     </xsp:logic>
  94.     <content>
  95.       <h1>Create a Lucene search index</h1>
  96.       <para>
  97.         <font size="-1">
  98.           <a href="welcome">Welcome</a>
  99.         </font>
  100.       </para>
  101.       <para>
  102.         This process might take some time (follow the tail of your logfiles
  103.         to see the indexer in progress).
  104.         <ul>
  105.           <li>LuceneCocoonIndexer.ROLE <xsp:expr>LuceneCocoonIndexer.ROLE</xsp:expr>
  106.           </li>
  107.           <li>context-path <xsp-request:get-context-path/>
  108.           </li>
  109.           <li>baseURL <xsp:expr>baseURL</xsp:expr>
  110.           </li>
  111.           <li>create <xsp:expr>String.valueOf(createParam)</xsp:expr>,
  112.             <xsp:expr>String.valueOf( create )</xsp:expr>
  113.           </li>
  114.           <li>get-uri <xsp-request:get-uri/>
  115.           </li>
  116.           <li>get-sitemap-uri <xsp-request:get-sitemap-uri/>
  117.           </li>
  118.         </ul>
  119.  
  120.         <form action="create">
  121.         <table>
  122.           <tr>
  123.             <td>BaseURL</td>
  124.             <td>
  125.               <input type="text" name="baseURL" size="60">
  126.                 <xsp:attribute name="value"><xsp:expr>baseURL</xsp:expr></xsp:attribute>
  127.               </input>
  128.             </td>
  129.           </tr>
  130.           <tr>
  131.             <td colspan="2">
  132.               <input type="radio" name="create" value="true" checked="checked"/>
  133.               Create/Overwrite the Index, or
  134.               <input type="radio" name="create" value="false"/>
  135.               Update the existing Index
  136.             </td>
  137.           </tr>
  138.           <tr>
  139.             <td colspan="2">
  140.               <input type="submit" name="find" value="Create"/>
  141.             </td>
  142.           </tr>
  143.         </table>
  144.         </form>
  145.  
  146.       </para>
  147.     </content>
  148.   </page>
  149.  
  150. </xsp:page>
  151.  
  152.