1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /* $Id: PDFElementMapping.java 1666117 2015-03-12 10:13:48Z ssteiner $ */
19 
20 package org.apache.fop.render.pdf.extensions;
21 
22 import org.apache.fop.fo.ElementMapping;
23 import org.apache.fop.fo.FONode;
24 
25 /**
26  * This class provides the element mapping for the PDF-specific extensions.
27  */
28 public class PDFElementMapping extends ElementMapping {
29 
30     /** Namespace for the extension */
31     public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/extensions/pdf";
32 
33     /** Main constructor */
PDFElementMapping()34     public PDFElementMapping() {
35         this.namespaceURI = NAMESPACE;
36     }
37 
38     /** {@inheritDoc} */
initialize()39     protected void initialize() {
40         if (foObjs == null) {
41             foObjs = new java.util.HashMap<String, Maker>();
42             // pdf:action
43             foObjs.put(PDFDictionaryType.Action.elementName(), new PDFActionElementMaker());
44             // pdf:array
45             foObjs.put(PDFObjectType.Array.elementName(), new PDFArrayElementMaker());
46             // pdf:boolean
47             foObjs.put(PDFObjectType.Boolean.elementName(), new PDFCollectionEntryElementMaker(PDFObjectType.Boolean));
48             // pdf:catalog
49             foObjs.put(PDFDictionaryType.Catalog.elementName(), new PDFCatalogElementMaker());
50             // pdf:dictionary
51             foObjs.put(PDFDictionaryType.Dictionary.elementName(), new PDFDictionaryElementMaker());
52             // pdf:embedded-file
53             foObjs.put(PDFEmbeddedFileElement.ELEMENT, new PDFEmbeddedFileElementMaker());
54             // pdf:name
55             foObjs.put(PDFObjectType.Name.elementName(), new PDFCollectionEntryElementMaker(PDFObjectType.Name));
56             // pdf:number
57             foObjs.put(PDFObjectType.Number.elementName(), new PDFCollectionEntryElementMaker(PDFObjectType.Number));
58             // pdf:navigator
59             foObjs.put(PDFDictionaryType.Navigator.elementName(), new PDFNavigatorElementMaker());
60             // pdf:layer
61             foObjs.put(PDFDictionaryType.Layer.elementName(), new PDFLayerElementMaker());
62             // pdf:page
63             foObjs.put(PDFDictionaryType.Page.elementName(), new PDFPageElementMaker());
64             // pdf:reference
65             foObjs.put(PDFObjectType.Reference.elementName(), new PDFReferenceElementMaker());
66             // pdf:string
67             foObjs.put(PDFObjectType.String.elementName(), new PDFCollectionEntryElementMaker(PDFObjectType.String));
68             // pdf:info
69             foObjs.put(PDFDictionaryType.Info.elementName(), new PDFDocumentInformationElementMaker());
70             // pdf:vt
71             foObjs.put(PDFDictionaryType.VT.elementName(), new PDFVTElementMaker());
72             // pdf:pagepiece
73             foObjs.put(PDFDictionaryType.PagePiece.elementName(), new PDFPagePieceElementMaker());
74         }
75     }
76 
77     static class PDFActionElementMaker extends ElementMapping.Maker {
make(FONode parent)78         public FONode make(FONode parent) {
79             return new PDFActionElement(parent);
80         }
81     }
82 
83     static class PDFArrayElementMaker extends ElementMapping.Maker {
make(FONode parent)84         public FONode make(FONode parent) {
85             return new PDFArrayElement(parent);
86         }
87     }
88 
89     static class PDFCatalogElementMaker extends ElementMapping.Maker {
make(FONode parent)90         public FONode make(FONode parent) {
91             return new PDFCatalogElement(parent);
92         }
93     }
94 
95     static class PDFDocumentInformationElementMaker extends ElementMapping.Maker {
make(FONode parent)96         public FONode make(FONode parent) {
97             return new PDFDocumentInformationElement(parent);
98         }
99     }
100 
101     static class PDFDictionaryElementMaker extends ElementMapping.Maker {
make(FONode parent)102         public FONode make(FONode parent) {
103             return new PDFDictionaryElement(parent, PDFDictionaryType.Dictionary);
104         }
105     }
106 
107     static class PDFEmbeddedFileElementMaker extends ElementMapping.Maker {
make(FONode parent)108         public FONode make(FONode parent) {
109             return new PDFEmbeddedFileElement(parent);
110         }
111     }
112 
113     static class PDFLayerElementMaker extends ElementMapping.Maker {
make(FONode parent)114         public FONode make(FONode parent) {
115             return new PDFLayerElement(parent);
116         }
117     }
118 
119     static class PDFNavigatorElementMaker extends ElementMapping.Maker {
make(FONode parent)120         public FONode make(FONode parent) {
121             return new PDFNavigatorElement(parent);
122         }
123     }
124 
125     static class PDFPageElementMaker extends ElementMapping.Maker {
make(FONode parent)126         public FONode make(FONode parent) {
127             return new PDFPageElement(parent);
128         }
129     }
130 
131     static class PDFCollectionEntryElementMaker extends ElementMapping.Maker {
132         private PDFObjectType entryType;
PDFCollectionEntryElementMaker(PDFObjectType entryType)133         PDFCollectionEntryElementMaker(PDFObjectType entryType) {
134             this.entryType = entryType;
135         }
make(FONode parent)136         public FONode make(FONode parent) {
137             return new PDFCollectionEntryElement(parent, entryType);
138         }
139     }
140 
141     static class PDFReferenceElementMaker extends ElementMapping.Maker {
make(FONode parent)142         public FONode make(FONode parent) {
143             return new PDFReferenceElement(parent);
144         }
145     }
146 
147     static class PDFVTElementMaker extends ElementMapping.Maker {
make(FONode parent)148         public FONode make(FONode parent) {
149             return new PDFVTElement(parent);
150         }
151     }
152 
153     static class PDFPagePieceElementMaker extends ElementMapping.Maker {
make(FONode parent)154         public FONode make(FONode parent) {
155             return new PDFPagePieceElement(parent);
156         }
157     }
158 }
159