CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 187   Methods: 11
NCLOC: 155   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CasStringUtils.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Portions of this file Copyright 1999-2005 University of Chicago
 3    * Portions of this file Copyright 1999-2005 The University of Southern California.
 4    *
 5    * This file or a portion of this file is licensed under the
 6    * terms of the Globus Toolkit Public License, found at
 7    * http://www.globus.org/toolkit/download/license.html.
 8    * If you redistribute this file, with or without
 9    * modifications, you must include this notice in the file.
 10    */
 11    package org.globus.cas.utils;
 12   
 13    import java.util.Vector;
 14   
 15    import org.globus.cas.types.TrustAnchorData;
 16    import org.globus.cas.types.NamespaceData;
 17    import org.globus.cas.types.ServiceTypeData;
 18    import org.globus.cas.types.UserData;
 19    import org.globus.cas.types.ObjectData;
 20    import org.globus.cas.types.PolicyData;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24   
 25    /**
 26    * Utlity class for cleaning up strings before storing and restoring them
 27    */
 28    public class CasStringUtils {
 29   
 30    static Log logger =
 31    LogFactory.getLog(CasStringUtils.class.getName());
 32   
 33    // Single quote needs to be escaped
 34    static String singleQuote = "'";
 35    static String escapedQuote = "\\'";
 36   
 37  0 public static String escapeSingleQuote(String str) {
 38  0 logger.debug("escapeSingleQuote called with " + str);
 39  0 int index;
 40  0 int indexFrom = 0;
 41  0 if (str!=null) {
 42  0 StringBuffer strBuf = new StringBuffer(str);
 43  0 while ((index = str.indexOf(singleQuote, indexFrom)) != -1) {
 44  0 strBuf = strBuf.replace(index,index+1,escapedQuote);
 45  0 str = strBuf.toString();
 46  0 indexFrom = index+2;
 47  0 logger.debug("string is " + str + "indexFrom is " + indexFrom);
 48    }
 49    }
 50  0 return str;
 51    }
 52   
 53  0 public static String restoreSingleQuote(String str) {
 54  0 logger.debug("restoreSingleQuote called with " + str);
 55  0 int index;
 56  0 if (str!=null) {
 57  0 StringBuffer strBuf = new StringBuffer(str);
 58  0 while ((index = str.indexOf(escapedQuote)) != -1) {
 59  0 strBuf.delete(index, index+1);
 60  0 str = strBuf.toString();
 61  0 logger.debug("string is " + str);
 62    }
 63    }
 64  0 return str;
 65    }
 66   
 67  0 public static String[] restoreSingleQuote(String strArray[]) {
 68  0 if (strArray != null) {
 69  0 for (int i=0; i<strArray.length; i++) {
 70  0 logger.debug("restoreSingleQuote called with " + strArray[i]);
 71  0 int index;
 72  0 if (strArray[i]!=null) {
 73  0 StringBuffer strBuf = new StringBuffer(strArray[i]);
 74  0 while ((index = strArray[i].indexOf(escapedQuote)) != -1) {
 75  0 strBuf.delete(index, index+1);
 76  0 strArray[i] = strBuf.toString();
 77  0 logger.debug("string " + i + " is " + strArray[i]);
 78    }
 79    }
 80    }
 81    }
 82  0 return strArray;
 83    }
 84   
 85  0 public static String userToString(UserData userData) {
 86  0 String returnString = " User data: \n Name: " + userData.getNickname()
 87    + "\n SubjectName: " + userData.getSubjectName()
 88    + "\n TrustAnchor " + userData.getTrustAnchorName()
 89    + "\n GroupNames: ";
 90  0 if (userData.getGroupNames() != null) {
 91  0 String gpNames[] = userData.getGroupNames().getStrings();
 92  0 if (gpNames != null) {
 93  0 StringBuffer buf = new StringBuffer(returnString);
 94  0 for (int i=0; i<gpNames.length; i++) {
 95  0 buf.append(" ");
 96  0 buf.append(gpNames[i]);
 97    }
 98  0 returnString = buf.toString();
 99    }
 100    }
 101  0 return returnString;
 102    }
 103   
 104  0 public static String namespaceToString(NamespaceData nsData) {
 105  0 return " Namespace data: \n Name: "
 106    + nsData.getNickname() + "\n ComparisonAlg: "
 107    + nsData.getComparisonAlg() + "\n Basename: "
 108    + nsData.getBasename();
 109    }
 110   
 111  0 public static String trustAnchorToString(TrustAnchorData anchorData) {
 112  0 return " TrustAnchor data: \n Name: "
 113    + anchorData.getNickname() + "\n AuthMethod: "
 114    + anchorData.getAuthMethod() + "\n AuthData: "
 115    + anchorData.getAuthData();
 116    }
 117   
 118  0 public static String objectToString(ObjectData objData) {
 119  0 String returnString = " Object data:\n ObjectId: "
 120    + objData.getObjectId() + "\n Name: " + objData.getObjectName()
 121    + "\n Namespace: " + objData.getObjectNamespace()
 122    + "\n GroupNames: ";
 123  0 if (objData.getGroupNames() != null) {
 124  0 String[] gpNames = objData.getGroupNames().getStrings();
 125  0 if (gpNames != null) {
 126  0 StringBuffer buf = new StringBuffer(returnString);
 127  0 for (int i=0; i<gpNames.length; i++) {
 128  0 buf.append(gpNames[i]);
 129    }
 130  0 returnString = buf.toString();
 131    }
 132    }
 133  0 return returnString;
 134    }
 135   
 136  0 public static String serviceTypeToString(ServiceTypeData serviceData) {
 137  0 String returnString = " ServiceType: " + serviceData.getName();
 138  0 if (serviceData.getActionNames() != null) {
 139  0 String actionNames[] = serviceData.getActionNames().getStrings();
 140  0 if (actionNames != null) {
 141  0 StringBuffer buf = new StringBuffer(returnString);
 142  0 buf.append("\n Action Names: ");
 143  0 for (int i=0; i<actionNames.length; i++) {
 144  0 buf.append(actionNames[i]);
 145    }
 146  0 returnString = buf.toString();
 147    }
 148    }
 149  0 return returnString;
 150    }
 151   
 152  0 public static String policyToString(PolicyData policyData) {
 153   
 154  0 return " Policy data: \n PolicyId: " + policyData.getPolicyId()
 155    + "\n UserGroupName: " + policyData.getUserGroupName()
 156    + "\n Object Specification: " + policyData.getObjectSpec()
 157    + "\n Object Specification Description: "
 158    + policyData.getObjectSpecDesc() + "\n Action Specification: "
 159    + policyData.getActionSpec()
 160    + "\n Action Specification Description: "
 161    + policyData.getActionSpecDesc();
 162    }
 163   
 164  0 public static boolean stringInVector(Vector array, String str) {
 165  0 if ((str == null) || (array == null))
 166  0 return false;
 167  0 logger.debug("String is " + str + " array length " + array.size());
 168  0 str = str.trim();
 169  0 for (int i=0; i<array.size(); i++) {
 170  0 if ((array.get(i)!=null) && (array.get(i).equals(str)))
 171  0 return true;
 172    }
 173  0 return false;
 174    }
 175   
 176  0 public static boolean stringInArray(String[] array, String str) {
 177  0 if ((str == null) || (array == null))
 178  0 return false;
 179  0 logger.debug("String is " + str + " array length " + array.length);
 180  0 str = str.trim();
 181  0 for (int i=0; i<array.length; i++) {
 182  0 if ((array[i]!=null) && (array[i].equals(str)))
 183  0 return true;
 184    }
 185  0 return false;
 186    }
 187    }