]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/JcrUrlStreamHandler.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
;
18 import java
.io
.IOException
;
19 import java
.io
.InputStream
;
21 import java
.net
.URLConnection
;
22 import java
.net
.URLStreamHandler
;
24 import javax
.jcr
.Item
;
25 import javax
.jcr
.Node
;
26 import javax
.jcr
.Property
;
27 import javax
.jcr
.PropertyType
;
28 import javax
.jcr
.RepositoryException
;
29 import javax
.jcr
.Session
;
30 import javax
.jcr
.nodetype
.NodeType
;
32 /** URL stream handler able to deal with nt:file node and properties. NOT FINISHED */
33 public class JcrUrlStreamHandler
extends URLStreamHandler
{
34 private final Session session
;
36 public JcrUrlStreamHandler(Session session
) {
37 this.session
= session
;
41 protected URLConnection
openConnection(final URL u
) throws IOException
{
42 // TODO Auto-generated method stub
43 return new URLConnection(u
) {
46 public void connect() throws IOException
{
47 String itemPath
= u
.getPath();
49 if (!session
.itemExists(itemPath
))
50 throw new IOException("No item under " + itemPath
);
52 Item item
= session
.getItem(u
.getPath());
54 // this should be a nt:file node
55 Node node
= (Node
) item
;
56 if (!node
.getPrimaryNodeType().isNodeType(
58 throw new IOException("Node " + node
+ " is not a "
62 Property property
= (Property
) item
;
63 if(property
.getType()==PropertyType
.BINARY
){
64 //Binary binary = property.getBinary();
68 } catch (RepositoryException e
) {
69 IOException ioe
= new IOException(
70 "Unexpected JCR exception");
77 public InputStream
getInputStream() throws IOException
{
78 // TODO Auto-generated method stub
79 return super.getInputStream();