예제 #1
0
    /** {@inheritDoc} */
    public void startElement(
        String namespaceURI, String localName, String rawName, Attributes attlist)
        throws SAXException {

      /* the node found in the FO document */
      FONode foNode;
      PropertyList propertyList = null;

      // Check to ensure first node encountered is an fo:root
      if (rootFObj == null) {
        empty = false;
        if (!namespaceURI.equals(FOElementMapping.URI) || !localName.equals("root")) {
          FOValidationEventProducer eventProducer =
              FOValidationEventProducer.Provider.get(userAgent.getEventBroadcaster());
          eventProducer.invalidFORoot(
              this, FONode.getNodeString(namespaceURI, localName), getEffectiveLocator());
        }
      } else { // check that incoming node is valid for currentFObj
        if (currentFObj.getNamespaceURI().equals(FOElementMapping.URI)
            || currentFObj.getNamespaceURI().equals(ExtensionElementMapping.URI)) {
          currentFObj.validateChildNode(locator, namespaceURI, localName);
        }
      }

      ElementMapping.Maker fobjMaker = findFOMaker(namespaceURI, localName);

      try {
        foNode = fobjMaker.make(currentFObj);
        if (rootFObj == null) {
          rootFObj = (Root) foNode;
          rootFObj.setBuilderContext(builderContext);
          rootFObj.setFOEventHandler(foEventHandler);
        }
        propertyList = foNode.createPropertyList(currentPropertyList, foEventHandler);
        foNode.processNode(localName, getEffectiveLocator(), attlist, propertyList);
        if (foNode.getNameId() == Constants.FO_MARKER) {
          if (builderContext.inMarker()) {
            nestedMarkerDepth++;
          } else {
            builderContext.switchMarkerContext(true);
          }
        }
        if (foNode.getNameId() == Constants.FO_PAGE_SEQUENCE) {
          builderContext.getXMLWhiteSpaceHandler().reset();
        }
      } catch (IllegalArgumentException e) {
        throw new SAXException(e);
      }

      ContentHandlerFactory chFactory = foNode.getContentHandlerFactory();
      if (chFactory != null) {
        ContentHandler subHandler = chFactory.createContentHandler();
        if (subHandler instanceof ObjectSource && foNode instanceof ObjectBuiltListener) {
          ((ObjectSource) subHandler).setObjectBuiltListener((ObjectBuiltListener) foNode);
        }

        subHandler.startDocument();
        subHandler.startElement(namespaceURI, localName, rawName, attlist);
        depth = 1;
        delegate = subHandler;
      }

      if (currentFObj != null) {
        currentFObj.addChildNode(foNode);
      }

      currentFObj = foNode;
      if (propertyList != null && !builderContext.inMarker()) {
        currentPropertyList = propertyList;
      }

      // fo:characters can potentially be removed during
      // white-space handling.
      // Do not notify the FOEventHandler.
      if (currentFObj.getNameId() != Constants.FO_CHARACTER) {
        currentFObj.startOfNode();
      }
    }