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: PSSetPageDeviceElement.java 1466146 2013-04-09 17:31:41Z vhennebert $ */
19 
20 package org.apache.fop.render.ps.extensions;
21 
22 import org.xml.sax.Attributes;
23 import org.xml.sax.Locator;
24 
25 import org.apache.fop.apps.FOPException;
26 import org.apache.fop.fo.Constants;
27 import org.apache.fop.fo.FONode;
28 import org.apache.fop.fo.PropertyList;
29 import org.apache.fop.fo.extensions.ExtensionAttachment;
30 
31 /**
32  * Extension element for ps:ps-setpagedevice.
33  */
34 public class PSSetPageDeviceElement extends AbstractPSExtensionElement {
35 
36     /** The element name */
37     protected static final String ELEMENT = "ps-setpagedevice";
38 
39     /**
40      * Main constructor
41      * @param parent parent FO node
42      */
PSSetPageDeviceElement(FONode parent)43     protected PSSetPageDeviceElement(FONode parent) {
44         super(parent);
45     }
46 
47     /**
48      * Called after processNode() is called. Subclasses can do additional processing.
49      * @throws FOPException if there's a problem during processing
50      * @see org.apache.fop.fo.FONode#startOfNode()
51      */
startOfNode()52     public void startOfNode() throws FOPException {
53         super.startOfNode();
54         if (!((parent.getNameId() == Constants.FO_DECLARATIONS)
55                 || (parent.getNameId() == Constants.FO_SIMPLE_PAGE_MASTER))) {
56             invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
57                     "rule.childOfSPMorDeclarations");
58         }
59     }
60 
61     /**
62      * Initialize the node with its name, location information, and attributes
63      * The attributes must be used immediately as the sax attributes
64      * will be altered for the next element.
65      * @param elementName element name (e.g., "fo:block")
66      * @param locator Locator object (ignored by default)
67      * @param attlist Collection of attributes passed to us from the parser.
68      * @param propertyList property list
69      * @throws FOPException if there's a problem during processing
70      * @see org.apache.fop.fo.FONode#processNode
71      */
processNode(String elementName, Locator locator, Attributes attlist, PropertyList propertyList)72     public void processNode(String elementName, Locator locator,
73                             Attributes attlist, PropertyList propertyList)
74                                 throws FOPException {
75         String name = attlist.getValue("name");
76         if (name != null && name.length() > 0) {
77             ((PSSetPageDevice)getExtensionAttachment()).setName(name);
78         }
79     }
80 
81     /**
82      * @return local name
83      * @see org.apache.fop.fo.FONode#getLocalName() */
getLocalName()84     public String getLocalName() {
85         return ELEMENT;
86     }
87 
88     /**
89      * @return a new PSSetPageDevice object
90      * @see org.apache.fop.render.ps.extensions.AbstractPSExtensionElement
91      * #instantiateExtensionAttachment()
92      */
instantiateExtensionAttachment()93     protected ExtensionAttachment instantiateExtensionAttachment() {
94         return new PSSetPageDevice();
95     }
96 }
97