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 package org.apache.openoffice.ooxml.framework.part;
23 
24 import java.io.InputStream;
25 
26 public class Part
27     implements IReferenceProvider
28 {
Part( final ContentType eType, final PartManager aPartManager, final PartName aPartName)29     public Part (
30         final ContentType eType,
31         final PartManager aPartManager,
32         final PartName aPartName)
33     {
34         meContentType = eType;
35         maPartManager = aPartManager;
36         maPartName = aPartName;
37         maRelatedParts = null;
38     }
39 
40 
41 
42 
getPartById(final String sId)43     public Part getPartById (final String sId)
44     {
45         final PartName aName = getRelatedParts().GetTargetForId(sId);
46         return new Part(
47             maPartManager.getContentTypes().getTypeForPartName(aName),
48             maPartManager,
49             aName);
50     }
51 
52 
53 
54 
getPartByRelationshipType(final RelationshipType eType)55     public Part getPartByRelationshipType (final RelationshipType eType)
56     {
57         final PartName aName = getRelatedParts().GetSingleTargetForType(eType);
58         return new Part(
59             maPartManager.getContentTypes().getTypeForPartName(aName),
60             maPartManager,
61             aName);
62     }
63 
64 
65 
66 
getPartName()67     public PartName getPartName ()
68     {
69         return maPartName;
70     }
71 
72 
73 
74 
getContentType()75     public ContentType getContentType ()
76     {
77         return meContentType;
78     }
79 
80 
81 
82 
getStream()83     public InputStream getStream()
84     {
85         return maPartManager.getStreamForPartName(maPartName);
86     }
87 
88 
89 
90 
91     @Override
getRelatedParts()92     public RelatedParts getRelatedParts ()
93     {
94         if (maRelatedParts == null)
95         {
96             maRelatedParts = new RelatedParts(
97                 maPartName,
98                 maPartManager);
99         }
100         return maRelatedParts;
101     }
102 
103 
104 
105 
106     private final ContentType meContentType;
107     private final PartManager maPartManager;
108     private final PartName maPartName;
109     private RelatedParts maRelatedParts;
110 }
111