private static String getActionIdentifier( final IAction actionBean, final String actionClassName, final String actionId ) { if ( actionBean != null ) { return actionBean.getClass().getName(); } else if ( !StringUtil.isEmpty( actionClassName ) ) { return actionClassName; } else if ( !StringUtil.isEmpty( actionId ) ) { return actionId; } return "?"; //$NON-NLS-1$ }
public static void main( final String[] args ) { String[] testStrings = { "../bart/maggie.xml", "/bart/..", "/bart/../maggie/homer.xml", "..//bart/maggie.xml", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "/bart//..", "/bart//../maggie/homer.xml", "/../", "/..", "../", "..\\bart\\maggie.xml", "\\bart\\..", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ "\\bart\\..\\maggie\\homer.xml", "I am clean", "/go/not/parent.xml", "\\go\\not\\parent.xml", "..", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ "should/not..not/match", "..should/not/match.xml", "should/not..", "..." }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ for ( String testString : testStrings ) { boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); if ( matches ) { System.out.println( testString + " matches." ); //$NON-NLS-1$ } else { System.out.println( "--------" + testString + " DOES NOT MATCH." ); //$NON-NLS-1$//$NON-NLS-2$ } } }
public String getRunningInBackgroundLocally( final String actionIdentifier, final Map params ) { return getString( "ActionInvoker.INFO_0001_RUNNING_IN_BG_LOCALLY", actionIdentifier, StringUtil.getMapAsPrettyString( params ) ); }
public int compare( final Object o1, final Object o2 ) { String str1 = o1.toString(); String str2 = o2.toString(); String[] str1Array = StringUtil.tokenStringToArray( str1, "/" ); //$NON-NLS-1$ String[] str2Array = StringUtil.tokenStringToArray( str2, "/" ); //$NON-NLS-1$ // If the solution paths are at the same depth, a straight compare will do if ( str1Array.length == str2Array.length ) { return ( str1.compareToIgnoreCase( str2 ) ); } // if the solution paths are un-even, just compare the path and not the Action Sequence int count = Math.min( str1Array.length, str2Array.length ); for ( int i = 0; i < count - 1; ++i ) { int compare = str1Array[i].compareToIgnoreCase( str2Array[i] ); if ( compare != 0 ) { return ( compare ); } } // The shortest one comes first return ( str1Array.length - str2Array.length ); } }
@Test public void testTrimStringList() { List<String> stringList = new ArrayList<>(); for ( int i = 0; i <= 32; i++ ) { stringList.add( (char) i + "foo" ); } stringList.add( "" ); stringList.add( null ); stringList = StringUtil.trimStringList( stringList ); for ( int i = 0; i <= 32; i++ ) { Assert.assertEquals( stringList.get( i ), "foo" ); } Assert.assertEquals( stringList.get( 33 ), "" ); Assert.assertEquals( stringList.get( 34 ), "" ); Assert.assertEquals( StringUtil.trimStringList( null ), null ); List<String> empty = new ArrayList(); Assert.assertEquals( StringUtil.trimStringList( empty ), empty ); }
@Test public void testMain() { try { StringUtil.main( null ); Assert.assertTrue( true ); } catch ( final Exception e ) { Assert.fail( "Exception occured: " + e ); } }
@Test public void testTokenStringToArray() { String token = " "; //$NON-NLS-2$ String tokenString = "This is a test to convert this string into an array"; //$NON-NLS-2$ String[] array = StringUtil.tokenStringToArray( tokenString, token ); StringBuilder buffer = new StringBuilder(); for ( String element : array ) { buffer.append( element ); buffer.append( token ); } Assert.assertEquals( buffer.toString().trim(), tokenString ); // when tokenizedString is null, the result should be null Assert.assertNull( StringUtil.tokenStringToArray( null, token ) ); Assert.assertNull( StringUtil.tokenStringToArray( null, null ) ); // when no token is provided, we should get back an array containing the entire input token as a single string tokenString = "some text"; //$NON-NLS-2$ array = StringUtil.tokenStringToArray( tokenString, null ); Assert.assertNotNull( array ); Assert.assertEquals( 1, array.length ); Assert.assertEquals( tokenString, array[ 0 ] ); }
public String decrypt( String encryptedPassword ) throws PasswordServiceException { return StringUtil.isEmpty( encryptedPassword ) ? encryptedPassword : new String( Base64 .decodeBase64( encryptedPassword.getBytes() ) ); } }
@Test public void testGetMapAsPrettyStringEmpty() { // When the provided map is empty or null, the result should be an empty string Assert.assertEquals( "Map = null" + System.getProperty( "line.separator" ), StringUtil.getMapAsPrettyString( null ) ); Assert.assertEquals( "Map = " + System.getProperty( "line.separator" ) + "{" + System.getProperty( "line" + ".separator" ) + "} java.util.HashMap" + System.getProperty( "line.separator" ), StringUtil .getMapAsPrettyString( new HashMap() ) ); }
boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertTrue( matches ); boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertFalse( matches );
public String encrypt( String password ) throws PasswordServiceException { return StringUtil.isEmpty( password ) ? password : new String( Base64.encodeBase64( password.getBytes() ) ); }
final String failureMessage = Messages.getInstance().getErrorString( "ActionAdapterQuartzJob.ERROR_0002_FAILED_TO_CREATE_ACTION", //$NON-NLS-1$ getActionIdentifier( null, actionClassName, actionId ), StringUtil.getMapAsPrettyString( params ) ); WorkItemLifecycleEventUtil.publish( workItemName, params, WorkItemLifecyclePhase.FAILED, failureMessage ); throw new LoggingJobExecutionException( failureMessage ); log.warn( Messages.getInstance().getErrorString( "ActionAdapterQuartzJob.WARN_0002_NO_STATUS", //$NON-NLS-1$ getActionIdentifier( actionBean, actionClassName, actionId ), StringUtil.getMapAsPrettyString( params ) ) );
@Override public String encrypt( String password ) throws PasswordServiceException { if ( StringUtil.isEmpty( password ) ) { return password; } else { return encoder.encode( password ); } }
@Test public void testGetMapAsPrettyString() { final Map testMap = getTestMap(); final String output = StringUtil.getMapAsPrettyString( testMap ); final String expectedOutput = getExpectedPrettyMapOutput(); Assert.assertEquals( expectedOutput, output ); }
/** * Creates the {@link WorkItemLifecycleEvent} with all the required parameters. * * @param workItemUid a {@link String} containing unique identifier for the {@link WorkItemLifecycleEvent} * @param workItemDetails an {@link String} containing details of the {@link WorkItemLifecycleEvent} * @param workItemLifecyclePhase a {@link WorkItemLifecyclePhase} representing the lifecycle event * @param lifecycleDetails a {@link String} containing any additional details about the lifecycle event, such as * pertinent failure messages * @param sourceTimestamp a {@link Date} representing the time the lifecycle change occurred. */ public WorkItemLifecycleEvent( final String workItemUid, final String workItemDetails, final WorkItemLifecyclePhase workItemLifecyclePhase, final String lifecycleDetails, final Date sourceTimestamp ) { this.workItemUid = workItemUid; this.workItemDetails = workItemDetails; this.workItemLifecyclePhase = workItemLifecyclePhase; this.lifecycleDetails = lifecycleDetails; this.sourceTimestamp = sourceTimestamp; // if the workItemUid is null, generate it if ( StringUtil.isEmpty( this.workItemUid ) ) { this.workItemUid = UUID.randomUUID().toString(); } // Set sourceTimestamp to current date only if not already provided if ( this.sourceTimestamp == null ) { this.sourceTimestamp = new Date(); } // set the default values for host name and ip, they can be changed directly if needed this.sourceHostName = HOST_NAME; this.sourceHostIp = HOST_IP; }
/** * Returns a name for a work item which includes the input file name (derived from {@code inputFilePath}) and * {@code user} that executed it, in the following format: %input file name%-%user%, stripping any * invalid characters. * * This workItemName will be used for logging only * * @param inputFilePath the path of the input file of the action being invoked - optional * @param userName the user executing the action * @return a name for the work item */ public static String generateWorkItemName( final String inputFilePath, final String userName ) { if ( StringUtil.isEmpty( inputFilePath ) ) { logger.info( "Input file path is not provided." ); } if ( StringUtil.isEmpty( userName ) ) { logger.info( "User name is not provided." ); } String workItemName = String.format( "%s[%s]", Optional.ofNullable( inputFilePath ).orElse( StringUtils.EMPTY ), Optional.ofNullable( userName ).orElse( StringUtils.EMPTY ) ); if ( workItemName.length() > WORK_ITEM_LENGTH_LIMIT ) { logger.info( String.format( "Work item name exceeds max character limit of %d: %d", WORK_ITEM_LENGTH_LIMIT, workItemName.length() ) ); } return workItemName; }
@Override public String decrypt( String encryptedPassword ) throws PasswordServiceException { if ( StringUtil.isEmpty( encryptedPassword ) ) { return encryptedPassword; } else { if ( encryptedPassword.startsWith( prefix ) ) { // If it starts with "Encrypted " then decode using KettleTwoWayPasswordEncoder return encoder.decode( encryptedPassword ); } else { // If not, likely Base64 encoded so twy that return super.decrypt( encryptedPassword ); } } }
private static String lookupSetting( IApplicationContext applicationContext, String applicationContextName, String hibernateSettingsName, String pentahoXmlName ) { // 1- Look in applicationContext // 2- Look in PentahoSystem/hibernate-settings.xml // 3- Look in pentaho.xml String tmp = null; tmp = applicationContext.getProperty( applicationContextName, null ); if ( ( tmp != null ) && ( !StringUtil.isEmpty( tmp ) ) ) { return tmp.trim(); } if ( tmp == null ) { tmp = PentahoSystem.getSystemSetting( "hibernate/hibernate-settings.xml", hibernateSettingsName, null ); //$NON-NLS-1$ if ( ( tmp != null ) && ( !StringUtil.isEmpty( tmp ) ) ) { return tmp.trim(); } } if ( tmp == null ) { tmp = PentahoSystem.getSystemSetting( pentahoXmlName, null ); if ( ( tmp != null ) && ( !StringUtil.isEmpty( tmp ) ) ) { return tmp.trim(); } } return null; }
/** * @param params a {@link Map} containing action/work item related attributes, in particular {@code inputFile} and * {@code actionUser}, which are both used for the purpose of generating the uid. * @return a name for the work item * @see {@link #generateWorkItemName(String, String)} */ public static String generateWorkItemName( final Map<String, Serializable> params ) { if ( params == null ) { return generateWorkItemName( null, null ); } // at the time this method is called, the quartz specific map keys may not have been mapped to their // corresponding action keys (see KEY_MAP), fall back on the quartz key, if the action key cannot be found final String userName = Optional.ofNullable( (String) params.get( INVOKER_ACTIONUSER ) ).orElse( (String) params .get( QUARTZ_ACTIONUSER ) ); String inputFilePath = Optional.ofNullable( (String) params.get( INVOKER_STREAMPROVIDER_INPUT_FILE ) ) .orElse( (String) params.get( QUARTZ_STREAMPROVIDER_INPUT_FILE ) ); // if we still cannot find the inputFile, we have one last attempt: check for inline passing of input and output files, // represented by 'ActionAdapterQuartzJob-StreamProvider -> input file = <path><colon>output file=<path> if ( StringUtil.isEmpty( inputFilePath ) && isInlinePassingOfInputOnStreamProvider( params ) ) { inputFilePath = getInlineInputFileOnStreamProvider( params ); } return generateWorkItemName( inputFilePath, userName ); }
public List<CmisObject> getDescendants( String repositoryId, String folderId, TypesOfFileableObjects type, int depth, String filter, boolean includeAllowableActions, boolean includeRelationships ) throws InvalidArgumentException, ConstraintViolationException, FilterNotValidException, RuntimeException, UpdateConflictException, ObjectNotFoundException, OperationNotSupportedException, PermissionDeniedException, FolderNotValidException { Collection filters = null; if ( !StringUtil.isEmpty( filter ) ) { filters = getFilterCollection( filter ); } if ( !repositoryId.equals( BiPlatformRepositoryClient.PLATFORMORIG ) ) { throw new InvalidArgumentException(); } List<CmisObject> objects = new ArrayList<CmisObject>(); // get the element for the specified object Element objectElement = getFolderElement( folderId ); addChildren( objects, objectElement, type, filters, 0, 0, depth, 1 ); return objects; }