/** For internal use only. */
 private static Object makeDerivedWrapper(Element elt, String baseTypeName) {
   synchronized (DOMUtils.getDOMLock(elt)) {
     QName typeName = XArchUtils.getXSIType(elt);
     if (typeName == null) {
       return null;
     } else {
       if (!DOMUtils.hasXSIType(
           elt, "http://www.ics.uci.edu/pub/arch/xArch/changesets.xsd", baseTypeName)) {
         try {
           String packageTitle = XArchUtils.getPackageTitle(typeName.getNamespaceURI());
           String packageName = XArchUtils.getPackageName(packageTitle);
           String implName = XArchUtils.getImplName(packageName, typeName.getName());
           Class c = Class.forName(implName);
           java.lang.reflect.Constructor con = c.getConstructor(new Class[] {Element.class});
           Object o = con.newInstance(new Object[] {elt});
           return o;
         } catch (Exception e) {
           // Lots of bad things could happen, but this
           // is OK, because this is best-effort anyway.
         }
       }
       return null;
     }
   }
 }
  /**
   * Type check a call to a standard function. Insert CastExprs when needed. If as a result of the
   * insertion of a CastExpr a type check error is thrown, then catch it and re-throw it with a new
   * "this".
   */
  public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
    _fname.clearNamespace(); // HACK!!!

    final int n = _arguments.size();
    final Vector argsType = typeCheckArgs(stable);
    final MethodType args = new MethodType(Type.Void, argsType);
    final MethodType ptype = lookupPrimop(stable, _fname.getLocalPart(), args);

    if (ptype != null) {
      for (int i = 0; i < n; i++) {
        final Type argType = (Type) ptype.argsType().elementAt(i);
        final Expression exp = (Expression) _arguments.elementAt(i);
        if (!argType.identicalTo(exp.getType())) {
          try {
            _arguments.setElementAt(new CastExpr(exp, argType), i);
          } catch (TypeCheckError e) {
            throw new TypeCheckError(this); // invalid conversion
          }
        }
      }
      _chosenMethodType = ptype;
      return _type = ptype.resultType();
    }
    throw new TypeCheckError(this);
  }
Exemplo n.º 3
0
  XmlNode.QName toNodeQName(Context cx, Object namespaceValue, Object nameValue) {
    // This is duplication of constructQName(cx, namespaceValue, nameValue)
    // but for XMLName

    String localName;

    if (nameValue instanceof QName) {
      QName qname = (QName) nameValue;
      localName = qname.localName();
    } else {
      localName = ScriptRuntime.toString(nameValue);
    }

    XmlNode.Namespace ns;
    if (namespaceValue == Undefined.instance) {
      if ("*".equals(localName)) {
        ns = null;
      } else {
        ns = getDefaultNamespace(cx).getDelegate();
      }
    } else if (namespaceValue == null) {
      ns = null;
    } else if (namespaceValue instanceof Namespace) {
      ns = ((Namespace) namespaceValue).getDelegate();
    } else {
      ns = this.namespacePrototype.constructNamespace(namespaceValue).getDelegate();
    }

    if (localName != null && localName.equals("*")) localName = null;
    return XmlNode.QName.create(ns, localName);
  }
 /*    */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) /*    */ {
   /* 88 */ ConstantPoolGen cpg = classGen.getConstantPool();
   /* 89 */ InstructionList il = methodGen.getInstructionList();
   /* 90 */ SymbolTable symbolTable = getParser().getSymbolTable();
   /*    */
   /* 93 */ for (int i = 0; i < this._sets.size(); i++)
   /*    */ {
     /* 95 */ QName name = (QName) this._sets.elementAt(i);
     /*    */
     /* 97 */ AttributeSet attrs = symbolTable.lookupAttributeSet(name);
     /*    */
     /* 99 */ if (attrs != null) {
       /* 100 */ String methodName = attrs.getMethodName();
       /* 101 */ il.append(classGen.loadTranslet());
       /* 102 */ il.append(methodGen.loadDOM());
       /* 103 */ il.append(methodGen.loadIterator());
       /* 104 */ il.append(methodGen.loadHandler());
       /* 105 */ il.append(methodGen.loadCurrentNode());
       /* 106 */ int method =
           cpg.addMethodref(
               classGen.getClassName(),
               methodName,
               "(Lcom/sun/org/apache/xalan/internal/xsltc/DOM;Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;I)V");
       /*    */
       /* 108 */ il.append(new INVOKESPECIAL(method));
       /*    */ }
     /*    */ else
     /*    */ {
       /* 112 */ Parser parser = getParser();
       /* 113 */ String atrs = name.toString();
       /* 114 */ reportError(this, parser, "ATTRIBSET_UNDEF_ERR", atrs);
       /*    */ }
     /*    */ }
   /*    */ }
