Esempio n. 1
0
        String processDispatch(CRoute route, String method, String uri, String query, String body)
        {
            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServe(rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";

            if (route.id.Length > 0)
            {
                strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
            }

            CRhoFile.recursiveCreateDir(strFilePath);
            CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strFilePath);
        }
Esempio n. 2
0
        //public static IDBResult createResult(){
        //	return getInstance().m_dbStorage.createResult();
        //}

        public String makeBlobFolderName()
        {
            String fName = CFilePath.join(CRhodesApp.getRhoRootPath(), "db/db-files");

            CRhoFile.recursiveCreateDir(fName);

            return(fName);
        }
Esempio n. 3
0
        IDictionary processIndex(CRoute route, String method, String uri, Dictionary <String, String> headers, String query, String body)
        {
            Object rhoResp = new Dictionary <String, String>();

            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strFilePath;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "404";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Not Found";
                return((IDictionary)rhoResp);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strIndexFile;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "200";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Ok";
                return((IDictionary)rhoResp);
            }

            Object rhoReq = create_request_hash(route, method, uri, query, headers, body);

            rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strRedirectUrl;
                return((IDictionary)rhoResp);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strIndexFile;
            return((IDictionary)rhoResp);
        }
Esempio n. 4
0
        String processIndex(CRoute route, String method, String uri, String query, String body)
        {
            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                return(strFilePath);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                return(strIndexFile);
            }

            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strIndexFile);
        }
Esempio n. 5
0
        public CResponse decide(String method, String uri, String query, String body)
        {
            if (uri.EndsWith(".gen.html") || (isknowntype(uri) && uri.StartsWith(m_root)))
            {
                return(new CResponse(false));
            }

            if (process_registered(uri))
            {
                return(new CResponse(false));
            }

            CRoute route = new CRoute();

            if (dispatch(uri, route))
            {
                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServe(rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";
                if (route.id.Length > 0)
                {
                    strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
                }

                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strFilePath));
            }

            String fullPath = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                if (!CRhoFile.isResourceFileExist(strIndexFile))
                {
                    String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                    String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                    CRhoFile.recursiveCreateDir(strFilePath);
                    CRhoFile.writeStringToFile(strFilePath, error);
                    return(new CResponse(strFilePath));
                }

                if (CFilePath.getExtension(fullPath).Length > 0)
                {
                    return(new CResponse(strIndexFile));
                }

                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                strIndexFile += ".gen.html";
                CRhoFile.recursiveCreateDir(strIndexFile);
                CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strIndexFile));
            }

            return(new CResponse(false));
        }
Esempio n. 6
0
 private void initFilePaths(String strDBName)
 {
     CRhoFile.recursiveCreateDir(strDBName);
     m_strDBPath    = strDBName;
     m_strDbVerPath = m_strDBPath + ".version";
 }