Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache.poi.hdf » extractor » data » [javadoc | source]
    1   
    2   /* ====================================================================
    3      Licensed to the Apache Software Foundation (ASF) under one or more
    4      contributor license agreements.  See the NOTICE file distributed with
    5      this work for additional information regarding copyright ownership.
    6      The ASF licenses this file to You under the Apache License, Version 2.0
    7      (the "License"); you may not use this file except in compliance with
    8      the License.  You may obtain a copy of the License at
    9   
   10          http://www.apache.org/licenses/LICENSE-2.0
   11   
   12      Unless required by applicable law or agreed to in writing, software
   13      distributed under the License is distributed on an "AS IS" BASIS,
   14      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15      See the License for the specific language governing permissions and
   16      limitations under the License.
   17   ==================================================================== */
   18           
   19   
   20   
   21   package org.apache.poi.hdf.extractor.data;
   22   
   23   import java.util;
   24   
   25   import org.apache.poi.hdf.extractor;
   26   
   27   
   28   /**
   29    * Comment me
   30    *
   31    * @author Ryan Ackley 
   32    */
   33   
   34   public class ListTables
   35   {
   36   
   37     LFO[] _pllfo;
   38     Hashtable _lists = new Hashtable();
   39   
   40     public ListTables(byte[] plcflst, byte[] plflfo)
   41     {
   42       initLST(plcflst);
   43       initLFO(plflfo);
   44     }
   45     public LVL getLevel(int list, int level)
   46     {
   47   
   48       LFO override = _pllfo[list - 1];
   49   
   50       for(int x = 0; x < override._clfolvl; x++)
   51       {
   52         if(override._levels[x]._ilvl == level)
   53         {
   54           LFOLVL lfolvl = override._levels[x];
   55           if(lfolvl._fFormatting)
   56           {
   57             LST lst = (LST)_lists.get(new Integer(override._lsid));
   58             LVL lvl = lfolvl._override;
   59             lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2);
   60             return lvl;
   61           }
   62           else if(lfolvl._fStartAt)
   63           {
   64             LST lst = (LST)_lists.get(new Integer(override._lsid));
   65             LVL lvl = lst._levels[level];
   66             LVL newLvl = (LVL)lvl.clone();
   67             newLvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2);
   68             newLvl._iStartAt = lfolvl._iStartAt;
   69             return newLvl;
   70           }
   71         }
   72       }
   73   
   74       LST lst = (LST)_lists.get(new Integer(override._lsid));
   75       LVL lvl = lst._levels[level];
   76       lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2);
   77       return lvl;
   78   
   79   
   80     }
   81     private void initLST(byte[] plcflst)
   82     {
   83       short length = Utils.convertBytesToShort(plcflst, 0);
   84       int nextLevelOffset = 0;
   85       //LST[] lstArray = new LST[length];
   86       for(int x = 0; x < length; x++)
   87       {
   88         LST lst = new LST();
   89         lst._lsid = Utils.convertBytesToInt(plcflst, 2 + (x * 28));
   90         lst._tplc = Utils.convertBytesToInt(plcflst, 2 + 4 + (x * 28));
   91         System.arraycopy(plcflst, 2 + 8 + (x * 28), lst._rgistd, 0, 18);
   92         byte code = plcflst[2 + 26 + (x * 28)];
   93         lst._fSimpleList = StyleSheet.getFlag(code & 0x01);
   94         //lstArray[x] = lst;
   95         _lists.put(new Integer(lst._lsid), lst);
   96   
   97         if(lst._fSimpleList)
   98         {
   99           lst._levels = new LVL[1];
  100         }
  101         else
  102         {
  103           lst._levels = new LVL[9];
  104         }
  105   
  106         for(int y = 0; y < lst._levels.length; y++)
  107         {
  108           int offset = 2 + (length * 28) + nextLevelOffset;
  109           lst._levels[y] = new LVL();
  110           nextLevelOffset += createLVL(plcflst, offset, lst._levels[y]);
  111         }
  112       }
  113   
  114   
  115     }
  116     private void initLFO(byte[] plflfo)
  117     {
  118       int lfoSize = Utils.convertBytesToInt(plflfo, 0);
  119       _pllfo = new LFO[lfoSize];
  120       for(int x = 0; x < lfoSize; x++)
  121       {
  122         LFO nextLFO = new LFO();
  123         nextLFO._lsid = Utils.convertBytesToInt(plflfo, 4 + (x * 16));
  124         nextLFO._clfolvl = plflfo[4 + 12 + (x * 16)];
  125         nextLFO._levels = new LFOLVL[nextLFO._clfolvl];
  126         _pllfo[x] = nextLFO;
  127       }
  128   
  129       int lfolvlOffset = (lfoSize * 16) + 4;
  130       int lvlOffset = 0;
  131       int lfolvlNum = 0;
  132       for(int x = 0; x < lfoSize; x++)
  133       {
  134         for(int y = 0; y < _pllfo[x]._clfolvl; y++)
  135         {
  136           int offset = lfolvlOffset + (lfolvlNum * 8) + lvlOffset;
  137           LFOLVL lfolvl = new LFOLVL();
  138           lfolvl._iStartAt = Utils.convertBytesToInt(plflfo, offset);
  139           lfolvl._ilvl = Utils.convertBytesToInt(plflfo, offset + 4);
  140           lfolvl._fStartAt = StyleSheet.getFlag(lfolvl._ilvl & 0x10);
  141           lfolvl._fFormatting = StyleSheet.getFlag(lfolvl._ilvl & 0x20);
  142           lfolvl._ilvl = (lfolvl._ilvl & (byte)0x0f);
  143           lfolvlNum++;
  144   
  145           if(lfolvl._fFormatting)
  146           {
  147             offset = lfolvlOffset + (lfolvlNum * 12) + lvlOffset;
  148             lfolvl._override = new LVL();
  149             lvlOffset += createLVL(plflfo, offset, lfolvl._override);
  150           }
  151           _pllfo[x]._levels[y] = lfolvl;
  152         }
  153       }
  154     }
  155     private int createLVL(byte[] data, int offset, LVL lvl)
  156     {
  157   
  158       lvl._iStartAt = Utils.convertBytesToInt(data, offset);
  159       lvl._nfc = data[offset + 4];
  160       int code = Utils.convertBytesToInt(data, offset + 5);
  161       lvl._jc = (byte)(code & 0x03);
  162       lvl._fLegal = StyleSheet.getFlag(code & 0x04);
  163       lvl._fNoRestart = StyleSheet.getFlag(code & 0x08);
  164       lvl._fPrev = StyleSheet.getFlag(code & 0x10);
  165       lvl._fPrevSpace = StyleSheet.getFlag(code & 0x20);
  166       lvl._fWord6 = StyleSheet.getFlag(code & 0x40);
  167       System.arraycopy(data, offset + 6, lvl._rgbxchNums, 0, 9);
  168       lvl._ixchFollow = data[offset + 15];
  169       int chpxSize = data[offset + 24];
  170       int papxSize = data[offset + 25];
  171       lvl._chpx = new byte[chpxSize];
  172       lvl._papx = new byte[papxSize];
  173       System.arraycopy(data, offset + 28, lvl._papx, 0, papxSize);
  174       System.arraycopy(data, offset + 28 + papxSize, lvl._chpx, 0, chpxSize);
  175       offset += 28 + papxSize + chpxSize;//modify offset
  176       int xstSize = Utils.convertBytesToShort(data, offset);
  177       lvl._xst = new char[xstSize];
  178   
  179       offset += 2;
  180       for(int x = 0; x < xstSize; x++)
  181       {
  182         lvl._xst[x] = (char)Utils.convertBytesToShort(data, offset + (x * 2));
  183       }
  184       return 28 + papxSize + chpxSize + 2 + (xstSize * 2);
  185     }
  186   }

Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache.poi.hdf » extractor » data » [javadoc | source]