/// <summary> /// Doc operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="dc"> /// Result of dynamic context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:doc operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence doc(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence doc(ICollection args, EvaluationContext ec) { ICollection cargs = Function.convert_arguments(args, expected_args()); // get args IEnumerator argiter = cargs.GetEnumerator(); argiter.MoveNext(); ResultSequence arg1 = (ResultSequence)argiter.Current; if (arg1 == null || arg1.empty()) { return(ResultSequenceFactory.create_new()); } string uri = ((XSString)arg1.item(0)).value(); DynamicContext dc = ec.DynamicContext; var resolved = dc.resolveUri(uri); if (resolved == null) { throw DynamicError.invalid_doc(null); } Document doc = dc.getDocument(resolved); if (doc == null) { throw DynamicError.doc_not_found(null); } return(new DocType(doc, ec.StaticContext.TypeModel)); }
/// <summary> /// Prefix-from-QName operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:prefix-from-QName operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence inScopePrefixes(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence inScopePrefixes(ICollection args, DynamicContext dc) { // Collection cargs = Function.convert_arguments(args, expected_args()); ICollection cargs = args; var i = cargs.GetEnumerator(); i.MoveNext(); ResultSequence arg1 = (ResultSequence)i.Current; if (arg1 == null || arg1.empty()) { return(ResultBuffer.EMPTY); } ResultBuffer rs = new ResultBuffer(); Item anytype = arg1.item(0); if (!(anytype is ElementType)) { throw new DynamicError(TypeError.invalid_type(null)); } ElementType element = (ElementType)anytype; IList prefixList = lookupPrefixes(element); createPrefixResultSet(rs, prefixList); return(rs.Sequence); }
/// <summary> /// Distinct-values operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:distinct-values operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence distinct_values(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence distinct_values(ICollection args, DynamicContext context) { ResultBuffer rs = new ResultBuffer(); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg1 = (ResultSequence)citer.Current; ResultSequence arg2 = ResultBuffer.EMPTY; if (citer.MoveNext()) { arg2 = (ResultSequence)citer.Current; } string collationURI = context.CollationProvider.DefaultCollation; if (!(arg2 == null || arg2.empty())) { XSString collation = (XSString)arg2.item(0); collationURI = collation.StringValue; } for (var iter = arg1.iterator(); iter.MoveNext();) { AnyAtomicType atomizedItem = (AnyAtomicType)FnData.atomize((Item)iter.Current); if (!contains(rs, atomizedItem, context, collationURI)) { rs.add(atomizedItem); } } return(rs.Sequence); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void considerSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence sequenceToConsider) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual void considerSequence(ResultSequence sequenceToConsider) { for (int i = 0; i < sequenceToConsider.size(); ++i) { Item item = sequenceToConsider.item(i); considerValue(item); } }
/// <summary> /// Evaluate the function using the arguments passed. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="sc"> /// Result of static context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the fn:dateTime operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence adjustDate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence adjustDate(ICollection args, DynamicContext dc) { ICollection cargs = Function.convert_arguments(args, expectedArgs()); // get args IEnumerator argiter = cargs.GetEnumerator(); argiter.MoveNext(); ResultSequence arg1 = (ResultSequence)argiter.Current; if (arg1 == null || arg1.empty()) { return(ResultBuffer.EMPTY); } ResultSequence arg2 = ResultBuffer.EMPTY; if (argiter.MoveNext()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: arg2 = (ResultSequence)argiter.Current; } XSDate date = (XSDate)arg1.item(0); XSDayTimeDuration timezone = null; if (arg2.empty()) { if (date.timezoned()) { XSDate localized = new XSDate(date.calendar(), null); return(localized); } return(arg1); } timezone = (XSDayTimeDuration)arg2.item(0); if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) { throw DynamicError.invalidTimezone(); } if (date.tz() == null) { return(new XSDate(date.calendar(), timezone)); } XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)date.normalizeCalendar(date.calendar(), date.tz())); Duration duration = _datatypeFactory.newDuration(timezone.StringValue); xmlCalendar.add(duration); return(new XSDate(xmlCalendar.toGregorianCalendar(), timezone)); }
/// <summary> /// Apply the URI escaping rules to the arguments. /// </summary> /// <param name="args"> /// have the URI escaping rules applied to them. </param> /// <param name="escape_space"> TODO </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> The result of applying the URI escaping rules to the arguments. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence escape_uri(java.util.Collection args, boolean escape_delimiters, boolean escape_space) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence escape_uri(ICollection args, bool escape_delimiters, bool escape_space) { ICollection cargs = Function.convert_arguments(args, expected_args()); IEnumerator argi = cargs.GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: argi.MoveNext(); ResultSequence arg1 = (ResultSequence)argi.Current; if (arg1.empty()) { return(new XSString("")); } AnyType aat = (AnyType)arg1.item(0); string str = aat.StringValue; var encoding = Encoding.UTF8; byte[] bytes = new byte[0]; Array.Resize(ref bytes, encoding.GetByteCount(str)); encoding.GetBytes(str, 0, str.Length, bytes, 0); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { byte x = bytes[i]; if (needs_escape((sbyte)x, escape_delimiters, escape_space)) { sb.Append("%"); sb.Append((x & 0xFF).ToString("x").ToUpper()); } else { sb.Append((char)x); } } return(new XSString(sb.ToString())); }
/// <summary> /// Reverse the arguments. /// </summary> /// <param name="args"> /// are reversed. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> The result of the reversal of the arguments. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence reverse(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence reverse(ICollection args) { Debug.Assert(args.Count == 1); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg = (ResultSequence)citer.Current; if (arg.size() <= 1) { return(arg); } ResultBuffer rs = new ResultBuffer(); for (int i = arg.size() - 1; i >= 0; --i) { rs.add(arg.item(i)); } return(rs.Sequence); }
/// <summary> /// Obtain numeric value from expression. /// </summary> /// <param name="arg"> /// input expression. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Resulting numeric type from the operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType get_single_numeric_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static NumericType get_single_numeric_arg(ResultSequence arg) { int size = arg.size(); if (size > 1) { DynamicError.throw_type_error(); } if (size == 0) { return(null); } arg = FnData.atomize(arg); AnyType at = (AnyType)arg.item(0); if (!(at is NumericType)) { throw DynamicError.invalidType(); } return((NumericType)at); }
/// <summary> /// Convert and promote arguments for operation. /// </summary> /// <param name="args"> /// input arguments. </param> /// <param name="sc"> </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of conversion. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static java.util.Collection convert_args(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError private static ICollection convert_args(ICollection args) { var result = new ArrayList(); // Keep track of numeric types for promotion bool has_float = false; bool has_double = false; // atomize arguments for (IEnumerator i = args.GetEnumerator(); i.MoveNext();) { ResultSequence rs = FnData.atomize((ResultSequence)i.Current); if (rs.empty()) { return(new ArrayList()); } if (rs.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } AnyType arg = (AnyType)rs.item(0); if (arg is XSUntypedAtomic) { arg = new XSDouble(arg.StringValue); } if (arg is XSDouble) { has_double = true; } if (arg is XSFloat) { has_float = true; } result.Add(ResultBuffer.wrap(arg)); } if (has_double) { has_float = false; } if (has_double || has_float) { var result2 = new ArrayList(); // promote arguments for (IEnumerator i = result.GetEnumerator(); i.MoveNext();) { ResultSequence rs = (ResultSequence)i.Current; Item arg = rs.item(0); if (has_double && (arg is XSFloat)) { arg = new XSDouble(((XSFloat)arg).float_value()); } else if (has_double && (arg is XSDecimal)) { arg = new XSDouble(((XSDecimal)arg).double_value()); } else if (has_float && (arg is XSDecimal)) { arg = new XSFloat((float)((XSDecimal)arg).double_value()); } result2.Add(arg); } return(result2); } return(result); }
/// <summary> /// Root operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <param name="dc"> /// Result of dynamic context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:root operation. </returns> public static ResultSequence fn_root(ICollection args, EvaluationContext ec) { ICollection cargs = Function.convert_arguments(args, expected_args()); if (cargs.Count > 1) { throw new DynamicError(TypeError.invalid_type(null)); } ResultSequence arg = null; if (cargs.Count == 0) { if (ec.ContextItem == null) { throw DynamicError.contextUndefined(); } arg = ResultBuffer.wrap(ec.ContextItem); } else { var i = cargs.GetEnumerator(); i.MoveNext(); arg = (ResultSequence)i.Current; } if (arg.empty()) { return(ResultBuffer.EMPTY); } Item aa = arg.item(0); if (!(aa is NodeType)) { throw new DynamicError(TypeError.invalid_type(null)); } NodeType nt = (NodeType)aa; // ok we got a sane argument... own it. Node root = nt.node_value(); while (root != null && !(root is Document)) { Node newroot = root.ParentNode; if (newroot == null && root is Attr) { newroot = ((Attr)root).OwnerElement; } // found it if (newroot == null) { break; } root = newroot; } return(NodeType.dom_to_xpath(root, ec.StaticContext.TypeModel)); }
/// <summary> /// Boolean operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <returns> Result of fn:boolean operation. </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean fn_boolean(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static XSBoolean fn_boolean(ResultSequence arg) { if (arg.empty()) { return(XSBoolean.FALSE); } Item at = arg.item(0); if (at is CalendarType) { throw DynamicError.throw_type_error(); } if (at is NodeType) { return(XSBoolean.TRUE); } if (arg.size() > 1) { throw DynamicError.throw_type_error(); } // XXX ?? if (!(at is AnyAtomicType)) { return(XSBoolean.TRUE); } // ok we got 1 single atomic type element if (at is XSBoolean) { if (!((XSBoolean)at).value()) { return(XSBoolean.FALSE); } } if ((at is XSString) || (at is XSUntypedAtomic)) { if (((AnyType)at).StringValue.Equals("")) { return(XSBoolean.FALSE); } } if (at is NumericType) { if (((NumericType)at).zero()) { return(XSBoolean.FALSE); } } if ((at is XSFloat) && (((XSFloat)at).nan())) { return(XSBoolean.FALSE); } if ((at is XSDouble) && (((XSDouble)at).nan())) { return(XSBoolean.FALSE); } return(XSBoolean.TRUE); }