Bunp... really no OpenCms-Api expert around ? :-)<br><br><div class="gmail_quote">On 18 June 2011 15:21, Yves Glodt <span dir="ltr"><<a href="mailto:yg@mind.lu">yg@mind.lu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Bump :-)<div><div></div><div class="h5"><br><br><div class="gmail_quote">On 16 June 2011 09:48, Yves Glodt <span dir="ltr"><<a href="mailto:yg@mind.lu" target="_blank">yg@mind.lu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hi there,<br><br>I am currently trying to do a interface to a Website where you 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 exception with the only message "Error creating the resource "/thepath/".<br>



<br>Here is the code, maybe someone spots the error :-)<br><br>Best regards,<br>Yves<br><br><br><br><font face="courier new,monospace"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false" %><br>



<%@ page import="java.io.*, java.lang.*, java.util.*, java.text.*" %><br><%@ page import="javax.servlet.*, javax.servlet.http.*" %><br><%@ page import="org.opencms.*, org.opencms.main.*, org.opencms.flex.*, org.opencms.jsp.*, org.opencms.file.*, org.opencms.file.types.*" %><br>



<%@ page import="org.apache.commons.lang.*" %><br><%@ page import="org.apache.commons.fileupload.*, org.apache.commons.fileupload.disk.*, 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 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", CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>



    }<br><br>    if (!cms.existsResource("/images/articles")) {<br>        System.out.println("Creating /images/articles");<br>        cms.createResource("/images/articles", CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>



    }<br><br>    if (!cms.existsResource("/images/articles/"+no_dossier)) {<br>        System.out.println("Creating /images/articles/"+no_dossier);<br>        cms.createResource("/images/articles/"+no_dossier, CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>



    }<br><br>    if (!cms.existsResource("/images/articles/"+no_dossier+"/"+no_article)) {<br>        System.out.println("Creating /images/articles/"+no_dossier+"/"+no_article);<br>



        cms.createResource("/images/articles/"+no_dossier+"/"+no_article, CmsResourceTypeFolder.RESOURCE_TYPE_ID);<br>    }<br><br>    String newResname = cms.getRequestContext().getFileTranslator().translateResource("/images/articles/"+no_dossier+"/"+no_article+"/" + filename);<br>



    int resTypeId = OpenCms.getResourceManager().getDefaultTypeForName(filename).getTypeId();<br>    cms.createResource(newResname, resTypeId, bytes, null);<br><br>    cms.unlockResource("/images/articles/"+no_dossier);<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>%></font><br>
</blockquote></div><br>
</div></div></blockquote></div><br>