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