/** Opens a path based on a Source. */
  ReadStream openPath(Source source) throws TransformerException, IOException {
    String systemId = source.getSystemId();

    Path path;
    if (systemId != null) path = getSearchPath().lookup(systemId);
    else path = getSearchPath().lookup("anonymous.xsl");

    if (source instanceof StreamSource) {
      StreamSource stream = (StreamSource) source;

      InputStream is = stream.getInputStream();

      if (is instanceof ReadStream) {
        ReadStream rs = (ReadStream) is;

        rs.setPath(path);

        return rs;
      } else if (is != null) {
        ReadStream rs = Vfs.openRead(is);
        rs.setPath(path);

        return rs;
      }

      Reader reader = stream.getReader();

      if (reader != null) {
        ReadStream rs = Vfs.openRead(reader);
        rs.setPath(path);

        return rs;
      }
    }

    if (systemId != null) return getSearchPath().lookup(systemId).openRead();

    throw new TransformerException("bad source " + source);
  }
  /** Parses a stylesheet from the source. */
  protected Node parseStylesheet(Source source) throws TransformerConfigurationException {
    if (source instanceof DOMSource) return ((DOMSource) source).getNode();
    else if (source instanceof StreamSource) {
      InputStream is = ((StreamSource) source).getInputStream();
      ReadStream rs = null;

      try {
        rs = Vfs.openRead(is);
        return parseXSL(rs);
      } catch (Exception e) {
        throw new TransformerConfigurationException(e);
      } finally {
        if (rs != null) rs.close();
      }
    } else return null;
  }
  private void handleExternalBody(String url) throws JspException, ServletException, IOException {
    URL netURL = new URL(url);

    URLConnection conn = netURL.openConnection();

    if (conn instanceof HttpURLConnection) ((HttpURLConnection) conn).setFollowRedirects(true);

    InputStream is = conn.getInputStream();
    try {
      ReadStream in = Vfs.openRead(is);
      String encoding = conn.getContentEncoding();
      String contentType = conn.getContentType();

      if (_charEncoding != null) {
        encoding = _charEncoding;
        if (encoding != null && !encoding.equals("")) in.setEncoding(encoding);
      } else if (encoding != null) in.setEncoding(encoding);
      else if (contentType != null) {
        int p = contentType.indexOf("charset=");
        if (p > 0) {
          CharBuffer cb = new CharBuffer();
          for (int i = p + 8; i < contentType.length(); i++) {
            int ch = contentType.charAt(i);
            if (ch == '"' || ch == '\'') {
            } else if (ch >= 'a' && ch <= 'z') cb.append((char) ch);
            else if (ch >= 'A' && ch <= 'Z') cb.append((char) ch);
            else if (ch >= '0' && ch <= '9') cb.append((char) ch);
            else if (ch == '-' || ch == '_') cb.append((char) ch);
            else break;
          }
          encoding = cb.toString();

          in.setEncoding(encoding);
        }
      }

      JspWriter out = pageContext.getOut();

      int ch;
      while ((ch = in.readChar()) >= 0) out.print((char) ch);
    } finally {
      is.close();
    }
  }
Example #4
0
  public boolean getFile(String tagName, String fileName, OutputStream os) throws IOException {
    StreamSource fileSource = _deployProxy.getFile(tagName, fileName);

    if (fileSource != null) {
      ReadStream is = null;
      GitObjectStream gitIs = new GitObjectStream(fileSource.getInputStream());

      try {
        is = Vfs.openRead(gitIs);

        is.writeToStream(os);
      } finally {
        gitIs.close();

        IoUtil.close(is);
      }

      return true;
    } else {
      return false;
    }
  }
Example #5
0
  private Map<String, RepositoryTagEntry> readTagMap(AbstractRepository repository, String sha1)
      throws IOException {
    TreeMap<String, RepositoryTagEntry> map = new TreeMap<String, RepositoryTagEntry>();

    InputStream is = repository.openBlob(sha1);
    try {
      ReadStream in = Vfs.openRead(is);

      String tag;

      while ((tag = in.readLine()) != null) {
        String entrySha1 = in.readLine();

        RepositoryTagEntry entry = new RepositoryTagEntry(repository, entrySha1);

        map.put(tag, entry);
      }
    } finally {
      is.close();
    }

    return Collections.unmodifiableMap(map);
  }
  /** Create a new stylesheet from an input stream. */
  public StylesheetImpl newStylesheet(InputStream is) throws Exception {
    ReadStream rs = Vfs.openRead(is);

    return (StylesheetImpl) generate(parseXSL(rs), rs.getPath());
  }