示例#1
0
  /** 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;
  }
示例#2
0
  /** copy the element, and contents to the result */
  protected void evalCopy(ContentHandler responseTarget, FXContext context) throws Exception {

    //           System.out.println("FXRequestServerSide::evalCopy()");

    context = extendContext(context);
    if (context == null) {
      throw new Exception("null context");
    }
    try {

      // copy the attributes
      AttributesImpl atts = new AttributesImpl();

      //            NamedNodeMap attsList = getAttributes();

      SafeNodeIterator ni = getNode().getAttributes();

      for (; ; ) {
        Node att = ni.next();
        if (att == null) {
          break;
        }
        Name attName = att.getName();
        String attNS = attName.getNamespace();
        if (attNS == null) {
          attNS = "";
        }

        String localName = attName.getLocalPart();
        String anp = attName.getPrefix();
        String qname = anp == null ? localName : (anp + ":" + localName);
        if (localName == null) {
          localName = qname;
        }
        String val = att.getData();
        try {
          // FIXME: do not do unless needed
          if (val.indexOf('{') >= 0) {
            val = FXContextImpl.parseAttributeExpr(val, (FXContextImpl) context);
            //
            //                        Expression exp =
            //                            XRExp.parseExpr(new StringReader((String)val));
            //                        StringWriter sw = new StringWriter();
            //                        exp.eval(context, sw);
            //                        val = sw.toString();
          }
        } catch (Throwable ex) {
          ex.printStackTrace();
          val =
              "** expression error: "
                  + // ex.getMessage() +
                  "in ["
                  + val
                  + "] **";
        }

        atts.addAttribute(attNS, localName, qname, "CDATA", val);
      }

      String nsURI = getNamespaceURI();
      if (nsURI == null) {
        nsURI = "";
      }

      String tagName = getTagName();
      String localName = getNode().getName().getLocalPart(); // getLocalName();

      evalBody(responseTarget, context, nsURI, localName, tagName, atts);

    } catch (Exception ex) {
      ex.printStackTrace();
      errorResponse(ex, responseTarget, context);
    }
  }
示例#3
0
  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();
    }
  }