Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 43275D9EB for ; Tue, 28 May 2013 10:12:59 +0000 (UTC) Received: (qmail 89313 invoked by uid 500); 28 May 2013 10:12:58 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 89238 invoked by uid 500); 28 May 2013 10:12:57 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 89194 invoked by uid 99); 28 May 2013 10:12:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 10:12:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 10:12:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0BDC52388C29 for ; Tue, 28 May 2013 10:12:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r863437 [6/12] - in /websites/staging/chemistry/trunk/content: ./ java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/ java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/css/ java/0.9.0/maven/chemistry... Date: Tue, 28 May 2013 10:12:01 -0000 To: commits@chemistry.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130528101204.0BDC52388C29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/FileCopier.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/FileCopier.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/FileCopier.html Tue May 28 10:11:59 2013 @@ -0,0 +1,257 @@ + + + + +FileCopier xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.tools.filecopy;
+20  
+21  import java.io.File;
+22  import java.io.FileInputStream;
+23  import java.io.IOException;
+24  import java.util.HashMap;
+25  import java.util.Map;
+26  
+27  import org.apache.chemistry.opencmis.client.api.Document;
+28  import org.apache.chemistry.opencmis.client.api.Folder;
+29  import org.apache.chemistry.opencmis.client.api.Session;
+30  import org.apache.chemistry.opencmis.client.api.SessionFactory;
+31  import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
+32  import org.apache.chemistry.opencmis.commons.PropertyIds;
+33  import org.apache.chemistry.opencmis.commons.data.ContentStream;
+34  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+35  import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+36  import org.apache.chemistry.opencmis.tools.mapper.Configurator;
+37  import org.apache.chemistry.opencmis.tools.mapper.MapperException;
+38  import org.apache.chemistry.opencmis.tools.mapper.PropertyMapper;
+39  import org.apache.chemistry.opencmis.tools.parser.MetadataParser;
+40  import org.apache.chemistry.opencmis.tools.parser.MetadataParserTika;
+41  import org.apache.tika.Tika;
+42  import org.slf4j.Logger;
+43  import org.slf4j.LoggerFactory;
+44      
+45  public class FileCopier {
+46      
+47      private static final Logger LOG = LoggerFactory.getLogger(FileCopier.class.getName());
+48      // initialize configurator to get parsers and property mappings
+49      private static final Configurator CFG = Configurator.getInstance(); 
+50      private static int TOTAL_NUM = 0;
+51      
+52      private Session session;
+53      
+54      public FileCopier() {
+55      }
+56      
+57      public void connect(Map<String, String> parameters) {
+58          System.out.println("Connecting to a repository ...");
+59  
+60          // Create a SessionFactory and set up the SessionParameter map
+61          SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
+62  
+63          session = sessionFactory.createSession(parameters);
+64  
+65          LOG.debug("Got a connection to repository.");
+66      }
+67          
+68      public void copyRecursive(String folderName, String folderId) {
+69  
+70          try {
+71              File fileOrDir = new File(folderName);
+72              if (fileOrDir.isDirectory()) {
+73                  String newFolderId = createFolderInRepository(fileOrDir.getAbsolutePath(), folderId);
+74                  File[] children = fileOrDir.listFiles();
+75                  for (File file: children) {
+76                      if (!file.getName().equals(".") && !file.getName().equals("..")) {
+77                          copyRecursive(file.getAbsolutePath(), newFolderId);
+78                      }
+79                  }
+80              } else {
+81                  copyFileToRepository(fileOrDir.getAbsolutePath(), folderId);
+82              }            
+83          } catch (Exception e) {
+84              LOG.error(e.toString(), e);
+85          } finally {  
+86          }
+87      }
+88      
+89      private String copyFileToRepository(String fileName, String folderId) {
+90          LOG.debug("uploading file " + fileName);
+91          FileInputStream is = null;
+92          Map<String, Object> properties = new HashMap<String, Object>();
+93          Folder parentFolder;
+94          String id = null;
+95          
+96          if (null == folderId)
+97              parentFolder = session.getRootFolder();
+98          else
+99              parentFolder = (Folder) session.getObject(folderId);
+100         
+101         try {
+102             File f = new File(fileName);
+103             Tika tika = new Tika();     
+104             String mimeType = tika.detect(f);
+105             LOG.info("Detected MIME type: "+ mimeType);
+106             
+107             // extract metadata: first get a parser
+108             MetadataParser parser = CFG.getParser(mimeType);
+109             if (null == parser) {
+110                 properties.put(PropertyIds.NAME, f.getName().replaceAll(" ", "_"));
+111                 properties.put(PropertyIds.OBJECT_TYPE_ID, CFG.getDefaultDocumentType());
+112             } else {
+113                 parser.reset();
+114                 PropertyMapper mapper = CFG.getPropertyMapper(mimeType);
+115                 if (null == mapper)
+116                     throw new MapperException("Unknown mime type (no configuration): " + mimeType);
+117                 String typeId = mapper.getMappedTypeId();
+118                 if (null == typeId)
+119                     throw new MapperException("No CMIS type configured for mime type" + mimeType);
+120                 TypeDefinition td = session.getTypeDefinition(typeId);
+121                 if (null == td)
+122                     throw new MapperException("CMIS type " + typeId + " does not exist on server.");
+123 
+124                 LOG.info("Detected MIME type: "+ mimeType + " is mapped to CMIS type id: " + td.getId());
+125                 parser.extractMetadata(f, td, session);
+126                 properties = parser.getCmisProperties();
+127             }
+128                         
+129             // check if there is an overridden content type configured
+130             int posLastDot = f.getName().indexOf('.');
+131             String ext = posLastDot < 0 ? null : f.getName().substring(posLastDot+1, f.getName().length());
+132             String overridden = null;
+133             if (null != ext && (overridden = CFG.getContentType(ext)) != null)
+134                 mimeType = overridden;
+135             long length = f.length();
+136             
+137             is = new FileInputStream(fileName);
+138 
+139             ContentStream contentStream = session.getObjectFactory().createContentStream(fileName,
+140                     length, mimeType, is);
+141             if (!properties.containsKey(PropertyIds.NAME))
+142                 properties.put(PropertyIds.NAME, f.getName().replaceAll(" ", "_"));
+143             LOG.debug("uploading document with content lenth: " + contentStream.getLength());
+144             Document doc = parentFolder.createDocument(properties, contentStream, VersioningState.NONE);
+145             is.close();
+146             
+147             id = doc.getId();
+148             LOG.info("New document created with id: " + id + ", name: " +  properties.get(PropertyIds.NAME) + " in folder: " + parentFolder.getId());
+149             LOG.debug("total number of creations : " + ++TOTAL_NUM);
+150         } catch (Exception e) {
+151             LOG.error("Failed to create CMIS document.", e);
+152         } finally {
+153             if (null != is) {
+154                 try {
+155                     is.close();
+156                 } catch (IOException e) {
+157                     LOG.error(e.toString(), e);
+158                 }
+159             }
+160             LOG.debug("Conversion and transfer done.");    
+161         }
+162         return id;
+163     }
+164     
+165     private  String createFolderInRepository(String fileName, String parentFolderId) {
+166         Folder parentFolder;
+167         String id = null;
+168         if (null == parentFolderId)
+169             parentFolder = session.getRootFolder();
+170         else
+171             parentFolder = (Folder) session.getObject(parentFolderId);
+172         Map<String, Object> properties = new HashMap<String, Object>();
+173         File f = new File(fileName);
+174         properties.put(PropertyIds.NAME, f.getName().replaceAll(" ", "_"));
+175         properties.put(PropertyIds.OBJECT_TYPE_ID, CFG.getDefaultFolderType());
+176         try {
+177             Folder folder = parentFolder.createFolder(properties);
+178             id = folder.getId();
+179             LOG.debug("New folder created with id: " + folder.getId() + ", path: " + folder.getPaths().get(0));
+180         } catch (Exception e) {
+181             LOG.error("Failed to create CMIS document.", e);
+182         } finally {
+183         }
+184         LOG.info("New folder created with id: " + id + ", name: " +  properties.get(PropertyIds.NAME) + " in parent folder: " + parentFolder.getId());
+185         return id;
+186     }
+187     
+188     public void listMetadata(String fileName) {
+189         try {
+190             File f = new File(fileName);
+191             Tika tika = new Tika();     
+192             String mimeType = tika.detect(f);
+193             LOG.info("Detected MIME type: "+ mimeType);
+194             
+195             // extract metadata: first get a parser
+196             MetadataParser parser = CFG.getParser(mimeType);
+197             if (null == parser) {
+198                 LOG.warn("Unknown content type " + mimeType + " no metadata found, listing all tags found in file.");
+199                 MetadataParserTika mpt = new MetadataParserTika();
+200                 mpt.listMetadata(f);
+201             } else {
+202                 PropertyMapper mapper = CFG.getPropertyMapper(mimeType);
+203                 if (null == mapper)
+204                     throw new MapperException("Unknown mime type (no configuration): " + mimeType);
+205                 String typeId = mapper.getMappedTypeId();
+206                 if (null == typeId)
+207                     throw new MapperException("No CMIS type configured for mime type" + mimeType);
+208                 
+209                 // Session available? if yes do conversion
+210                 TypeDefinition td = null;
+211                 if (null!= session) {
+212                     td = session.getTypeDefinition(typeId);
+213                     if (null == td)
+214                         throw new MapperException("CMIS type " + typeId + " does not exist on server.");
+215                     else
+216                     	LOG.info("Detected MIME type: "+ mimeType + " is mapped to CMIS type id: " + td.getId());
+217                 }
+218                 
+219                 parser.extractMetadata(f, td, session);
+220                 Map<String, Object> properties = parser.getCmisProperties();
+221                 for (String key : properties.keySet()) {
+222                     LOG.info("Found metadata tag " + key + "mapped to " + properties.get(key));
+223                 }
+224             }                        
+225         } catch (Exception e) {
+226             LOG.error("Failed to list metadata", e);
+227         } finally {
+228         }
+229         LOG.debug("Conversion and transfer done.");            
+230     }
+231     
+232     static public void main(String[] args) {
+233         String fileName = args[0];
+234         LOG.debug("extracting CMIS properties for file " + fileName);
+235         try {
+236             new FileCopier().listMetadata(fileName);            
+237         } catch (Exception e) {
+238             LOG.error(e.toString(), e);
+239         } finally {
+240         }
+241         LOG.debug("Extraction done.");    
+242     }
+243 }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-frame.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-frame.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-frame.html Tue May 28 10:11:59 2013 @@ -0,0 +1,24 @@ + + + + + + OpenCMIS Tools 0.9.0 Reference Package org.apache.chemistry.opencmis.tools.filecopy + + + + +

+ org.apache.chemistry.opencmis.tools.filecopy +

+ +

Classes

+ + + + + \ No newline at end of file Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-summary.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-summary.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-test/chemistry-opencmis-test-tools/xref/org/apache/chemistry/opencmis/tools/filecopy/package-summary.html Tue May 28 10:11:59 2013 @@ -0,0 +1,67 @@ + + + + + + OpenCMIS Tools 0.9.0 Reference Package org.apache.chemistry.opencmis.tools.filecopy + + + +
+ +
+
+ +
+ +

Package org.apache.chemistry.opencmis.tools.filecopy

+ + + + + + + + + + + + +
Class Summary
+ FileCopier +
+ +
+ +
+
+ +
+
+ Copyright © 2009-2013 The Apache Software Foundation. All Rights Reserved. + + \ No newline at end of file