/**
         * Executes the script.
         */
        public Value execute(Path path)

        {
            init();

            ReadStream reader = path.openRead();

            QuercusProgram program = QuercusParser.parse(_quercus, null, reader);

            OutputStream os = _out;
            WriteStream out;

            if (os != null)
            {
                OutputStreamStream s  = new OutputStreamStream(os);
                WriteStream        ws = new WriteStream(s);

                ws.setNewlineString("\n");

                try {
                    ws.setEncoding("iso-8859-1");
                } catch (Exception e) {
                }

                @out = ws;
            }
            else
            {
                @out = new WriteStream(StdoutStream.create());
            }

            QuercusPage page = new InterpretedPage(program);

            Env env = new Env(_quercus, page, @out, null, null);

            Value value = NullValue.NULL;

            try {
                env.start();

                value = program.execute(env);
            }
            catch (QuercusExitException e) {
            }

            @out.flushBuffer();
            @out.free();

            if (os != null)
            {
                os.flush();
            }

            return(value);
        }
Example #2
0
        public QuercusPage parseImpl(Path path, string fileName, int line)

        {
            try {
                SoftReference <QuercusProgram> programRef = _programCache.get(path);

                QuercusProgram program = programRef != null?programRef.get() : null;

                bool isModified = false;

                if (program != null)
                {
                    isModified = program.isModified();

                    if (program.isCompilable())
                    {
                    }
                    else if (isModified)
                    {
                        program.setCompilable(true);
                    }
                    else
                    {
                        if (log.isLoggable(Level.FINE))
                        {
                            log.fine(L.l("Quercus[{0}] loading interpreted page", path));
                        }

                        return(new InterpretedPage(program));
                    }
                }

                if (program == null || isModified)
                {
                    clearProgram(path, program);

                    program = preloadProgram(path, fileName);

                    if (program == null)
                    {
                        if (log.isLoggable(Level.FINE))
                        {
                            log.fine(L.l("Quercus[{0}] parsing page", path));
                        }

                        program = QuercusParser.parse(_quercus,
                                                      path,
                                                      _quercus.getScriptEncoding(),
                                                      fileName,
                                                      line);
                    }

                    _programCache.put(path, new SoftReference <QuercusProgram>(program));
                }

                if (program.getCompiledPage() != null)
                {
                    return(program.getCompiledPage());
                }

                return(compilePage(program, path));
            } catch (IOException e) {
                throw e;
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable e) {
                throw new IOExceptionWrapper(e);
            }
        }