jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles Brooking" <public+jackrab...@charlie.brooking.id.au>
Subject Files for binary properties
Date Mon, 01 Dec 2008 01:27:15 GMT
Hi all

I've had a requirement recently to access the (operating system) files in
which binary properties are stored. I know the standard means for
obtaining binary content is through streams, but here are my reasons:

  * I need to use a third-party C library, through JNI, that takes
    a file path as its argument and does some image processing.

  * Files are large so creating an entirely new copy from a stream
    is not very appealing.

  * I am considering a separate backup format for my repository's
    metadata - to sit alongside a backup of Jackrabbit's own
    repository files - so I have things in an absolutely recoverable
    format in case of disaster. In this format, though, I want to
    use paths to Jackrabbit's files instead of creating new copies.

  * In all cases these are nt:file instances deposited using WebDAV,
    and I believe that there should be access to an actual file on
    the server side. This is subject to repository configuration,
    because I acknowledge the use of bundles, data stores, etc.
    I am currently using the XMLPersistenceManager.

Listed below is the code I've used to obtain file paths. One problem is
that BLOBInResource does not have a getFileSystem() method - is there a
reason for this?

Do people have general comments about what I'm doing here? Is it
potentially a complete disaster?!

public static File getBLOBFile(Property property) throws Exception {
  // Retrieve Jackrabbit-specific InternalValue object.
  InternalValue internalValue =
    ((PropertyImpl) property).internalGetValue();

  // Assume property is a BLOB (arguments are not currently checked).
  // Assume all BLOBs stored in filesystem resources (repository config).
  BLOBFileValue blobFileValue = internalValue.getBLOBFileValue();
  BLOBInResource blobInResource = (BLOBInResource) blobFileValue;

  // Access private fsResource field in BLOBInResource class!
  Field fsResourceField =
    BLOBInResource.class.getDeclaredField("fsResource");
  fsResourceField.setAccessible(true);
  FileSystemResource fsResource =
    (FileSystemResource) fsResourceField.get(blobInResource);

  // Assume resource stored in local filesystem (repository config).
  LocalFileSystem lfs = (LocalFileSystem) fsResource.getFileSystem();

  // Construct resource path relative to root of local filesystem.
  return new File(lfs.getPath(), fsResource.getPath());
}

Later
Charlie


Mime
View raw message