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 / document-files.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  3.4 KB  |  108 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:include>java.util.*</xsp:include>
  34.   </xsp:structure>
  35.  
  36.   <xsp:logic>
  37.   String base = "docs/xdocs" ;
  38.   String baseContext = "context://" + base;
  39.  
  40.   File []allFiles(File base) {
  41.     List allFiles = new ArrayList();
  42.  
  43.     try {
  44.       if (base == null) {
  45.         base = theBaseDir();
  46.       }
  47.       File []allTheFiles = base.listFiles();
  48.  
  49.       for (int i = 0; i < allTheFiles.length; i++ ) {
  50.         File f = allTheFiles[i];
  51.         if (f.isDirectory()) {
  52.           File[] allFilesOfDirectory = allFiles( f );
  53.           allFiles.addAll( Arrays.asList( allFilesOfDirectory ) );
  54.         } else if (f.isFile()) {
  55.           if (f.canRead() && f.getName().endsWith( ".xml" )) {
  56.             allFiles.add( f );
  57.           }
  58.         }
  59.       }
  60.     } catch (Exception e) {
  61.       e.printStackTrace();
  62.     }
  63.     return (File[])allFiles.toArray(new File[0]);
  64.   }
  65.  
  66.   File theBaseDir() {
  67.     File f = null;
  68.     try {
  69.       org.apache.excalibur.source.Source source = resolver.resolveURI( baseContext );
  70.       String s = source.getURI();
  71.       f = new File( new URL(s).getFile() );
  72.     } catch (Exception e) {
  73.       e.printStackTrace();
  74.     }
  75.     return f; 
  76.   }
  77.  
  78.   String strippedFileName( File f ) {
  79.     String sf = f.toString();
  80.     int index = sf.indexOf("xdocs");
  81.     if (index >= 0) {
  82.       sf = sf.substring( index + 5 + 1);
  83.     }
  84.     sf = sf.replace( '\\', '/' );
  85.     return sf;
  86.   }
  87.  
  88.   </xsp:logic>
  89.  
  90.   <files>
  91.     <path><xsp:expr>theBaseDir()</xsp:expr></path>
  92.     <xsp:logic>
  93.       File []allFiles = allFiles(null); 
  94.       for (int i = 0; allFiles != null && i < allFiles.length; i++) {
  95.         File f = allFiles[i];
  96.         if (f.isFile()) {
  97.         <xsp:content>
  98.           <file>
  99.             <path><xsp:expr>strippedFileName(f)</xsp:expr></path>
  100.             <absolutePath><xsp:expr>f.getAbsolutePath()</xsp:expr></absolutePath>
  101.           </file>
  102.         </xsp:content>
  103.         }
  104.       }
  105.     </xsp:logic>
  106.   </files>
  107. </xsp:page>
  108.