themeinstaller/source/src/com/nokia/tools/themeinstaller/odtconverter/ODTHeader.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 meta information about the theme.
       
    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 meta information about the theme.
       
    27  */
       
    28 public class ODTHeader extends Hashtable
       
    29     {
       
    30     // Default serial version UID
       
    31     private static final long serialVersionUID = 1L;
       
    32 
       
    33     // Header fields
       
    34     public static final String ApplicationUID = "ApplicationUID";
       
    35     public static final String ProviderUID = "ProviderUID";
       
    36     public static final String ThemeUID = "ThemeUID";
       
    37     public static final String ProviderName = "ProviderName";
       
    38     public static final String ThemeFullName = "ThemeFullName";
       
    39     public static final String ThemeShortName = "ThemeShortName";
       
    40     public static final String ThemeVersion = "ThemeVersion";
       
    41     public static final String ScreenSizeX = "ScreenSizeX";
       
    42     public static final String ScreenSizeY = "ScreenSizeY";
       
    43     public static final String Language = "Language";
       
    44     public static final String Flags = "Flags";
       
    45 
       
    46     /**
       
    47      * Gets binary representation of ODTHeader
       
    48      * @return binary representation of ODTHeader
       
    49      * @throws IOException if stream I/O fails
       
    50      * @throws ODTException if header externalization fails
       
    51      */
       
    52     public byte[] getBinaryODTHeader() throws IOException, ODTException
       
    53         {
       
    54         ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    55         ODTDataOutputStream dos = new ODTDataOutputStream( baos );
       
    56 
       
    57         byte[] binaryODTHeader = null;
       
    58 
       
    59         try
       
    60             {
       
    61             // Externalize header contents to the byte stream
       
    62             if(null!=get(ApplicationUID))
       
    63         	dos.writeUnsignedInt32( ( ( Long )get( ApplicationUID ) ).longValue() );
       
    64             if(null!=get(ProviderUID))
       
    65             dos.writeUnsignedInt32( ( ( Long )get( ProviderUID ) ).longValue() );
       
    66             if(null!=get(ThemeUID))
       
    67             dos.writeUnsignedInt32( ( ( Long )get( ThemeUID ) ).longValue() );
       
    68             if(null!=get(ProviderName))
       
    69             dos.writeString16( ( String )get( ProviderName ) );
       
    70             if(null!=get(ThemeFullName))
       
    71             dos.writeString16( ( String )get( ThemeFullName ) );
       
    72             if(null!=get(ThemeShortName))
       
    73             dos.writeString16( ( String )get( ThemeShortName ) );
       
    74             if(null!=get(ThemeVersion))
       
    75            
       
    76             dos.writeString16( ( String )get( ThemeVersion ) );
       
    77            
       
    78             dos.writeInt32( ( ( Integer )get( ScreenSizeX ) ).intValue() );
       
    79             dos.writeInt32( ( ( Integer )get( ScreenSizeY ) ).intValue() );
       
    80             dos.writeInt32( ( ( Integer )get( Language ) ).intValue() );
       
    81             dos.writeInt32( ( ( Integer )get( Flags ) ).intValue() );
       
    82             binaryODTHeader = baos.toByteArray();
       
    83             }
       
    84         catch( Exception e )
       
    85             {
       
    86             throw new ODTException( e.getMessage() );
       
    87             }
       
    88         finally
       
    89             {
       
    90             // Close the streams
       
    91             if( dos != null )
       
    92                 {
       
    93                 dos.close();
       
    94                 }
       
    95             if( baos != null )
       
    96                 {
       
    97                 baos.close();
       
    98                 }
       
    99             }
       
   100 
       
   101         return binaryODTHeader;
       
   102         }
       
   103     }