]> git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrUrlStreamHandler.java
1f803bf8028259754db3c144093f4a0ce27034f7
[lgpl/argeo-commons.git] / JcrUrlStreamHandler.java
1 package org.argeo.jcr;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.net.URL;
6 import java.net.URLConnection;
7 import java.net.URLStreamHandler;
8
9 import javax.jcr.Binary;
10 import javax.jcr.Item;
11 import javax.jcr.Node;
12 import javax.jcr.Property;
13 import javax.jcr.PropertyType;
14 import javax.jcr.RepositoryException;
15 import javax.jcr.Session;
16 import javax.jcr.nodetype.NodeType;
17
18 /** URL stream handler able to deal with nt:file node and properties. NOT FINISHED */
19 public class JcrUrlStreamHandler extends URLStreamHandler {
20 private final Session session;
21
22 public JcrUrlStreamHandler(Session session) {
23 this.session = session;
24 }
25
26 @Override
27 protected URLConnection openConnection(final URL u) throws IOException {
28 // TODO Auto-generated method stub
29 return new URLConnection(u) {
30
31 @Override
32 public void connect() throws IOException {
33 String itemPath = u.getPath();
34 try {
35 if (!session.itemExists(itemPath))
36 throw new IOException("No item under " + itemPath);
37
38 Item item = session.getItem(u.getPath());
39 if (item.isNode()) {
40 // this should be a nt:file node
41 Node node = (Node) item;
42 if (!node.getPrimaryNodeType().isNodeType(
43 NodeType.NT_FILE))
44 throw new IOException("Node " + node + " is not a "
45 + NodeType.NT_FILE);
46
47 } else {
48 Property property = (Property) item;
49 if(property.getType()==PropertyType.BINARY){
50 Binary binary = property.getBinary();
51
52 }
53 }
54 } catch (RepositoryException e) {
55 IOException ioe = new IOException(
56 "Unexpected JCR exception");
57 ioe.initCause(e);
58 throw ioe;
59 }
60 }
61
62 @Override
63 public InputStream getInputStream() throws IOException {
64 // TODO Auto-generated method stub
65 return super.getInputStream();
66 }
67
68 };
69 }
70
71 }