You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Domagoj Cosic <Do...@hypercis.de> on 2000/09/21 16:34:52 UTC

Solution for broken FOTree building from DOM Document

FOTree building from DOM Document is currently really broken, as some people
already reported. The reason is the changed namespace handling in the new
FOP. I have tried to find a solution which would only cause changes
inorg.apache.fop.apps.Driver but I had to modify
org.apache.fop.fo.FOTreeBuilder also. Currently neither attribute name or
namespace nor element name or namespace are set correctly. I used the
special value for uri, null, to transport the information to the
FOTreeBuilder that the Driver cannot resolve the namespace URI in that case.
To do so, Driver would have to either have an own stack of namespaces, or,
alternatively, findURI in the FOTreeBuilder should be public. I chose the
way to leave URI resolution to FOTreeBuilder completely, as there is the
Namespace-Stack.

In org.apache.fop.apps.Driver change the method buildFOTree(Document
document):

 /**
  * build the formatting object tree using the given DOM Document
  */
 public void buildFOTree(Document document) 
 throws FOPException {

... omitted

  case Node.ELEMENT_NODE:
      NamedNodeMap map = currentNode.getAttributes();
      currentAtts.clear();
      for (int i = map.getLength() - 1; i >= 0; i--) {
   Attr att = (Attr)map.item(i);
   String rawName = att.getName();
   int prefixIndex = rawName.indexOf(':');
   String localName = rawName.substring(prefixIndex + 1);
   currentAtts.addAttribute("",
       localName,
       rawName,
       "CDATA",
       att.getValue());
      }
      
   String rawName = currentNode.getNodeName();
   String localName = rawName.substring(rawName.indexOf(':') + 1);
      this.treeBuilder.startElement(
   null, localName, rawName, currentAtts);
      break;
  }
  
... omitted

 }



In org.apache.fop.fo.FOTreeBuilder change the method startElement:

	/** SAX Handler for the start of an element */
	public void startElement(String uri,
		String localName, String rawName, Attributes attlist)
	throws SAXException { 

... omitted

	String fullName = mapName(rawName);

	fobjMaker = (FObj.Maker) fobjTable.get(fullName);
	if (uri == null) {
		int prefixIndex = rawName.indexOf(':');
		String prefix = rawName.substring(0, prefixIndex >= 0 ?
prefixIndex : 0);
		uri = findURI(prefix);
	}
	PropertyListBuilder plBuilder =
(PropertyListBuilder)this.propertylistTable.get(uri);

... omitted

	}





Regards, Domagoj

Dr. Domagoj Cosic
hyperCIS AG, Am Köllnischen Park 1, D-10179 Berlin
Tel.:+49-30-22337012   Fax.: +49-30-22337001
e-Mail: Domagoj.Cosic@HyperCIS.de