Source Code Cross Referenced for FileOption.java in  » Portal » Open-Portal » com » sun » portal » netfile » servlet » java1 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.netfile.servlet.java1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * $Id: FileOption.java,v 1.57 2005/11/30 11:26:33 ss150821 Exp $
0003:         * Copyright 2002 Sun Microsystems, Inc. All
0004:         * rights reserved. Use of this product is subject
0005:         * to license terms. Federal Acquisitions:
0006:         * Commercial Software -- Government Users
0007:         * Subject to Standard License Terms and
0008:         * Conditions.
0009:         *
0010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011:         * are trademarks or registered trademarks of Sun Microsystems,
0012:         * Inc. in the United States and other countries.
0013:         */package com.sun.portal.netfile.servlet.java1;
0014:
0015:        import com.iplanet.sso.*;
0016:        import com.sun.portal.log.common.PortalLogger;
0017:        import java.util.*;
0018:        import java.util.logging.*;
0019:        import java.io.*;
0020:
0021:        class FileOption {
0022:
0023:            /* Supported machine types */
0024:            private static final String WIN = "WIN";
0025:            private static final String NT = "NT";
0026:            private static final String NFS = "NFS";
0027:            private static final String NETWARE = "NETWARE";
0028:            private static final String FTP = "FTP";
0029:            private static final String ERROR = "ERROR:";
0030:            private static final String MESSAGE_1 = " Processing of file ";
0031:            private static final String TEXT_SEPERATOR = "textseperator";
0032:
0033:            /* .properties files to pick localised messages from */
0034:            public static final String SERVLET_PROPERTIES = "srapNetFileServletJava1";
0035:            public static final String APPLET_PROPERTIES = "srapNetFileAppletJava1";
0036:
0037:            private static final String END_OF_STRING = "\0";
0038:            private String[] pathinfo;
0039:            private String s_empty_string = "";
0040:            private String exerr = s_empty_string;
0041:            private String[] rettxt = new String[2];
0042:            private static NetFileResource nfr_platform_locale_i18n_bucket;
0043:            private static Logger logger = PortalLogger
0044:                    .getLogger(FileOption.class);
0045:            private static String s_platform_locale_error;
0046:            private NetFileLogManager logMgr = null;
0047:            private String s_machine_encoding;
0048:            private SSOToken ssoToken = null;
0049:            private char c_eol = '\n';
0050:
0051:            FileOption(NetFileLogManager log_Mgr, String s_machine_encoding) {
0052:                this .logMgr = log_Mgr;
0053:                this .s_machine_encoding = s_machine_encoding;
0054:                pathinfo = new String[2];
0055:                try {
0056:                    setPlatformLocaleBundle();
0057:                } catch (NetFileException e) {
0058:                    //            logger.log(Level.SEVERE, "Could not obtain platform specific locale bundle properly", e);
0059:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1000");
0060:                }
0061:            }
0062:
0063:            FileOption(NetFileLogManager log_Mgr, String s_machine_encoding,
0064:                    SSOToken ssoToken) {
0065:                this .logMgr = log_Mgr;
0066:                this .s_machine_encoding = s_machine_encoding;
0067:                pathinfo = new String[2];
0068:                setSSOToken(ssoToken);
0069:                try {
0070:                    setPlatformLocaleBundle();
0071:                } catch (NetFileException e) {
0072:                    //            logger.log(Level.SEVERE, "Could not obtain platform specific locale bundle properly", e);
0073:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1001");
0074:                }
0075:            }
0076:
0077:            private synchronized static void setPlatformLocaleBundle()
0078:                    throws NetFileException {
0079:                if (nfr_platform_locale_i18n_bucket == null) {
0080:                    nfr_platform_locale_i18n_bucket = NetFileResource
0081:                            .getInstance(FileOption.SERVLET_PROPERTIES);
0082:                    s_platform_locale_error = nfr_platform_locale_i18n_bucket
0083:                            .getString("error");
0084:                    if (s_platform_locale_error == null) {
0085:                        throw new NetFileException(
0086:                                "There is no entry for key error in srapNetFileServletJava1.properties");
0087:                    }
0088:                }
0089:            }
0090:
0091:            public void setSSOToken(SSOToken token) {
0092:                this .ssoToken = token;
0093:            }
0094:
0095:            public SSOToken getSSOToken() {
0096:                return this .ssoToken;
0097:            }
0098:
0099:            public String getPlatformLocalisedString(String string) {
0100:                return nfr_platform_locale_i18n_bucket.getString(string);
0101:            }
0102:
0103:            public NetFileResource getPlatformLocalisedBundle() {
0104:                if (nfr_platform_locale_i18n_bucket == null) {
0105:                    //            logger.severe(" nfr_platform_locale_i18n_bucket not initialised yet in FileOption");
0106:                    logger.severe("PSSRNF_CSPNSJ1002");
0107:                }
0108:                return nfr_platform_locale_i18n_bucket;
0109:            }
0110:
0111:            //-------------------------------------------------
0112:            // Expand the "root" level of a machine
0113:            //  - depending on the machine type, we'll do
0114:            //    different things:
0115:            //    FileOption.NETWARE - get a directory listing using FileOption.FTP
0116:            //    FileOption.WIN / FileOption.NT - read the root level of the share
0117:            //    UNIX - first figure out whether we're going
0118:            //           to use ftp or nfs and then get
0119:            //           the listing of the dir/mount point.
0120:            //
0121:            //  All routines MUST return data in the following
0122:            //  way:
0123:            //  <type>\t<filename>\t<size>\t<timestamp>
0124:            //  where type = D (directory) or anything else
0125:            //  Called by Java NetFile.
0126:            //-------------------------------------------------
0127:
0128:            String[] expandVMS(String user_name, String password,
0129:                    String machine_name, String domain, String machine_type,
0130:                    String VMS, String temporary_directory,
0131:                    NetFileResource nfr_user_locale_i18n_bucket)
0132:                    throws Throwable {
0133:                return expandDir(user_name, password, machine_name, domain,
0134:                        machine_type, s_empty_string, VMS, temporary_directory,
0135:                        nfr_user_locale_i18n_bucket);
0136:            }
0137:
0138:            //-------------------------------------------------
0139:            // Expand a directory
0140:            //  - depending on the machine type, we'll do
0141:            //    different things:
0142:            //    FileOption.NETWARE - get a directory listing by running the
0143:            //    ftp 'dir' command
0144:            //    FileOption.WIN / FileOption.NT - read the given directory of the share
0145:            //    UNIX - ???
0146:            //
0147:            //  All routines MUST return data in the following
0148:            //  way:
0149:            //  <type>\t<filename>\t<size>\t<timestamp>
0150:            //  where type = D (directory) or anything else
0151:            //-------------------------------------------------
0152:
0153:            String[] expandDir(String user_name, String password,
0154:                    String machine_name, String domain, String machine_type,
0155:                    String directory, String VMS, String temporary_directory,
0156:                    NetFileResource nfr_user_locale_i18n_bucket)
0157:                    throws NetFileException, Exception {
0158:
0159:                if (user_name == null) {
0160:                    throw new NetFileException(new String[] {
0161:                            NetFileException.KEY_IDENTIFIER_PREFIX
0162:                                    + "invalid_user_name",
0163:                            NetFileException.KEY_IDENTIFIER_PREFIX
0164:                                    + FileOption.TEXT_SEPERATOR, user_name });
0165:                } else if (user_name.equals(s_empty_string)) {
0166:                    throw new NetFileException(new String[] {
0167:                            NetFileException.KEY_IDENTIFIER_PREFIX
0168:                                    + "invalid_user_name",
0169:                            NetFileException.KEY_IDENTIFIER_PREFIX
0170:                                    + FileOption.TEXT_SEPERATOR, user_name });
0171:                }
0172:                if (password == null) {
0173:                    throw new NetFileException(
0174:                            NetFileException.KEY_IDENTIFIER_PREFIX
0175:                                    + "invalid_password");
0176:                }
0177:                if (machine_name == null) {
0178:                    throw new NetFileException(new String[] {
0179:                            NetFileException.KEY_IDENTIFIER_PREFIX
0180:                                    + "invalid_machine_name",
0181:                            NetFileException.KEY_IDENTIFIER_PREFIX
0182:                                    + FileOption.TEXT_SEPERATOR, machine_name });
0183:                } else if (machine_name.equals(s_empty_string)) {
0184:                    throw new NetFileException(new String[] {
0185:                            NetFileException.KEY_IDENTIFIER_PREFIX
0186:                                    + "invalid_machine_name",
0187:                            NetFileException.KEY_IDENTIFIER_PREFIX
0188:                                    + FileOption.TEXT_SEPERATOR, machine_name });
0189:                }
0190:                boolean is_machine_type_invalid = false;
0191:                if ((machine_type == null)
0192:                        || (machine_type.equalsIgnoreCase(s_empty_string))) {
0193:                    is_machine_type_invalid = true;
0194:                } else if (!(machine_type.equals(FileOption.FTP)
0195:                        || machine_type.equals(FileOption.NFS)
0196:                        || machine_type.equals(FileOption.WIN)
0197:                        || machine_type.equals(FileOption.NT) || machine_type
0198:                        .equals(FileOption.NETWARE))) {
0199:                    is_machine_type_invalid = true;
0200:                }
0201:                if (is_machine_type_invalid) {
0202:                    throw new NetFileException(new String[] {
0203:                            NetFileException.KEY_IDENTIFIER_PREFIX
0204:                                    + "invalid_machine_type",
0205:                            NetFileException.KEY_IDENTIFIER_PREFIX
0206:                                    + FileOption.TEXT_SEPERATOR, machine_type });
0207:                }
0208:
0209:                if ((VMS == null) || (VMS.equals(s_empty_string))) {
0210:                    throw new NetFileException(new String[] {
0211:                            NetFileException.KEY_IDENTIFIER_PREFIX
0212:                                    + "invalid_vms_name",
0213:                            NetFileException.KEY_IDENTIFIER_PREFIX
0214:                                    + FileOption.TEXT_SEPERATOR, VMS });
0215:                }
0216:                if (directory == null) {
0217:                    throw new NetFileException(new String[] {
0218:                            NetFileException.KEY_IDENTIFIER_PREFIX
0219:                                    + "invalid_directory_name",
0220:                            NetFileException.KEY_IDENTIFIER_PREFIX
0221:                                    + FileOption.TEXT_SEPERATOR, directory });
0222:                }
0223:                if (temporary_directory == null) {
0224:                    throw new NetFileException(new String[] {
0225:                            NetFileException.KEY_IDENTIFIER_PREFIX
0226:                                    + "invalid_temporary_directory_name",
0227:                            NetFileException.KEY_IDENTIFIER_PREFIX
0228:                                    + FileOption.TEXT_SEPERATOR, directory });
0229:                }
0230:
0231:                //        logger.info("VMS is " + VMS);
0232:                Object[] params3 = { VMS };
0233:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1003", params3);
0234:                //        logger.info("Directory is " + directory);
0235:                Object[] params4 = { directory };
0236:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1004", params4);
0237:                //        logger.info("Expanding " + VMS + directory);
0238:                Object[] params5 = { VMS, directory };
0239:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1005", params5);
0240:
0241:                // Gets the formatted output of 'ls -l' or 'dir' for netware ftp
0242:                if (machine_type.indexOf(FileOption.NETWARE, 0) >= 0) {
0243:                    NetWareFile netwaredir = new NetWareFile(logMgr,
0244:                            s_machine_encoding);
0245:                    rettxt = netwaredir.getFTPDir(user_name, password,
0246:                            machine_name, VMS, directory,
0247:                            nfr_user_locale_i18n_bucket);
0248:
0249:                } else if ((machine_type.indexOf(FileOption.WIN, 0) >= 0)
0250:                        || (machine_type.indexOf(FileOption.NT, 0) >= 0)) {
0251:                    if (directory.equals(" ") || (directory == null)
0252:                            || (directory.equals(s_empty_string))) {
0253:                        directory = "\\";
0254:                    }
0255:                    XFileInterface gpc = XFileFactory.getInstance()
0256:                            .newXFileInstance(logMgr, s_machine_encoding,
0257:                                    this .ssoToken);
0258:
0259:                    rettxt = gpc.getDirectory(user_name, password,
0260:                            machine_name, VMS, directory, domain,
0261:                            nfr_user_locale_i18n_bucket);
0262:                } else if (machine_type.indexOf(FileOption.FTP, 0) >= 0) {
0263:                    FtpFile gff = new FtpFile(logMgr, s_machine_encoding);
0264:                    rettxt = gff.getFTPDir(user_name, password, machine_name,
0265:                            VMS, directory, nfr_user_locale_i18n_bucket);
0266:                } else if (machine_type.indexOf(FileOption.NFS, 0) >= 0) {
0267:                    NfsFile gnf = new NfsFile(logMgr, s_machine_encoding);
0268:                    rettxt = gnf.getNFSDir(user_name, password, VMS,
0269:                            machine_name, directory, temporary_directory,
0270:                            nfr_user_locale_i18n_bucket);
0271:                } else {
0272:                    throw new Exception(nfr_platform_locale_i18n_bucket
0273:                            .getString("error3"));
0274:                }
0275:
0276:                //        logger.info("Expand over");
0277:                logger.info("PSSRNF_CSPNSJ1006");
0278:
0279:                return rettxt;
0280:            }
0281:
0282:            //-------------------------------------------------
0283:            // Open a file
0284:            //  - input (all environment vars)
0285:            //    username
0286:            //    pass
0287:            //    machine
0288:            //    VMS
0289:            //    dir
0290:            //    filename
0291:            //
0292:            // - output
0293:            //    localfile
0294:            //-------------------------------------------------
0295:            String openFile(String username, String password, String machname,
0296:                    String domain, String machtype, String dir, String VMSname,
0297:                    String mainfilenam, String tmpdir,
0298:                    NetFileResource nfr_user_locale_i18n_bucket,
0299:                    String usersession) throws NetFileException {
0300:
0301:                String mainfilename = s_empty_string;
0302:                String txt = s_empty_string;
0303:                try {
0304:
0305:                    int indx = mainfilenam.indexOf("*", 0);
0306:                    if (indx >= 0) {
0307:                        mainfilename = mainfilenam.substring(0, indx);
0308:                    } else {
0309:                        mainfilename = mainfilenam;
0310:                    }
0311:
0312:                    if (machtype.equalsIgnoreCase(s_empty_string)) {
0313:                        throw new NetFileException(
0314:                                NetFileException.KEY_IDENTIFIER_PREFIX
0315:                                        + "error1");
0316:                    }
0317:
0318:                    //            logger.info("Getting " + mainfilename);
0319:                    Object[] params7 = { mainfilename };
0320:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ1007", params7);
0321:
0322:                    // Returns the name of the file, which has the contents
0323:                    if ((machtype.indexOf(FileOption.FTP, 0) >= 0)
0324:                            || (machtype.indexOf(FileOption.NETWARE, 0) >= 0)) {
0325:                        FtpFile gff = new FtpFile(logMgr, s_machine_encoding);
0326:                        txt = gff.getFTPFile(username, password, machname,
0327:                                VMSname, mainfilename, dir, tmpdir,
0328:                                nfr_user_locale_i18n_bucket, usersession);
0329:
0330:                    } else if ((machtype.indexOf(FileOption.WIN, 0) >= 0)
0331:                            || (machtype.indexOf(FileOption.NT, 0) >= 0)) {
0332:                        if (dir.equals(" ") || (dir == null)
0333:                                || (dir.equals(s_empty_string))) {
0334:                            dir = "\\";
0335:                        }
0336:                        XFileInterface gpc = XFileFactory.getInstance()
0337:                                .newXFileInstance(logMgr, s_machine_encoding,
0338:                                        this .ssoToken);
0339:                        txt = gpc.getFile(username, password, machname,
0340:                                VMSname, mainfilename, dir, domain, tmpdir,
0341:                                nfr_user_locale_i18n_bucket);
0342:
0343:                    } else if (machtype.indexOf(FileOption.NFS, 0) >= 0) {
0344:                        NfsFile gfs = new NfsFile(logMgr, s_machine_encoding);
0345:                        txt = gfs.getNFSFile(username, password, VMSname,
0346:                                machname, mainfilename, dir, tmpdir,
0347:                                nfr_user_locale_i18n_bucket);
0348:                    }
0349:
0350:                    if (txt.indexOf("FileNotFound", 0) >= 0) {
0351:                        throw new NetFileException(new String[] {
0352:                                mainfilename,
0353:                                NetFileException.KEY_IDENTIFIER_PREFIX
0354:                                        + FileOption.TEXT_SEPERATOR,
0355:                                NetFileException.KEY_IDENTIFIER_PREFIX
0356:                                        + "error2" });
0357:                    } else if (txt.toUpperCase().indexOf("ERROR", 0) >= 0) {
0358:                        throw new NetFileException(new String[] {
0359:                                mainfilename,
0360:                                NetFileException.KEY_IDENTIFIER_PREFIX
0361:                                        + FileOption.TEXT_SEPERATOR,
0362:                                NetFileException.KEY_IDENTIFIER_PREFIX
0363:                                        + "error2" });
0364:                    } else {
0365:                        //                logger.info("Obtained " + txt);
0366:                        Object[] params8 = { txt };
0367:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ1008", params8);
0368:                    }
0369:                } catch (Exception e) {
0370:                    txt = FileOption.ERROR + e.getMessage();
0371:                    //            logger.log(Level.SEVERE, "Problem getting file",e);
0372:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1009");
0373:                }
0374:                return txt;
0375:            }
0376:
0377:            //---------------------------------------------------------------------
0378:            // Get the File content type based on the suffix of the given file
0379:            //---------------------------------------------------------------------
0380:
0381:            String getFileContentType(String filsuffix,
0382:                    NetFileResource nfr_user_locale_i18n_bucket) {
0383:
0384:                String filesuffix = filsuffix;
0385:
0386:                grepPlatinfo();
0387:                String mimepath = pathinfo[1];
0388:
0389:                String filecontenttype = s_empty_string;
0390:                String mimefile = mimepath + "/mime.types";
0391:                //        logger.info("The mime.types file is at " + mimefile);
0392:                Object[] params10 = { mimefile };
0393:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1010", params10);
0394:                filecontenttype = mimeTypes(mimefile, filesuffix,
0395:                        nfr_user_locale_i18n_bucket);
0396:                if (filecontenttype.equals(s_empty_string)) {
0397:                    return "application/octet-stream";
0398:                } else {
0399:                    return filecontenttype;
0400:                }
0401:            }
0402:
0403:            String mimeTypes(String mimefile, String filesuffix,
0404:                    NetFileResource nfr_user_locale_i18n_bucket) {
0405:
0406:                String mimtyp = s_empty_string;
0407:                String[] tokn = new String[200];
0408:                StringTokenizer pars;
0409:                int parscnt;
0410:                ArrayList cache;
0411:                String sep = ",";
0412:                String MIME_typ = s_empty_string;
0413:                String fil_suffix = filesuffix.toLowerCase();
0414:                boolean found = false;
0415:                try {
0416:                    File inputFile = new File(mimefile);
0417:                    StringBuffer buftxt = new StringBuffer(80);
0418:                    FileInputStream fis = new FileInputStream(inputFile);
0419:                    int c;
0420:
0421:                    while ((c = fis.read()) != -1) {
0422:                        char chtxt = ((char) c);
0423:                        buftxt.append(chtxt);
0424:                    }
0425:
0426:                    fis.close();
0427:                    mimtyp = buftxt.toString();
0428:                } catch (FileNotFoundException e) {
0429:                    //            logger.log(Level.SEVERE, "FileOption mimetypes Filenotfound exception: " , e);
0430:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1011");
0431:                } catch (IOException e) {
0432:                    //            logger.log(Level.SEVERE, "FileOption mimetypes IOException: " , e);
0433:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1012");
0434:                }
0435:
0436:                int indx = mimtyp.indexOf("type=", 0);
0437:                String mimetyp = s_empty_string;
0438:                if (indx >= 0) {
0439:                    mimetyp = mimtyp.substring(indx);
0440:                }
0441:
0442:                cache = new ArrayList();
0443:                pars = new StringTokenizer(mimetyp, "\n");
0444:                parscnt = pars.countTokens();
0445:                cache.clear();
0446:
0447:                for (int i = 0; i < parscnt; i++) {
0448:                    tokn[i] = pars.nextToken();
0449:                    cache.add(tokn[i]);
0450:                }
0451:                Object[] rowdata = new Object[100];
0452:                Object[] coldata = new Object[100];
0453:                if (cache.size() > 0) {
0454:                    for (int row = 0; row < cache.size() && !found; row++) {
0455:                        String str_cache = (String) cache.get(row);
0456:                        StringTokenizer parsnew = new StringTokenizer(
0457:                                str_cache, " ");
0458:                        int parscntnew = parsnew.countTokens();
0459:                        for (int j = 0; j < parscntnew && !found; j++) {
0460:                            rowdata[j] = parsnew.nextToken();
0461:                            int extindx = rowdata[j].toString().indexOf(
0462:                                    "exts=", 0);
0463:                            if (extindx >= 0) {
0464:                                String extstr = rowdata[j].toString()
0465:                                        .substring(extindx);
0466:                                StringTokenizer extpars = new StringTokenizer(
0467:                                        extstr, sep);
0468:                                int extparscnt = extpars.countTokens();
0469:                                for (int s = 0; s < extparscnt && !found; s++) {
0470:                                    coldata[s] = extpars.nextToken();
0471:                                    if (coldata[s].toString().indexOf(
0472:                                            fil_suffix) >= 0) {
0473:                                        int typindx = str_cache.indexOf(
0474:                                                "type=", 0);
0475:                                        MIME_typ = str_cache.substring(
0476:                                                typindx + 5, str_cache
0477:                                                        .indexOf("exts="));
0478:                                        found = true; // return as soon as found. Don't iterate further.
0479:                                    }
0480:                                }
0481:                            }
0482:                        }
0483:
0484:                    }
0485:
0486:                }
0487:
0488:                return MIME_typ;
0489:            }
0490:
0491:            //-------------------------------------------------
0492:            // Compress a file by getting the file from remote server and use the
0493:            // compression utility from JAVA
0494:            // - output
0495:            //    compression statistics
0496:            //-------------------------------------------------
0497:
0498:            String[] compressFile(String username, String password,
0499:                    String machname, String domain, String machtype,
0500:                    String dir_nam, String VMSname, String mainfilenam,
0501:                    String tmpdir, NetFileResource nfr_user_locale_i18n_bucket,
0502:                    String usersession, String szCompressMethod)
0503:                    throws Exception, NetFileException {
0504:
0505:                String usernam = username;
0506:                String passwrd = password;
0507:                String machnam = machname;
0508:                String machtyp = machtype;
0509:                String VMSnam = VMSname;
0510:                String mainfile_name = mainfilenam;
0511:                String dir = dir_nam;
0512:                String domainname = domain;
0513:                String text = s_empty_string;
0514:
0515:                try {
0516:                    if (machtyp.equalsIgnoreCase(s_empty_string)) {
0517:                        throw new NetFileException(
0518:                                NetFileException.KEY_IDENTIFIER_PREFIX
0519:                                        + "error1");
0520:                    }
0521:                    if (mainfile_name.equals(s_empty_string)) {
0522:                        throw new NetFileException(
0523:                                NetFileException.KEY_IDENTIFIER_PREFIX
0524:                                        + "error1");
0525:                    }
0526:
0527:                    List cachechk = parse(mainfile_name, "\n");
0528:
0529:                    if (cachechk.size() <= 0) {
0530:                        //                logger.severe("No files selected for compression");
0531:                        logger.severe("PSSRNF_CSPNSJ1013");
0532:                    }
0533:                    if (cachechk.size() > 0) {
0534:                        for (int fil_zip = 0; fil_zip < cachechk.size(); fil_zip++) {
0535:                            FtpFile gff = null;
0536:                            NfsFile nfsFile = null;
0537:                            XFileInterface gpc = null;
0538:
0539:                            OutputStream outstream = null;
0540:                            InputStream instream = null;
0541:
0542:                            if (szCompressMethod.equalsIgnoreCase("gzip")) {
0543:                                mainfile_name = (String) cachechk.get(fil_zip)
0544:                                        + ".gz";
0545:                            } else if (szCompressMethod.equalsIgnoreCase("zip")) {
0546:                                mainfile_name = (String) cachechk.get(fil_zip)
0547:                                        + ".zip";
0548:                            }
0549:
0550:                            //                    logger.info(szCompressMethod + FileOption.MESSAGE_1 + (String) cachechk.get(fil_zip));
0551:                            Object[] params14 = { FileOption.MESSAGE_1,
0552:                                    (String) cachechk.get(fil_zip) };
0553:                            logger.log(Level.INFO, "PSSRNF_CSPNSJ1014",
0554:                                    params14);
0555:
0556:                            if ((machtyp.indexOf(FileOption.FTP, 0) >= 0)
0557:                                    || (machtyp.indexOf(FileOption.NETWARE, 0) >= 0)) {
0558:                                gff = new FtpFile(logMgr, s_machine_encoding);
0559:                                instream = gff.getInputFTPStream(usernam,
0560:                                        passwrd, machnam, VMSnam,
0561:                                        (String) cachechk.get(fil_zip), dir);
0562:                                outstream = gff.getOutputFTPStream(usernam,
0563:                                        passwrd, machnam, VMSnam,
0564:                                        mainfile_name, dir);
0565:
0566:                            } else if ((machtyp.indexOf(FileOption.NFS, 0) >= 0)) {
0567:                                nfsFile = new NfsFile(logMgr,
0568:                                        s_machine_encoding);
0569:                                instream = nfsFile.getNFSInputStream(usernam,
0570:                                        passwrd, VMSnam, machnam,
0571:                                        (String) cachechk.get(fil_zip), dir);
0572:                                outstream = nfsFile.getNFSOutputStream(usernam,
0573:                                        passwrd, machnam, VMSnam,
0574:                                        mainfile_name, dir);
0575:
0576:                            } else if ((machtyp.indexOf(FileOption.WIN, 0) >= 0)
0577:                                    || (machtyp.indexOf(FileOption.NT, 0) >= 0)) {
0578:                                gpc = XFileFactory.getInstance()
0579:                                        .newXFileInstance(logMgr,
0580:                                                s_machine_encoding,
0581:                                                this .ssoToken);
0582:                                instream = gpc.getInputStream(usernam, passwrd,
0583:                                        domainname, machnam, VMSnam, dir,
0584:                                        (String) cachechk.get(fil_zip),
0585:                                        nfr_user_locale_i18n_bucket);
0586:                                outstream = gpc.getOutputStream(usernam,
0587:                                        passwrd, domainname, machnam, VMSnam,
0588:                                        dir, mainfile_name,
0589:                                        nfr_user_locale_i18n_bucket);
0590:
0591:                            } else {
0592:                                break;
0593:                            }
0594:
0595:                            try {
0596:                                NetFileCompress nfComp = new NetFileCompression();
0597:                                nfComp.setCompressMethod(szCompressMethod);
0598:                                nfComp.doCompress(instream, outstream, cachechk
0599:                                        .get(fil_zip));
0600:                            } catch (Exception e) {
0601:                                text = FileOption.ERROR;
0602:                                //                        logger.log(Level.SEVERE, "Error in compressing file to Server " + machnam, e);
0603:                                Object[] params15 = { machnam, e };
0604:                                logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1015",
0605:                                        params15);
0606:                                continue;
0607:                            } finally {
0608:                                if (gff != null)
0609:                                    gff.closeFtpFile();
0610:                                else if (nfsFile != null)
0611:                                    nfsFile.closeNfsFile();
0612:                                else if (gpc != null) {
0613:                                    if (instream != null)
0614:                                        instream.close();
0615:                                    if (outstream != null)
0616:                                        outstream.close();
0617:                                }
0618:                            } // finally
0619:                        } //for
0620:                    } // if(cachechk ....
0621:
0622:                } catch (Exception e) {
0623:                    //            logger.log(Level.SEVERE, "Exception compressing file",e);
0624:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1016");
0625:                    return new String[] {
0626:                            FileOption.ERROR
0627:                                    + " "
0628:                                    + nfr_user_locale_i18n_bucket
0629:                                            .getString("error2"),
0630:                            FileOption.END_OF_STRING };
0631:                } finally {
0632:                    if (text.startsWith(FileOption.ERROR)) {
0633:                        if ((machtyp.indexOf(FileOption.NETWARE) > 0)
0634:                                && (text.indexOf(nfr_user_locale_i18n_bucket
0635:                                        .getString("error6")) >= 0)) {
0636:                            doError(getPlatformLocalisedString("invalidfilename"));
0637:                            rettxt[0] = FileOption.ERROR
0638:                                    + " "
0639:                                    + nfr_user_locale_i18n_bucket
0640:                                            .getString("invalidfilename");
0641:                            rettxt[1] = FileOption.END_OF_STRING;
0642:                            return rettxt;
0643:                        } else {
0644:                            doError(getPlatformLocalisedString("error2"));
0645:                            rettxt[0] = FileOption.ERROR
0646:                                    + " "
0647:                                    + nfr_user_locale_i18n_bucket
0648:                                            .getString("error2");
0649:                            rettxt[1] = FileOption.END_OF_STRING;
0650:                            return rettxt;
0651:                        }
0652:                    }
0653:                }
0654:                rettxt[0] = nfr_user_locale_i18n_bucket.getString("info9");
0655:                return rettxt;
0656:            }
0657:
0658:            String mailFile(String username, String password, String machine,
0659:                    String domain, String machine_type, String directory,
0660:                    String share, String files_to_send, String mail_server,
0661:                    String from, String to, String reply, String cc,
0662:                    String bcc, String subject, String message,
0663:                    String debug_value, String temporary_directory,
0664:                    NetFileResource nfr_user_locale_i18n_bucket,
0665:                    String character_set, String usersession)
0666:                    throws NetFileException {
0667:
0668:                //        logger.info("Mailing files=" + files_to_send);
0669:                Object[] params17 = { files_to_send };
0670:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1017", params17);
0671:
0672:                Map m_files_to_send = new HashMap();
0673:                try {
0674:                    try {
0675:                        if ((from.equals(s_empty_string))
0676:                                || (to.equals(s_empty_string))) {
0677:                            throw new NetFileException(
0678:                                    NetFileException.KEY_IDENTIFIER_PREFIX
0679:                                            + "error41");
0680:                        }
0681:                        if (files_to_send.equals(s_empty_string)) {
0682:                            throw new NetFileException(
0683:                                    NetFileException.KEY_IDENTIFIER_PREFIX
0684:                                            + "warning9");
0685:                        }
0686:                        if ((directory.trim().equals(" "))
0687:                                || (directory == null)) {
0688:                            directory = s_empty_string;
0689:                        }
0690:                        if (machine_type.equalsIgnoreCase(s_empty_string)) {
0691:                            throw new NetFileException(
0692:                                    NetFileException.KEY_IDENTIFIER_PREFIX
0693:                                            + "error1");
0694:                        }
0695:
0696:                        List v_files_to_send = parse(files_to_send, "*,");
0697:
0698:                        if (v_files_to_send.size() > 0) {
0699:                            for (int fil_mail = 0; fil_mail < v_files_to_send
0700:                                    .size(); fil_mail++) {
0701:                                String filename = (String) v_files_to_send
0702:                                        .get(fil_mail);
0703:                                String result = openFile(username, password,
0704:                                        machine, domain, machine_type,
0705:                                        directory, share, filename,
0706:                                        temporary_directory,
0707:                                        nfr_user_locale_i18n_bucket,
0708:                                        usersession);
0709:                                if (result.startsWith(FileOption.ERROR)) {
0710:                                    return result;
0711:                                }
0712:                                m_files_to_send.put(result, filename);
0713:                            }
0714:                            SendFile sendfil = new SendFile();
0715:                            String result = sendfil.sendAttachedFile(to, from,
0716:                                    reply, cc, bcc, mail_server, subject,
0717:                                    message, m_files_to_send, debug_value,
0718:                                    character_set, nfr_user_locale_i18n_bucket,
0719:                                    files_to_send);
0720:                            //                    logger.info("Number of files in map="+m_files_to_send.size());
0721:                            Object[] params18 = { new Integer(m_files_to_send
0722:                                    .size()) };
0723:                            logger.log(Level.INFO, "PSSRNF_CSPNSJ1018",
0724:                                    params18);
0725:                            return result;
0726:                        } else {
0727:                            return nfr_user_locale_i18n_bucket
0728:                                    .getString("no_files_to_mail");
0729:                        }
0730:                    } catch (NetFileException nfe) {
0731:                        //              logger.log(Level.SEVERE, "NetFile Exception when mailing file", nfe);
0732:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1019");
0733:                        return FileOption.ERROR
0734:                                + nfe.getMessage(nfr_user_locale_i18n_bucket);
0735:                    } catch (Exception e) {
0736:                        //              logger.log(Level.SEVERE, "Error mailing file", e);
0737:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1020");
0738:                        return FileOption.ERROR
0739:                                + nfr_user_locale_i18n_bucket
0740:                                        .getString("error4");
0741:                    }
0742:                } finally {
0743:                    deleteFiles(m_files_to_send);
0744:                }
0745:            }
0746:
0747:            private void deleteFiles(Map list_of_files) {
0748:                //        logger.info("Deleting temp files");
0749:                logger.info("PSSRNF_CSPNSJ1021");
0750:
0751:                Iterator it = list_of_files.keySet().iterator();
0752:                while (it.hasNext()) {
0753:                    try {
0754:                        Object o_filename = it.next();
0755:                        String s_filename = (String) o_filename;
0756:                        File delFil = new File(s_filename);
0757:
0758:                        //                logger.info("Deleting :" + delFil.getAbsolutePath());
0759:                        Object[] params22 = { delFil.getAbsolutePath() };
0760:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ1022", params22);
0761:
0762:                        if (delFil.exists()) {
0763:                            delFil.delete();
0764:                        }
0765:                    } catch (Exception e) {
0766:                        //                logger.log(Level.SEVERE, "Exception deleting file",e);
0767:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1023");
0768:                    }
0769:                }
0770:            }
0771:
0772:            //-------------------------------------------------
0773:            // Search for a filename (pattern)
0774:            //-------------------------------------------------
0775:
0776:            String[] searchFile(String username, String password,
0777:                    String machname, String domain, String machtype,
0778:                    String dir, String VMSname, String searchpattern,
0779:                    int maxsearchdir, String tmpdir,
0780:                    NetFileResource nfr_user_locale_i18n_bucket)
0781:                    throws NetFileException {
0782:
0783:                String newname = s_empty_string;
0784:                String txt[] = new String[100];
0785:                try {
0786:
0787:                    if ((machtype.indexOf(FileOption.WIN, 0) >= 0)
0788:                            || (machtype.indexOf(FileOption.NT, 0) >= 0)) {
0789:                        newname = VMSname + dir;
0790:                    } else if (machtype.indexOf(FileOption.NETWARE, 0) >= 0) {
0791:                        newname = VMSname + "/" + dir;
0792:                    } else {
0793:                        newname = VMSname + "/" + dir;
0794:                    }
0795:
0796:                    if (newname.indexOf("//", 0) >= 0) {
0797:                        newname = newname.replace('/', ' ');
0798:                    }
0799:
0800:                    //            logger.info("Starting search in directory " + dir + " of VMS " + VMSname + " with pattern " + searchpattern);
0801:                    Object[] params24 = { dir, " of VMS ", VMSname,
0802:                            " with pattern ", searchpattern };
0803:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ1024", params24);
0804:
0805:                    if ((machtype.indexOf(FileOption.WIN, 0) >= 0)
0806:                            || (machtype.indexOf(FileOption.NT, 0) >= 0)) {
0807:                        XFileInterface srpat = XFileFactory.getInstance()
0808:                                .newXFileInstance(logMgr, s_machine_encoding,
0809:                                        this .ssoToken);
0810:                        txt = srpat.doSearch(username, password, machname,
0811:                                VMSname, searchpattern, dir, domain,
0812:                                maxsearchdir, nfr_user_locale_i18n_bucket);
0813:
0814:                    } else if (machtype.indexOf(FileOption.FTP, 0) >= 0) {
0815:                        FtpFile srpat = new FtpFile(logMgr, s_machine_encoding);
0816:                        txt = srpat.ftpDir(username, password, machname,
0817:                                VMSname, searchpattern, dir, maxsearchdir,
0818:                                nfr_user_locale_i18n_bucket);
0819:
0820:                    } else if (machtype.indexOf(FileOption.NETWARE, 0) >= 0) {
0821:                        NetWareFile srpat = new NetWareFile(logMgr,
0822:                                s_machine_encoding);
0823:                        txt = srpat.ftpDir(username, password, machname,
0824:                                VMSname, searchpattern, dir, maxsearchdir,
0825:                                nfr_user_locale_i18n_bucket);
0826:
0827:                    } else if (machtype.indexOf(FileOption.NFS, 0) >= 0) {
0828:                        NfsFile nfsFile = new NfsFile(logMgr,
0829:                                s_machine_encoding);
0830:                        txt = nfsFile.search(username, password, machname,
0831:                                VMSname, searchpattern, dir, domain,
0832:                                maxsearchdir, nfr_user_locale_i18n_bucket);
0833:                        if (txt.length == 0) {
0834:                            txt = new String[] { "    " };
0835:                        }
0836:
0837:                    } else {
0838:                        txt[0] = FileOption.ERROR
0839:                                + nfr_user_locale_i18n_bucket
0840:                                        .getString("error1");
0841:                    }
0842:                } catch (Exception e) {
0843:                    //            logger.log(Level.SEVERE, "Exception searching files",e);
0844:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1025");
0845:                    txt[0] = (FileOption.ERROR + e.getMessage());
0846:                }
0847:                // do the logging
0848:                //        logger.info("Search completed");
0849:                logger.info("PSSRNF_CSPNSJ1026");
0850:
0851:                txt = makeSearchResultsPresentable(txt);
0852:                return txt;
0853:            }
0854:
0855:            /*
0856:             *Remove multiple consicutive '\' and '/'
0857:             */
0858:            private String[] makeSearchResultsPresentable(String[] sa_results) {
0859:                for (int i = 0; i < sa_results.length; ++i) {
0860:                    String s_result = sa_results[i];
0861:
0862:                    char c_separator = s_result.charAt(0);
0863:                    StringTokenizer st_tokens;
0864:                    if (c_separator == '\\' || c_separator == '/') {
0865:                        st_tokens = new StringTokenizer(s_result,
0866:                                s_empty_string + c_separator);
0867:                        StringBuffer sb_presentable_result = new StringBuffer();
0868:                        sb_presentable_result.append(c_separator);
0869:                        int i_num_tokens = st_tokens.countTokens();
0870:                        for (int j = 0; j < i_num_tokens - 1; ++j) {
0871:                            sb_presentable_result.append(st_tokens.nextToken())
0872:                                    .append(c_separator);
0873:                        }
0874:                        sb_presentable_result.append(st_tokens.nextToken());
0875:
0876:                        if (s_result.charAt(s_result.length() - 1) == c_separator) {
0877:                            sb_presentable_result.append(c_separator);
0878:                        }
0879:                        sa_results[i] = sb_presentable_result.toString();
0880:                    }
0881:                }
0882:                return sa_results;
0883:            }
0884:
0885:            //-----------------------
0886:            // Create a new directory
0887:            //-----------------------
0888:
0889:            String[] createDir(String username, String password,
0890:                    String machinename, String domain, String machtype,
0891:                    String dir, String VMSname, String newDirName,
0892:                    String tmpdir, NetFileResource nfr_user_locale_i18n_bucket)
0893:                    throws NetFileException {
0894:
0895:                String mkdirres = s_empty_string;
0896:                String[] returnmkdirres = new String[100];
0897:                int mk = 0;
0898:
0899:                try {
0900:                    returnmkdirres[mk] = nfr_user_locale_i18n_bucket
0901:                            .getString("warning52")
0902:                            + newDirName + c_eol;
0903:                    mk++;
0904:
0905:                    if ((machtype.indexOf(FileOption.WIN, 0) >= 0)
0906:                            || (machtype.indexOf(FileOption.NT, 0) >= 0)) {
0907:                        XFileInterface gpc = XFileFactory.getInstance()
0908:                                .newXFileInstance(logMgr, s_machine_encoding,
0909:                                        this .ssoToken);
0910:                        return new String[] {
0911:                                gpc
0912:                                        .doCreateDirectory(machinename,
0913:                                                VMSname, username, password,
0914:                                                domain, dir, newDirName,
0915:                                                nfr_user_locale_i18n_bucket),
0916:                                s_empty_string };
0917:
0918:                    } else if ((machtype.indexOf(FileOption.FTP, 0) >= 0)
0919:                            || (machtype.indexOf(FileOption.NETWARE, 0) >= 0)) {
0920:                        String oldftpdir = VMSname + dir;
0921:                        FullFtpClient fc;
0922:                        StringBuffer buftxt = new StringBuffer();
0923:
0924:                        try {
0925:                            fc = new FullFtpClient(machinename,
0926:                                    s_machine_encoding);
0927:                            fc.login(username, password);
0928:                            fc.cd(oldftpdir);
0929:                            fc.pwd();
0930:                            fc.mkdir(newDirName);
0931:                            fc.setMachineToAccess(machinename);
0932:                            BufferedReader theList = new BufferedReader(
0933:                                    new InputStreamReader(fc.list()));
0934:                            String theLine;
0935:                            while ((theLine = theList.readLine()) != null) {
0936:                                buftxt.append(theLine).append(c_eol);
0937:                            }
0938:                            mkdirres = buftxt.toString();
0939:                            theList.close();
0940:                            fc.closeServer();
0941:                        } catch (IOException ex) {
0942:                            exerr = ex.toString();
0943:                        }
0944:
0945:                    } else if (machtype.indexOf(FileOption.NFS, 0) >= 0) {
0946:                        return new String[] {
0947:                                (new NfsFile(logMgr, s_machine_encoding))
0948:                                        .mkdir(machinename, VMSname, username,
0949:                                                password, dir, newDirName,
0950:                                                nfr_user_locale_i18n_bucket),
0951:                                s_empty_string };
0952:
0953:                    } else {
0954:                        doError(getPlatformLocalisedString("error3"));
0955:                        returnmkdirres[mk] = FileOption.ERROR
0956:                                + nfr_user_locale_i18n_bucket
0957:                                        .getString("error3");
0958:                    }
0959:
0960:                    if ((exerr.indexOf("File exists", 0) >= 0)
0961:                            || (exerr.indexOf("550", 0) >= 0)) {
0962:                        doError(newDirName
0963:                                + getPlatformLocalisedString("error6"));
0964:                        returnmkdirres[mk] = FileOption.ERROR
0965:                                + newDirName
0966:                                + nfr_user_locale_i18n_bucket
0967:                                        .getString("error6");
0968:                        mk++;
0969:                        for (int k = mk; k < returnmkdirres.length; k++) {
0970:                            returnmkdirres[mk] = FileOption.END_OF_STRING;
0971:                            mk++;
0972:                        }
0973:                        return returnmkdirres;
0974:                    }
0975:
0976:                    if ((exerr.indexOf("LoginException", 0) >= 0)
0977:                            || (exerr.indexOf("password", 0) >= 0)) {
0978:                        doError(newDirName
0979:                                + getPlatformLocalisedString("error6"));
0980:                        returnmkdirres[mk] = FileOption.ERROR
0981:                                + newDirName
0982:                                + nfr_user_locale_i18n_bucket
0983:                                        .getString("error6");
0984:                        mk++;
0985:                        for (int k = mk; k < returnmkdirres.length; k++) {
0986:                            returnmkdirres[mk] = FileOption.END_OF_STRING;
0987:                            mk++;
0988:                        }
0989:                        return returnmkdirres;
0990:                    }
0991:
0992:                    if ((exerr.indexOf("errsrv", 0) >= 0)
0993:                            || (exerr.indexOf("fail", 0) >= 0)) {
0994:                        doError(newDirName
0995:                                + getPlatformLocalisedString("error6"));
0996:                        returnmkdirres[mk] = FileOption.ERROR
0997:                                + newDirName
0998:                                + nfr_user_locale_i18n_bucket
0999:                                        .getString("error6");
1000:                        mk++;
1001:                        for (int k = mk; k < returnmkdirres.length; k++) {
1002:                            returnmkdirres[mk] = FileOption.END_OF_STRING;
1003:                            mk++;
1004:                        }
1005:                        return returnmkdirres;
1006:                    }
1007:
1008:                    if ((exerr.indexOf("errdos", 0) >= 0)
1009:                            || (exerr.indexOf("fail", 0) >= 0)) {
1010:                        doError(newDirName
1011:                                + getPlatformLocalisedString("error6"));
1012:                        returnmkdirres[mk] = FileOption.ERROR
1013:                                + newDirName
1014:                                + nfr_user_locale_i18n_bucket
1015:                                        .getString("error6");
1016:                        mk++;
1017:                        for (int k = mk; k < returnmkdirres.length; k++) {
1018:                            returnmkdirres[mk] = FileOption.END_OF_STRING;
1019:                            mk++;
1020:                        }
1021:                        return returnmkdirres;
1022:                    }
1023:
1024:                    if (exerr.indexOf("smbclient: not found", 0) >= 0) {
1025:                        doError(newDirName
1026:                                + getPlatformLocalisedString("error35"));
1027:                        returnmkdirres[mk] = FileOption.ERROR
1028:                                + newDirName
1029:                                + nfr_user_locale_i18n_bucket
1030:                                        .getString("error35");
1031:                        mk++;
1032:                        for (int k = mk; k < returnmkdirres.length; k++) {
1033:                            returnmkdirres[mk] = FileOption.END_OF_STRING;
1034:                            mk++;
1035:                        }
1036:                        return returnmkdirres;
1037:                    }
1038:                    doLog(getPlatformLocalisedString("func34"));
1039:
1040:                    for (int k = mk; k < returnmkdirres.length; k++) {
1041:                        returnmkdirres[mk] = FileOption.END_OF_STRING;
1042:                        mk++;
1043:                    }
1044:                } catch (Exception e) {
1045:                    returnmkdirres[0] = (FileOption.ERROR + e.getMessage());
1046:                    //            logger.log(Level.SEVERE, "Error creating directory", e);
1047:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1027");
1048:                }
1049:                return returnmkdirres;
1050:            }
1051:
1052:            private List parse(String string, String delimiter) {
1053:                int i_index_of_delimiter = 0;
1054:                int i_start_index = 0;
1055:                int i_size_of_delimiter = delimiter.length();
1056:                List v_tokens = new ArrayList();
1057:
1058:                //        logger.info("Parsing file names ... ");
1059:                logger.info("PSSRNF_CSPNSJ1028");
1060:
1061:                while (true) {
1062:                    i_index_of_delimiter = string.indexOf(delimiter,
1063:                            i_start_index);
1064:                    if (i_start_index >= i_index_of_delimiter) {
1065:                        break;
1066:                    }
1067:                    String token = string.substring(i_start_index,
1068:                            i_index_of_delimiter);
1069:                    v_tokens.add(token);
1070:                    i_start_index = i_index_of_delimiter + i_size_of_delimiter;
1071:                }
1072:
1073:                //        logger.info("Parsing completed. File names are " + v_tokens.toString());
1074:                Object[] params29 = { v_tokens.toString() };
1075:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1029", params29);
1076:
1077:                return v_tokens;
1078:            }
1079:
1080:            String deleteFile(String username, String password,
1081:                    String machname, String domain, String machtype,
1082:                    String dir_nam, String VMSname, String mainfilenam,
1083:                    String tmpdir, NetFileResource nfr_user_locale_i18n_bucket)
1084:                    throws NetFileException {
1085:
1086:                String usernam = username;
1087:                String passwrd = password;
1088:                String machnam = machname;
1089:                String machtyp = machtype;
1090:                String VMSnam = VMSname;
1091:                String mainfile_name = mainfilenam;
1092:                String dir = dir_nam;
1093:                String tempdir = tmpdir;
1094:                String domainname = domain;
1095:
1096:                String txt = s_empty_string;
1097:                List cachechk = new ArrayList();
1098:                String mainfilename = s_empty_string;
1099:                int indx = 0;
1100:                int intflg = 1;
1101:                String newstr = s_empty_string;
1102:                String oldstr = mainfile_name;
1103:                XFileInterface gpc = null;
1104:                NetWareFile netware = null;
1105:                FtpFile gff = null;
1106:                NfsFile gfs = null;
1107:
1108:                try {
1109:
1110:                    if (mainfile_name.equals(s_empty_string)) {
1111:                        doError(getPlatformLocalisedString("warning9"));
1112:                        txt = FileOption.ERROR
1113:                                + nfr_user_locale_i18n_bucket
1114:                                        .getString("warning9");
1115:                        return txt;
1116:                    } else {
1117:                        cachechk.clear();
1118:                        while (intflg == 1) {
1119:                            indx = mainfile_name.indexOf("*,", 0);
1120:                            if (indx >= 0) {
1121:                                newstr = mainfile_name.substring(0, indx);
1122:                                cachechk.add(newstr);
1123:                                oldstr = mainfile_name.substring(indx + 2);
1124:                                mainfile_name = oldstr;
1125:                            } else {
1126:                                indx = oldstr.indexOf("*", 0);
1127:                                if (indx >= 0) {
1128:                                    newstr = oldstr.substring(0, indx);
1129:                                    cachechk.add(newstr);
1130:                                }
1131:                                intflg = 0;
1132:                            }
1133:                        }
1134:
1135:                        if (cachechk.size() > 0) {
1136:                            StringBuffer deletedFiles = new StringBuffer(); //Stores list of deleted file(s).
1137:                            if (machtyp.equalsIgnoreCase(s_empty_string)) {
1138:                                doError(getPlatformLocalisedString("error1"));
1139:                                return FileOption.ERROR
1140:                                        + nfr_user_locale_i18n_bucket
1141:                                                .getString("error1");
1142:
1143:                            } else if (machtyp.indexOf(FileOption.NETWARE, 0) >= 0) {
1144:                                netware = new NetWareFile(logMgr,
1145:                                        s_machine_encoding);
1146:                                for (int fil = 0; fil < cachechk.size(); fil++) {
1147:                                    mainfilename = (String) cachechk.get(fil);
1148:                                    try {
1149:                                        txt = netware.delFTPFile(usernam,
1150:                                                passwrd, machnam, VMSnam,
1151:                                                mainfilename, dir,
1152:                                                nfr_user_locale_i18n_bucket);
1153:                                    } catch (NetFileException nfe) {
1154:                                        netware.closeFtpFile();
1155:                                        return getReturnText(
1156:                                                deletedFiles,
1157:                                                mainfilename,
1158:                                                nfe
1159:                                                        .getMessage(nfr_platform_locale_i18n_bucket),
1160:                                                nfr_platform_locale_i18n_bucket);
1161:                                    }
1162:                                    deletedFiles.append(mainfilename).append(
1163:                                            '\n');
1164:                                    String returnTxt = checkOutputForError(txt,
1165:                                            mainfilename,
1166:                                            nfr_user_locale_i18n_bucket);
1167:                                    if (returnTxt != null)
1168:                                        return returnTxt;
1169:                                }
1170:                            } else if ((machtyp.indexOf(FileOption.WIN, 0) >= 0)
1171:                                    || (machtyp.indexOf(FileOption.NT, 0) >= 0)) {
1172:                                gpc = XFileFactory.getInstance()
1173:                                        .newXFileInstance(logMgr,
1174:                                                s_machine_encoding,
1175:                                                this .ssoToken);
1176:
1177:                                for (int fil = 0; fil < cachechk.size(); fil++) {
1178:                                    mainfilename = (String) cachechk.get(fil);
1179:                                    try {
1180:                                        txt = gpc.doDeleteFile(usernam,
1181:                                                passwrd, machnam, VMSnam,
1182:                                                mainfilename, dir, domainname,
1183:                                                nfr_user_locale_i18n_bucket);
1184:                                    } catch (NetFileException nfe) {
1185:                                        return getReturnText(
1186:                                                deletedFiles,
1187:                                                mainfilename,
1188:                                                nfe
1189:                                                        .getMessage(nfr_platform_locale_i18n_bucket),
1190:                                                nfr_platform_locale_i18n_bucket);
1191:                                    }
1192:                                    deletedFiles.append(mainfilename).append(
1193:                                            '\n');
1194:                                    String returnTxt = checkOutputForError(txt,
1195:                                            mainfilename,
1196:                                            nfr_user_locale_i18n_bucket);
1197:                                    if (returnTxt != null)
1198:                                        return returnTxt;
1199:                                }
1200:                            } else if (machtyp.indexOf(FileOption.FTP, 0) >= 0) {
1201:                                gff = new FtpFile(logMgr, s_machine_encoding);
1202:                                for (int fil = 0; fil < cachechk.size(); fil++) {
1203:                                    mainfilename = (String) cachechk.get(fil);
1204:                                    try {
1205:                                        txt = gff.delFTPFile(usernam, passwrd,
1206:                                                machnam, VMSnam, mainfilename,
1207:                                                dir,
1208:                                                nfr_user_locale_i18n_bucket);
1209:                                    } catch (NetFileException nfe) {
1210:                                        return getReturnText(
1211:                                                deletedFiles,
1212:                                                mainfilename,
1213:                                                nfe
1214:                                                        .getMessage(nfr_platform_locale_i18n_bucket),
1215:                                                nfr_platform_locale_i18n_bucket);
1216:                                    }
1217:                                    deletedFiles.append(mainfilename).append(
1218:                                            '\n');
1219:                                    String returnTxt = checkOutputForError(txt,
1220:                                            mainfilename,
1221:                                            nfr_user_locale_i18n_bucket);
1222:                                    if (returnTxt != null)
1223:                                        return returnTxt;
1224:                                }
1225:                            } else if (machtyp.indexOf(FileOption.NFS, 0) >= 0) {
1226:                                gfs = new NfsFile(logMgr, s_machine_encoding);
1227:                                for (int fil = 0; fil < cachechk.size(); fil++) {
1228:                                    mainfilename = (String) cachechk.get(fil);
1229:                                    try {
1230:                                        txt = gfs.delNFSFile(usernam, passwrd,
1231:                                                VMSnam, machnam, mainfilename,
1232:                                                dir, tempdir,
1233:                                                nfr_user_locale_i18n_bucket);
1234:                                    } catch (NetFileException nfe) {
1235:                                        return getReturnText(
1236:                                                deletedFiles,
1237:                                                mainfilename,
1238:                                                nfe
1239:                                                        .getMessage(nfr_platform_locale_i18n_bucket),
1240:                                                nfr_platform_locale_i18n_bucket);
1241:                                    }
1242:                                    deletedFiles.append(mainfilename).append(
1243:                                            '\n');
1244:                                    String returnTxt = checkOutputForError(txt,
1245:                                            mainfilename,
1246:                                            nfr_user_locale_i18n_bucket);
1247:                                    if (returnTxt != null)
1248:                                        return returnTxt;
1249:                                }
1250:                            }
1251:                        }
1252:
1253:                        return txt;
1254:                    }
1255:                } catch (Exception e) {
1256:                    //            logger.log(Level.SEVERE, "Problem deleting file", e);
1257:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1030");
1258:                    return FileOption.ERROR + e.getMessage();
1259:                } finally {
1260:                    if (gff != null)
1261:                        gff.closeFtpFile();
1262:                    else if (netware != null)
1263:                        netware.closeFtpFile();
1264:                }
1265:            }
1266:
1267:            private String getReturnText(StringBuffer deletedFiles,
1268:                    String mainfile, String msg, NetFileResource nfRes) {
1269:                //Generate text to be returned to client.
1270:                String returnTxt = "";
1271:                if (deletedFiles.length() > 0) {
1272:                    returnTxt = nfRes.getString("returnTxt1") + "\n"
1273:                            + deletedFiles.toString() + "\n";
1274:                }
1275:                returnTxt += nfRes.getString("returnTxt2") + "\n" + mainfile
1276:                        + " - " + msg;
1277:                return returnTxt;
1278:            }
1279:
1280:            private String checkOutputForError(String txt, String mainfilename,
1281:                    NetFileResource nfRes) {
1282:                String returnStr = null;
1283:                if (txt.indexOf("FileNotFound", 0) >= 0) {
1284:                    doError(getPlatformLocalisedString("error2"));
1285:                    returnStr = FileOption.ERROR + " "
1286:                            + nfRes.getString("error2") + ": " + mainfilename;
1287:                } else if (txt.indexOf("ERROR", 0) >= 0) {
1288:                    doError(getPlatformLocalisedString("error37"));
1289:                    returnStr = FileOption.ERROR + " "
1290:                            + nfRes.getString("error37") + ": " + mainfilename;
1291:                }
1292:                return returnStr;
1293:            }
1294:
1295:            //-------------------------------------------------------------
1296:            // This method logs error messages
1297:            //-------------------------------------------------------------
1298:            void doError(String msg) {
1299:                if (logMgr == null)
1300:                    return;
1301:                logMgr.doError(s_platform_locale_error + msg);
1302:            }
1303:
1304:            //-------------------------------------------------------------
1305:            // This method logs successful events ( messages )
1306:            //-------------------------------------------------------------
1307:
1308:            void doLog(String msg) {
1309:                if (logMgr == null)
1310:                    return;
1311:                logMgr.doLog(msg);
1312:            }
1313:
1314:            String[] grepPlatinfo() {
1315:                NetFileContext nfContext = new NetFileContextImpl(getSSOToken());
1316:                Map[] prefs = nfContext.getPreferences();
1317:
1318:                NetFileAttributeExtractor nfAttrs = new NetFileAttributeExtractor(
1319:                        prefs[0]);
1320:
1321:                pathinfo[0] = nfAttrs.getString("sunPortalNetFileWINSServer",
1322:                        s_empty_string);
1323:                pathinfo[1] = nfAttrs.getString(
1324:                        "sunPortalNetFileMimetypesConfigFileLocation",
1325:                        s_empty_string);
1326:
1327:                //        logger.info("Name resolution server and mime-types file location are " + pathinfo[0] + c_eol + pathinfo[1]);
1328:                Object[] params31 = { pathinfo[0], c_eol + "", pathinfo[1] };
1329:                logger.log(Level.INFO, "PSSRNF_CSPNSJ1031", params31);
1330:
1331:                return pathinfo;
1332:            }
1333:
1334:            /*
1335:             *RFE 4431570
1336:             *
1337:             *@param sa_user_hosts_data  List of machines, types, shares, passwrords
1338:             *@param profile  Profile object for this user
1339:             *@exception Exception We pass on all the exceptions to calling method
1340:             */
1341:            public void downloadFolder(PrintWriter out, String[] parameters,
1342:                    NetFileResource nfr_user_locale_i18n_bucket)
1343:                    throws NetFileException, Exception {
1344:                if (out == null) {
1345:                    throw new NetFileException(
1346:                            NetFileException.KEY_IDENTIFIER_PREFIX
1347:                                    + "null_writer_to_applet_error");
1348:                }
1349:                if (parameters == null) {
1350:                    throw new NetFileException(
1351:                            NetFileException.KEY_IDENTIFIER_PREFIX
1352:                                    + "null_parameters_error");
1353:                }
1354:                if (nfr_user_locale_i18n_bucket == null) {
1355:                    throw new NetFileException(
1356:                            NetFileException.KEY_IDENTIFIER_PREFIX
1357:                                    + "null_localistaion_bucket_error");
1358:                }
1359:                if (parameters.length != 10) {
1360:                    throw new NetFileException(
1361:                            NetFileException.KEY_IDENTIFIER_PREFIX
1362:                                    + "missing_parameters_error");
1363:                }
1364:                String[] files = getFilesInDirectory(parameters,
1365:                        nfr_user_locale_i18n_bucket);
1366:                if (files.length < 1) {
1367:                    throw new NetFileException("empty directory");
1368:                }
1369:
1370:                for (int i = 0; i < files.length; ++i) {
1371:                    String file_name = files[i];
1372:                    out.println(file_name);
1373:                    out.flush();
1374:                }
1375:                out.println();
1376:                out.flush();
1377:            }
1378:
1379:            private String[] getFilesInDirectory(String[] parameters,
1380:                    NetFileResource nfr_user_locale_i18n_bucket)
1381:                    throws NetFileException, Exception {
1382:
1383:                String[] listing = expandDir(
1384:                        parameters[NetFileServlet.SOURCE_USER_NAME],
1385:                        parameters[NetFileServlet.SOURCE_PASSWORD],
1386:                        parameters[NetFileServlet.SOURCE_MACHINE_NAME],
1387:                        parameters[NetFileServlet.SOURCE_MACHINE_DOMAIN],
1388:                        parameters[NetFileServlet.SOURCE_MACHINE_TYPE],
1389:                        parameters[NetFileServlet.SOURCE_DIRECTORY],
1390:                        parameters[NetFileServlet.SOURCE_VMS],
1391:                        parameters[NetFileServlet.SOURCE_TEMP_DIR],
1392:                        nfr_user_locale_i18n_bucket);
1393:                if (listing == null)
1394:                    throw new NetFileException(
1395:                            NetFileException.KEY_IDENTIFIER_PREFIX
1396:                                    + "unable_to_get_listing_error");
1397:                if (listing.length == 0) {
1398:                    throw new NetFileException(
1399:                            NetFileException.KEY_IDENTIFIER_PREFIX
1400:                                    + "empty_directory");
1401:                    //return listing;
1402:                }
1403:                if (listing[0] == null) {
1404:                    throw new NetFileException(
1405:                            NetFileException.KEY_IDENTIFIER_PREFIX
1406:                                    + "empty_directory");
1407:                }
1408:                if (listing[0].startsWith((FileOption.ERROR))) {
1409:                    throw new NetFileException(
1410:                            NetFileException.KEY_IDENTIFIER_PREFIX
1411:                                    + listing[0].substring(((FileOption.ERROR))
1412:                                            .length() + 1, listing[0].length()));
1413:                }
1414:                if (listing.length % 4 == 0) {
1415:                } else {
1416:                    throw new NetFileException(
1417:                            NetFileException.KEY_IDENTIFIER_PREFIX
1418:                                    + "The array size is not multiple of 4");
1419:                }
1420:
1421:                return listing;
1422:            }
1423:
1424:            public void rename(String username, String password,
1425:                    String machine, String type, String domain, String share,
1426:                    String directory, String old_file_name,
1427:                    String new_file_name, String s_machine_encoding,
1428:                    NetFileResource nfRes) throws NetFileException {
1429:
1430:                if (type.equals(FileOption.WIN) || type.equals(FileOption.NT)) {
1431:                    XFileInterface gpc = XFileFactory.getInstance()
1432:                            .newXFileInstance(logMgr, s_machine_encoding,
1433:                                    this .ssoToken);
1434:
1435:                    gpc.doRenameFile(username, password, machine, domain,
1436:                            share, directory, old_file_name, new_file_name,
1437:                            nfRes);
1438:                } else if ((type.equals(FileOption.FTP))
1439:                        || (type.equals(FileOption.NETWARE))) {
1440:                    FtpFile ftpFile = new FtpFile(logMgr, s_machine_encoding);
1441:                    ftpFile.rename(username, password, machine, share,
1442:                            directory, old_file_name, new_file_name);
1443:                } else if (type.equals(FileOption.NFS)) {
1444:                    (new NfsFile(logMgr, s_machine_encoding)).rename(username,
1445:                            password, machine, share, directory, old_file_name,
1446:                            new_file_name);
1447:                } else {
1448:                    throw new NetFileException(
1449:                            NetFileException.KEY_IDENTIFIER_PREFIX
1450:                                    + "invalid_machine_type_error");
1451:                }
1452:            }
1453:
1454:            String doesFileExist(String username, String password,
1455:                    String machine, String type, String domain, String share,
1456:                    String directory, String file_name,
1457:                    String temporary_directory,
1458:                    NetFileResource nfr_user_locale_i18n_bucket)
1459:                    throws Exception, NetFileException {
1460:
1461:                String[] sa_file_listing = new String[] {};
1462:                try {
1463:                    sa_file_listing = this .expandDir(username, password,
1464:                            machine, domain, type, directory, share,
1465:                            temporary_directory, nfr_user_locale_i18n_bucket);
1466:
1467:                    //            logger.info("File listing obtained :" + sa_file_listing.length);
1468:                    Object[] params32 = { new Integer(sa_file_listing.length) };
1469:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ1032", params32);
1470:
1471:                } catch (Exception e) {
1472:                    //            logger.log(Level.SEVERE, "Exception in getting the listing",e);
1473:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1033");
1474:                }
1475:
1476:                for (int i_file_name_pointer = 1; i_file_name_pointer < sa_file_listing.length; i_file_name_pointer = i_file_name_pointer + 4) {
1477:                    if (file_name.equals(sa_file_listing[i_file_name_pointer])) {
1478:                        return "YES";
1479:                    }
1480:                }
1481:                return "NO";
1482:            }
1483:
1484:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.