blob: dae69ade1148f239c7ee9d2d1f9c6c35986c39f5 [file] [log] [blame]
<?xml version="1.0"?>
<!--
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.
-->
<!-- CVS $Id$ -->
<xsp:page language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"
xmlns:xsp-response="http://apache.org/xsp/response/2.0"
xmlns:log="http://apache.org/xsp/log/2.0">
<xsp:structure>
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
</xsp:structure>
<xsp:logic>
File uploadDir = null;
/** Contextualize this class */
public void contextualize(Context context) throws ContextException {
uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
}
</xsp:logic>
<page>
<title>This form allows you upload files</title>
<content>
<para>Uploads in cocoon are handled automatically, as configured in web.xml.
The relevant init-params controlling upload behavior are: enable-uploads,
upload-directory, autosave-uploads, overwrite-uploads, upload-max-size.
</para>
<para>All files are cleaned out of the upload directory at the end of the
request. The assumption is that other application logic will have acted on
the files during the request.</para>
<para>
<form method="post" enctype="multipart/form-data" action="upload">
File: <input type="file" name="uploaded_file" size="50" />
<p>
<input type="submit" value="Upload File" />
</p>
</form>
</para>
<para>
<xsp:logic>
if (<xsp-request:get-parameter name="uploaded_file"/> != null) {
<xsp:content>
Parameter uploaded_file:
<strong>
<xsp-request:get-parameter name="uploaded_file"/>
</strong>
<br/>
Parameter uploaded_file is instance of:
<!-- note usage of get() instead of getParameter() -->
<strong>
<xsp:expr>
request.get("uploaded_file").getClass()
</xsp:expr>
</strong>
<br/>
</xsp:content>
} else if (request.getContentType()!=null &amp;&amp; request.getContentType().indexOf("multipart/form-data") != -1) {
<para><strong>Either uploads are turned off, or you submitted a blank form.</strong></para>
<para>To enable uploads, ensure that the value for the init-param "enable-uploads" in web.xml is set to true.</para>
}
</xsp:logic>
Upload directory content:
<ul>
<xsp:logic>
getLogger().debug("Dir=" + uploadDir);
String[] filelist = uploadDir.list();
<![CDATA[
getLogger().debug("List=" + filelist.length);
for (int i = 0; i < filelist.length; i++) {
getLogger().debug("File [" + i + "]=" + filelist[i]);
]]>
<li>
<xsp:expr>filelist[i]</xsp:expr>
</li>
<![CDATA[
}
]]>
</xsp:logic>
</ul>
</para>
<para>Brought to you by Cocoon at <xsp:expr>new Date()</xsp:expr>.</para>
</content>
</page>
</xsp:page>