001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: AbstractPSExtensionObject.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.ps.extensions;
021:
022: // FOP
023: import org.apache.fop.apps.FOPException;
024: import org.apache.fop.fo.FONode;
025: import org.apache.fop.fo.PropertyList;
026: import org.apache.fop.fo.ValidationException;
027: import org.apache.fop.fo.extensions.ExtensionAttachment;
028: import org.xml.sax.Attributes;
029: import org.xml.sax.Locator;
030:
031: /**
032: * Base class for the PostScript-specific extension elements.
033: */
034: public abstract class AbstractPSExtensionObject extends FONode {
035:
036: private PSSetupCode setupCode = new PSSetupCode();
037:
038: /**
039: * @see org.apache.fop.fo.FONode#FONode(FONode)
040: */
041: public AbstractPSExtensionObject(FONode parent) {
042: super (parent);
043: }
044:
045: /**
046: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
047: * here, blocks XSL FO's from having non-FO parents.
048: */
049: protected void validateChildNode(Locator loc, String nsURI,
050: String localName) throws ValidationException {
051: if (FO_URI.equals(nsURI)) {
052: invalidChildError(loc, nsURI, localName);
053: }
054: }
055:
056: /** @see org.apache.fop.fo.FONode */
057: protected void addCharacters(char[] data, int start, int length,
058: PropertyList pList, Locator locator) {
059: if (setupCode.getContent() != null) {
060: StringBuffer sb = new StringBuffer(setupCode.getContent());
061: sb.append(data, start, length - start);
062: setupCode.setContent(sb.toString());
063: } else {
064: setupCode
065: .setContent(new String(data, start, length - start));
066: }
067: }
068:
069: /** @see org.apache.fop.fo.FONode#getNamespaceURI() */
070: public String getNamespaceURI() {
071: return PSExtensionElementMapping.NAMESPACE;
072: }
073:
074: /**@see org.apache.fop.fo.FONode#getNormalNamespacePrefix() */
075: public String getNormalNamespacePrefix() {
076: return "fox";
077: }
078:
079: /** @see org.apache.fop.fo.FONode#processNode */
080: public void processNode(String elementName, Locator locator,
081: Attributes attlist, PropertyList propertyList)
082: throws FOPException {
083: String name = attlist.getValue("name");
084: if (name != null && name.length() > 0) {
085: setupCode.setName(name);
086: }
087: }
088:
089: /** @see org.apache.fop.fo.FONode#endOfNode() */
090: protected void endOfNode() throws FOPException {
091: super .endOfNode();
092: String s = setupCode.getContent();
093: if (s == null || s.length() == 0) {
094: missingChildElementError("#PCDATA");
095: }
096: }
097:
098: /** @see org.apache.fop.fo.FONode#getExtensionAttachment() */
099: public ExtensionAttachment getExtensionAttachment() {
100: return this.setupCode;
101: }
102:
103: }
|