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 * The Data file name.
37 */
38 public static final String FILE_NAME = "zipData";
39
40 /**
41 * Constructor.
42 */
43 protected PrometheusSpreadSheet() {
44 }
45
46 /**
47 * Obtain a sheet reader.
48 *
49 * @param pReport the report
50 * @param pPasswordMgr the password manager
51 * @return the sheet reader
52 */
53 protected abstract PrometheusSheetReader getSheetReader(TethysUIThreadStatusReport pReport,
54 PrometheusSecurityPasswordManager pPasswordMgr);
55
56 /**
57 * Obtain a sheet writer.
58 *
59 * @param pReport the report
60 * @return the sheet writer
61 */
62 protected abstract PrometheusSheetWriter getSheetWriter(TethysUIThreadStatusReport pReport);
63
64 /**
65 * Load a Backup Workbook.
66 *
67 * @param pReport the report
68 * @param pPasswordMgr the password manager
69 * @param pData the data to load into
70 * @param pFile the backup file to load from
71 * @throws OceanusException on error
72 */
73 public void loadBackup(final TethysUIThreadStatusReport pReport,
74 final PrometheusSecurityPasswordManager pPasswordMgr,
75 final PrometheusDataSet pData,
76 final File pFile) throws OceanusException {
77 /* Create a sheet reader object */
78 final PrometheusSheetReader myReader = getSheetReader(pReport, pPasswordMgr);
79
80 /* Load the backup */
81 myReader.loadBackup(pFile, pData);
82 }
83
84 /**
85 * Load a Backup Workbook.
86 *
87 * @param pReport the report
88 * @param pPasswordMgr the password manager
89 * @param pData the data to load into
90 * @param pInStream the input stream to load from
91 * @param pName the filename
92 * @throws OceanusException on error
93 */
94 public void loadBackup(final TethysUIThreadStatusReport pReport,
95 final PrometheusSecurityPasswordManager pPasswordMgr,
96 final PrometheusDataSet pData,
97 final InputStream pInStream,
98 final String pName) throws OceanusException {
99 /* Create a sheet reader object */
100 final PrometheusSheetReader myReader = getSheetReader(pReport, pPasswordMgr);
101
102 /* Load the backup */
103 myReader.loadBackup(pInStream, pData, pName);
104 }
105
106 /**
107 * Create a Backup Workbook.
108 *
109 * @param pReport the report
110 * @param pData Data to write out
111 * @param pFile the backup file to write to
112 * @param pType the workBookType
113 * @throws OceanusException on error
114 */
115 public void createBackup(final TethysUIThreadStatusReport pReport,
116 final PrometheusDataSet pData,
117 final File pFile,
118 final PrometheusSheetWorkBookType pType) throws OceanusException {
119 /* Create a sheet writer object */
120 final PrometheusSheetWriter myWriter = getSheetWriter(pReport);
121
122 /* Create the backup */
123 myWriter.createBackup(pData, pFile, pType);
124 }
125
126 /**
127 * Create a Backup Workbook.
128 *
129 * @param pReport the report
130 * @param pData Data to write out
131 * @param pZipStream the stream to write to
132 * @param pType the workBookType
133 * @throws OceanusException on error
134 */
135 public void createBackup(final TethysUIThreadStatusReport pReport,
136 final PrometheusDataSet pData,
137 final OutputStream pZipStream,
138 final PrometheusSheetWorkBookType pType) throws OceanusException {
139 /* Create a sheet writer object */
140 final PrometheusSheetWriter myWriter = getSheetWriter(pReport);
141
142 /* Create the backup */
143 myWriter.createBackup(pData, pZipStream, pType);
144 }
145 }