You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Zamek <za...@vili.pmmf.hu> on 2004/03/04 14:32:31 UTC
xsp upload nightmare
Hello All,
I try to use upload with xsp.
Sample is working well, and I try to move uploaded file to my path.
here is my xsp (based upload.xsp):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- CVS $Id: upload.xsp,v 1.1 2003/09/07 06:09:10 vgritsenko Exp $ -->
<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:include>java.io.File</xsp:include>
<xsp:include>org.apache.cocoon.environment.*</xsp:include>
<xsp:include>org.apache.cocoon.components.request.multipart.*</xsp:include>
</xsp:structure>
<xsp:logic>
version 1.
String filename=request.getParameter("upload-file");
here I am get an error: java.lang.NullPointerException
It is ok, because there is no upload-file parameter, but I have to handle
empty parameters.
and then I try to test it:
version 2.
if (request.getParameter("upload-file") != null) {
String filename=request.getParameter("upload-file");
}
Once more error:
// end error String filename=request.getParameter("upload-file"); } File
uploadDir = null; ... Line 76, column 0: Syntax error on keyword "if";
"boolean", "void", "byte", "short", "int", "long", "char", "float",
"double", "Identifier", "interface", "class" expected
I don't know what is it, but another try:
version 3.
String filename=<xsp:request-parameter name="upload-file"/>;
and another error:
. Line 77, column 0: Syntax error on token ";", "{", "+", "-", "--", "++",
"boolean", "void", "byte", "short", "int", "long", "char", "float",
"double", "(", "true", "false", "IntegerLiteral", "LongLiteral",
"FloatingPointLiteral", "DoubleLiteral", "CharacterLiteral",
"StringLiteral", "null", "~", "!", "super", "this", "new", "Identifier"
expected
File uploadDir = null;
/** Contextualize this class */
public void contextualize(Context context) throws ContextException {
uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
}
</xsp:logic>
So can anybody send me a working xsp which is move uploaded file to any
path?
--
thx,
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
SV: xsp upload nightmare
Posted by Askild Aaberg Olsen <as...@xangeli.com>.
http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=106918964613219&w=2
You should probably rewrite it to an XSPAction when you get this thing
working, or follow the examples in the wiki (flow or (java)-action).
That is much more in coherence with the Cocoon concept, but the linked xsp
is working in 2.1.3 og 2.1.4 at least.
Hope this is helpfull! I've been there, so I know your pain ;-)
Askild
-
Zamek wrote:
> So can anybody send me a working xsp which is move uploaded
> file to any
> path?
>
> --
> thx,
> Zoltan Zidarics programmer
> PTE University Pecs, Hungary
> icq: 43288694
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: xsp upload nightmare
Posted by "Z.Z." <za...@vili.pmmf.hu>.
Hello,
gounis@osmosis.gr wrote:
>
> can i add your modification in a new wiki page ?
yes absolutely
> can you describe what else is this code make ?
I need to pass cocoon:/ to upload action. I am using cocoon on Linux, and my
app is in my home directory.
So link is: http://server:8080/cocoon/~user/app/
Originally upload action cannot handle this directory entry, because
relative reference is relative to cocoon_install directory, and absolute
reference is "not known" only ~user is signing users's home.
It need to pass cocoon:/ to upload action, which is getting by
Source inputSource = resolver.resolveURI("");
String sysId = inputSource.getURI();
from org.apache.excalibur.source.Source.
I attached source of Upload.java to this letter.
--
thx,
----------------------------------------------------
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694
Re: xsp upload nightmare
Posted by go...@osmosis.gr.
hi marcius
can i add your modification in a new wiki page ?
can you describe what else is this code make ?
--stavros
On Sat, 6 Mar 2004, Z.Z. wrote:
> Hello All,
> 2004. mαrcius 4. 14.47 dαtummal gounis@osmosis.gr ezt νrta:
> > take a look here
> >
> > http://wiki.cocoondev.org/Wiki.jsp?page=RecipeUploadUsingAction
> >
> > it working
>
> Thanks a lot, it working really.
>
> I use it in Linux and my context is my home directory, link is:
> server/cocoon/~zamek/app/
>
> I cannot pass it to Fileupload. I think I try to pass cocoon:/ but it doesn
> ΄t works.
>
> I modified your code to accept cocoon:/ protocoll:
>
> declarations section:
>
> /* cocoon:/ */
> private static final String COCOON_ENTRY = "cocoon:/";
> private final static String FILE_ENTRY = "file:";
>
> and act method:
>
> originally:
> if (req instanceof HttpRequest) {
>
> HttpRequest request = (HttpRequest) req;
>
> /* create necessary directory structure */
> File uplDir = new File(parUploadDirectory);
> if (isDebugEnabled) {
> myLogger.debug(
> "upload directory is: " + uplDir.getAbsolutePath());
> }
>
> if (uplDir.isAbsolute() == false) {
> // check for first relative slash
> if (parUploadDirectory.indexOf('/') != 0) {
> parUploadDirectory = "/" + parUploadDirectory;
> }
>
> uplDir = new File(context.getRealPath(parUploadDirectory));
> }
>
> if (isDebugEnabled) {
> myLogger.debug(
> "absolute upload directory is: "
> + uplDir.getAbsolutePath());
> }
>
> modified:
> if (req instanceof HttpRequest) {
>
> HttpRequest request = (HttpRequest) req;
>
> /* create necessary directory structure */
> File uplDir = new File(parUploadDirectory);
> if (isDebugEnabled) {
> myLogger.debug(
> "upload directory is: " + uplDir.getAbsolutePath());
> }
>
> if (parUploadDirectory.startsWith(COCOON_ENTRY) ) {
> parUploadDirectory =
> parUploadDirectory.substring(COCOON_ENTRY.length());
> Source inputSource = resolver.resolveURI("");
> String sysId = inputSource.getURI();
> sysId = sysId.substring(new String(FILE_ENTRY).length());
> uplDir = new File (sysId+parUploadDirectory);
> }
> else {
>
> if (uplDir.isAbsolute() == false) {
> // check for first relative slash
> if (parUploadDirectory.indexOf('/') != 0) {
> parUploadDirectory = "/" + parUploadDirectory;
> }
>
> uplDir = new File(context.getRealPath(parUploadDirectory));
> }
> }
>
> if (isDebugEnabled) {
> myLogger.debug(
> "absolute upload directory is: "
> + uplDir.getAbsolutePath());
> }
>
>
> and need to import
> import org.apache.excalibur.source.Source;
>
> in sitemap you can use:
>
> <map:match pattern="upload-*">
> <map:act type="file-upload-action">
> <map:parameter name="number-of-files" value="1"/>
> <map:parameter name="file-form-field-prefix"
> value="upload-file"/>
> <map:parameter name="upload-directory"
> value="cocoon:/{request-param:upload-dir}"/>
> <map:parameter name="overwrite-file" value="rename"/>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: xsp upload nightmare
Posted by "Z.Z." <za...@vili.pmmf.hu>.
Hello All,
2004. március 4. 14.47 dátummal gounis@osmosis.gr ezt írta:
> take a look here
>
> http://wiki.cocoondev.org/Wiki.jsp?page=RecipeUploadUsingAction
>
> it working
Thanks a lot, it working really.
I use it in Linux and my context is my home directory, link is:
server/cocoon/~zamek/app/
I cannot pass it to Fileupload. I think I try to pass cocoon:/ but it doesn
´t works.
I modified your code to accept cocoon:/ protocoll:
declarations section:
/* cocoon:/ */
private static final String COCOON_ENTRY = "cocoon:/";
private final static String FILE_ENTRY = "file:";
and act method:
originally:
if (req instanceof HttpRequest) {
HttpRequest request = (HttpRequest) req;
/* create necessary directory structure */
File uplDir = new File(parUploadDirectory);
if (isDebugEnabled) {
myLogger.debug(
"upload directory is: " + uplDir.getAbsolutePath());
}
if (uplDir.isAbsolute() == false) {
// check for first relative slash
if (parUploadDirectory.indexOf('/') != 0) {
parUploadDirectory = "/" + parUploadDirectory;
}
uplDir = new File(context.getRealPath(parUploadDirectory));
}
if (isDebugEnabled) {
myLogger.debug(
"absolute upload directory is: "
+ uplDir.getAbsolutePath());
}
modified:
if (req instanceof HttpRequest) {
HttpRequest request = (HttpRequest) req;
/* create necessary directory structure */
File uplDir = new File(parUploadDirectory);
if (isDebugEnabled) {
myLogger.debug(
"upload directory is: " + uplDir.getAbsolutePath());
}
if (parUploadDirectory.startsWith(COCOON_ENTRY) ) {
parUploadDirectory =
parUploadDirectory.substring(COCOON_ENTRY.length());
Source inputSource = resolver.resolveURI("");
String sysId = inputSource.getURI();
sysId = sysId.substring(new String(FILE_ENTRY).length());
uplDir = new File (sysId+parUploadDirectory);
}
else {
if (uplDir.isAbsolute() == false) {
// check for first relative slash
if (parUploadDirectory.indexOf('/') != 0) {
parUploadDirectory = "/" + parUploadDirectory;
}
uplDir = new File(context.getRealPath(parUploadDirectory));
}
}
if (isDebugEnabled) {
myLogger.debug(
"absolute upload directory is: "
+ uplDir.getAbsolutePath());
}
and need to import
import org.apache.excalibur.source.Source;
in sitemap you can use:
<map:match pattern="upload-*">
<map:act type="file-upload-action">
<map:parameter name="number-of-files" value="1"/>
<map:parameter name="file-form-field-prefix"
value="upload-file"/>
<map:parameter name="upload-directory"
value="cocoon:/{request-param:upload-dir}"/>
<map:parameter name="overwrite-file" value="rename"/>
--
thx,
----------------------------------------------------
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: xsp upload nightmare
Posted by go...@osmosis.gr.
take a look here
http://wiki.cocoondev.org/Wiki.jsp?page=RecipeUploadUsingAction
it working
On Thu, 4 Mar 2004, Zamek wrote:
> Hello All,
>
> I try to use upload with xsp.
> Sample is working well, and I try to move uploaded file to my path.
>
> here is my xsp (based upload.xsp):
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <!-- CVS $Id: upload.xsp,v 1.1 2003/09/07 06:09:10 vgritsenko Exp $ -->
>
> <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:include>java.io.File</xsp:include>
> <xsp:include>org.apache.cocoon.environment.*</xsp:include>
> <xsp:include>org.apache.cocoon.components.request.multipart.*</xsp:include>
> </xsp:structure>
>
> <xsp:logic>
> version 1.
> String filename=request.getParameter("upload-file");
>
> here I am get an error: java.lang.NullPointerException
> It is ok, because there is no upload-file parameter, but I have to handle
> empty parameters.
>
> and then I try to test it:
>
> version 2.
> if (request.getParameter("upload-file") != null) {
> String filename=request.getParameter("upload-file");
> }
>
> Once more error:
> // end error String filename=request.getParameter("upload-file"); } File
> uploadDir = null; ... Line 76, column 0: Syntax error on keyword "if";
> "boolean", "void", "byte", "short", "int", "long", "char", "float",
> "double", "Identifier", "interface", "class" expected
> I don't know what is it, but another try:
>
> version 3.
> String filename=<xsp:request-parameter name="upload-file"/>;
>
> and another error:
> . Line 77, column 0: Syntax error on token ";", "{", "+", "-", "--", "++",
> "boolean", "void", "byte", "short", "int", "long", "char", "float",
> "double", "(", "true", "false", "IntegerLiteral", "LongLiteral",
> "FloatingPointLiteral", "DoubleLiteral", "CharacterLiteral",
> "StringLiteral", "null", "~", "!", "super", "this", "new", "Identifier"
> expected
>
>
> File uploadDir = null;
> /** Contextualize this class */
> public void contextualize(Context context) throws ContextException {
> uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
> }
> </xsp:logic>
>
>
> So can anybody send me a working xsp which is move uploaded file to any
> path?
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org