Exemplo n.º 5
0
 static QName create(Namespace namespace, String localName) {
   //    A null namespace indicates a wild-card match for any namespace
   //    A null localName indicates "*" from the point of view of ECMA357
   if (localName != null && localName.equals("*"))
     throw new RuntimeException("* is not valid localName");
   QName rv = new QName();
   rv.namespace = namespace;
   rv.localName = localName;
   return rv;
 }
Exemplo n.º 6
0
  /**
   * If value represents Uint32 index, make it available through ScriptRuntime.lastUint32Result(cx)
   * and return null. Otherwise return the same value as toXMLName(cx, value).
   */
  XMLName toXMLNameOrIndex(Context cx, Object value) {
    XMLName result;

    if (value instanceof XMLName) {
      result = (XMLName) value;
    } else if (value instanceof String) {
      String str = (String) value;
      long test = ScriptRuntime.testUint32String(str);
      if (test >= 0) {
        ScriptRuntime.storeUint32Result(cx, test);
        result = null;
      } else {
        result = toXMLNameFromString(cx, str);
      }
    } else if (value instanceof Number) {
      double d = ((Number) value).doubleValue();
      long l = (long) d;
      if (l == d && 0 <= l && l <= 0xFFFFFFFFL) {
        ScriptRuntime.storeUint32Result(cx, l);
        result = null;
      } else {
        throw badXMLName(value);
      }
    } else if (value instanceof QName) {
      QName qname = (QName) value;
      String uri = qname.uri();
      boolean number = false;
      result = null;
      if (uri != null && uri.length() == 0) {
        // Only in this case qname.toString() can resemble uint32
        long test = ScriptRuntime.testUint32String(uri);
        if (test >= 0) {
          ScriptRuntime.storeUint32Result(cx, test);
          number = true;
        }
      }
      if (!number) {
        result = XMLName.formProperty(uri, qname.localName());
      }
    } else if (value instanceof Boolean || value == Undefined.instance || value == null) {
      throw badXMLName(value);
    } else {
      String str = ScriptRuntime.toString(value);
      long test = ScriptRuntime.testUint32String(str);
      if (test >= 0) {
        ScriptRuntime.storeUint32Result(cx, test);
        result = null;
      } else {
        result = toXMLNameFromString(cx, str);
      }
    }

    return result;
  }
Exemplo n.º 7
0
 /**
  * Registers an element and gives it a type so that it can be mapped to DOM element types at
  * run-time.
  */
 public int registerElement(QName name) {
   // Register element (full QName)
   Integer code = (Integer) _elements.get(name.toString());
   if (code == null) {
     _elements.put(name.toString(), code = new Integer(_nextGType++));
     _namesIndex.addElement(name.toString());
   }
   if (name.getLocalPart().equals("*")) {
     registerNamespace(name.getNamespace());
   }
   return code.intValue();
 }
Exemplo n.º 8
0
  private void exportToScope(boolean sealed) {
    xmlPrototype = newXML(XmlNode.createText(options, ""));
    xmlListPrototype = newXMLList();
    namespacePrototype = Namespace.create(this.globalScope, null, XmlNode.Namespace.GLOBAL);
    qnamePrototype =
        QName.create(
            this, this.globalScope, null, XmlNode.QName.create(XmlNode.Namespace.create(""), ""));

    xmlPrototype.exportAsJSClass(sealed);
    xmlListPrototype.exportAsJSClass(sealed);
    namespacePrototype.exportAsJSClass(sealed);
    qnamePrototype.exportAsJSClass(sealed);
  }
