View Javadoc

1   package org.kuali.ole;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.commons.io.IOUtils;
5   
6   import java.io.*;
7   import java.net.URISyntaxException;
8   import java.net.URL;
9   
10  /**
11   * Created with IntelliJ IDEA.
12   * User: peris
13   * Date: 10/31/12
14   * Time: 4:57 PM
15   * To change this template use File | Settings | File Templates.
16   */
17  public class ResourceFilesHandler {
18      public static final String OLE_AGREEMENT_MAINTENANCE_DOC_TYPE_XML = "OleAgreementMaintenanceDocType.xml";
19      public static final String OLE_CATALOG_DOC_TYPE_XML = "OleCatalogDocType.xml";
20      public static final String OLE_DELIVER_DOC_TYPE_XML = "OleDeliverDocType.xml";
21      public static final String OLE_LICENSE_REQUEST_DOC_TYPES_XML = "OleLicenseRequestDocTypes.xml";
22      public static final String OLE_PATRON_DOC_TYPE_XML = "OlePatronDocType.xml";
23      public static final String OLE_REFERENCE_DOC_TYPE_XML = "OleReferenceDocType.xml";
24      public static final String OLE_FEE_TYPE_MAINTENANCE_DOC_TYPE_XML = "OleFeeTypeMaintenanceDocType.xml";
25      private String folderPath;
26  
27      public void copyResourcesToTarget() {
28          String tmpDir = System.getProperty("java.io.tmpdir");
29          InputStream oleAgreementMaintDocTypeResourceStream = getClass().getResourceAsStream(OLE_AGREEMENT_MAINTENANCE_DOC_TYPE_XML);
30          InputStream oleCatalogDocTypeResourceStream = getClass().getResourceAsStream(OLE_CATALOG_DOC_TYPE_XML);
31          InputStream oleDeliverDocTypeResourceStream = getClass().getResourceAsStream(OLE_DELIVER_DOC_TYPE_XML);
32          InputStream oleLicenseRequestDocTypesResourceStream = getClass().getResourceAsStream(OLE_LICENSE_REQUEST_DOC_TYPES_XML);
33          InputStream olePatronDocTypeResourceStream = getClass().getResourceAsStream(OLE_PATRON_DOC_TYPE_XML);
34          InputStream oleReferenceDocTypeResourceStream = getClass().getResourceAsStream(OLE_REFERENCE_DOC_TYPE_XML);
35          InputStream oleFeeTypeMaintenanceDocTypeResourceStream = getClass().getResourceAsStream(OLE_FEE_TYPE_MAINTENANCE_DOC_TYPE_XML);
36  
37          File oleAgreementMaintDocTypeXML = new File(tmpDir, OLE_AGREEMENT_MAINTENANCE_DOC_TYPE_XML);
38          File oleCatalogDocTypeXML = new File(tmpDir, OLE_CATALOG_DOC_TYPE_XML);
39          File oleDeliverDocTypeXML = new File(tmpDir, OLE_DELIVER_DOC_TYPE_XML);
40          File oleLicenseRequestDocTypeXML = new File(tmpDir, OLE_LICENSE_REQUEST_DOC_TYPES_XML);
41          File olePatronDocTypeXML = new File(tmpDir, OLE_PATRON_DOC_TYPE_XML);
42          File oleReferenceDocTypeXML = new File(tmpDir, OLE_REFERENCE_DOC_TYPE_XML);
43          File oleFeeTypeMaintenanceDocTypeXML = new File(tmpDir, OLE_FEE_TYPE_MAINTENANCE_DOC_TYPE_XML);
44          File destDir = new File(getFolderPath());
45  
46          try {
47              IOUtils.copy(oleAgreementMaintDocTypeResourceStream, new FileOutputStream(oleAgreementMaintDocTypeXML));
48              FileUtils.copyFileToDirectory(oleAgreementMaintDocTypeXML, destDir);
49              IOUtils.copy(oleCatalogDocTypeResourceStream, new FileOutputStream(oleCatalogDocTypeXML));
50              FileUtils.copyFileToDirectory(oleCatalogDocTypeXML, destDir);
51              IOUtils.copy(oleDeliverDocTypeResourceStream, new FileOutputStream(oleDeliverDocTypeXML));
52              FileUtils.copyFileToDirectory(oleDeliverDocTypeXML, destDir);
53              IOUtils.copy(oleLicenseRequestDocTypesResourceStream, new FileOutputStream(oleLicenseRequestDocTypeXML));
54              FileUtils.copyFileToDirectory(oleLicenseRequestDocTypeXML, destDir);
55              IOUtils.copy(olePatronDocTypeResourceStream, new FileOutputStream(olePatronDocTypeXML));
56              FileUtils.copyFileToDirectory(olePatronDocTypeXML, destDir);
57              IOUtils.copy(oleReferenceDocTypeResourceStream, new FileOutputStream(oleReferenceDocTypeXML));
58              FileUtils.copyFileToDirectory(oleReferenceDocTypeXML, destDir);
59              IOUtils.copy(oleFeeTypeMaintenanceDocTypeResourceStream, new FileOutputStream(oleFeeTypeMaintenanceDocTypeXML));
60              FileUtils.copyFileToDirectory(oleFeeTypeMaintenanceDocTypeXML, destDir);
61  
62          } catch (FileNotFoundException e) {
63              e.printStackTrace();
64          } catch (IOException e) {
65              e.printStackTrace();
66          }
67      }
68  
69      public String getFolderPath() {
70          return folderPath;
71      }
72  
73      public void setFolderPath(String folderPath) {
74          this.folderPath = folderPath;
75      }
76  }