Exemple #1
0
        /// <summary>
        /// Get a list of external variables used by the expression. This will include both variables that were explicitly
        /// declared to the <c>XPathCompiler</c>, and (if the <c>AllowUndeclaredVariables</c> option was set) variables that
        /// are referenced within the expression but not explicitly declared.
        /// </summary>
        /// <returns>
        /// An IEnumerator over the names of the external variables, as instances of <c>QName</c>.</returns>

        public IEnumerator EnumerateExternalVariables()
        {
            ArrayList list = new ArrayList();
            JIterator iter = env.iterateExternalVariables();

            while (iter.hasNext())
            {
                JXPathVariable   var = (JXPathVariable)iter.next();
                JStructuredQName q   = var.getVariableQName();
                list.Add(new QName(q.getPrefix(), q.getURI(), q.getLocalPart()));
            }
            return(list.GetEnumerator());
        }
Exemple #2
0
        internal JReceiver GetReceiver(Serializer serializer)
        {
            net.sf.saxon.expr.instruct.Executable executable = exp.getExecutable();
            JConfiguration         config = executable.getConfiguration();
            JPipelineConfiguration pipe   = config.makePipelineConfiguration();

            pipe.setHostLanguage(executable.getHostLanguage());
            JProperties baseProps = new JProperties(executable.getDefaultOutputProperties());

            JCharacterMapIndex charMapIndex = executable.getCharacterMapIndex();
            JCharacterMapIndex characterMap = serializer.GetCharacterMap();

            if (charMapIndex.isEmpty())
            {
                charMapIndex = characterMap;
            }
            else if (characterMap != null && !characterMap.isEmpty() && charMapIndex != characterMap)
            {
                // Merge the character maps
                java.util.Iterator mapIter = characterMap.iterator();
                while (mapIter.hasNext())
                {
                    net.sf.saxon.serialize.CharacterMap map = (net.sf.saxon.serialize.CharacterMap)mapIter.next();
                    charMapIndex.putCharacterMap(map.getName(), map);
                }
            }

            JProperties properties = serializer.GetOutputProperties();

            object [] propSet = properties.entrySet().toArray();

            for (int i = 0; i < properties.size(); i++)
            {
                java.util.Map.Entry             entry = (java.util.Map.Entry)propSet[i];
                net.sf.saxon.om.StructuredQName name  = net.sf.saxon.om.StructuredQName.fromClarkName((String)entry.getKey());
                net.sf.saxon.expr.instruct.ResultDocument.setSerializationProperty(
                    baseProps, name.getURI(), name.getLocalPart(), (String)entry.getValue(), null, true, config);
            }
            serializer.SetDefaultOutputProperties(baseProps);
            serializer.SetCharacterMap(charMapIndex);

            JReceiver target = serializer.GetReceiver(pipe);

            return(target);
        }
Exemple #3
0
        /// <summary>
        /// Sets a property of a selected decimal format, for use by the <c>format-number</c> function.
        /// </summary>
        /// <remarks>
        /// This method checks that the value is valid for the particular property, but it does not
        /// check that all the values for the decimal format are consistent (for example, that the
        /// decimal separator and grouping separator have different values). This consistency
        /// check is performed only when the decimal format is used.
        /// </remarks>
        /// <param name="format">The name of the decimal format whose property is to be set.
        ///  Supply null to set a property of the default (unnamed) decimal format.
        ///  This correponds to a name used in the third argument of <c>format-number</c>.</param>
        /// <param name="property">The name of the property to set: one of
        ///   "decimal-separator", "grouping-separator", "infinity", "NaN",
        ///   "minus-sign", "percent", "per-mille", "zero-digit", "digit",
        ///   or "pattern-separator".</param>
        /// <param name="value">The new value for the property.</param>

        public void SetDecimalFormatProperty(QName format, String property, String value)
        {
            net.sf.saxon.trans.DecimalFormatManager dfm = env.getDecimalFormatManager();
            if (dfm == null)
            {
                dfm = new net.sf.saxon.trans.DecimalFormatManager(net.sf.saxon.Configuration.XPATH, env.getXPathVersion());
                env.setDecimalFormatManager(dfm);
            }

            net.sf.saxon.om.StructuredQName   sqname  = null;
            net.sf.saxon.trans.DecimalSymbols symbols = null;

            if (format != null)
            {
                sqname  = net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName);
                symbols = dfm.obtainNamedDecimalFormat(sqname);
            }
            else
            {
                symbols = dfm.getDefaultDecimalFormat();
            }

            if (property.Equals("decimal-separator"))
            {
                symbols.setDecimalSeparator(value);
            }
            else if (property.Equals("grouping-separator"))
            {
                symbols.setGroupingSeparator(value);
            }
            else if (property.Equals("infinity"))
            {
                symbols.setInfinity(value);
            }
            else if (property.Equals("NaN"))
            {
                symbols.setNaN(value);
            }
            else if (property.Equals("minus-sign"))
            {
                symbols.setMinusSign(value);
            }
            else if (property.Equals("percent"))
            {
                symbols.setPercent(value);
            }
            else if (property.Equals("per-mille"))
            {
                symbols.setPerMille(value);
            }
            else if (property.Equals("zero-digit"))
            {
                symbols.setZeroDigit(value);
                if (!net.sf.saxon.trans.DecimalSymbols.isValidZeroDigit(symbols.getZeroDigit()))
                {
                    throw new ArgumentException("Value supplied for zero-digit is not a Unicode digit representing zero");
                }
            }
            else if (property.Equals("digit"))
            {
                symbols.setDigit(value);
            }
            else if (property.Equals("pattern-separator"))
            {
                symbols.setPatternSeparator(value);
            }
            else
            {
                throw new ArgumentException("Unknown decimal format property " + property);
            }
        }
