Exemple #1
0
        public ArrayValue getProperties(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashMap <StringValue, ClassField> fieldMap = _cls.getClassFields();

            for (ClassField field : fieldMap.values())
            {
                /// XXX: private fields of parent classes are hidden
                ReflectionProperty prop
                    = ReflectionProperty.create(env, _cls, field.getName(), false);

                array.put(env.wrapJava(prop));
            }

            ArrayList <StringValue> staticFieldList = _cls.getStaticFieldNames();

            for (StringValue fieldName : staticFieldList)
            {
                ReflectionProperty prop
                    = ReflectionProperty.create(env, _cls, fieldName, true);

                array.put(env.wrapJava(prop));
            }

            return(array);
        }
        public override StringValue serialize(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            StringValue objStr   = env.createString("obj");
            StringValue valueStr = env.createString("inf");

            ObjectEntry entry = _head;

            while (entry != null)
            {
                ArrayValue inner = new ArrayValueImpl();

                inner.put(objStr, entry.getObject());
                inner.put(valueStr, entry.getValue());

                array.append(inner);

                entry = entry.getNext();
            }

            string str = VariableModule.serialize(env, array);

            return(env.createString(str));
        }
Exemple #3
0
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            for (int i = 0; i < _values.length; i++)
            {
                Expr keyExpr = _keys[i];

                Value value = _values[i].evalArg(env, true);
                // php/0471
                value = value.toRefValue();

                if (keyExpr != null)
                {
                    Value key = keyExpr.evalArg(env, true).toLocalValue();

                    array.put(key, value);
                }
                else
                {
                    array.put(value);
                }
            }

            return(array);
        }
Exemple #4
0
        private static void addAbbreviation(ArrayValue array,
                                            TimeZone tz,
                                            bool isDST)
        {
            ArrayValueImpl zone = new ArrayValueImpl();

            zone.put("dst", isDST);

            int offset = tz.getRawOffset() / 1000;

            if (isDST)
            {
                offset += tz.getDSTSavings() / 1000;
            }

            zone.put("offset", offset);
            zone.put("timezone_id", tz.getID());

            string name  = tz.getDisplayName(isDST, TimeZone.SHORT);
            Value  nameV = StringValue.create(name.toLowerCase(Locale.ENGLISH));

            Value zones = array.get(nameV);

            if (zones.isNull())
            {
                zones = new ArrayValueImpl();

                array.put(nameV, zones);
            }

            zones.put(zone);
        }
        /*
         * Returns an array of decoded Mime headers/fields.
         */
        public static Value decodeMimeHeaders(Env env,
                                              StringValue encodedHeaders,
                                              string charset)

        {
            ArrayValue headers = new ArrayValueImpl();

            try {
                Enumeration <Header> enumeration
                    = new InternetHeaders(encodedHeaders.toInputStream()).getAllHeaders();

                while (enumeration.hasMoreElements())
                {
                    Header header = enumeration.nextElement();

                    StringValue name
                        = QuercusMimeUtility.decodeMime(env, header.getName(), charset);
                    StringValue val
                        = QuercusMimeUtility.decodeMime(env, header.getValue(), charset);

                    Value headerName;
                    if ((headerName = headers.containsKey(name)) == null)
                    {
                        headers.put(name, val);
                        continue;
                    }

                    ArrayValue inner;
                    if (headerName.isArray())
                    {
                        inner = headerName.toArrayValue(env);
                    }
                    else
                    {
                        inner = new ArrayValueImpl();
                        inner.put(headerName);
                    }

                    inner.put(val);
                    headers.put(name, inner);
                }

                return(headers);
            } catch (MessagingException e) {
                log.log(Level.FINE, e.getMessage(), e);
                env.warning(e.getMessage());

                return(BooleanValue.FALSE);
            }
        }
 /**
  * Sets the unparsedEntityDecl handler
  *
  * @param handler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_unparsed_entity_decl_handler(Env env, Value handler)
 {
     if (_obj == null)
     {
         _unparsedEntityDeclHandler = handler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(handler);
         _unparsedEntityDeclHandler = value.toCallable(env, false);
     }
     return(true);
 }
 /**
  * Sets the notationDecl handler
  *
  * @param handler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_notation_decl_handler(Env env, Value handler)
 {
     if (_obj == null)
     {
         _notationDeclHandler = handler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(handler);
         _notationDeclHandler = value.toCallable(env, false);
     }
     return(true);
 }
        /**
         * Sets the character data handler function.
         *
         * @param handler can be empty string or FALSE
         * @return true always even if handler @is disabled
         */
        public bool xml_set_character_data_handler(Env env, Value handler)
        {
            if (_obj == null)
            {
                _characterDataHandler = handler.toCallable(env, false);
            }
            else
            {
                Value value = new ArrayValueImpl();
                value.put(_obj);
                value.put(handler);
                _characterDataHandler = value.toCallable(env, false);
            }

            return(true);
        }
        public override Value wrap(Env env, Object obj)
        {
            if (!_isInit)
            {
                init();
            }

            ArrayValueImpl arrayValueImpl = new ArrayValueImpl();

            // XXX: needs to go into constructor
            Class componentClass = getType().getComponentType();

            MarshalFactory factory = getModuleContext().getMarshalFactory();
            Marshal        componentClassMarshal = factory.create(componentClass);

            int length = Array.getLength(obj);

            for (int i = 0; i < length; i++)
            {
                Object component = Array.get(obj, i);

                arrayValueImpl.put(componentClassMarshal.unmarshal(env, component));
            }

            return(arrayValueImpl);
        }
        public ArrayValue getINIEntries(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            for (ModuleInfo moduleInfo : env.getQuercus().getModules())
            {
                Set <String> extensionSet = moduleInfo.getLoadedExtensions();

                if (extensionSet.contains(_name))
                {
                    IniDefinitions iniDefs = moduleInfo.getIniDefinitions();

                    Set <Map.Entry <String, IniDefinition> > entrySet = iniDefs.entrySet();

                    if (entrySet != null)
                    {
                        for (Map.Entry <String, IniDefinition> entry : entrySet)
                        {
                            array.put(StringValue.create(entry.getKey()),
                                      entry.getValue().getValue(env));
                        }
                    }
                }
            }

            return(array);
        }
        private static ConstArrayValue toUnicodeArray(Env env, ArrayValue array)
        {
            ArrayValueImpl copy = new ArrayValueImpl();

            Iterator <Map.Entry <Value, Value> > iter = array.getIterator(env);

            while (iter.hasNext())
            {
                Map.Entry <Value, Value> entry = iter.next();

                Value key   = entry.getKey();
                Value value = entry.getValue();

                if (key.isString())
                {
                    key = key.toUnicodeValue(env);
                }

                if (value.isString())
                {
                    value = value.toUnicodeValue(env);
                }

                copy.put(key, value);
            }

            return(new ConstArrayValue(copy));
        }
