예제 #1
0
  /** Compile a schema. */
  public Schema compileSchema(Path path) throws SAXException, IOException {
    String nativePath = path.getNativePath();

    SoftReference<Schema> schemaRef = _schemaMap.get(path);
    Schema schema = null;

    if (schemaRef != null && (schema = schemaRef.get()) != null) {
      // XXX: probably eventually add an isModified
      return schema;
    }

    ReadStream is = path.openRead();

    try {
      InputSource source = new InputSource(is);

      source.setSystemId(path.getUserPath());

      schema = compileSchema(source);

      if (schema != null) _schemaMap.put(path, new SoftReference<Schema>(schema));
    } finally {
      is.close();
    }

    return schema;
  }
예제 #2
0
  /** Sets the resource directory. */
  public void setPath(Path path) {
    if (path.getPath().endsWith(".jar") || path.getPath().endsWith(".zip")) {
      path = JarPath.create(path);
    }

    _path = path;
  }
  @Override
  public String toString() {
    Path path = _path;

    if (path != null) return getClass().getSimpleName() + "[" + path.getTail() + "]";
    else return getClass().getSimpleName() + "[" + path + "]";
  }
  /**
   * Convenience class to create a compiled stylesheet.
   *
   * @param systemId source path for the stylesheet.
   * @return a compiled stylesheet
   */
  public javax.xml.transform.Templates newTemplates(String systemId)
      throws TransformerConfigurationException {
    StylesheetImpl stylesheet = loadPrecompiledStylesheet(systemId, systemId);

    if (stylesheet != null) return stylesheet;
    else if (systemId == null) return generate(new QDocument(), null);

    Path path = getSearchPath().lookup(systemId);

    try {
      ReadStream is = path.openRead();
      Document doc;
      try {
        doc = parseXSL(is);
      } finally {
        is.close();
      }

      return generate(doc, path);
    } catch (TransformerConfigurationException e) {
      throw e;
    } catch (IOException e) {
      System.out.println("MP: " + ((MergePath) getSearchPath()).getMergePaths());
      throw new TransformerConfigurationExceptionWrapper(e);
    } catch (Exception e) {
      throw new TransformerConfigurationExceptionWrapper(e);
    }
  }
  /** Opens a relative path. */
  private Source getSource(String href, String base) throws Exception {
    Path subpath;

    if (href == null) href = "";
    if (base == null) base = "/";

    if (_uriResolver != null) {
      if (href.startsWith("/") || base.equals("/")) subpath = getSearchPath().lookup(href);
      else {
        subpath = getSearchPath().lookup(base).getParent().lookup(href);
      }

      Source source = _uriResolver.resolve(href, base);

      if (source != null) {
        if (source.getSystemId() == null) source.setSystemId(subpath.getURL());

        return source;
      }
    }

    if (href.startsWith("/") || base.equals("/")) subpath = getSearchPath().lookup(href);
    else {
      if (base.startsWith("file:")) base = base.substring(5);

      subpath = getSearchPath().lookup(base).getParent().lookup(href);
    }

    return new StreamSource(subpath.getURL());
  }
  private Path writeTempFile(Node node) throws IOException {
    Path workDir = CauchoSystem.getWorkPath().lookup("_xsl");
    workDir.mkdirs();

    // Path temp = workDir.createTempFile("tmp", "xsl");

    WriteStream os = Vfs.lookup("null:").openWrite();
    Crc64Stream crcStream = new Crc64Stream(os.getSource());
    os.init(crcStream);
    try {
      XmlPrinter printer = new XmlPrinter(os);

      printer.printNode(node);
    } finally {
      os.close();
    }

    long crc = crcStream.getCRC();
    CharBuffer cb = new CharBuffer();
    Base64.encode(cb, crc);

    String crcValue = cb.toString().replace('/', '-');

    Path xslPath = workDir.lookup(crcValue + ".xsl");

    // temp.renameTo(xslPath);

    return xslPath;
  }
