001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.quercus.lib.file;
031:
032: import com.caucho.quercus.env.BooleanValue;
033: import com.caucho.quercus.env.Env;
034: import com.caucho.quercus.env.LongValue;
035: import com.caucho.quercus.env.QuercusClass;
036: import com.caucho.quercus.env.StringValue;
037: import com.caucho.quercus.env.Value;
038: import com.caucho.quercus.program.AbstractFunction;
039:
040: public class ProtocolWrapper {
041: private QuercusClass _qClass;
042:
043: protected ProtocolWrapper() {
044: }
045:
046: public ProtocolWrapper(QuercusClass qClass) {
047: _qClass = qClass;
048: }
049:
050: public BinaryStream fopen(Env env, StringValue path,
051: StringValue mode, LongValue options) {
052: return new WrappedStream(env, _qClass, path, mode, options);
053: }
054:
055: public Value opendir(Env env, StringValue path, LongValue flags) {
056: WrappedDirectoryValue value = new WrappedDirectoryValue(env,
057: _qClass);
058:
059: if (!value.opendir(path, flags))
060: return BooleanValue.FALSE;
061: else
062: return value;
063: }
064:
065: public boolean unlink(Env env, StringValue path) {
066: AbstractFunction function = _qClass.getStaticFunction("unlink");
067:
068: if (function == null)
069: return false;
070:
071: return function.call(env, path).toBoolean();
072: }
073:
074: public boolean rename(Env env, StringValue path_from,
075: StringValue path_to) {
076: AbstractFunction function = _qClass.getStaticFunction("rename");
077:
078: if (function == null)
079: return false;
080:
081: return function.call(env, path_from, path_to).toBoolean();
082: }
083:
084: public boolean mkdir(Env env, StringValue path, LongValue mode,
085: LongValue options) {
086: AbstractFunction function = _qClass.getStaticFunction("mkdir");
087:
088: if (function == null)
089: return false;
090:
091: return function.call(env, path, mode, options).toBoolean();
092: }
093:
094: public boolean rmdir(Env env, StringValue path, LongValue options) {
095: AbstractFunction function = _qClass.getStaticFunction("rmdir");
096:
097: if (function == null)
098: return false;
099:
100: return function.call(env, path, options).toBoolean();
101: }
102:
103: public Value url_stat(Env env, StringValue path, LongValue flags) {
104: AbstractFunction function = _qClass
105: .getStaticFunction("url_stat");
106:
107: if (function == null)
108: return BooleanValue.FALSE;
109:
110: return function.call(env, path, flags);
111: }
112:
113: }
|