public static String idToPath( String pathId ) { String path = pathId; path = RepositoryPathEncoder.decodeRepositoryPath( path ); if ( path == null || path.trim().isEmpty() ) { path = ""; } else { if ( !path.startsWith( PATH_SEPARATOR ) ) { path = PATH_SEPARATOR + path; } } return path; }
/** * Create URL to access REST API based on provided parameters * * @return * @throws Exception */ private String createPurgeServiceURL() throws Exception { StringBuffer service = new StringBuffer(); service.append( url ); service.append( BASE_PATH ); service.append( "/" ); String path = RepositoryPathEncoder.encodeRepositoryPath( repositoryPath ); path = RepositoryPathEncoder.encode( path ); service.append( path + "/" ); service.append( SERVICE_NAME ); return service.toString(); }
private synchronized FileVersioningConfiguration callVersioningService( String fullPath ) throws KettleException { // If we just made this web service call on this file, don't do it again if ( fullPath.equals( lastFileVersioningPath ) && ( new Date() ).getTime() - lastVersioningTime.getTime() < 2000 ) { return lastFileVersioningConfiguration; } // Do the web service call PurRepositoryRestService.PurRepositoryPluginApiRevision servicePort = (PurRepositoryRestService.PurRepositoryPluginApiRevision) repository .getService( PurRepositoryRestService.PurRepositoryPluginApiRevision.class ); PentahoDiPlugin.PurRepositoryPluginApiRevision.PathIdVersioningConfiguration fileVersioningConfigurationService = servicePort.pathIdVersioningConfiguration( RepositoryPathEncoder.encodeRepositoryPath( fullPath ) ); lastFileVersioningConfiguration = fileVersioningConfigurationService.getAsFileVersioningConfigurationXml(); lastVersioningTime = new Date(); lastFileVersioningPath = fullPath; return fileVersioningConfigurationService.getAsFileVersioningConfigurationXml(); }
static String encodePathForRequest( String path ) { String pathEncoded = RepositoryPathEncoder.encodeRepositoryPath( path ); String utf8 = RepositoryPathEncoder.encodeURIComponent( pathEncoded ); // replace encoded colons with original return utf8.replaceAll( ENCODED_COLON, ":" ); }
/** * Use this function to escape the "colonized" path for addition to a url. * * @param value * The colonized string (eg: ":public:Steel Wheels:File::WithColon") * @return Escaped version of value (eg: "%3Apublic%3ASteel%20Wheels%3AFile%3A%3AWithColon") */ public static String encode( String value ) { String encoded = encodeURIComponent( value ); return encoded.replace( "%5C", "%255C" ).replace( "%2F", "%252F" ); }
@Test public void testEncode() { Assert.assertEquals( "%3Apublic%3ASteel%20Wheels%3AFile%09WithColon", RepositoryPathEncoder .encode( ":public:Steel Wheels:File\tWithColon" ) ); Assert.assertEquals( "%3Apublic%3ASteel%20Wheels%3AFile%09With%255CColon", RepositoryPathEncoder .encode( ":public:Steel Wheels:File\tWith%5CColon" ) ); }
private static String normalizePath( final String path ) { return RepositoryPathEncoder.encodeRepositoryPath( path ); }
static String idToPath( String relPath ) { relPath = RepositoryPathEncoder.decodeRepositoryPath( relPath ); return relPath.replaceFirst( "^/?([A-z])/[/\\\\](.*)", "$1:/$2" ); }
@Test public void testEncodeRepositoryPath() { Assert.assertEquals( ":public:Steel Wheels:File\tWithColon", RepositoryPathEncoder .encodeRepositoryPath( "/public/Steel Wheels/File:WithColon" ) ); }
@Test public void testDecodeRepositoryPath() { Assert.assertEquals( "/public/Steel Wheels/File:WithColon", RepositoryPathEncoder .decodeRepositoryPath( ":public:Steel Wheels:File\tWithColon" ) ); } }