Exemple #12
0
        public static Value class_parents(Env env,
                                          Value obj,
                                          @Optional bool autoload)
        {
            QuercusClass cls;

            if (obj.isObject())
            {
                cls = ((ObjectValue)obj.toObject(env)).getQuercusClass();
            }
            else
            {
                cls = env.findClass(obj.ToString(), autoload, true, true);
            }

            if (cls != null)
            {
                ArrayValue array = new ArrayValueImpl();

                QuercusClass parent = cls;

                while ((parent = parent.getParent()) != null)
                {
                    string name = parent.getName();

                    array.put(name, name);
                }

                return(array);
            }
            else
            {
                return(BooleanValue.FALSE);
            }
        }
 /**
  * Sets the endPrefixMapping handler
  *
  * @param endNamespaceDeclHandler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_end_namespace_decl_handler(
     Env env,
     Value endNamespaceDeclHandler)
 {
     if (_obj == null)
     {
         _endNamespaceDeclHandler = endNamespaceDeclHandler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(endNamespaceDeclHandler);
         _endNamespaceDeclHandler = value.toCallable(env, false);
     }
     return(true);
 }
 /**
  * Sets the processing instruction handler function
  *
  * @param processingInstructionHandler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_processing_instruction_handler(
     Env env,
     Value processingInstructionHandler)
 {
     if (_obj == null)
     {
         _processingInstructionHandler
             = processingInstructionHandler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(processingInstructionHandler);
         _processingInstructionHandler = value.toCallable(env, false);
     }
     return(true);
 }
        private ArrayValue toArrayValue(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            StringValue objStr   = env.createString("obj");
            StringValue valueStr = env.createString("inf");

            for (Map.Entry <StringValue, ObjectEntry> entry : _objMap.entrySet())
            {
                ArrayValue inner = new ArrayValueImpl();

                inner.put(objStr, entry.getValue().getObject());
                inner.put(valueStr, entry.getValue().getValue());

                array.put(entry.getKey(), inner);
            }

            return(array);
        }
Exemple #16
0
        /**
         * The each iterator
         */
        public Value each()
        {
            if (_next < _list.size())
            {
                ArrayValue result = new ArrayValueImpl();

                result.put(LongValue.ZERO, key());
                result.put(KEY, key());

                result.put(LongValue.ONE, current());
                result.put(VALUE, current());

                _next++;

                return(result);
            }
            else
            {
                return(NullValue.NULL);
            }
        }
        protected override ArrayValue createArgv()
        {
            ArrayValue array = new ArrayValueImpl();

            String[] argv = _argv;

            for (int i = 0; i < argv.length; i++)
            {
                array.put(argv[i]);
            }

            return(array);
        }
Exemple #18
0
        public ArrayValue getParameters(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            Arg [] args = _callable.getArgs(env);

            for (int i = 0; i < args.length; i++)
            {
                array.put(env.wrapJava(new ReflectionParameter(_callable, args[i])));
            }

            return(array);
        }