예제 #7
0
  public SplFileInfo(Env env, StringValue fileName) {
    _path = env.lookupPwd(fileName);

    _parent = _path.getParent();

    _fileName = _path.getTail();
  }
  /** Removes logs passing the rollover count. */
  private void removeOldLogs() {
    try {
      Path path = getPath();
      Path parent = path.getParent();

      String[] list = parent.list();

      ArrayList<String> matchList = new ArrayList<String>();

      Pattern archiveRegexp = getArchiveRegexp();
      for (int i = 0; i < list.length; i++) {
        Matcher matcher = archiveRegexp.matcher(list[i]);

        if (matcher.matches()) matchList.add(list[i]);
      }

      Collections.sort(matchList);

      if (_rolloverCount <= 0 || matchList.size() < _rolloverCount) return;

      for (int i = 0; i + _rolloverCount < matchList.size(); i++) {
        try {
          parent.lookup(matchList.get(i)).remove();
        } catch (Throwable e) {
        }
      }
    } catch (Throwable e) {
    }
  }
  /**
   * Converts node tree to a valid xml string.
   *
   * @return xml string
   */
  public final Value asXML(Env env, @Optional Value filename) {
    Value value = toXML(env);

    if (!value.isString()) {
      return value;
    }

    StringValue str = value.toStringValue(env);

    if (filename.isDefault()) {
      return str;
    } else {
      Path path = env.lookupPwd(filename);

      OutputStream os = null;

      try {
        os = path.openWrite();

        str.writeTo(os);

        return BooleanValue.TRUE;
      } catch (IOException e) {
        env.warning(e);

        return BooleanValue.FALSE;
      } finally {
        if (os != null) {
          IoUtil.close(os);
        }
      }
    }
  }
  public Path getCauchoPath(String name) {
    String realPath = getRealPath(name);

    Path rootDirectory = getRootDirectory();
    Path path = rootDirectory.lookupNative(realPath);

    return path;
  }
예제 #11
0
  /** Adds the class of this resource. */
  @Override
  protected void buildClassPath(ArrayList<String> pathList) {
    String path = null;

    if (_path instanceof JarPath) path = ((JarPath) _path).getContainer().getNativePath();
    else if (_path.isDirectory()) path = _path.getNativePath();

    if (path != null && !pathList.contains(path)) pathList.add(path);
  }
예제 #12
0
  /**
   * Given a class or resource name, returns a patch to that resource.
   *
   * @param name the class or resource name.
   * @return the path representing the class or resource.
   */
  @Override
  public Path getPath(String name) {
    if (_prefix != null && _pathPrefix == null) _pathPrefix = _prefix.replace('.', '/');

    if (_pathPrefix != null && !name.startsWith(_pathPrefix)) return null;

    if (name.startsWith("/")) return _path.lookup("." + name);
    else return _path.lookup(name);
  }
예제 #13
0
    public int hashCode() {
      int hash = 37;

      hash = 65537 * hash + _include.hashCode();
      hash = 65537 * hash + _includePath.hashCode();
      hash = 65537 * hash + _pwd.hashCode();
      hash = 65537 * hash + _scriptPwd.hashCode();

      return hash;
    }
예제 #14
0
    public boolean equals(Object o) {
      if (!(o instanceof IncludeKey)) return false;

      IncludeKey key = (IncludeKey) o;

      return (_include.equals(key._include)
          && _includePath.equals(key._includePath)
          && _pwd.equals(key._pwd)
          && _scriptPwd.equals(key._scriptPwd));
    }
  /** Returns the path to be used as the servlet name. */
  private Path getPagePath(String pathName) {
    Path rootDir = _webApp.getRootDirectory();
    String realPath = _webApp.getRealPath(pathName);
    Path path = rootDir.lookupNative(realPath);

    if (path.isFile() && path.canRead()) return path;

    java.net.URL url;
    ClassLoader loader = _webApp.getClassLoader();
    if (loader != null) {
      url = _webApp.getClassLoader().getResource(pathName);

      String name = url != null ? url.toString() : null;

      path = null;
      if (url != null && (name.endsWith(".jar") || name.endsWith(".zip")))
        path = JarPath.create(Vfs.lookup(url.toString())).lookup(pathName);
      else if (url != null) path = Vfs.lookup(url.toString());

      if (path != null && path.isFile() && path.canRead()) return path;
    }

    url = ClassLoader.getSystemResource(pathName);
    String name = url != null ? url.toString() : null;

    path = null;
    if (url != null && (name.endsWith(".jar") || name.endsWith(".zip")))
      path = JarPath.create(Vfs.lookup(url.toString())).lookup(pathName);
    else if (url != null) path = Vfs.lookup(url.toString());

    if (path != null && path.isFile() && path.canRead()) return path;
    else return null;
  }
