Example #1
0
        String getIndex(String path)
        {
            String[] index_files = { "index_erb.rb", "index.html", "index.htm", "index.php", "index.cgi" };

            if (CFilePath.getExtension(path).Length == 0)
            {
                return(CFilePath.join(path, index_files[0]));
            }

            String strFileName = CFilePath.getBaseName(path);

            return(find_in_string_array(strFileName, index_files) ? path : "");
        }
Example #2
0
        String makeBulkDataFileName(String strDataUrl, String strDbPath, String strExt)
        {
            String strNewName = CFilePath.getBaseName(strDataUrl);
            String strOldName = RhoConf.getInstance().getString("bulksync_filename");

            if (strOldName.length() > 0 && strNewName.compareTo(strOldName) != 0)
            {
                String strFToDelete = CFilePath.changeBaseName(strDbPath, strOldName + strExt);
                LOG.INFO("Bulk sync: remove old bulk file '" + strFToDelete + "'");

                //RhoFile.deleteFile( strFToDelete.c_str() );
                CRhoFile.deleteFile(strFToDelete);
            }

            RhoConf.getInstance().setString("bulksync_filename", strNewName, true);

            return(CFilePath.changeBaseName(strDbPath, strNewName + strExt));
        }
Example #3
0
        //static String szMultipartPostfix =
        //    "\r\n------------A6174410D6AD474183FDE48F5662FCC5--";

        //static String szMultipartContType =
        //    "multipart/form-data; boundary=----------A6174410D6AD474183FDE48F5662FCC5";

        void processMultipartItems(Vector <MultipartItem> arItems)
        {
            for (int i = 0; i < (int)arItems.size(); i++)
            {
                MultipartItem oItem = (MultipartItem)arItems.elementAt(i);

                if (oItem.m_strName.length() == 0)
                {
                    oItem.m_strName = "blob";
                }

                if (oItem.m_strFileName.length() == 0)
                {
                    if (oItem.m_strFilePath.length() > 0)
                    {
                        oItem.m_strFileName = CFilePath.getBaseName(oItem.m_strFilePath);
                    }
                    //else
                    //    oItem.m_strFileName = "doesnotmatter.txt";
                }

                oItem.m_strDataPrefix  = i > 0 ? "\r\n" : "";
                oItem.m_strDataPrefix +=
                    "------------A6174410D6AD474183FDE48F5662FCC5\r\n" +
                    "Content-Disposition: form-data; name=\"";
                oItem.m_strDataPrefix += oItem.m_strName + "\"";
                if (oItem.m_strFileName.length() > 0)
                {
                    oItem.m_strDataPrefix += "; filename=\"" + oItem.m_strFileName + "\"";
                }
                oItem.m_strDataPrefix += "\r\n";
                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Type: " + oItem.m_strContentType + "\r\n";
                }

                long nContentSize = 0;
                if (oItem.m_strFilePath.length() > 0)
                {
                    //TODO: process file

/*	                SimpleFile file = null;
 *                          try{
 *                                  file = RhoClassFactory.createFile();
 *                                  file.open(oItem.m_strFilePath, true, true);
 *                                  nContentSize = file.length();
 *                                  if ( !file.isOpened() ){
 *                                          LOG.ERROR("File not found: " + oItem.m_strFilePath);
 *                                          throw new RuntimeException("File not found:" + oItem.m_strFilePath);
 *                                  }
 *                          }finally{
 *                                  if ( file != null )
 *                                          try{ file.close(); }catch(IOException e){}
 *                          }*/
                }
                else
                {
                    nContentSize = oItem.m_strBody.length();
                }

                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Length: " + nContentSize + "\r\n";
                }

                oItem.m_strDataPrefix += "\r\n";
            }
        }
Example #4
0
        void processMultipartItems(Vector <MultipartItem> arItems)
        {
            for (int i = 0; i < (int)arItems.size(); i++)
            {
                MultipartItem oItem = (MultipartItem)arItems.elementAt(i);

                if (oItem.m_strName.length() == 0)
                {
                    oItem.m_strName = "blob";
                }

                if (oItem.m_strFileName.length() == 0)
                {
                    if (oItem.m_strFilePath.length() > 0)
                    {
                        oItem.m_strFileName = CFilePath.getBaseName(oItem.m_strFilePath);
                    }
                    //else
                    //    oItem.m_strFileName = "doesnotmatter.txt";
                }

                oItem.m_strDataPrefix  = i > 0 ? "\r\n" : "";
                oItem.m_strDataPrefix +=
                    "------------A6174410D6AD474183FDE48F5662FCC5\r\n" +
                    "Content-Disposition: form-data; name=\"";
                oItem.m_strDataPrefix += oItem.m_strName + "\"";
                if (oItem.m_strFileName.length() > 0)
                {
                    oItem.m_strDataPrefix += "; filename=\"" + oItem.m_strFileName + "\"";
                }
                oItem.m_strDataPrefix += "\r\n";
                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Type: " + oItem.m_strContentType + "\r\n";
                }

                long nContentSize = 0;
                if (oItem.m_strFilePath.length() > 0)
                {
                    CRhoFile file = null;
                    try{
                        file = RhoClassFactory.createFile();
                        file.open(oItem.m_strFilePath, CRhoFile.EOpenModes.OpenReadOnly);
                        nContentSize = file.size();
                        if (!file.isOpened())
                        {
                            LOG.ERROR("File not found: " + oItem.m_strFilePath);
                            throw new Exception("File not found:" + oItem.m_strFilePath);
                        }
                    }finally{
                        if (file != null)
                        {
                            try{ file.close(); }catch (IOException e)
                            {
                                LOG.ERROR("file closing failed.", e);
                            }
                        }
                    }
                }
                else
                {
                    nContentSize = oItem.m_strBody.length();
                }

                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Length: " + nContentSize + "\r\n";
                }

                oItem.m_strDataPrefix += "\r\n";
            }
        }