View Javadoc
1   /*
2    * Prometheus: Application Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.prometheus.sheets;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
21  import io.github.tonywasher.joceanus.prometheus.security.PrometheusSecurityPasswordManager;
22  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetWorkBookType;
23  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadStatusReport;
24  
25  import java.io.File;
26  import java.io.InputStream;
27  import java.io.OutputStream;
28  
29  /**
30   * Spreadsheet control.
31   *
32   * @author Tony Washer
33   */
34  public abstract class PrometheusSpreadSheet {
35      /**
36       * Constructor.
37       */
38      protected PrometheusSpreadSheet() {
39      }
40  
41      /**
42       * Obtain a sheet reader.
43       *
44       * @param pReport      the report
45       * @param pPasswordMgr the password manager
46       * @return the sheet reader
47       */
48      protected abstract PrometheusSheetReader getSheetReader(TethysUIThreadStatusReport pReport,
49                                                              PrometheusSecurityPasswordManager pPasswordMgr);
50  
51      /**
52       * Obtain a sheet writer.
53       *
54       * @param pReport the report
55       * @return the sheet writer
56       */
57      protected abstract PrometheusSheetWriter getSheetWriter(TethysUIThreadStatusReport pReport);
58  
59      /**
60       * Load a Backup Workbook.
61       *
62       * @param pReport      the report
63       * @param pPasswordMgr the password manager
64       * @param pData        the data to load into
65       * @param pFile        the backup file to load from
66       * @throws OceanusException on error
67       */
68      public void loadBackup(final TethysUIThreadStatusReport pReport,
69                             final PrometheusSecurityPasswordManager pPasswordMgr,
70                             final PrometheusDataSet pData,
71                             final File pFile) throws OceanusException {
72          /* Create a sheet reader object */
73          final PrometheusSheetReader myReader = getSheetReader(pReport, pPasswordMgr);
74  
75          /* Load the backup */
76          myReader.loadBackup(pFile, pData);
77      }
78  
79      /**
80       * Load a Backup Workbook.
81       *
82       * @param pReport      the report
83       * @param pPasswordMgr the password manager
84       * @param pData        the data to load into
85       * @param pInStream    the input stream to load from
86       * @param pName        the filename
87       * @throws OceanusException on error
88       */
89      public void loadBackup(final TethysUIThreadStatusReport pReport,
90                             final PrometheusSecurityPasswordManager pPasswordMgr,
91                             final PrometheusDataSet pData,
92                             final InputStream pInStream,
93                             final String pName) throws OceanusException {
94          /* Create a sheet reader object */
95          final PrometheusSheetReader myReader = getSheetReader(pReport, pPasswordMgr);
96  
97          /* Load the backup */
98          myReader.loadBackup(pInStream, pData, pName);
99      }
100 
101     /**
102      * Create a Backup Workbook.
103      *
104      * @param pReport the report
105      * @param pData   Data to write out
106      * @param pFile   the backup file to write to
107      * @param pType   the workBookType
108      * @throws OceanusException on error
109      */
110     public void createBackup(final TethysUIThreadStatusReport pReport,
111                              final PrometheusDataSet pData,
112                              final File pFile,
113                              final PrometheusSheetWorkBookType pType) throws OceanusException {
114         /* Create a sheet writer object */
115         final PrometheusSheetWriter myWriter = getSheetWriter(pReport);
116 
117         /* Create the backup */
118         myWriter.createBackup(pData, pFile, pType);
119     }
120 
121     /**
122      * Create a Backup Workbook.
123      *
124      * @param pReport    the report
125      * @param pData      Data to write out
126      * @param pZipStream the stream to write to
127      * @param pType      the workBookType
128      * @throws OceanusException on error
129      */
130     public void createBackup(final TethysUIThreadStatusReport pReport,
131                              final PrometheusDataSet pData,
132                              final OutputStream pZipStream,
133                              final PrometheusSheetWorkBookType pType) throws OceanusException {
134         /* Create a sheet writer object */
135         final PrometheusSheetWriter myWriter = getSheetWriter(pReport);
136 
137         /* Create the backup */
138         myWriter.createBackup(pData, pZipStream, pType);
139     }
140 }