javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/utils/Args.java
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 package com.nokia.mj.impl.installer.utils;
    19 package com.nokia.mj.impl.installer.utils;
    20 
    20 
    21 import com.nokia.mj.impl.installer.utils.InstallerException;
    21 import com.nokia.mj.impl.installer.utils.InstallerException;
    22 import com.nokia.mj.impl.installer.utils.Log;
    22 import com.nokia.mj.impl.installer.utils.Log;
    23 import com.nokia.mj.impl.utils.Base64;
       
    24 import com.nokia.mj.impl.utils.Tokenizer;
    23 import com.nokia.mj.impl.utils.Tokenizer;
    25 
    24 
    26 import java.util.Hashtable;
    25 import java.util.Hashtable;
    27 
    26 
    28 /**
    27 /**
    58                 //}
    57                 //}
    59                 iArgs.put(arg, value);
    58                 iArgs.put(arg, value);
    60                 //Log.log("Args: " + arg + "=" + value);
    59                 //Log.log("Args: " + arg + "=" + value);
    61             }
    60             }
    62         }
    61         }
    63         decodeBase64Args();
       
    64     }
    62     }
    65 
    63 
    66     /**
    64     /**
    67      * Returns command line argument with the specified name.
    65      * Returns command line argument with the specified name.
    68      * If argument is not found, returns null.
    66      * If argument is not found, returns null.
   203                 InstallerException.internalError(
   201                 InstallerException.internalError(
   204                     "Invalid drive argument: " + aDrive);
   202                     "Invalid drive argument: " + aDrive);
   205             }
   203             }
   206             drive = aDrive.toLowerCase().charAt(0) - 'a';
   204             drive = aDrive.toLowerCase().charAt(0) - 'a';
   207         }
   205         }
   208         Log.log("Args: Parsed drive " + aDrive + " --> " + drive);
   206         Log.log("Parsed drive " + aDrive + " --> " + drive);
   209         return drive;
   207         return drive;
   210     }
   208     }
   211 
       
   212     /**
       
   213      * Decodes base64 encoded arguments.
       
   214      * In Symbian environment the decoded argument is UTF-16LE string.
       
   215      *
       
   216      * @see /sf/app/jrt/javacommons/utils/inc/javacommonutils.h,
       
   217      *  wbase64encode()
       
   218      */
       
   219     private void decodeBase64Args()
       
   220     {
       
   221         String base64Value = get("base64");
       
   222         if (base64Value == null || base64Value.length() == 0)
       
   223         {
       
   224             return;
       
   225         }
       
   226         String[] tokens = Tokenizer.split(base64Value, ",");
       
   227         String name = null;
       
   228         String value = null;
       
   229         for (int i = 0; i < tokens.length; i++)
       
   230         {
       
   231             name = tokens[i];
       
   232             value = null;
       
   233             if (name != null && name.length() > 0)
       
   234             {
       
   235                 value = get(name);
       
   236             }
       
   237             if (value != null && value.length() > 0)
       
   238             {
       
   239                 try
       
   240                 {
       
   241                     byte[] valueBytes = Base64.decode(value);
       
   242                     if (valueBytes != null && valueBytes.length > 0)
       
   243                     {
       
   244                         value = new String(valueBytes, "UTF-16LE");
       
   245                         Log.log("Args: Base64 decoded option " +
       
   246                                 name + "=" + value);
       
   247                         iArgs.put(name, value);
       
   248                     }
       
   249                     else
       
   250                     {
       
   251                         Log.logError("Args: Base64 decoding failed for " +
       
   252                                      name + "=" + value);
       
   253                     }
       
   254                 }
       
   255                 catch (Throwable t)
       
   256                 {
       
   257                     Log.logError("Args: Base64 decoding failed for " +
       
   258                                  name + "=" + value, t);
       
   259                 }
       
   260             }
       
   261         }
       
   262     }
       
   263 }
   209 }