Exemplo n.º 9
0
 void invalidateNamespacePrefix() {
   if (!(dom instanceof Element)) throw new IllegalStateException();
   String prefix = this.dom.getPrefix();
   QName after = QName.create(this.dom.getNamespaceURI(), this.dom.getLocalName(), null);
   renameNode(after);
   NamedNodeMap attrs = this.dom.getAttributes();
   for (int i = 0; i < attrs.getLength(); i++) {
     if (attrs.item(i).getPrefix().equals(prefix)) {
       createImpl(attrs.item(i))
           .renameNode(
               QName.create(attrs.item(i).getNamespaceURI(), attrs.item(i).getLocalName(), null));
     }
   }
 }
Exemplo n.º 10
0
  /**
   * Registers a namespace prefix and gives it a type so that it can be mapped to DOM namespace
   * types at run-time.
   */
  public int registerNamespacePrefix(QName name) {

    Integer code = (Integer) _namespacePrefixes.get(name.toString());
    if (code == null) {
      code = new Integer(_nextGType++);
      _namespacePrefixes.put(name.toString(), code);
      final String uri = name.getNamespace();
      if ((uri != null) && (!uri.equals(""))) {
        // namespace::ext2:ped2 will be made empty in TypedNamespaceIterator
        _namesIndex.addElement("?");
      } else {
        _namesIndex.addElement("?" + name.getLocalPart());
      }
    }
    return code.intValue();
  }
 /** Translate code to call the BasisLibrary.unallowed_extensionF(String) method. */
 private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) {
   int index =
       cpg.addMethodref(
           BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V");
   il.append(new PUSH(cpg, _fname.toString()));
   il.append(new INVOKESTATIC(index));
 }
  /**
   * Returns a vector with all constructors named <code>_fname</code> after stripping its namespace
   * or <code>null</code> if no such methods exist.
   */
  private Vector findConstructors() {
    Vector result = null;
    final String namespace = _fname.getNamespace();

    final int nArgs = _arguments.size();
    try {
      if (_clazz == null) {
        _clazz = ObjectFactory.findProviderClass(_className, ObjectFactory.findClassLoader(), true);

        if (_clazz == null) {
          final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
          getParser().reportError(Constants.ERROR, msg);
        }
      }

      final Constructor[] constructors = _clazz.getConstructors();

      for (int i = 0; i < constructors.length; i++) {
        final int mods = constructors[i].getModifiers();
        // Is it public, static and same number of args ?
        if (Modifier.isPublic(mods) && constructors[i].getParameterTypes().length == nArgs) {
          if (result == null) {
            result = new Vector();
          }
          result.addElement(constructors[i]);
        }
      }
    } catch (ClassNotFoundException e) {
      final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
      getParser().reportError(Constants.ERROR, msg);
    }

    return result;
  }
Exemplo n.º 13
0
 final void setLocalName(String localName) {
   if (dom instanceof ProcessingInstruction) {
     setProcessingInstructionName(localName);
   } else {
     String prefix = dom.getPrefix();
     if (prefix == null) prefix = "";
     this.dom =
         dom.getOwnerDocument()
             .renameNode(dom, dom.getNamespaceURI(), QName.qualify(prefix, localName));
   }
 }
Exemplo n.º 14
0
 /*
    TODO: Too general; this should be split into overloaded methods.
    Is that possible?
 */
 XmlNode.QName toNodeQName(Context cx, Object nameValue, boolean attribute) {
   if (nameValue instanceof XMLName) {
     return ((XMLName) nameValue).toQname();
   } else if (nameValue instanceof QName) {
     QName qname = (QName) nameValue;
     return qname.getDelegate();
   } else if (nameValue instanceof Boolean
       || nameValue instanceof Number
       || nameValue == Undefined.instance
       || nameValue == null) {
     throw badXMLName(nameValue);
   } else {
     String local = null;
     if (nameValue instanceof String) {
       local = (String) nameValue;
     } else {
       local = ScriptRuntime.toString(nameValue);
     }
     return toNodeQName(cx, local, attribute);
   }
 }
Exemplo n.º 15
0
  /* TODO: Marked deprecated by original author */
  XMLName toXMLName(Context cx, Object nameValue) {
    XMLName result;

    if (nameValue instanceof XMLName) {
      result = (XMLName) nameValue;
    } else if (nameValue instanceof QName) {
      QName qname = (QName) nameValue;
      result = XMLName.formProperty(qname.uri(), qname.localName());
    } else if (nameValue instanceof String) {
      result = toXMLNameFromString(cx, (String) nameValue);
    } else if (nameValue instanceof Boolean
        || nameValue instanceof Number
        || nameValue == Undefined.instance
        || nameValue == null) {
      throw badXMLName(nameValue);
    } else {
      String name = ScriptRuntime.toString(nameValue);
      result = toXMLNameFromString(cx, name);
    }

    return result;
  }
  /** Return the signature of the current method */
  private String getMethodSignature(Vector argsType) {
    final StringBuffer buf = new StringBuffer(_className);
    buf.append('.').append(_fname.getLocalPart()).append('(');

    int nArgs = argsType.size();
    for (int i = 0; i < nArgs; i++) {
      final Type intType = (Type) argsType.elementAt(i);
      buf.append(intType.toString());
      if (i < nArgs - 1) buf.append(", ");
    }

    buf.append(')');
    return buf.toString();
  }
Exemplo n.º 17
0
 /**
  * Registers an attribute and gives it a type so that it can be mapped to DOM attribute types at
  * run-time.
  */
 public int registerAttribute(QName name) {
   Integer code = (Integer) _attributes.get(name.toString());
   if (code == null) {
     code = new Integer(_nextGType++);
     _attributes.put(name.toString(), code);
     final String uri = name.getNamespace();
     final String local = "@" + name.getLocalPart();
     if ((uri != null) && (!uri.equals(""))) _namesIndex.addElement(uri + ":" + local);
     else _namesIndex.addElement(local);
     if (name.getLocalPart().equals("*")) {
       registerNamespace(name.getNamespace());
     }
   }
   return code.intValue();
 }
Exemplo n.º 18
0
  /** Parse the name of the <xsl:decimal-formatting/> element */
  public void parseContents(Parser parser) {
    // Get the name of these decimal formatting symbols
    final String name = getAttribute("name");
    if (name.length() > 0) {
      if (!XML11Char.isXML11ValidQName(name)) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
        parser.reportError(Constants.ERROR, err);
      }
    }
    _name = parser.getQNameIgnoreDefaultNs(name);
    if (_name == null) {
      _name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING);
    }

    // Check if a set of symbols has already been registered under this name
    SymbolTable stable = parser.getSymbolTable();
    if (stable.getDecimalFormatting(_name) != null) {
      reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR, _name.toString());
    } else {
      stable.addDecimalFormatting(_name, this);
    }
  }
