Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 49648 invoked from network); 20 Apr 2007 13:15:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Apr 2007 13:15:57 -0000 Received: (qmail 64741 invoked by uid 500); 20 Apr 2007 13:16:03 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 64723 invoked by uid 500); 20 Apr 2007 13:16:03 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 64714 invoked by uid 99); 20 Apr 2007 13:16:02 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Apr 2007 06:16:02 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of stefan.guggisberg@gmail.com designates 66.249.92.168 as permitted sender) Received: from [66.249.92.168] (HELO ug-out-1314.google.com) (66.249.92.168) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Apr 2007 06:15:55 -0700 Received: by ug-out-1314.google.com with SMTP id p31so774935ugc for ; Fri, 20 Apr 2007 06:15:34 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=jaVnmm4EYZgPnJwE1x1aK7H1itIQ8GVOU+GGXPBaDlkXLpJtL5wYKLHja/ToePrRifdsnb2adAApecPi4mvMWV/9uNO3WLV45Po0i9p7zBYbMR27o8ggKe9XTppicceHiezCjXvRBkzK/QZenF91o3UOF/2Ep1v93VhgCnivWSA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=bDkXQV1ygOtvenswHwvJ6ql/t87UV/G67zHkHEEw7Uc+P5ooMUPwe0HpFIIf2E8u0dVIk/TXeAUd5nwyD+jrauMkOV8fY2i+KkG1NLfkD4ZNs4dj2shBD+2w7uE4O+ZWxq9UR2TVdyUmeoP3qh9F5lpW/uCf+/H2Z57qIlIN+xo= Received: by 10.82.108.9 with SMTP id g9mr4614759buc.1177074933992; Fri, 20 Apr 2007 06:15:33 -0700 (PDT) Received: by 10.82.153.6 with HTTP; Fri, 20 Apr 2007 06:15:33 -0700 (PDT) Message-ID: <90a8d1c00704200615w2537e4xc8266089cc951a1c@mail.gmail.com> Date: Fri, 20 Apr 2007 15:15:33 +0200 From: "Stefan Guggisberg" To: users@jackrabbit.apache.org Subject: Re: import end export file from repository problem In-Reply-To: <10094070.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <10094070.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org hi michal, the problem is that you're retrieving the binary contents of your file as a String, i.e. > String data = resNode.getProperty("jcr:data").getValue().getString(); > long lastModified = > resNode.getProperty("jcr:lastModified").getValue().getLong(); > > file = new > File(tempDir.getPath()+System.getProperty("file.separator")+name); > file.setLastModified(lastModified); > > FileWriter writer = new FileWriter(file); > writer.write(data, 0, data.length()-1); > writer.close(); try something like this instead: InputStream in = resNode.getProperty("jcr:data").getStream(); // spool stream to temp file FileOutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int read = 0; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); } } finally { out.close(); in.close(); } cheers stefan On 4/20/07, Michal Hybler wrote: > > I have problem with files stored in repository. > > In first phase I import file into repository. > > --------------------import------------------------------------- > Node childNode = null; > Node parentNode = getNodeById(pol.getId()); > try { > String name = file.getName(); > > childNode = parentNode.addNode(name,"nt:unstructured"); > childNode.setProperty("owner", getUserName()); > childNode.addMixin("mix:referenceable"); > MimeTable mt = MimeTable.getDefaultTable(); > String mimeType = mt.getContentTypeFor(file.getName()); > > if (mimeType == null || mimeType.equals("application/xml")) { > if (mimeType == null) { > mimeType = "null"; > } > if(name.endsWith(".doc")){ > mimeType = "application/msword"; > } > if(name.endsWith(".xls")){ > mimeType = "application/vnd.ms-excel"; > } > if(name.endsWith(".ppt")){ > mimeType = "application/vnd.ms-powerpoint"; > } > if (mimeType.equals("application/xml")) { > mimeType = "text/xml"; > } > if(mimeType.equals("null")){ > int lenght = name.length(); > mimeType = name.substring(lenght-3, lenght); > } > } > > //create the mandatory child node - jcr:content > Node resNode = childNode.addNode ("jcr:content", "nt:resource"); > > resNode.setProperty ("jcr:mimeType", mimeType); > > resNode.setProperty ("jcr:encoding", ""); > > resNode.setProperty ("jcr:data", new FileInputStream (file)); > > Calendar lastModified = Calendar.getInstance (); > lastModified.setTimeInMillis (file.lastModified ()); > resNode.setProperty ("jcr:lastModified", lastModified); > > > saveSession(); > ---------------------------end import > ----------------------------------------------- > > afther that I would like to open this file by Runtime.getRuntime().exec > > I get this file like this > ---------------------------------------export----------------------------------- > File tempDir = File.createTempFile("CMS temp", "", null); > > if (tempDir.delete()) { > if (tempDir.mkdir()) { > > tempDir.deleteOnExit(); > > //Long start = System.currentTimeMillis(); > File file = null; > Node node = getNodeById(id); //my own method session.getNodeById(id) > if (node == null) { > return null; > } > //Long end = System.currentTimeMillis(); > Node resNode = getResNode(node);//my own like Node.getNode(jcr:content) > if (hasProperty(resNode, "jcr:data")) { > try { > String name = getName(node); > String data = resNode.getProperty("jcr:data").getValue().getString(); > long lastModified = > resNode.getProperty("jcr:lastModified").getValue().getLong(); > > file = new > File(tempDir.getPath()+System.getProperty("file.separator")+name); > file.setLastModified(lastModified); > > FileWriter writer = new FileWriter(file); > writer.write(data, 0, data.length()-1); > writer.close(); > file.deleteOnExit(); > > } catch (ValueFormatException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (PathNotFoundException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (RepositoryException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > > return file; > afther that i call > > File file = cmsBI.getFile(pol.getId()); //the method for export - above > Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL > \""+file.getAbsolutePath()+"\""); > > word even the excel from microsoft ofiice pack shows message like file is > damaged or bad format > where is the problem, someone can help me? > Thanks for your ideas > Michal > > -- > View this message in context: http://www.nabble.com/import-end-export-file-from-repository-problem-tf3612072.html#a10094070 > Sent from the Jackrabbit - Users mailing list archive at Nabble.com. > >