예제 #16
0
 public String getType(Env env) {
   if (_path.isLink()) {
     return "link";
   } else if (_path.isDirectory()) {
     return "dir";
   } else if (_path.isFile()) {
     return "file";
   } else {
     /// XXX: throw RuntimeException
     return null;
   }
 }
  /**
   * Create a compiled stylesheet from an input stream.
   *
   * @param source the source stream
   * @return the compiled stylesheet
   */
  public Templates newTemplates(Source source) throws TransformerConfigurationException {
    String systemId = source.getSystemId();

    try {
      if (systemId != null) {
        StylesheetImpl stylesheet = loadPrecompiledStylesheet(systemId, systemId);

        if (stylesheet != null) return stylesheet;
      }

      if (source instanceof DOMSource) {
        Node node = ((DOMSource) source).getNode();

        return generateFromNode(node, systemId);
      } else if (source instanceof SAXSource) {
        SAXSource saxSource = (SAXSource) source;
        XMLReader reader = saxSource.getXMLReader();
        InputSource inputSource = saxSource.getInputSource();

        Document doc = new QDocument();
        DOMBuilder builder = new DOMBuilder();
        builder.init(doc);
        reader.setContentHandler(builder);

        reader.parse(inputSource);

        return generateFromNode(doc, systemId);
      }

      ReadStream rs = openPath(source);
      try {
        Path path = rs.getPath();

        Document doc = parseXSL(rs);

        if (systemId != null) {
          String mangledName = getMangledName(systemId);
          Path genPath = getWorkPath().lookup(mangledName);

          genPath.setUserPath(systemId);

          return generate(doc, genPath);
        } else return generateFromNode(doc, null);
      } finally {
        if (rs != null) rs.close();
      }
    } catch (TransformerConfigurationException e) {
      throw e;
    } catch (Exception e) {
      throw new XslParseException(e);
    }
  }
  /** Compile a schema. */
  public Schema compileSchema(String url) throws SAXException, IOException {
    Path path = Vfs.lookup(url);

    ReadStream is = path.openRead();
    try {
      InputSource source = new InputSource(is);
      source.setSystemId(url);

      return compileSchema(source);
    } finally {
      is.close();
    }
  }
  private Templates generateFromNode(Node node, String systemId)
      throws IOException, TransformerConfigurationException {
    Path tempPath = writeTempFile(node);

    String tempId = tempPath.getTail();

    StylesheetImpl stylesheet = loadPrecompiledStylesheet(tempId, tempId, false);

    if (systemId != null) tempPath.setUserPath(systemId);

    if (stylesheet != null) return stylesheet;

    return generate(node, tempPath);
  }
  /** Called from rollover worker */
  private void rolloverLogTask() {
    try {
      if (_isInit) flush();
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }

    _isRollingOver = true;

    try {
      if (!_isInit) return;

      Path savedPath = null;

      long now = CurrentTime.getCurrentTime();

      long lastPeriodEnd = _nextPeriodEnd;

      _nextPeriodEnd = nextRolloverTime(now);

      Path path = getPath();

      synchronized (_logLock) {
        flushTempStream();

        if (lastPeriodEnd <= now && lastPeriodEnd > 0) {
          closeLogStream();

          savedPath = getSavedPath(lastPeriodEnd - 1);
        } else if (path != null && getRolloverSize() <= path.getLength()) {
          closeLogStream();

          savedPath = getSavedPath(now);
        }
      }

      // archiving of path is outside of the synchronized block to
      // avoid freezing during archive
      if (savedPath != null) {
        movePathToArchive(savedPath);
      }
    } finally {
      synchronized (_logLock) {
        _isRollingOver = false;
        flushTempStream();
      }

      _rolloverListener.requeue(_rolloverAlarm);
    }
  }
  /** Opens a relative path. */
  ReadStream openPath(String href, String base) throws TransformerException, IOException {
    if (_uriResolver != null) {
      Source source = _uriResolver.resolve(href, base);

      if (source != null) return openPath(source);
    }

    if (href.startsWith("/") || base.equals("/")) return getSearchPath().lookup(href).openRead();
    else {
      Path path = getSearchPath().lookup(base).getParent().lookup(href);

      if (path.exists()) return path.openRead();
      else return getSearchPath().lookup(href).openRead();
    }
  }