Exemplo n.º 19
0
 @Override
 public String getMessage() {
   String id = fieldName != null ? fieldName.toString() : fieldId;
   return "Field <" + id + "> could not be found.";
 }
  /**
   * Find a type object in the context of the class.
   *
   * @param name The name to search for.
   */
  public Named find(Matcher<Named> matcher, Context context) throws SemanticException {
    Name name = matcher.name();

    if (Report.should_report(TOPICS, 2)) Report.report(2, "Looking for " + name + " in " + this);

    if (!(type instanceof ClassType)) {
      throw new NoClassException(name.toString(), type);
    }

    ClassType type = (ClassType) this.type;

    Named m = null;

    QName fullName = null;
    QName rawName = null;

    if (type.isGloballyAccessible()) {
      fullName = QName.make(type.fullName(), name);
      QName q = ts.getTransformedClassName(type.def());
      rawName = QName.make(q.qualifier(), Name.make(q.name() + "$" + name));
    }

    if (fullName != null) {
      // First check the system resolver.
      m = ts.systemResolver().check(fullName);

      // Try the raw class file name.
      if (m == null) {
        m = ts.systemResolver().check(rawName);
      }

      if (m == null) {
        // Go to disk, but only if there is no job for the type.
        // If there is a job, all members should be in the resolver
        // already.
        boolean useLoadedResolver = true;

        if (type instanceof ParsedTypeObject) {
          ParsedTypeObject pto = (ParsedTypeObject) type;
          if (pto.job() != null) {
            useLoadedResolver = false;
          }
        }

        if (useLoadedResolver) {
          try {
            m = ts.systemResolver().find(rawName);
          } catch (SemanticException e) {
            // Not found; will fall through to error handling code
          }
        }
      }

      // If we found something, verify that it matches.
      if (m != null) {
        try {
          m = matcher.instantiate(m);
        } catch (SemanticException e) {
          // Doesn't match; try again.
          m = null;
        }
      }
    }

    // Check if the member was explicitly declared.
    if (m == null) {
      m = type.memberTypeMatching(matcher);
    }

    // If we found something, make sure it's accessible.
    if (m instanceof ClassType) {
      ClassType mt = (ClassType) m;

      if (!mt.isMember()) {
        throw new SemanticException(
            "Class " + mt + " is not a member class, " + " but was found in " + type + ".");
      }

      if (!mt.outer().equals((Object) type)) {
        throw new SemanticException(
            "Class " + mt + " is not a member class " + " of " + type + ".");
      }

      return mt;
    }

    if (m instanceof MemberInstance) {
      MemberInstance<?> mi = (MemberInstance<?>) m;

      if (!mi.container().equals((Object) type)) {
        throw new SemanticException("Type " + mi + " is not a member " + " of " + type + ".");
      }
    }

    if (m != null) {
      if (!canAccess(m, context.currentClassDef(), context)) {
        throw new SemanticException("Cannot access member type \"" + m + "\".");
      }
      return m;
    }

    // If we struck out, try the super types.

    // Collect all members of the super types.
    // Use a Set to eliminate duplicates.
    Set<Named> acceptable = new HashSet<Named>();

    if (type.superClass() != null) {
      Type sup = type.superClass();
      if (sup instanceof ClassType) {
        Resolver r = ts.classContextResolver((ClassType) sup, context);
        try {
          Named n = r.find(matcher);
          acceptable.add(n);
        } catch (SemanticException e) {
        }
      }
    }

    for (Iterator<Type> i = type.interfaces().iterator(); i.hasNext(); ) {
      Type sup = (Type) i.next();
      if (sup instanceof ClassType) {
        Resolver r = ts.classContextResolver((ClassType) sup, context);
        try {
          Named n = r.find(matcher);
          acceptable.add(n);
        } catch (SemanticException e) {
        }
      }
    }

    if (acceptable.size() == 0) {
      throw new NoClassException(name.toString(), type);
    } else if (acceptable.size() > 1) {
      Set<Type> containers = new HashSet<Type>(acceptable.size());
      for (Named n : acceptable) {
        if (n instanceof MemberInstance) {
          MemberInstance<?> mi = (MemberInstance<?>) n;
          containers.add(mi.container());
        }
      }

      if (containers.size() == 2) {
        Iterator<Type> i = containers.iterator();
        Type t1 = (Type) i.next();
        Type t2 = (Type) i.next();
        throw new SemanticException(
            "Member \""
                + name
                + "\" of "
                + type
                + " is ambiguous; it is defined in both "
                + t1
                + " and "
                + t2
                + ".");
      } else if (containers.size() == 0) {
        throw new SemanticException("Member \"" + name + "\" of " + type + " is ambiguous.");
      } else {
        throw new SemanticException(
            "Member \""
                + name
                + "\" of "
                + type
                + " is ambiguous; it is defined in "
                + CollectionUtil.listToString(new ArrayList<Type>(containers))
                + ".");
      }
    }

    assert acceptable.size() == 1;

    Named t = acceptable.iterator().next();

    if (Report.should_report(TOPICS, 2)) Report.report(2, "Found member type " + t);

    return t;
  }