Exemple #4
0
        /// <summary>
        /// Sets a property of a selected decimal format, for use by the <c>format-number</c> function.
        /// </summary>
        /// <remarks>
        /// This method checks that the value is valid for the particular property, but it does not
        /// check that all the values for the decimal format are consistent (for example, that the
        /// decimal separator and grouping separator have different values). This consistency
        /// check is performed only when the decimal format is used.
        /// </remarks>
        /// <param name="format">The name of the decimal format whose property is to be set.
        ///  Supply null to set a property of the default (unnamed) decimal format.
        ///  This correponds to a name used in the third argument of <c>format-number</c>.</param>
        /// <param name="property">The name of the property to set: one of
        ///   "decimal-separator", "grouping-separator", "infinity", "NaN",
        ///   "minus-sign", "percent", "per-mille", "zero-digit", "digit",
        ///   or "pattern-separator".</param>
        /// <param name="value">The new value for the property.</param>

        public void SetDecimalFormatProperty(QName format, String property, String value)
        {
            net.sf.saxon.trans.DecimalFormatManager dfm = env.getDecimalFormatManager();
            if (dfm == null)
            {
                dfm = new net.sf.saxon.trans.DecimalFormatManager();
                env.setDecimalFormatManager(dfm);
            }

            net.sf.saxon.om.StructuredQName   sqname  = null;
            net.sf.saxon.trans.DecimalSymbols symbols = null;

            if (format != null)
            {
                sqname  = net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName);
                symbols = dfm.obtainNamedDecimalFormat(sqname);
            }
            else
            {
                symbols = dfm.getDefaultDecimalFormat();
            }

            if (property.Equals("decimal-separator"))
            {
                symbols.decimalSeparator = checkSingleChar(value);
            }
            else if (property.Equals("grouping-separator"))
            {
                symbols.groupingSeparator = checkSingleChar(value);
            }
            else if (property.Equals("infinity"))
            {
                symbols.infinity = value;
            }
            else if (property.Equals("NaN"))
            {
                symbols.NaN = value;
            }
            else if (property.Equals("minus-sign"))
            {
                symbols.minusSign = checkSingleChar(value);
            }
            else if (property.Equals("percent"))
            {
                symbols.percent = checkSingleChar(value);
            }
            else if (property.Equals("per-mille"))
            {
                symbols.permill = checkSingleChar(value);
            }
            else if (property.Equals("zero-digit"))
            {
                symbols.zeroDigit = checkSingleChar(value);
                if (!symbols.isValidZeroDigit())
                {
                    throw new ArgumentException("Value supplied for zero-digit is not a Unicode digit representing zero");
                }
            }
            else if (property.Equals("digit"))
            {
                symbols.digit = checkSingleChar(value);
            }
            else if (property.Equals("pattern-separator"))
            {
                symbols.patternSeparator = checkSingleChar(value);
            }
            else
            {
                throw new ArgumentException("Unknown decimal format property " + property);
            }

            try
            {
                if (format == null)
                {
                    dfm.setDefaultDecimalFormat(symbols, 0);
                }
                else
                {
                    dfm.setNamedDecimalFormat(net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName), symbols, 0);
                }
            }
            catch (net.sf.saxon.trans.XPathException e)
            {
                throw new DynamicError(e);
            }
        }