View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.compound;
22  
23  import org.millscript.office.endianness.EndianDecoder;
24  
25  /**
26   * 
27   */
28  public class DirectoryEntry {
29  
30      private final int center;
31  
32      private final byte colour;
33  
34      private final int directoryID;
35  
36      private final int left;
37  
38      private final String name;
39  
40      private final int right;
41  
42      private final int streamSID;
43  
44      private final int streamSize;
45  
46      private final DirectoryEntryType type;
47  
48      /**
49       * 
50       * @param endianDecoder
51       * @param data
52       */
53      public DirectoryEntry( final EndianDecoder endianDecoder, final byte[] data, final int did ) {
54          // Store the directory ID
55          this.directoryID = did;
56          // Calculate the offset of this directory entry in the data array
57          final int firstByteOffset = did * 128;
58          // Extract the length of the name
59          final int nameLength = ( endianDecoder.decode2ByteInt( data, firstByteOffset + 64 ) >> 1 ) - 1;
60          // Extract the characters in the name
61          if ( nameLength == -1 ) {
62              this.name = null;
63          } else {
64              final char[] chars = new char[ nameLength ];
65              for ( int i = 0; i < nameLength; i++ ) {
66                  chars[ i ] = endianDecoder.decode2ByteChar( data, firstByteOffset + i * 2 );
67              }
68              // and fill in the name
69              this.name = new String( chars );
70          }
71          // Extract the type of this entry
72          this.type = DirectoryEntryType.getType( data[ firstByteOffset + 66 ] );
73          // Extract the colour of this entry
74          this.colour = data[ firstByteOffset + 67 ];
75          // Extract the directory ID of the left node(belongs to parent)
76          this.left = endianDecoder.decode4ByteInt( data, firstByteOffset + 68 );
77          // Extract the directory ID of the right node(belongs to parent)
78          this.right = endianDecoder.decode4ByteInt( data, firstByteOffset + 72 );
79          // Extract the directory ID of the child node(belongs to this node)
80          // e.g. if this entry is a storage, this would be the directory ID for
81          // the root entry in the tree for all the children of this node
82          this.center = endianDecoder.decode4ByteInt( data, firstByteOffset + 76 );
83          // Extract the SID of any stream this entry might refer to
84          this.streamSID = endianDecoder.decode4ByteInt( data, firstByteOffset + 116 );
85          // Extract the size of any stream this entry might refer to
86          this.streamSize = endianDecoder.decode4ByteInt( data, firstByteOffset + 120 );
87      }
88  
89      public int getCenter() {
90          return this.center;
91      }
92  
93      /**
94       * @return Returns the directoryID.
95       */
96      public int getDirectoryID() {
97          return this.directoryID;
98      }
99  
100     public int getLeft() {
101         return this.left;
102     }
103 
104     public String getName() {
105         return this.name;
106     }
107 
108     public int getRight() {
109         return this.right;
110     }
111 
112     public int getStreamSID() {
113         return this.streamSID;
114     }
115 
116     public int getStreamSize() {
117         return this.streamSize;
118     }
119 
120     public DirectoryEntryType getType() {
121         return this.type;
122     }
123 
124     /**
125      * @see java.lang.Object#toString()
126      */
127     @Override
128     public String toString() {
129         final StringBuilder builder = new StringBuilder();
130         builder.append( this.directoryID );
131         builder.append( ": " );
132         builder.append( this.name );
133         return builder.toString();
134     }
135 
136 }