Exemplo n.º 21
0
 /**
  * Create an <tt>xs:QName</tt> atomic value
  *
  * @param value the <tt>xs:QName</tt> value, as a QName
  */
 public XdmAtomicValue(QName value) {
   super(new QNameValue(value.getStructuredQName(), BuiltInAtomicType.QNAME));
 }
Exemplo n.º 22
0
 /**
  * Bind a variable to the given value within all query expression evaluated subsequently.
  *
  * @param variableName the qualified name of the variable to bind; prefixes are taken from the
  *     namespace mappings of the folder that provided this service; if the name starts with a
  *     <code>$</code>, it will be stripped automatically
  * @param value the value the variable should take
  * @return this service, to chain calls
  */
 public QueryService let(String variableName, Object value) {
   if (variableName == null) throw new NullPointerException("null variable name");
   if (variableName.startsWith("$")) variableName = variableName.substring(1);
   if (variableName.length() == 0) throw new IllegalArgumentException("empty variable name");
   return let(QName.parse(variableName, namespaceBindings, ""), value);
 }
Exemplo n.º 23
0
 final QName getQname() {
   String uri = (dom.getNamespaceURI()) == null ? "" : dom.getNamespaceURI();
   String prefix = (dom.getPrefix() == null) ? "" : dom.getPrefix();
   return QName.create(uri, dom.getLocalName(), prefix);
 }
