--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id: AbstractPSExtensionObject.java 426576 2006-07-28 15:44:37Z jeremias $ */\r
+ \r
+package org.apache.fop.render.ps.extensions;\r
+\r
+// FOP\r
+import org.apache.fop.apps.FOPException;\r
+import org.apache.fop.fo.FONode;\r
+import org.apache.fop.fo.PropertyList;\r
+import org.apache.fop.fo.ValidationException;\r
+import org.apache.fop.fo.extensions.ExtensionAttachment;\r
+\r
+import org.xml.sax.Locator;\r
+\r
+/**\r
+ * Base class for the PostScript-specific extension elements.\r
+ */\r
+public abstract class AbstractPSExtensionElement extends FONode {\r
+\r
+ /**\r
+ * extension attachment\r
+ */\r
+ protected PSExtensionAttachment attachment;\r
+ \r
+ /**\r
+ * Default constructor\r
+ * \r
+ * @param parent parent of this node\r
+ * @see org.apache.fop.fo.FONode#FONode(FONode)\r
+ */\r
+ public AbstractPSExtensionElement(FONode parent) {\r
+ super(parent);\r
+ }\r
+\r
+ /**\r
+ * Blocks XSL FO's from having non-FO parents.\r
+ * \r
+ * @param loc location in the FO source file\r
+ * @param nsURI namespace of incoming node\r
+ * @param localName (e.g. "table" for "fo:table")\r
+ * @throws ValidationException if incoming node not valid for parent\r
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)\r
+ */\r
+ protected void validateChildNode(Locator loc, String nsURI, String localName) \r
+ throws ValidationException {\r
+ if (FO_URI.equals(nsURI)) {\r
+ invalidChildError(loc, nsURI, localName);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Adds characters (does nothing here)\r
+ * @param data array of characters containing text to be added\r
+ * @param start starting array element to add\r
+ * @param length of data array to add\r
+ * @param pList currently applicable PropertyList \r
+ * @param locator location in fo source file.\r
+ * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, PropertyList, Locator)\r
+ */\r
+ protected void addCharacters(char[] data, int start, int length,\r
+ PropertyList pList, Locator locator) {\r
+ PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment();\r
+ if (a.getContent() != null) {\r
+ StringBuffer sb = new StringBuffer(a.getContent());\r
+ sb.append(data, start, length - start);\r
+ a.setContent(sb.toString());\r
+ } else {\r
+ a.setContent(new String(data, start, length - start));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @return a String representation of this object\r
+ * @see org.apache.fop.fo.FONode#getNamespaceURI()\r
+ */\r
+ public String getNamespaceURI() {\r
+ return PSExtensionElementMapping.NAMESPACE;\r
+ }\r
+ \r
+ /**\r
+ * @return a String representation of this object\r
+ * @see org.apache.fop.fo.FONode#getNormalNamespacePrefix()\r
+ */\r
+ public String getNormalNamespacePrefix() {\r
+ return "fox";\r
+ }\r
+\r
+ /**\r
+ * @see org.apache.fop.fo.FONode#endOfNode()\r
+ * @throws FOPException if there's a problem during processing\r
+ */\r
+ protected void endOfNode() throws FOPException {\r
+ super.endOfNode();\r
+ String s = ((PSExtensionAttachment)getExtensionAttachment()).getContent();\r
+ if (s == null || s.length() == 0) {\r
+ missingChildElementError("#PCDATA");\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * @return the extension attachment if one is created by the extension element, null otherwise.\r
+ * @see org.apache.fop.fo.FONode#getExtensionAttachment()\r
+ */\r
+ public ExtensionAttachment getExtensionAttachment() {\r
+ if (attachment == null) {\r
+ this.attachment = (PSExtensionAttachment)instantiateExtensionAttachment();\r
+ }\r
+ return this.attachment;\r
+ }\r
+ \r
+ /**\r
+ * Instantiates extension attachment object\r
+ * @return extension attachment\r
+ */\r
+ protected abstract ExtensionAttachment instantiateExtensionAttachment();\r
+}\r
+\r