1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.loader;
24 
25 import com.sun.star.report.InputRepository;
26 
27 import java.io.IOException;
28 import java.io.InputStream;
29 
30 import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
31 import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException;
32 import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
33 import org.pentaho.reporting.libraries.resourceloader.loader.AbstractResourceData;
34 
35 
36 public class InputRepositoryResourceData extends AbstractResourceData
37 {
38 
39     private final InputRepository inputRepository;
40     private final ResourceKey key;
41     private final String resourceIdentifer;
42 
InputRepositoryResourceData(final ResourceKey key, final InputRepository repository)43     public InputRepositoryResourceData(final ResourceKey key,
44             final InputRepository repository)
45     {
46         this.key = key;
47         this.inputRepository = repository;
48         final InputResourceKey rkey = (InputResourceKey) key.getIdentifier();
49         final String identifier = rkey.getPath();
50         this.resourceIdentifer = identifier.substring("sun:oo://".length());
51     }
52 
getAttribute(final String key)53     public Object getAttribute(final String key)
54     {
55         // we dont support attributes here ..
56         return null;
57     }
58 
getKey()59     public ResourceKey getKey()
60     {
61         return key;
62     }
63 
getResourceAsStream(final ResourceManager caller)64     public InputStream getResourceAsStream(final ResourceManager caller)
65             throws ResourceLoadingException
66     {
67         try
68         {
69             return inputRepository.createInputStream(resourceIdentifer);
70         }
71         catch (IOException e)
72         {
73             throw new ResourceLoadingException("Failed to create input stream for " + resourceIdentifer, e);
74         }
75     }
76 
getVersion(final ResourceManager caller)77     public long getVersion(final ResourceManager caller)
78     {
79         return inputRepository.getVersion(resourceIdentifer);
80     }
81 }
82