Exemplo n.º 24
0
 final void renameNode(QName qname) {
   this.dom = dom.getOwnerDocument().renameNode(dom, qname.getUri(), qname.qualify(dom));
 }
  int elementCloseAction(XmlParser parser, QName node, String tagEnd) throws XmlParseException {
    String nodeName = node.getName();
    if (nodeName.equals(tagEnd)) return POP;

    if (nodeName == "#document" && tagEnd.equals("")) {
      /*
      Document doc = (Document) node;

      // If JSP, move any text into the body element
      if (isJsp && doc.getDocumentElement() == null &&
          node.getFirstChild() instanceof Text) {
        Element html = doc.createElement("html");
        doc.appendChild(html);
        Element body = doc.createElement("body");
        html.appendChild(body);
        Node child;
        while ((child = doc.getFirstChild()) instanceof Text ||
        child instanceof Comment) {
          body.appendChild(child);
        }
      }
      */
      return POP;
    }
    switch (names.get(tagEnd)) {
      case BASEFONT:
      case BR:
      case AREA:
      case LINK:
      case IMG:
      case PARAM:
      case HR:
      case INPUT:
      case COL:
      case FRAME:
      case ISINDEX:
      case BASE:
      case META:
        String errorTagEnd;
        if (tagEnd.equals("")) errorTagEnd = L.l("end of file");
        else errorTagEnd = "`<" + tagEnd + ">'";

        throw parser.error(L.l("{0} expects to be empty", errorTagEnd));
    }

    switch (names.get(nodeName)) {
      case BODY:
      case P:
      case DT:
      case DD:
      case LI:
      case OPTION:
      case THEAD:
      case TFOOT:
      case TBODY:
      case COLGROUP:
      case TR:
      case TH:
      case TD:
        return POP_AND_LOOP;

      case HTML:
      case HEAD:
        // If JSP and missing a body, move any text into the body element
        /*
        if (isJsp && node.getLastChild() instanceof Text) {
          Node child;

          for (child = node.getLastChild();
               child != null;
               child = child.getPreviousSibling()) {
            if (child.getNodeName().equals("body"))
              return POP_AND_LOOP;
          }

          Document doc = node.getOwnerDocument();
          Element body = doc.createElement("body");

          while ((child = node.getLastChild()) instanceof Text ||
                 child instanceof Comment) {
            body.insertBefore(child, body.getFirstChild());
          }

          doc.getDocumentElement().appendChild(body);
        }
        */
        return POP_AND_LOOP;

      default:
        if (forgiving) {
          /*
          Node parent = node;
          for (; parent != null; parent = parent.getParentNode()) {
            if (parent.getNodeName().equals(tagEnd))
              return POP_AND_LOOP;
          }
          return IGNORE;
                 */
          return POP_AND_LOOP;
        }

        String errorTagEnd;
        if (tagEnd.equals("")) errorTagEnd = L.l("end of file");
        else errorTagEnd = "`</" + tagEnd + ">'";

        String expect;
        if (nodeName.equals("#document")) {
          throw parser.error(L.l("expected {0} at {1}", L.l("end of document"), errorTagEnd));
        } else expect = "`</" + nodeName + ">'";

        throw parser.error(
            L.l(
                "expected {0} at {1} (open at {2})",
                expect, errorTagEnd, "" + parser.getNodeLine()));
    }
  }
 public boolean isExtension() {
   final String namespace = _fname.getNamespace();
   return (namespace != null) && (namespace.equals(EXT_XSLTC));
 }
