<div>Hi, </div><div><br></div><div>I had a similar problem, was a contact form, which should </div><div>create a structured content then submit contact form . </div><div><br></div><div>The problem was the User logoff, and permission/security, because if user´s (a lot user´s) submit, if get logout in moment that a procedure is occurring. </div>
<div><br></div><div>If I do not log out, a visitor could also log User /system/login/, and we would have a major security problem, because access to information not allowed.</div><div><br></div><div>Other problem, maybe, if you give a logout and use your portal Session to something, because logout execute a session.invalidate().</div>
<div><br></div><div>My Object, I did not know this form CmsObject OpenCms.initCmsObject cms = ("Guest"), I make this :</div><div><div>        CmsObject cmsObject = cms.getCmsObject();</div><div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>CmsProject cmsproject = cmsObject.readProject("Offline");</div>
<div><span class="Apple-tab-span" style="white-space: pre; ">   </span>cmsObject.getRequestContext().setCurrentProject(cmsproject);</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>cmsObject.getRequestContext().setSiteRoot("/myproject");</div>
</div></div><div><br></div><div>Regards,</div><div><br></div><div>Deiverson Silveira</div><div><br></div><div>2011/6/22 Michael Emmerich <span dir="ltr"><<a href="mailto:m.emmerich@alkacon.com">m.emmerich@alkacon.com</a>></span></div>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Yves,<br>
<br>
the problem is in the following code:<br>
<br>
[...]<br>
<div class="im">CmsObject cms = OpenCms.initCmsObject("Guest");<br>
cms.loginUser("contentcreator", "thepassword");<br>
</div>[...]<br>
<br>
By doing so, you log in as the user "contentcreator", but you are in the<br>
Online project. And there, you cannot create a resource of course.<br>
<br>
So you must at least add the following lines after this code:<br>
<br>
<br>
<br>
[...]<br>
<div class="im">CmsObject cms = OpenCms.initCmsObject("Guest");<br>
cms.loginUser("contentcreator", "thepassword");<br>
</div>CmsProject project = cms.readProject("Offline");<br>
cms.getRequestContext().setCurrentProject(project);<br>
[...]<br>
<br>
By this, you change to the Offline project. You also might have to<br>
change to the correct site, so you can use the setSiteRoot Method in the<br>
request context.<br>
<br>
It would be a good idea to check what you have in the request context<br>
after you initialized the CmsObect (cms.getRequestContext()) to see how<br>
your current request is initialized.<br>
<br>
<br>
Kind Regards,<br>
Michael.<br>
<br>
Am 21.06.2011 22:57, schrieb Yves Glodt:<br>
<div class="im">> Bunp... really no OpenCms-Api expert around ? :-)<br>
><br>
</div><div class="im">> On 18 June 2011 15:21, Yves Glodt <<a href="mailto:yg@mind.lu">yg@mind.lu</a> <mailto:<a href="mailto:yg@mind.lu">yg@mind.lu</a>>> wrote:<br>
><br>
>     Bump :-)<br>
><br>
><br>
</div>>     On 16 June 2011 09:48, Yves Glodt <<a href="mailto:yg@mind.lu">yg@mind.lu</a> <mailto:<a href="mailto:yg@mind.lu">yg@mind.lu</a>>><br>
<div><div></div><div class="h5">>     wrote:<br>
><br>
>         Hi there,<br>
><br>
>         I am currently trying to do a interface to a Website where you<br>
>         can import files to the VFS with an http post.<br>
><br>
>         Unfortunately it does not work, and I do not find why. I get an<br>
>         exception with the only message "Error creating the resource<br>
>         "/thepath/".<br>
><br>
>         Here is the code, maybe someone spots the error :-)<br>
><br>
>         Best regards,<br>
>         Yves<br>
><br>
><br>
><br>
>         <%@ page language="java" contentType="text/html; charset=UTF-8"<br>
>         pageEncoding="UTF-8" session="false" %><br>
>         <%@ page import="java.io.*, java.lang.*, java.util.*,<br>
>         java.text.*" %><br>
>         <%@ page import="javax.servlet.*, javax.servlet.http.*" %><br>
>         <%@ page import="org.opencms.*, org.opencms.main.*,<br>
>         org.opencms.flex.*, org.opencms.jsp.*, org.opencms.file.*,<br>
>         org.opencms.file.types.*" %><br>
>         <%@ page import="org.apache.commons.lang.*" %><br>
>         <%@ page import="org.apache.commons.fileupload.*,<br>
>         org.apache.commons.fileupload.disk.*,<br>
>         org.apache.commons.fileupload.servlet.*" %><br>
>         <%<br>
><br>
>         FileItemFactory factory = new DiskFileItemFactory();<br>
>         ServletFileUpload upload = new ServletFileUpload(factory);<br>
><br>
>         List<FileItem> items = null;<br>
><br>
>         try {<br>
>              items = upload.parseRequest(request);<br>
>         } catch (FileUploadException e) {<br>
>              out.println("Error parsing request");<br>
>              System.out.println(request.getRemoteAddr()+": Import: Error<br>
>         parsing request.");<br>
>              return;<br>
>         }<br>
><br>
>         Iterator<FileItem> iter = items.iterator();<br>
><br>
>         Integer no_dossier = null;<br>
>         String no_article = null;<br>
>         String filename = null;<br>
>         byte[] bytes = null;<br>
><br>
>         while (iter.hasNext()) {<br>
>              FileItem item = (FileItem) iter.next();<br>
><br>
>              if (item.isFormField()) {<br>
><br>
>                  if (item.getFieldName().equals("no_dossier")) {<br>
>                      no_dossier = Integer.parseInt(item.getString());<br>
>                  }<br>
><br>
>                  if (item.getFieldName().equals("no_article")) {<br>
>                      no_article = item.getString();<br>
>                  }<br>
><br>
>              } else {<br>
>                  filename = item.getName();<br>
>                  bytes = item.get();<br>
>              }<br>
>         }<br>
><br>
>         try {<br>
><br>
>              CmsObject cms = OpenCms.initCmsObject("Guest");<br>
>              cms.loginUser("contentcreator", "thepassword");<br>
><br>
>              if (!cms.existsResource("/images")) {<br>
>                  System.out.println("Creating /images");<br>
>                  cms.createResource("/images",<br>
>         CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>
>              }<br>
><br>
>              if (!cms.existsResource("/images/articles")) {<br>
>                  System.out.println("Creating /images/articles");<br>
>                  cms.createResource("/images/articles",<br>
>         CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>
>              }<br>
><br>
>              if (!cms.existsResource("/images/articles/"+no_dossier)) {<br>
>                  System.out.println("Creating<br>
>         /images/articles/"+no_dossier);<br>
>                  cms.createResource("/images/articles/"+no_dossier,<br>
>         CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>
>              }<br>
><br>
>              if<br>
>         (!cms.existsResource("/images/articles/"+no_dossier+"/"+no_article))<br>
>         {<br>
>                  System.out.println("Creating<br>
>         /images/articles/"+no_dossier+"/"+no_article);<br>
><br>
>         cms.createResource("/images/articles/"+no_dossier+"/"+no_article, CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>
>              }<br>
><br>
>              String newResname =<br>
>         cms.getRequestContext().getFileTranslator().translateResource("/images/articles/"+no_dossier+"/"+no_article+"/"<br>
>         + filename);<br>
>              int resTypeId =<br>
>         OpenCms.getResourceManager().getDefaultTypeForName(filename).getTypeId();<br>
>              cms.createResource(newResname, resTypeId, bytes, null);<br>
><br>
>              cms.unlockResource("/images/articles/"+no_dossier);<br>
><br>
>         cms.unlockResource("/images/articles/"+no_dossier+"/"+no_article);<br>
><br>
>              //cms.publishResource(newResname);<br>
>              //OpenCms.getPublishManager().publishResource(cms, folder);<br>
>              //OpenCms.getPublishManager().waitWhileRunning();<br>
><br>
>         } catch (Exception e) {<br>
>              out.println("Error: "+e.getMessage() );<br>
>         }<br>
><br>
>         %><br>
><br>
><br>
><br>
><br>
><br>
><br>
</div></div><div class="im">> _______________________________________________<br>
> This mail is sent to you from the opencms-dev mailing list<br>
> To change your list options, or to unsubscribe from the list, please visit<br>
> <a href="http://lists.opencms.org/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/mailman/listinfo/opencms-dev</a><br>
<br>
</div>--<br>
Kind Regards,<br>
Michael.<br>
<br>
-------------------<br>
Michael Emmerich<br>
<br>
Alkacon Software GmbH  - The OpenCms Experts<br>
<a href="http://www.alkacon.com" target="_blank">http://www.alkacon.com</a> - <a href="http://www.opencms.org" target="_blank">http://www.opencms.org</a><br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
This mail is sent to you from the opencms-dev mailing list<br>
To change your list options, or to unsubscribe from the list, please visit<br>
<a href="http://lists.opencms.org/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/mailman/listinfo/opencms-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><i><div><span style="font-style:normal"><i><div><span style="font-style:normal"><i><div style="display:inline !important"><span style="font-style:normal"><i><a href="http://www.solutioncms.com" target="_blank">www.solutioncms.com</a></i></span></div>
</i></span></div><div><span style="font-style:normal"><i><span style="font-style:normal"><i><div><span style="font-style:normal"><i><div style="display:inline !important"><span style="font-style:normal"><i><span style="font-style:normal"><i><div style="display:inline !important">
<i>The Brazilian </i><span style="font-style:normal"><i><div style="display:inline !important"><span style="font-style:normal"><i><span style="font-style:normal"><i><div style="display:inline !important"><i>Official Provider OpenCms</i></div>
</i></span></i></span></div></i></span></div></i></span></i></span></div></i></span></div></i></span></i></span></div></i></span></div></i><br>