javaextensions/wma/mms/javasrc/com/nokia/mj/impl/gcf/protocol/mms/PushValidatorImpl.java
changeset 21 2a9601315dfc
child 78 71ad690e91f5
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.mj.impl.gcf.protocol.mms;
       
    19 
       
    20 import java.lang.String;
       
    21 import com.nokia.mj.impl.utils.Uid;
       
    22 import com.nokia.mj.impl.gcf.PushValidator;
       
    23 import com.nokia.mj.impl.mms.MMSPermissionImpl;
       
    24 import com.nokia.mj.impl.rt.support.ApplicationUtils;
       
    25 /**
       
    26  * This is implementation for validation of URI and 'filter' push arguments for
       
    27  * MMS.
       
    28  */
       
    29 public class PushValidatorImpl extends PushValidator
       
    30 {
       
    31     private static final String MMS_PREFIX = "mms://:";
       
    32     private final String INVALID_URI = "Invalid MMS URI";
       
    33 
       
    34     public PushValidatorImpl()
       
    35     {
       
    36 
       
    37     }
       
    38 
       
    39     /**
       
    40      * Validates both Uri and Filter
       
    41      * @param aUri Uri to be validated
       
    42      * @param aFilter filter to be validated
       
    43      */
       
    44     public void validate(String aUri, String aFilter, Uid aSuiteUid,
       
    45                          String aMidletName, boolean aIsStaticRegistration)
       
    46     {
       
    47         if (!(aUri.startsWith(MMS_PREFIX)))
       
    48         {
       
    49             throw new IllegalArgumentException(INVALID_URI);
       
    50         }
       
    51         String appId = aUri.substring(MMS_PREFIX.length());
       
    52 
       
    53         for (int i = 0; i < appId.length(); i++)
       
    54         {
       
    55             char ch = appId.charAt(i);
       
    56 
       
    57             if (!(Character.isDigit(ch) || Character.isLowerCase(ch)||
       
    58                     Character.isUpperCase(ch) || (ch == '.') || (ch == '_')))
       
    59             {
       
    60                 throw new IllegalArgumentException(INVALID_URI);
       
    61             }
       
    62         }
       
    63 
       
    64         // Filter Validation Part
       
    65         if (!isValidPhoneNumber(aFilter))
       
    66         {
       
    67             throw new IllegalArgumentException("Invalid Filter");
       
    68 
       
    69         }
       
    70         ApplicationUtils appUtils = ApplicationUtils.getInstance();
       
    71         MMSPermissionImpl permission = new MMSPermissionImpl("mms://*","open");
       
    72         appUtils.checkPermission(permission);
       
    73     }
       
    74 
       
    75     private boolean isValidPhoneNumber(String aFilter)
       
    76     {
       
    77         for (int i = 0; i < aFilter.length(); i++)
       
    78         {
       
    79             char ch = aFilter.charAt(i);
       
    80             if (i == 0 && (ch == '+'))
       
    81             {
       
    82                 continue;
       
    83             }
       
    84             if (!(Character.isDigit(ch) || (ch == '*') || (ch == '?')))
       
    85             {
       
    86                 return false;
       
    87             }
       
    88         }
       
    89         return true;
       
    90     }
       
    91 }