Exemplo n.º 27
0
 void setAttribute(QName name, String value) {
   if (!(dom instanceof Element))
     throw new IllegalStateException("Can only set attribute on elements.");
   name.setAttribute((Element) dom, value);
 }
Exemplo n.º 28
0
  /**
   * This method is called when the constructor is compiled in Stylesheet.compileConstructor() and
   * not as the syntax tree is traversed.
   */
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    // DecimalFormatSymbols.<init>(Locale);
    // xsl:decimal-format - except for the NaN and infinity attributes.
    final int init = cpg.addMethodref(DFS_CLASS, "<init>", "(" + LOCALE_SIG + ")V");

    // Push the format name on the stack for call to addDecimalFormat()
    il.append(classGen.loadTranslet());
    il.append(new PUSH(cpg, _name.toString()));

    // Manufacture a DecimalFormatSymbols on the stack
    // for call to addDecimalFormat()
    // Use the US Locale as the default, as most of its settings
    // are equivalent to the default settings required of
    il.append(new NEW(cpg.addClass(DFS_CLASS)));
    il.append(DUP);
    il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", LOCALE_SIG)));
    il.append(new INVOKESPECIAL(init));

    String tmp = getAttribute("NaN");
    if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
      int nan = cpg.addMethodref(DFS_CLASS, "setNaN", "(Ljava/lang/String;)V");
      il.append(DUP);
      il.append(new PUSH(cpg, "NaN"));
      il.append(new INVOKEVIRTUAL(nan));
    }

    tmp = getAttribute("infinity");
    if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
      int inf = cpg.addMethodref(DFS_CLASS, "setInfinity", "(Ljava/lang/String;)V");
      il.append(DUP);
      il.append(new PUSH(cpg, "Infinity"));
      il.append(new INVOKEVIRTUAL(inf));
    }

    final int nAttributes = _attributes.getLength();
    for (int i = 0; i < nAttributes; i++) {
      final String name = _attributes.getQName(i);
      final String value = _attributes.getValue(i);

      boolean valid = true;
      int method = 0;

      if (name.equals("decimal-separator")) {
        // DecimalFormatSymbols.setDecimalSeparator();
        method = cpg.addMethodref(DFS_CLASS, "setDecimalSeparator", "(C)V");
      } else if (name.equals("grouping-separator")) {
        method = cpg.addMethodref(DFS_CLASS, "setGroupingSeparator", "(C)V");
      } else if (name.equals("minus-sign")) {
        method = cpg.addMethodref(DFS_CLASS, "setMinusSign", "(C)V");
      } else if (name.equals("percent")) {
        method = cpg.addMethodref(DFS_CLASS, "setPercent", "(C)V");
      } else if (name.equals("per-mille")) {
        method = cpg.addMethodref(DFS_CLASS, "setPerMill", "(C)V");
      } else if (name.equals("zero-digit")) {
        method = cpg.addMethodref(DFS_CLASS, "setZeroDigit", "(C)V");
      } else if (name.equals("digit")) {
        method = cpg.addMethodref(DFS_CLASS, "setDigit", "(C)V");
      } else if (name.equals("pattern-separator")) {
        method = cpg.addMethodref(DFS_CLASS, "setPatternSeparator", "(C)V");
      } else if (name.equals("NaN")) {
        method = cpg.addMethodref(DFS_CLASS, "setNaN", "(Ljava/lang/String;)V");
        il.append(DUP);
        il.append(new PUSH(cpg, value));
        il.append(new INVOKEVIRTUAL(method));
        valid = false;
      } else if (name.equals("infinity")) {
        method = cpg.addMethodref(DFS_CLASS, "setInfinity", "(Ljava/lang/String;)V");
        il.append(DUP);
        il.append(new PUSH(cpg, value));
        il.append(new INVOKEVIRTUAL(method));
        valid = false;
      } else {
        valid = false;
      }

      if (valid) {
        il.append(DUP);
        il.append(new PUSH(cpg, value.charAt(0)));
        il.append(new INVOKEVIRTUAL(method));
      }
    }

    final int put =
        cpg.addMethodref(TRANSLET_CLASS, "addDecimalFormat", "(" + STRING_SIG + DFS_SIG + ")V");
    il.append(new INVOKEVIRTUAL(put));
  }
  /**
   * Returns the appropriate action when opening a HTML tag.
   *
   * @param parser the XML parser
   * @param node the parent node
   * @param next the next child
   * @return the action code
   */
  int openAction(XmlParser parser, QName node, QName next) throws XmlParseException {
    String nodeName = node == null ? "#document" : node.getName();
    String nextName = next.getName();

    int nextCode = names.get(nextName);

    switch (names.get(nodeName)) {
      case DOCUMENT:
        switch (nextCode) {
          case HTML:
            return PUSH;

          case COMMENT:
            return PUSH;

          case HEAD:
          case TITLE:
          case ISINDEX:
          case BASE:
          case SCRIPT:
          case STYLE:
          case META:
          case LINK:
          case OBJECT:
            opt = htmlName;
            return PUSH_OPT;

          case WHITESPACE:
            return IGNORE;

          case JSP:
            return PUSH;

          default:
            if (autoHtml) return PUSH;

            autoHtml = true;
            opt = htmlName;
            return PUSH_OPT;
        }

      case HTML:
        switch (nextCode) {
          case HTML:
            return ERROR;

          case HEAD:
          case COMMENT:
          case FRAMESET:
            return PUSH;

          case BODY:
            hasBody = true;
            return PUSH;

          case TITLE:
          case ISINDEX:
          case BASE:
          case SCRIPT:
          case STYLE:
          case META:
          case LINK:
          case OBJECT:
            opt = headName;
            autoHead = true;
            return PUSH_OPT;

          case WHITESPACE:
            return PUSH;

          case JSP:
            return PUSH;

          default:
            if (hasBody) return PUSH;

            hasBody = true;
            opt = bodyName;
            return PUSH_OPT;
        }

      case HEAD:
        switch (nextCode) {
          case META:
            // checkMetaEncoding((Element) next);
            return PUSH_EMPTY;

          case LINK:
          case ISINDEX:
          case BASE:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          case TITLE:
          case OBJECT:
            return PUSH;

          case WHITESPACE:
            return PUSH;

          case JSP:
          case TEXT:
            if (autoHead) return POP;
            else return PUSH;

          default:
            return POP;
        }

      case LI:
        switch (nextCode) {
          case LI:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case OPTION:
        switch (nextCode) {
          case WHITESPACE:
          case TEXT:
            return PUSH;

          default:
            return POP;
        }

      case DD:
        switch (nextCode) {
          case DD:
          case DT:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case THEAD:
      case TFOOT:
      case COLGROUP:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TR:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
          case TR:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case TD:
          case TH:
            return PUSH;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TD:
      case TH:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
          case TR:
          case TD:
          case TH:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case P:
      case DT:
        switch (nextCode) {
          case BLOCK:
          case P:
          case TABLE:
          case CAPTION:
          case THEAD:
          case TFOOT:
          case COLGROUP:
          case TBODY:
          case TR:
          case TD:
          case TH:
          case DT:
          case LI:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TABLE:
        switch (nextCode) {
          case CAPTION:
          case THEAD:
          case TFOOT:
          case COL:
          case COLGROUP:
          case TBODY:
          case TR:
            return PUSH;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            /*
            opt = "tr";
            return PUSH_OPT;
                   */
            return PUSH;
        }

      default:
        switch (nextCode) {
          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }
    }
  }
Exemplo n.º 30
0
 QName newQName(XmlNode.QName qname) {
   return QName.create(this, this.globalScope, this.qnamePrototype, qname);
 }