LibreOffice Module xmerge (master) 1
PalmDB.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.converter.palm;
20
21import java.io.UnsupportedEncodingException;
22
59public final class PalmDB {
60
62 public static final int NAME_LENGTH = 32;
63
65 private Record[] records;
66
68 private byte[] bName = null;
69
71 private String sName = null;
72
74 private int creatorID = 0;
75
77 private int typeID = 0;
78
84 private int version = 0;
85
90 private short attribute = 0;
91
100 public PalmDB(int creatorID, int typeID, int version, short attribute) {
101 records = new Record[0];
103 }
104
121 public PalmDB(String name, int creatorID, int typeID, int version,
122 short attribute, Record[] recs)
123 throws UnsupportedEncodingException {
124
125 this(name.getBytes(PdbUtil.ENCODING), creatorID, typeID, version,
126 attribute, recs);
127 }
128
145 public PalmDB(byte[] name, int creatorID, int typeID, int version,
146 short attribute, Record[] recs)
147 throws UnsupportedEncodingException {
148
149 store(name);
150
151 records = new Record[recs.length];
152 System.arraycopy(recs, 0, records, 0, recs.length);
154 }
155
164 private void setAttributes (int creatorID, int typeID, int version,
165 short attribute) {
166 this.creatorID = creatorID;
167 this.typeID = typeID;
168 this.version = version;
169 this.attribute = attribute;
170 }
171
186 private void store(byte[] bytes) throws UnsupportedEncodingException {
187
188 // note that this will initialize all bytes in name to 0.
189 bName = new byte[NAME_LENGTH];
190
191 // determine minimum length to copy over from bytes to bName.
192 // Note that the last byte in bName has to be '\0'.
193
194 int lastIndex = NAME_LENGTH - 1;
195 int len = (bytes.length < lastIndex)? bytes.length: lastIndex;
196
197 int i;
198 for (i = 0; i < len; i++) {
199
200 if (bytes[i] == 0) {
201 break;
202 }
203
204 bName[i] = bytes[i];
205 }
206
207 // set sName, no need to include the '\0' character.
208 sName = new String(bName, 0, i, PdbUtil.ENCODING);
209 }
210
216 public int getCreatorID() {
217 return creatorID;
218 }
219
225 public int getTypeID() {
226 return typeID;
227 }
228
234 public short getAttribute() {
235 return attribute;
236 }
237
243 public int getVersion() {
244 return version;
245 }
246
252 public int getRecordCount() {
253 return records.length;
254 }
255
266 public Record getRecord(int index) {
267 return records[index];
268 }
269
275 public Record[] getRecords() {
276 return records;
277 }
278
285 return sName;
286 }
287
294 public byte[] getPDBNameBytes() {
295 return bName;
296 }
297
311 @Override
312 public boolean equals(Object obj) {
313
314 boolean bool = false;
315
316 if (obj instanceof PalmDB) {
317
318 PalmDB pdb = (PalmDB) obj;
319
320 checkLabel: {
321
322 // compare sName
323 if (!sName.equals(pdb.sName)) {
324 break checkLabel;
325 }
326
327 // compare bName
328 if (bName.length != pdb.bName.length) {
329 break checkLabel;
330 }
331 for (int i = 0; i < bName.length; i++) {
332 if (bName[i] != pdb.bName[i]) {
333 break checkLabel;
334 }
335 }
336
337 // compare each Record
338 if (records.length != pdb.records.length) {
339 break checkLabel;
340 }
341 for (int i = 0; i < records.length; i++) {
342 if (!records[i].equals(pdb.records[i])) {
343 break checkLabel;
344 }
345 }
346
347 // all checks done
348 bool = true;
349 }
350 }
351
352 return bool;
353 }
354
355 @Override
356 public int hashCode() {
357 return 0;
358 }
359
360}
This class contains data for a single Palm database for use during a conversion process.
Definition: PalmDB.java:59
Record[] records
List of Record objects.
Definition: PalmDB.java:65
void store(byte[] bytes)
This private method is mainly used by the constructors above.
Definition: PalmDB.java:186
void setAttributes(int creatorID, int typeID, int version, short attribute)
Set the attributes for the PalmDB object.
Definition: PalmDB.java:164
PalmDB(byte[] name, int creatorID, int typeID, int version, short attribute, Record[] recs)
Constructor to create object with Record objects.
Definition: PalmDB.java:145
int getCreatorID()
Returns creator ID.
Definition: PalmDB.java:216
short attribute
PDB attribute - flags for the database.
Definition: PalmDB.java:90
byte[] getPDBNameBytes()
Return the PDB name associated with this object in byte array of exact length of 32 bytes.
Definition: PalmDB.java:294
String getPDBNameString()
Return the PDB name associated with this object.
Definition: PalmDB.java:284
PalmDB(int creatorID, int typeID, int version, short attribute)
Default constructor.
Definition: PalmDB.java:100
Record[] getRecords()
Return the list of Record objects.
Definition: PalmDB.java:275
static final int NAME_LENGTH
Number of bytes for the name field in the PDB.
Definition: PalmDB.java:62
short getAttribute()
Returns attribute flag.
Definition: PalmDB.java:234
int getRecordCount()
Return the number of Records contained in this PDB PalmDB object.
Definition: PalmDB.java:252
PalmDB(String name, int creatorID, int typeID, int version, short attribute, Record[] recs)
Constructor to create PalmDB object with Record objects.
Definition: PalmDB.java:121
boolean equals(Object obj)
Override equals method of Object.
Definition: PalmDB.java:312
Record getRecord(int index)
Return the specific Record object associated with the Record number.
Definition: PalmDB.java:266
String sName
PDB name in String.
Definition: PalmDB.java:71
Contains common static methods and constants for use within the package.
Definition: PdbUtil.java:24
Contains the raw bytes for a Record in a PDB.
Definition: Record.java:35
const char * name
int i
index
std::vector< sal_uInt8 > bytes