/** returns a child request which is not a "context, paramSet, documentation or meta" element */ public FXRequest getSubRequest(int position) throws Exception // which kind { SafeNodeIterator nl = getChildNodes(); if (nl == null) { return null; } Node n = nl.next(); while (n != null) { if (n.getType() == Node.ELEMENT) { String tagname = ((Node) n).getName().getLocalPart(); NodeExtension ne = n.getNodeExtension(); if ((ne instanceof FXContextImpl) || (ne instanceof Import) || (ne instanceof DocumentationImpl) || (ne instanceof ParamSetImpl) || "context".equals(tagname)) { // skip the context, we already got it } else { if (--position == 0) { return (FXRequest) ne; } } } n = nl.next(); } return null; }
/** adds a new context frame, attaching any locally bound parameters */ public FXContext extendContext(FXContext parentContext) throws Exception { FXContext ctx = null; if (parentContext == null) { Name self = getNode().getName(); System.out.println("no context in " + self.getNamespace() + ":" + self.getLocalPart()); throw new Exception("null context in " + self.getNamespace() + ":" + self.getLocalPart()); } parentContext = parentContext.extend(); ctx = parentContext; ctx.setNode(this.getNode()); // first, we pick up attributes SafeNodeIterator atts = this.getNode().getAttributes(); // FIXME: do we really wanna always add attrs to context? // what about arbitrary, non-echo elements? if (atts != null) { Node n = atts.next(); while (n != null) { String attrName = n.getName().getLocalPart(); /// System.out.println("FXRequestServerSide:: extending context with : " + attrName); if (!attrName.equals("userID") && !attrName.startsWith("xmlns")) { if (!"{''}".equals(n.getData())) { // new behavior resolves attribute expressions during extend context ctx.put( n.getName().getLocalPart(), FXContextImpl.parseAttributeExpr(n.getData(), parentContext)); } else { ctx.put(n.getName().getLocalPart(), n.getData()); } } n = atts.next(); } } // process context and paramset children, in order SafeNodeIterator nl = this.getNode().getChildren(); Node n = nl.next(); while (n != null) { if (n.getType() == Node.ELEMENT) { // String tagname = ((Element) n).getTagName(); NodeExtension ne = n.getNodeExtension(); if (ne instanceof FXContext) { ctx = ((FXContextImpl) parentContext).extend((FXContext) ne); parentContext = ctx; } else if (ne instanceof Import) { ctx = ((Import) ne).getBindings(parentContext); parentContext = ctx; } else if (ne instanceof ParamSetImpl) { // stashDefaultParams((FXContextImpl) parentContext, // ((Element) // n).getElementsByTagNameNS(FXHome.NAMESPACE, // "param")); // stashDefaultParams((FXContextImpl) parentContext, // ((Element) // n).getElementsByTagNameNS("http://namespaces.snapbridge.com/xrap", // "param")); // stashDefaultParams((FXContextImpl) parentContext, // ((Element) // n).getElementsByTagNameNS(FXHome.NAMESPACE, // // "function")); // stashDefaultParams((FXContextImpl) parentContext, // ((Element) // n).getElementsByTagNameNS("http://namespaces.snapbridge.com/xrap", // // "function")); // // FIXME: we should deprecate non-namespaced params? // stashDefaultParams((FXContextImpl) parentContext, // ((Element) n).getElementsByTagName("param")); } } n = nl.next(); } parentContext.put("ctx:elementName", this.getTagName()); parentContext.put("ctx:commandName", this.getClass().getName()); SourceLocator loc = this.getNode(); // FIXME: location from node! this.getLocation(); if (loc != null) { parentContext.put("ctx:sysID", "" + loc.getSystemId()); parentContext.put("ctx:lineNo", "" + loc.getLineNumber()); parentContext.put("ctx:colNo", "" + loc.getColumnNumber()); } return parentContext; }
public void processChildren(ContentHandler responseTarget, FXContext context, boolean trim) throws Exception { SafeNodeIterator kids = getChildNodes(); char[] chars; Node n = kids.next(); while (n != null) { NodeExtension ne = n.getNodeExtension(); if (ne instanceof FXRequest) { if (!(ne instanceof FXContextImpl) && !(ne instanceof ParamSetImpl) && !(ne instanceof Import) && !(ne instanceof DocumentationImpl) && !(ne instanceof NullTransformImpl)) { FXRequest child = (FXRequest) ne; XMLReader reader = new NullDocEventXMLFilter(context, child); String uri = child.getURI(context); InputSource is = new InputSource(uri); reader.setContentHandler(responseTarget); reader.parse(is); } else { // we ignore these guys } } else { switch (n.getType()) { case Node.PROCESSING_INSTRUCTION: responseTarget.processingInstruction(n.getName().getLocalPart(), n.getData()); break; case Node.TEXT: chars = n.getData().toCharArray(); if (trim) { int cl = chars.length; int j = 0; for (; j < cl; ++j) { if (!Character.isWhitespace(chars[j])) { break; } } for (; j < cl; --cl) { if (!Character.isWhitespace(chars[cl - 1])) { responseTarget.characters(chars, j, cl - j); break; } } } else { responseTarget.characters(chars, 0, chars.length); } break; case Node.COMMENT: // if (responseTarget instanceof LexicalHandler) { chars = n.getData().toCharArray(); ((LexicalHandler) responseTarget).comment(chars, 0, chars.length); } break; default: throw new Exception("FX unable to process DOM node type"); } } n = kids.next(); } }