public static String encodeUTF8( final String s ) { try { return encode( s, "UTF-8" ); } catch ( UnsupportedEncodingException e ) { //ignore } return null; }
public static String encode (final String s, final String encoding) throws UnsupportedEncodingException { if ("utf-8".equalsIgnoreCase(encoding)) { return encodeUTF8(s); } return encodeBytes(s.getBytes(encoding)); }
private String getFormattedServiceUrl( final String urlService, final FileName file ) throws FileSystemException { if ( urlService == null ) { throw new NullPointerException(); } final String[] fileName = computeFileNames( file ); final RepositoryFileTreeDto fileInfo = lookupNode( fileName ); if ( fileInfo == null ) { throw new FileSystemException( FILE_NOT_FOUND, file ); } final String restName = normalizePath( file.getPath() ); return MessageFormat .format( urlService, URLEncoder.encodeUTF8( restName ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ) ); }
URLEncoder.encodeUTF8( normalizePath( b.toString() ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ) ) ); final WebResource resource = client.resource( url + service ); final ByteArrayInputStream stream = new ByteArrayInputStream( data );
/** * Encodes the given value. The encoding process is skipped, if the value is null, is a number or is a date. * * @param fieldValue * the value that should be encoded. * @return the encoded value. */ private Object encode( final Object fieldValue ) { if ( fieldValue == null ) { return null; } if ( fieldValue instanceof Date ) { return fieldValue; } else if ( fieldValue instanceof Number ) { return fieldValue; } try { return URLEncoder.encode( String.valueOf( fieldValue ), encoding ); } catch ( UnsupportedEncodingException e ) { MessageFormatExpression.logger.debug( "Unsupported Encoding: " + encoding ); return null; } }
public byte[] getData( final FileName file ) throws FileSystemException { final String[] fileName = computeFileNames( file ); final RepositoryFileTreeDto fileInfo = lookupNode( fileName ); if ( fileInfo == null ) { throw new FileSystemException( FILE_NOT_FOUND, file ); } final RepositoryFileDto fileDto = fileInfo.getFile(); if ( fileDto == null ) { throw new IllegalStateException( BI_SERVER_NULL_OBJECT ); } final String path = normalizePath( fileDto.getPath() ); String urlPath = path; try { urlPath = URLEncoder.encodeUTF8( path ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ); } catch ( Exception ex ) { } //tcb final String service = MessageFormat.format( DOWNLOAD_SERVICE, urlPath ); return client.resource( url + service ).accept( MediaType.APPLICATION_XML_TYPE ).get( byte[].class ); }
/** * Encodes the value read from the defined field. The value is converted to a string using the "toString" method. * * @return the value of the function. */ public Object getValue() { if ( field == null ) { return null; } final Object value = getDataRow().get( getField() ); if ( value == null ) { return null; } try { return URLEncoder.encode( String.valueOf( value ), encoding ); } catch ( UnsupportedEncodingException e ) { return null; } }
public void createFolder( final FileName file ) throws FileSystemException { try { final String path = URLEncoder .encodeUTF8( URLDecoder.decode( normalizePath( file.getPath().replaceAll( "\\+", "%2B" ) ), "UTF-8" ) ) .replaceAll( "\\!", "%21" ); final String service = MessageFormat.format( CREATE_FOLDER_SERVICE, path ); final WebResource resource = client.resource( url + service ); final ClientResponse response = resource.type( "text/plain" ).put( ClientResponse.class, null ); if ( response.getStatus() == 200 ) { refresh(); } else { throw new FileSystemException( "Failed with error-code", response.getStatus() ); } } catch ( FileSystemException fse ) { throw fse; } catch ( Exception e ) { throw new FileSystemException( "Failed", e ); } }
retval[i] = fieldValue; } else if ( isUrlEncodeValues() ) { retval[i] = URLEncoder.encode( String.valueOf( fieldValue ), encoding ); } else { retval[i] = fieldValue;
return URLEncoder.encode( result, getEncoding() ); } else { return result;
/** * Returns the formatted message. * * @return the formatted message. */ public Object getValue() { final ResourceBundleFactory resourceBundleFactory = getResourceBundleFactory(); messageFormatSupport.setFormatString( pattern ); messageFormatSupport.setLocale( resourceBundleFactory.getLocale() ); final String result; if ( isUrlEncodeValues() ) { final EncodeDataRow dataRow = new EncodeDataRow(); dataRow.setEncoding( encoding ); dataRow.setWrappedDataRow( getDataRow() ); result = messageFormatSupport.performFormat( dataRow ); } else { result = messageFormatSupport.performFormat( getDataRow() ); } if ( isUrlEncodeResult() ) { try { return URLEncoder.encode( result, getEncoding() ); } catch ( UnsupportedEncodingException e ) { MessageFormatExpression.logger.debug( "Unsupported Encoding: " + encoding ); return null; } } else { return result; } }
return new TypeValuePair( TextType.TYPE, URLEncoder.encode( s, encodingResult ) );
( TextType.TYPE, URLEncoder.encode( textResult, encodingResult ) );