예제 #22
0
  /** Tests for equality. */
  @Override
  public boolean equals(Object o) {
    if (o == null || !getClass().equals(o.getClass())) return false;

    ExpandDeployGenerator<?> deploy = (ExpandDeployGenerator<?>) o;

    Path expandDirectory = getExpandDirectory();
    Path deployExpandDirectory = deploy.getExpandDirectory();

    if (expandDirectory != deployExpandDirectory
        && (expandDirectory == null || !expandDirectory.equals(deployExpandDirectory)))
      return false;

    return true;
  }
  /** Returns the code source. */
  public CodeSource getCodeSource(String path) {
    try {
      Path jarPath = _jarPath.lookup(path);

      Certificate[] certificates = jarPath.getCertificates();

      URL url = new URL(_jarPath.getContainer().getURL());

      return new CodeSource(url, certificates);
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);

      return null;
    }
  }
예제 #24
0
 public void init(com.caucho.java.LineMap lineMap, com.caucho.vfs.Path appDir)
     throws javax.servlet.ServletException {
   com.caucho.vfs.Path resinHome = com.caucho.util.CauchoSystem.getResinHome();
   com.caucho.vfs.MergePath mergePath = new com.caucho.vfs.MergePath();
   mergePath.addMergePath(appDir);
   mergePath.addMergePath(resinHome);
   com.caucho.loader.DynamicClassLoader loader;
   loader = (com.caucho.loader.DynamicClassLoader) getClass().getClassLoader();
   String resourcePath = loader.getResourcePathSpecificFirst();
   mergePath.addClassPath(resourcePath);
   _caucho_line_map = new com.caucho.java.LineMap("_main__jsp.java", "foo");
   _caucho_line_map.add("/myadmin/main.jsp", 14, 30);
   _caucho_line_map.add(14, 32);
   _caucho_line_map.add(22, 34);
   _caucho_line_map.add(62, 75);
   _caucho_line_map.add(63, 77);
   _caucho_line_map.add(67, 79);
   _caucho_line_map.add(68, 81);
   _caucho_line_map.add(69, 83);
   _caucho_line_map.add(70, 85);
   _caucho_line_map.add(74, 87);
   _caucho_line_map.add(83, 96);
   _caucho_line_map.add(92, 98);
   com.caucho.vfs.Depend depend;
   depend =
       new com.caucho.vfs.Depend(
           appDir.lookup("myadmin/main.jsp"), "AOlUHB8X9qDorKgZ7MCqag==", false);
   _caucho_depends.add(depend);
 }
