Source Code Cross Referenced for NetWareFile.java in  » Portal » Open-Portal » com » sun » portal » netfile » servlet » java2 » 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.java2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /** 
002:         * $Id: NetWareFile.java,v 1.17 2006/05/17 11:57:38 bustamam Exp $ 
003:         * Copyright 2002 Sun Microsystems, Inc. All 
004:         * rights reserved. Use of this product is subject 
005:         * to license terms. Federal Acquisitions: 
006:         * Commercial Software -- Government Users 
007:         * Subject to Standard License Terms and 
008:         * Conditions. 
009:         * 
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
011:         * are trademarks or registered trademarks of Sun Microsystems, 
012:         * Inc. in the United States and other countries. 
013:         */package com.sun.portal.netfile.servlet.java2;
014:
015:        import java.util.*;
016:        import com.sun.portal.log.common.PortalLogger;
017:        import java.io.*;
018:        import java.text.SimpleDateFormat;
019:
020:        import com.sun.portal.netfile.shared.*;
021:
022:        /*
023:         * getFTPDir by Sushma Chakkirala Jun 14th 2000
024:         * Subclassed to use common methods from FtpFile by Ali Baqri
025:         * Modified for Java2 by Suresh Yellamaraju
026:         */
027:
028:        class NetWareFile extends FtpFile {
029:
030:            private final int MAX_COLUMNS = 8;
031:            private Locale clocale;
032:
033:            public NetWareFile(String szMachineEncoding, Locale cloc) {
034:                super (szMachineEncoding, cloc);
035:            }
036:
037:            public String[] getFTPDir(String username, String password,
038:                    String machname, String VMSname, String dirS,
039:                    NetFileResource nfrUsrResBundle) throws NetFileException {
040:
041:                writeDebug("Expanding Netware directory", null);
042:
043:                int txt = 0;
044:                StringBuffer buftxt = new StringBuffer(400);
045:                String textouting = "";
046:                String col_type = "";
047:                String col_junk1 = "";
048:                String col_size = "";
049:                String col_month = "";
050:                String col_day = "";
051:                String col_time = "";
052:                String type = "";
053:                String date = "";
054:                FullFtpClient ffc = null;
055:                String error6 = "";
056:                try {
057:
058:                    writeDebug("VMS= " + VMSname + ",Dir=" + dirS
059:                            + " ,machine=" + machname + ",user name="
060:                            + username + ", encoding=" + szEncoding, null);
061:
062:                    ffc = initialiseFtpClient(username, password, machname,
063:                            VMSname, dirS);
064:
065:                    writeDebug("Fetching listing for \n" + ffc.pwd(), null);
066:
067:                    // Do a 'dir' using FTP command LIST
068:                    BufferedReader theList = new BufferedReader(
069:                            new InputStreamReader(ffc.list(), this .szEncoding));
070:                    String theLine;
071:                    while ((theLine = theList.readLine()) != null) {
072:                        buftxt.append(theLine).append("\n");
073:                    }
074:                    textouting = buftxt.toString();
075:
076:                    writeDebug("The Netware File Listing obtained is \n"
077:                            + textouting, null);
078:
079:                    theList.close();
080:                    ffc.closeServer();
081:
082:                } catch (Exception ex) {
083:                    writeDebug(
084:                            "Exception in getting Netware file listing from "
085:                                    + machname, ex);
086:
087:                    if (ex instanceof  NetFileException) {
088:                        throw (NetFileException) ex;
089:                    } else {
090:                        throw new NetFileException(
091:                                NetFileException.NETFILE_GENERROR_CODE,
092:                                //"Error occured in fetching listing from " + VMSname+dirS + " of " + machname);
093:                                nfrUsrResBundle
094:                                        .getString("nwf.1", new Object[] {
095:                                                VMSname, dirS, machname }));
096:                    }
097:
098:                }
099:
100:                if (textouting.indexOf("Permission denied") > 0) {
101:                    throw new NetFileException(
102:                            NetFileException.NETFILE_GENERROR_CODE,
103:                            //error6 + " in fetching listing from " + VMSname+dirS + " of " + machname);
104:                            nfrUsrResBundle.getString("nwf.2", new Object[] {
105:                                    error6, VMSname, dirS, machname }));
106:                }
107:
108:                ArrayList cache = new ArrayList();
109:                cache.clear();
110:                StringTokenizer pars = new StringTokenizer(textouting, "\n");
111:                /** Output looks like this. parse it.
112:                 * ftp> dir
113:                 * 200 PORT command okay.
114:                 * 150 Opening data connection for  (192.18.178.58,36872).
115:                 * total 0
116:                 * - [RWCEAFMS] supervisor                        890 May 07 22:33 vol$log.err
117:                 * - [RWCEAFMS] supervisor                        607 May 07 22:33 tts$log.err
118:                 * - [RWCEAFMS] supervisor                      65536 May 12 19:32 backout.tts
119:                 * d [RWCEAFMS] supervisor                        512 Jun 13 12:37 login
120:                 * d [RWCEAFMS] icebox81                          512 May 02 22:40 ndps
121:                 * 226 Transfer complete.
122:                 * 1687 bytes received in 0.01 seconds (163.70 Kbytes/s)
123:                 * ftp>
124:                 **/
125:
126:                String tmp = "";
127:                while (pars.hasMoreElements()) {
128:                    tmp = (String) pars.nextElement();
129:                    /* grep for the 'total' word in the 'ls' output */
130:                    /**
131:                     * Bug 4521436
132:                     *
133:                     * while (tmp.startsWith(nfrUsrResBundle.getString("total"))) {
134:                     * while (pars.hasMoreElements()) {
135:                     * tmp = (String)pars.nextElement();
136:                     * cache.addElement(tmp);
137:                     * }
138:                     * }
139:                     *
140:                     */
141:                    if (pars.countTokens() == 0) {
142:                        return new String[] {};
143:                    }
144:                    while (tmp.startsWith(nfrUsrResBundle.getString("total"))) {
145:                        while (pars.hasMoreTokens()) {
146:                            tmp = pars.nextToken();
147:                            cache.add(tmp);
148:                        }
149:                    }
150:                    // end of code change for Bug 4521436
151:                }
152:
153:                Object[] rowdata = new Object[300];
154:                int i_number_of_files = cache.size();
155:                if (i_number_of_files == 0) {
156:                    return new String[] {};
157:                }
158:
159:                String[] sa_file_listing = new String[i_number_of_files * 4];
160:
161:                writeDebug("Netware file listing size = " + i_number_of_files,
162:                        null);
163:
164:                int i_index = 0;
165:                if (cache.size() > 0) {
166:                    for (int row = 0; row < cache.size(); row++) {
167:                        String str_cache = (String) cache.get(row);
168:                        StringTokenizer parsnew = new StringTokenizer(
169:                                str_cache, " ");
170:                        String col_name = "";
171:                        int parscntnew = parsnew.countTokens();
172:                        for (int j = 0; j < parscntnew; j++) {
173:                            rowdata[j] = parsnew.nextToken();
174:                        }
175:
176:                        /* Format of ftpd from Sun Solaris
177:                         * drwxrwxrwt   8                               sys     sys     2717    May
178:                         * 7       17:11 tmp
179:                         * Format of ftpd from Novell Netware
180:                         * d            [RWCEAFMS]                      admin   512     May     03
181:                         **/
182:                        /*
183:                         * - [RWCEAFMS] supervisor                        890 May 07 22:33 vol$log.err
184:                         * - [RWCEAFMS] supervisor                        607 May 07 22:33 tts$log.err
185:                         */
186:                        col_type = rowdata[0].toString();
187:                        col_junk1 = rowdata[1].toString();
188:                        col_size = rowdata[3].toString();
189:                        col_month = rowdata[4].toString();
190:                        col_day = rowdata[5].toString();
191:                        col_time = rowdata[6].toString();
192:
193:                        // This is for the spaced files(directories)
194:                        if (parscntnew > MAX_COLUMNS - 1) {
195:                            for (int l = MAX_COLUMNS - 1; l < parscntnew; l++) {
196:                                col_name = col_name + rowdata[l].toString()
197:                                        + " ";
198:                            }
199:                        } else {
200:                            col_name = col_name
201:                                    + rowdata[MAX_COLUMNS - 1].toString();
202:                        }
203:                        col_name = col_name.trim();
204:
205:                        if ((col_name.equals(".")) || (col_name.equals(".."))) {
206:                        } else {
207:                            type = col_type.substring(0, 1);
208:                            date = getModifiedDateFormat(col_month, col_day,
209:                                    col_time, nfrUsrResBundle
210:                                            .getString("nwf.DateFormat"));
211:                            sa_file_listing[i_index++] = type;
212:                            sa_file_listing[i_index++] = col_name;
213:                            sa_file_listing[i_index++] = col_size;
214:                            sa_file_listing[i_index++] = date;
215:                            writeDebug("Type = " + type, null);
216:                            writeDebug("Name = " + col_name, null);
217:                            writeDebug("Size = " + col_size, null);
218:                            writeDebug("Date = " + date, null);
219:                            txt++;
220:                        }
221:                    }
222:                }
223:                writeDebug("Returning from expanding Netware directory", null);
224:                return sa_file_listing;
225:            }
226:
227:            private String getModifiedDateFormat(String month, String date,
228:                    String time, String datef) {
229:                GregorianCalendar calendar = new GregorianCalendar(TimeZone
230:                        .getDefault());
231:                calendar.set(Calendar.MONTH, getMonthCode(month));
232:                calendar.set(Calendar.DATE, Integer.parseInt(date));
233:                if (time.indexOf(":") != -1) {
234:                    int colonIndex = time.indexOf(":");
235:                    String hourStr = time.substring(0, colonIndex);
236:                    String minuteStr = time.substring(colonIndex + 1).trim();
237:                    calendar.set(Calendar.HOUR_OF_DAY, Integer
238:                            .parseInt(hourStr));
239:                    calendar.set(Calendar.MINUTE, Integer.parseInt(minuteStr));
240:                } else {
241:                    calendar.set(Calendar.YEAR, Integer.parseInt(time.trim()));
242:                }
243:                Date d = calendar.getTime();
244:                SimpleDateFormat sdf = new SimpleDateFormat(datef, clocale);
245:                sdf.setCalendar(new GregorianCalendar(TimeZone.getDefault()));
246:                return sdf.format(d);
247:            }
248:
249:            /* Checks if the machine type is Unix FTP or NetWare Ftp */
250:            boolean getFTPType(String machname) {
251:                FullFtpClient fc;
252:                String ftpResponse;
253:                String novellResponse = "NetWare";
254:                boolean novellServer = false;
255:
256:                writeDebug("Detecting if " + machname
257:                        + "Netware FTP or other FTP server", null);
258:                try {
259:                    ffc = new FullFtpClient(machname, szEncoding);
260:                    ftpResponse = ffc.getResponseString();
261:                    ffc.closeServer();
262:
263:                    /* Verify if the server is a Unix FTP server
264:                     * or a Novell FTP Server
265:                     */
266:                    if (ftpResponse.indexOf(novellResponse) != -1) {
267:                        novellServer = true;
268:                    } else {
269:                        novellServer = false;
270:                    }
271:                } catch (Exception e) {
272:                    writeDebug("getFTPType: Exception: ", e);
273:                }
274:                return novellServer;
275:            }
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.