themeinstaller/source/src/com/nokia/tools/themeinstaller/odtconverter/ODTResource.java
branchRCL_3
changeset 17 fe49e33862e2
parent 16 b685c59de105
child 18 04b7640f6fb5
equal deleted inserted replaced
16:b685c59de105 17:fe49e33862e2
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class contains data about theme resource.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.tools.themeinstaller.odtconverter;
       
    20 
       
    21 import java.io.ByteArrayOutputStream;
       
    22 import java.io.IOException;
       
    23 import java.util.Hashtable;
       
    24 
       
    25 /**
       
    26  * This class contains data about theme resource.
       
    27  */
       
    28 public class ODTResource extends Hashtable
       
    29     {
       
    30     // Default serial version UID
       
    31     private static final long serialVersionUID = 1L;
       
    32 
       
    33     // ODT Resource properties, externalized
       
    34     public static final String LockingPolicy = "LockingPolicy";
       
    35     public static final String CacheType = "CacheType";
       
    36     public static final String ResourceType = "ResourceType";
       
    37     public static final String ResourceID = "ResourceID";
       
    38     public static final String NameSpace = "NameSpace";
       
    39     public static final String FileName = "FileName";
       
    40     public static final String MimeType = "MimeType";
       
    41 
       
    42     // Size and offset are hard-coded because they are not used in Xuikon
       
    43     private static final int SIZE = 0;
       
    44     private static final int OFFSET = 0;
       
    45 
       
    46     // Name of the temporary file, not externalized
       
    47     public static final String TempFileName = "TempFileName";
       
    48 
       
    49 
       
    50     /**
       
    51      * Gets binary representation of one ODTResource
       
    52      * @return binary representation of one ODTResource
       
    53      * @throws IOException
       
    54      * @throws ODTException
       
    55      */
       
    56     public byte[] getBinaryODTResource() throws IOException, ODTException
       
    57         {
       
    58         ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    59         ODTDataOutputStream dos = new ODTDataOutputStream( baos );
       
    60 
       
    61         byte[] binaryODTResource = null;
       
    62 
       
    63         try
       
    64             {
       
    65             // Write properties of the resource to the byte stream
       
    66             dos.writeInt32( ( ( Integer ) get( LockingPolicy ) ).intValue() );
       
    67             dos.writeInt32( ( ( Integer ) get( CacheType ) ).intValue() );
       
    68             dos.writeInt32( ( ( Integer ) get( ResourceType ) ).intValue() );
       
    69             dos.writeString16( ( String ) get( ResourceID ) );
       
    70             dos.writeString16( ( String ) get( NameSpace ) );
       
    71             dos.writeString16( ( String ) get( FileName ) );
       
    72             dos.writeString8( ( String ) get( MimeType ) );
       
    73             dos.writeInt32( SIZE );
       
    74             dos.writeInt32( OFFSET );
       
    75 
       
    76             binaryODTResource = baos.toByteArray();
       
    77             }
       
    78         catch ( Exception e )
       
    79             {
       
    80             throw new ODTException( e.getMessage() );
       
    81             }
       
    82         finally
       
    83             {
       
    84             // Close the streams
       
    85             if( dos != null )
       
    86                 {
       
    87                 dos.close();
       
    88                 }
       
    89             if( baos != null )
       
    90                 {
       
    91                 baos.close();
       
    92                 }
       
    93             }
       
    94 
       
    95         return binaryODTResource;
       
    96         }
       
    97     }