예제 #25
0
 public void init(com.caucho.vfs.Path appDir) throws javax.servlet.ServletException {
   com.caucho.vfs.Path resinHome = com.caucho.server.util.CauchoSystem.getResinHome();
   com.caucho.vfs.MergePath mergePath = new com.caucho.vfs.MergePath();
   mergePath.addMergePath(appDir);
   mergePath.addMergePath(resinHome);
   com.caucho.loader.DynamicClassLoader loader;
   loader = (com.caucho.loader.DynamicClassLoader) getClass().getClassLoader();
   String resourcePath = loader.getResourcePathSpecificFirst();
   mergePath.addClassPath(resourcePath);
   com.caucho.vfs.Depend depend;
   depend =
       new com.caucho.vfs.Depend(appDir.lookup("tweetSearch.jsp"), -3076669215319968785L, false);
   _caucho_depends.add(depend);
   depend = new com.caucho.vfs.Depend(appDir.lookup("header.jsp"), 7773134504633206276L, false);
   _caucho_depends.add(depend);
 }
  /** Executes the JSP Page */
  public void service(ServletRequest request, ServletResponse response)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    _caucho_init(req, res);

    if (_hasSession) {
      req.getSession();
      res.setHeader("Cache-Control", "private");
    }

    // res.setContentLength(_contentLength);

    TempCharBuffer buf = TempCharBuffer.allocate();
    char[] cBuf = buf.getBuffer();
    int len;

    PrintWriter out = response.getWriter();

    ReadStream rs = _cacheEntry.openRead();
    rs.setEncoding("UTF-8");
    try {
      while ((len = rs.read(cBuf, 0, cBuf.length)) > 0) {
        out.write(cBuf, 0, len);
      }
    } finally {
      rs.close();
    }

    TempCharBuffer.free(buf);
  }
  /**
   * Create a new Static page.
   *
   * @param path the underlying file
   * @param hasSession if true, create a new session
   */
  StaticPage(Path path, boolean hasSession) throws IOException {
    _cacheEntry = path;
    _contentLength = (int) _cacheEntry.getLength();
    _hasSession = hasSession;

    _caucho_setCacheable();
  }
 public void init(com.caucho.vfs.Path appDir) throws javax.servlet.ServletException {
   com.caucho.vfs.Path resinHome = com.caucho.server.util.CauchoSystem.getResinHome();
   com.caucho.vfs.MergePath mergePath = new com.caucho.vfs.MergePath();
   mergePath.addMergePath(appDir);
   mergePath.addMergePath(resinHome);
   com.caucho.loader.DynamicClassLoader loader;
   loader = (com.caucho.loader.DynamicClassLoader) getClass().getClassLoader();
   String resourcePath = loader.getResourcePathSpecificFirst();
   mergePath.addClassPath(resourcePath);
   com.caucho.vfs.Depend depend;
   depend =
       new com.caucho.vfs.Depend(appDir.lookup("EthnicGroup.jsp"), 6847378287986436659L, false);
   _caucho_depends.add(depend);
   depend = new com.caucho.vfs.Depend(appDir.lookup("Footer.jsp"), -3074380813858324039L, false);
   _caucho_depends.add(depend);
 }
예제 #29
0
 public void init(com.caucho.vfs.Path appDir) throws javax.servlet.ServletException {
   com.caucho.vfs.Path resinHome = com.caucho.server.util.CauchoSystem.getResinHome();
   com.caucho.vfs.MergePath mergePath = new com.caucho.vfs.MergePath();
   mergePath.addMergePath(appDir);
   mergePath.addMergePath(resinHome);
   com.caucho.loader.DynamicClassLoader loader;
   loader = (com.caucho.loader.DynamicClassLoader) getClass().getClassLoader();
   String resourcePath = loader.getResourcePathSpecificFirst();
   mergePath.addClassPath(resourcePath);
   com.caucho.vfs.Depend depend;
   depend = new com.caucho.vfs.Depend(appDir.lookup("initpass.jsp"), 7048575714632404679L, false);
   com.caucho.jsp.JavaPage.addDepend(_caucho_depends, depend);
   depend =
       new com.caucho.vfs.Depend(appDir.lookup("login_check.jsp"), 5313538553479869376L, false);
   com.caucho.jsp.JavaPage.addDepend(_caucho_depends, depend);
 }
예제 #30
0
  public String getPathname(Env env) {
    String parentPath = "";

    if (_parent != null) {
      parentPath = _parent.getNativePath();
    }

    StringBuilder sb = new StringBuilder();
    sb.append(parentPath);

    if (!parentPath.endsWith(FileModule.DIRECTORY_SEPARATOR)) {
      sb.append(FileModule.DIRECTORY_SEPARATOR);
    }

    if (_fileName.startsWith(FileModule.DIRECTORY_SEPARATOR)) {
      sb.append(_fileName, 1, _fileName.length());
    } else {
      sb.append(_fileName);
    }

    return sb.toString();

    /*
    if (".".equals(_fileName)) {
      return _path.getNativePath() + FileModule.DIRECTORY_SEPARATOR + _fileName;
    }
    else if ("..".equals(_fileName)) {
      return _path.getNativePath() + FileModule.DIRECTORY_SEPARATOR + _fileName;
    }
    else {
      return _path.getNativePath();
    }
    */
  }