KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > contents > xObjects > XObject


1 /*
2   Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright © 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.documents.contents.xObjects;
28
29 import it.stefanochizzolini.clown.documents.Document;
30 import it.stefanochizzolini.clown.objects.PdfDirectObject;
31 import it.stefanochizzolini.clown.objects.PdfName;
32 import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
33 import it.stefanochizzolini.clown.objects.PdfReference;
34 import it.stefanochizzolini.clown.objects.PdfStream;
35
36 /**
37   Abstract external object [PDF:1.6:4.7].
38 */

39 public abstract class XObject
40   extends PdfObjectWrapper<PdfStream>
41 {
42   // <class>
43
// <static>
44
// <interface>
45
// <public>
46
/**
47     Wraps an external object reference into an external object.
48     @param reference Reference to an external object.
49     @return External object associated to the reference.
50   */

51   public static XObject wrap(
52     PdfReference reference
53     )
54   {
55     /*
56       NOTE: This is a factory method for any xobject-derived object.
57     */

58     if(reference == null)
59       return null;
60
61     PdfName subtype = (PdfName)((PdfStream)reference.getDataObject()).getHeader().get(PdfName.Subtype);
62     if(subtype.equals(PdfName.Form))
63       return new FormXObject(reference);
64     else if(subtype.equals(PdfName.Image))
65       return new ImageXObject(reference);
66     else
67       return null;
68   }
69   // </public>
70
// </interface>
71
// </static>
72

73   // <dynamic>
74
// <constructors>
75
/**
76     Creates a new external object inside the document.
77   */

78   protected XObject(
79     Document context
80     )
81   {
82     this(
83       context,
84       new PdfStream()
85       );
86   }
87
88   /**
89     Creates a new external object inside the document.
90   */

91   protected XObject(
92     Document context,
93     PdfStream baseDataObject
94     )
95   {
96     super(
97       context.getFile(),
98       baseDataObject
99       );
100
101     baseDataObject.getHeader().put(PdfName.Type,PdfName.XObject);
102   }
103
104   /**
105     Instantiates an existing external object.
106   */

107   protected XObject(
108     PdfDirectObject baseObject
109     )
110   {
111     super(
112       baseObject,
113       null // NO container (baseObject is (by definition) a PDF stream, so it MUST be an indirect object [PDF:1.6:3.2.7]).
114
);
115   }
116   // </constructors>
117
// </dynamic>
118
// </class>
119
}
Popular Tags