Hi Marcel,
thanks for answering so quickly.
I've put together a simple class that illustrates the issue. The
whole point of
accessing the jcr:data property directly (instead of using e.g.
Workspace.copy)
it that the file is not reflected as nt:file in the target workspace,
but
rather as a binary property of a domain-specific node type.
Thanks for looking into this,
Kim
// I'm using this as a singleton Bean instantiated by Spring (which also
// injects the session which is shared among all my listeners) with
// jackrabbit 1.2.1 under Tomcat 5.5.20 deployed in 'model 1'.
public class SimpleWebdavDropFileListener implements EventListener {
private final static Logger log = LoggerFactory.getLogger
(MyListener.class);
private Session systemSession;
public SimpleWebdavDropFileListener(Session session) {
this.systemSession = session;
ObservationManager omgr = systemSession.getWorkspace
().getObservationManager();
omgr.addEventListener(
this, // register myself
Event.NODE_ADDED, // on node added events
session.getRootNode().getPath(), // at root node
true, // and descendants
null, // not using uuid constraints
new String[] { "nt:file" }, // receiving events only for
files
false // ignoring local events
);
}
public void onEvent(EventIterator events) {
while (events.hasNext()) {
Event event = events.nextEvent();
// strip leading '/'
String path = event.getPath().substring(1);
try {
Node theFile = systemSession.getRootNode().getNode(path);
Node contentNode = theFile.getNode("jcr:content");
// this will be zero unless we're implementing
SynchronousEventListener
long dataLength = contentNode.getProperty
("jcr:data").getLength();
log.info("Just received a file and the size of it's
jcr:content/jcr:data property is: " + dataLength);
// walk through all properties and output their name and
value (as string)
// -> every property except jcr:data will have a value printed
PropertyIterator props = contentNode.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
log.info(prop.getName() + " has value: " + prop.getString());
}
} catch (Exception e) {
e.printStackTrace(); // whatever
}
}
}
}
Marcel Reutegger <marcel.reutegger <at> gmx.net> writes:
>
> Hi Kim,
>
> I'm not able to reproduce the behaviour you described. Though I
didn't use
> WebDAV to import files, but just imported them using a JCR session.
>
> Can you please provide a code fragment that shows how you access
the content
> from within the event listener?
>
> regards
> marcel
>
> Kim Altintop wrote:
> > Hi,
> >
> > I'm trying to implement a simple "Drop Folder" setup where users
would
> > connect to one Jackrabbit workspace using (simple) WebDAV, drop
files in
> > there, and an EventListener listening for NODE_ADDED events
(restricted
> > to "nt:file") would then copy the file(s) to another workspace.
As it
> > turned out, the EventListener is able to locate the just-dropped
file
> > and read its properties but the jcr:data property is always
empty (i.e.
> > contains no data). If I change my listener to implement
> > SynchronousEventListener it works fine. However, from the spec I
would
> > expect it to work just the other way round...
> >
> > Am I getting something wrong here?
> >
> > Regards,
> > Kim
> >
> >
>
>