Exemple #19
0
        public ArrayValue getMethods(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            MethodMap <AbstractFunction> map = _cls.getMethodMap();

            for (AbstractFunction method : map.values())
            {
                array.put(env.wrapJava(new ReflectionMethod(_cls.getName(), method)));
            }

            return(array);
        }
        public Value readInfo(Env env, Value msgsInQueue)
        {
            if (_msgQueue.size() == 0)
            {
                return(BooleanValue.FALSE);
            }

            StringValue msgStr    = env.createString("msg");
            StringValue resultStr = env.createString("result");
            StringValue handleStr = env.createString("handle");

            CurlResource curl = _msgQueue.remove(0);

            ArrayValue array = new ArrayValueImpl();

            array.put(msgStr, LongValue.create(CurlModule.CURLMSG_DONE));
            array.put(resultStr, LongValue.create(CurlModule.CURLE_OK));
            array.put(handleStr, curl);

            msgsInQueue.set(LongValue.create(_msgQueue.size()));

            return(array);
        }
Exemple #21
0
        /**
         * Parses the string.
         */
        public static ArrayValue token_get_all(Env env, StringValue s)
        {
            ArrayValue result = new ArrayValueImpl();

            Token lexer = new Token(env, s);
            int   token;

            while ((token = lexer.nextToken()) >= 0)
            {
                if (0x20 <= token && token <= 0x7f)
                {
                    result.put(env.createString((char)token));
                }
                else
                {
                    result.put(new ArrayValueImpl()
                               .append(LongValue.create(token))
                               .append(lexer.getLexeme()));
                }
            }

            return(result);
        }
Exemple #22
0
        public static ArrayValue listIdentifiers()
        {
            ArrayValue array = new ArrayValueImpl();

            string [] ids = TimeZone.getAvailableIDs();

            java.util.Arrays.sort(ids);

            for (int i = 0; i < ids.length; i++)
            {
                array.put(ids[i]);
            }

            return(array);
        }
Exemple #23
0
        public ArrayValue getConstants(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashMap <StringValue, Value> _constMap = _cls.getConstantMap(env);

            for (Map.Entry <StringValue, Value> entry : _constMap.entrySet())
            {
                Value name = entry.getKey();

                array.put(name, entry.getValue());
            }

            return(array);
        }
        private ArrayValue createAndFillArray()
        {
            ArrayValue array = new ArrayValueImpl();

            for (Map.Entry <StringValue, EnvVar> entry : _env.getGlobalEnv()
                 .entrySet())
            {
                Value key = entry.getKey();
                Value val = entry.getValue().get();

                array.put(key, val);
            }

            return(array);
        }
        public static Value func_get_args(Env env)
        {
            Value [] args = env.getFunctionArgs();

            ArrayValue result = new ArrayValueImpl();

            if (args != null)
            {
                for (int i = 0; i < args.length; i++)
                {
                    result.put(args[i]);
                }
            }

            return(result);
        }
        public ArrayValue getClassNames(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashSet <String> exts = env.getModuleContext().getExtensionClasses(_name);

            if (exts != null)
            {
                for (String name : exts)
                {
                    array.put(name);
                }
            }

            return(array);
        }
        /**
         * Returns all the request headers
         */
        public Value apache_request_headers(Env env)
        {
            QuercusHttpServletRequest req = env.getRequest();

            ArrayValue result = new ArrayValueImpl();

            Enumeration e = req.getHeaderNames();

            while (e.hasMoreElements())
            {
                string key = (String)e.nextElement();

                result.put(env.createString(key), env.createString(req.getHeader(key)));
            }

            return(result);
        }
        public ArrayValue getClasses(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashSet <String> exts = env.getModuleContext().getExtensionClasses(_name);

            if (exts != null)
            {
                for (String name : exts)
                {
                    array.put(StringValue.create(name),
                              env.wrapJava(new ReflectionClass(env, name)));
                }
            }

            return(array);
        }
        public static ArrayValue parse(Env env, ReadStream @is, bool isProcessSections)

        {
            ArrayValue top     = new ArrayValueImpl();
            ArrayValue section = top;

            while (true)
            {
                int ch = skipWhitespaces(is);

                if (ch < 0)
                {
                    break;
                }
                else if (ch == ';')
                {
                    skipToNewline(is);
                }
                else if (ch == '#')
                {
                    // nam 2013-10-02: box
                    skipToNewline(is);
                }
                else if (ch == '[')
                {
                    StringValue key = parseBracketKey(env, is);

                    if (isProcessSections)
                    {
                        section = new ArrayValueImpl();

                        top.put(key, section);
                    }
                }
                else
                {
                    @is.unread();
                    parseIniLine(env, @is, section);
                }
            }

            return(top);
        }
        public ArrayValue getConstants(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            for (ModuleInfo moduleInfo : env.getQuercus().getModules())
            {
                Set <String> extensionSet = moduleInfo.getLoadedExtensions();

                if (extensionSet.contains(_name))
                {
                    for (Map.Entry <StringValue, Value> entry : moduleInfo
                         .getConstMap().entrySet())
                    {
                        array.put(entry.getKey(), entry.getValue());
                    }
                }
            }

            return(array);
        }