Example #1
0
  private void stashDefaultParams(FXContextImpl context, SafeNodeIterator nl) {

    Node n = nl.next();

    while (n != null) {

      String name = n.getAttributeValue(name("name"));
      if (name != null && name.length() > 0) {
        Object val = FXContextImpl.getParamBindingValue(n, context);
        context.putDefault(name, val);
      }
      n = nl.next();
    }
  }
Example #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);
    }
  }
Example #3
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;
  }