27 March 2008

The caret synbol( ^ ) in bindings

The caret symbol( ^ ) indicates that the value should be taken from the parent component.

11 March 2008

Getting resources from Unit Tests

Since Unit Tests are run from the command line( or Ant ) access to Resources of a WebObjects project are no good with ResourceManager. Simple functions to get resources based on the filesystem:


/**
* Returns a path to a resource filename in a folder(s) under the root folder
* */
private String resourceLocationString( String filename, String folder ) {
String urlToFile = getClass().getResource( "/" ).toString();
urlToFile = urlToFile.replace( "bin/", "" );
urlToFile = urlToFile.replace( "file:", "" ); // now we should be at the projects root directory
urlToFile = urlToFile.concat( folder + "/" + filename );
return urlToFile;
}

/**
* Returns data for pdf file
* */
private byte[] bytesForPDFResource( String urlToFile ) throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream( urlToFile );
byte[] data = new byte[in.available()];
in.read(data);
return data;
}

Write data to a file in the filesystem


FileOutputStream fs = new FileOutputStream( ABSOLUTE_PATH_TO_FILE );
fs.write( SOME_DATA );
fs.close();