Source Code Cross Referenced for NfsFile.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: NfsFile.java,v 1.36 2006/08/04 06:44:13 aj157941 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.io.*;
016:        import com.sun.portal.log.common.PortalLogger;
017:        import java.util.Date;
018:        import java.util.GregorianCalendar;
019:        import java.util.TimeZone;
020:        import java.util.logging.*;
021:        import java.util.Locale;
022:        import java.text.SimpleDateFormat;
023:
024:        import com.sun.xfile.*;
025:        import com.sun.portal.netfile.shared.*;
026:
027:        class NfsFile {
028:
029:            private static Logger logger = PortalLogger
030:                    .getLogger(NfsFile.class);
031:            public static boolean SHOULD_HAVE_READ_PERMISSION = true;
032:            public static boolean SHOULD_NOT_HAVE_READ_PERMISSION = false;
033:            public static final String encoding = "UTF8";
034:            private static final int[] ia_unable_to_login = new int[] { -1, -1 };
035:            private String s_machine_encoding;
036:            private Locale clocale;
037:
038:            private com.sun.xfile.XFileInputStream instream = null;
039:            private com.sun.xfile.XFileOutputStream outstream = null;
040:
041:            private int i_number_of_directories_traversed; //Keep track of number of directories scanned during single instance of a search
042:
043:            public native int[] getUserInfo(String user_name) throws Exception;
044:
045:            private native boolean doNativeAuth(String username, String password)
046:                    throws Exception;
047:
048:            static {
049:                if (System.getProperty("os.name").indexOf("indows") == -1) {
050:                    System.loadLibrary("getpwnam2");
051:                }
052:            }
053:
054:            NfsFile(String s_machine_encoding, Locale cloc) {
055:                this .s_machine_encoding = s_machine_encoding;
056:                this .clocale = cloc;
057:                i_number_of_directories_traversed = 0;
058:            }
059:
060:            NfsFile(String s_machine_encoding, Locale cloc, int authPort) {
061:                this (s_machine_encoding, cloc);
062:            }
063:
064:            int[] getUserIDs(String user_name, String password,
065:                    NetFileResource resourceBundle) throws NetFileException {
066:                int[] i_ids = ia_unable_to_login;
067:                try {
068:                    i_ids = getUserInfo(new String(user_name.getBytes(), "UTF8"));
069:                } catch (java.io.UnsupportedEncodingException e) {
070:                    throw new NetFileException(
071:                            NetFileException.NETFILE_GENERROR_CODE,
072:                            resourceBundle.getString("nf.1"));
073:                } catch (Exception e) {
074:                    throw new NetFileException(
075:                            NetFileException.NETFILE_GENERROR_CODE,
076:                            resourceBundle.getString("nf.11"));
077:                }
078:                if (i_ids[0] == -1) {
079:                    throw new NetFileException(
080:                            NetFileException.NETFILE_GENERROR_CODE,
081:                            resourceBundle.getString("nf.2"));
082:                }
083:                return i_ids;
084:            }
085:
086:            String mkdir(String machine, String share, String user_name,
087:                    String password, String target_dir,
088:                    String directory_to_create, NetFileResource resourceBundle)
089:                    throws NetFileException {
090:                try {
091:                    if (!doAuthenticate(user_name, password, resourceBundle))
092:                        throw new NetFileException(
093:                                NetFileException.NETFILE_GENERROR_CODE,
094:                                resourceBundle.getString("nf.2"));
095:
096:                    int[] i_ids = getUserIDs(user_name, password,
097:                            resourceBundle);
098:                    com.sun.xfile.XFile xf_parent_dir = getXFile(share,
099:                            machine, target_dir, true,
100:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
101:                    if (!(xf_parent_dir.canWrite())) {
102:                        throw new NetFileException(
103:                                NetFileException.NETFILE_GENERROR_CODE,
104:                                resourceBundle
105:                                        .getString("nf.7",
106:                                                new Object[] { xf_parent_dir
107:                                                        .getPath() }));
108:                    }
109:
110:                    com.sun.xfile.XFile xfile = getXFile(share, machine,
111:                            target_dir + "/" + directory_to_create, false,
112:                            SHOULD_NOT_HAVE_READ_PERMISSION, i_ids,
113:                            resourceBundle);
114:                    if (!xfile.mkdir()) {
115:                        throw new NetFileException(
116:                                NetFileException.NETFILE_GENERROR_CODE,
117:                                resourceBundle.getString("nf.4"));
118:                    }
119:                } catch (Exception e) {
120:                    if (e instanceof  NetFileException) {
121:                        throw (NetFileException) e;
122:                    } else {
123:                        throw new NetFileException(
124:                                NetFileException.NETFILE_GENERROR_CODE,
125:                                resourceBundle.getString("nf.4"));
126:                    }
127:                }
128:                return resourceBundle.getString("warning52");
129:            }
130:
131:            String[] getNFSDir(String username, String password, String VMSnam,
132:                    String machname, String dir_nam, String tmpdir,
133:                    NetFileResource resourceBundle) throws NetFileException {
134:                if (!doAuthenticate(username, password, resourceBundle))
135:                    throw new NetFileException(
136:                            NetFileException.NETFILE_GENERROR_CODE,
137:                            resourceBundle.getString("nf.2"));
138:                int[] i_ids = getUserIDs(username, password, resourceBundle);
139:                com.sun.xfile.XFile xfile = getXFile(VMSnam, machname, dir_nam,
140:                        true, SHOULD_HAVE_READ_PERMISSION, i_ids,
141:                        resourceBundle);
142:                String[] sa_files_list = xfile.list();
143:                String[] sa_listing = null;
144:
145:                if (sa_files_list == null) {
146:                    throw new NetFileException(
147:                            NetFileException.NETFILE_GENERROR_CODE,
148:                            resourceBundle.getString("nf.5"));
149:                } else {
150:                    sa_listing = new String[sa_files_list.length * 4];
151:                    for (int i = 0, j = 0; i < sa_files_list.length; ++i) {
152:                        com.sun.xfile.XFile xf_curr_file = new com.sun.xfile.XFile(
153:                                xfile, sa_files_list[i]);
154:                        if (xf_curr_file.isFile()) {
155:                            sa_listing[j] = "-";
156:                        } else {
157:                            sa_listing[j] = "d";
158:                        }
159:                        ++j;
160:                        sa_listing[j] = xf_curr_file.getName();
161:                        ++j;
162:                        sa_listing[j] = (new Long(xf_curr_file.length()))
163:                                .toString();
164:                        ++j;
165:                        Date d = new java.util.Date(xf_curr_file.lastModified());
166:                        SimpleDateFormat sdf = new SimpleDateFormat(
167:                                resourceBundle.getString("nf.DateFormat"),
168:                                clocale);
169:                        sdf.setCalendar(new GregorianCalendar(TimeZone
170:                                .getDefault()));
171:                        sa_listing[j] = sdf.format(d);
172:                        ++j;
173:                    }
174:                }
175:                if (sa_listing == null) {
176:                    throw new NetFileException(
177:                            NetFileException.NETFILE_GENERROR_CODE,
178:                            resourceBundle.getString("nf.5"));
179:                }
180:                return sa_listing;
181:            }
182:
183:            String getNFSFile(String username, String password, String VMSname,
184:                    String machname, String mainfilename, String dir_nam,
185:                    String tmpdir, NetFileResource resourceBundle,
186:                    String usersession) throws NetFileException {
187:                File temp_file = null;
188:                byte[] buffer = new byte[8 * 1024];
189:
190:                if (!doAuthenticate(username, password, resourceBundle))
191:                    throw new NetFileException(
192:                            NetFileException.NETFILE_GENERROR_CODE,
193:                            resourceBundle.getString("nf.2"));
194:                try {
195:
196:                    int[] i_ids = getUserIDs(username, password, resourceBundle);
197:                    writeDebug("Getting file " + machname + ":" + VMSname
198:                            + dir_nam + "/" + mainfilename);
199:                    com.sun.xfile.XFile xfile = getXFile(VMSname, machname,
200:                            dir_nam + "/" + mainfilename, true,
201:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
202:                    com.sun.xfile.XFileInputStream xfis_file = new com.sun.xfile.XFileInputStream(
203:                            xfile);
204:                    Long time = new Long(System.currentTimeMillis());
205:                    String s_temp_file = tmpdir + "/" + time.toString()
206:                            + username.toUpperCase() + mainfilename;
207:                    temp_file = new File(s_temp_file);
208:                    temp_file.createNewFile();
209:                    FileOutputStream fops_tmp = new FileOutputStream(temp_file);
210:                    int c = 0;
211:                    while ((c = xfis_file.read(buffer)) > -1) {
212:                        fops_tmp.write(buffer, 0, c);
213:                    }
214:                    fops_tmp.close();
215:                    xfis_file.close();
216:                    fops_tmp = null;
217:                    xfis_file = null;
218:                    xfile = null;
219:                    time = null;
220:                    temp_file = null;
221:                    writeDebug("Got " + machname + ":" + VMSname + dir_nam
222:                            + "/" + mainfilename);
223:                    return s_temp_file;
224:                } catch (Exception e) {
225:                    writeErrorDebug("Error in putting NFS File", e);
226:                    return "ERROR:" + e.getMessage();
227:                } finally {
228:                    if (temp_file != null) {
229:                        try {
230:                            temp_file.delete();
231:                        } catch (Exception e) {
232:                        }
233:                        temp_file = null;
234:                    }
235:                }
236:            }
237:
238:            String[] search(String usernam, String passwrd, String machnam,
239:                    String VMSnam, String pattern, boolean ignoreCase,
240:                    boolean searchSubfolders, String dir_nam,
241:                    String domainname, int maxsrchdir,
242:                    NetFileResource resourceBundle) throws NetFileException {
243:                return search(usernam, passwrd, machnam, VMSnam, pattern,
244:                        ignoreCase, searchSubfolders, dir_nam, maxsrchdir,
245:                        resourceBundle);
246:            }
247:
248:            String[] search(String usernam, String passwrd, String machnam,
249:                    String VMSnam, String pattern, boolean ignoreCase,
250:                    boolean searchSubfolders, String dir_nam, int maxsrchdir,
251:                    NetFileResource resourceBundle) throws NetFileException {
252:                if (!doAuthenticate(usernam, passwrd, resourceBundle))
253:                    throw new NetFileException(
254:                            NetFileException.NETFILE_GENERROR_CODE,
255:                            resourceBundle.getString("nf.2"));
256:
257:                int[] i_ids = getUserIDs(usernam, passwrd, resourceBundle);
258:                com.sun.xfile.XFile xfile = getXFile(VMSnam, machnam, dir_nam,
259:                        true, false, i_ids, resourceBundle);
260:                String s_prefix = "nfs://" + machnam;
261:                int i_prefix_length = s_prefix.length();
262:
263:                if (xfile.isFile()) {
264:                    throw new NetFileException(
265:                            NetFileException.NETFILE_GENERROR_CODE,
266:                            resourceBundle.getString("nf.6"));
267:                }
268:
269:                java.util.ArrayList v_search_results = new java.util.ArrayList();
270:
271:                int i_directories_searched = 0;
272:
273:                search(xfile, ++i_directories_searched, maxsrchdir,
274:                        i_prefix_length, v_search_results, pattern, ignoreCase,
275:                        i_ids, resourceBundle);
276:
277:                if (i_number_of_directories_traversed > maxsrchdir) {
278:                    String[] searchResults = new String[v_search_results.size() + 1];
279:                    searchResults[0] = "ERROR:"
280:                            + resourceBundle.getString("maxSearch");
281:                    for (int j = 1; j < searchResults.length; j++) {
282:                        searchResults[j] = (String) v_search_results.get(j - 1);
283:                    }
284:                    return searchResults;
285:                }
286:
287:                String[] sa_resulsts = new String[v_search_results.size()];
288:
289:                for (int i = 0; i < v_search_results.size(); ++i) {
290:                    sa_resulsts[i] = (String) (v_search_results.get(i));
291:                    writeDebug("Search result:" + sa_resulsts[i]);
292:                }
293:
294:                return sa_resulsts;
295:            }
296:
297:            void search(com.sun.xfile.XFile xfile, int i_directories_searched,
298:                    int maxsrchdir, int i_prefix_length,
299:                    java.util.ArrayList v_search_results, String pattern,
300:                    boolean ignoreCase, int[] i_ids,
301:                    NetFileResource resourceBundle) throws NetFileException {
302:                ++i_number_of_directories_traversed;
303:                if (i_number_of_directories_traversed > maxsrchdir) {
304:                    return;
305:                }
306:                if (xfile.isFile()) {
307:                    throw new NetFileException(
308:                            NetFileException.NETFILE_GENERROR_CODE,
309:                            resourceBundle.getString("nf.6"));
310:                }
311:                String[] sa_contents = xfile.list();
312:                String s_path = xfile.toString();
313:                writeDebug("Searching:" + s_path);
314:                if (sa_contents == null) {
315:                    v_search_results
316:                            .add("Permission denied :"
317:                                    + s_path.substring(i_prefix_length, s_path
318:                                            .length()));
319:                } else {
320:                    for (int i = 0; ((i < sa_contents.length) && (!(i_number_of_directories_traversed > maxsrchdir))); ++i) {
321:                        String s_current_path = s_path + "/" + sa_contents[i];
322:                        com.sun.xfile.XFile x_file = null;
323:                        try {
324:                            x_file = getXFile(s_current_path, true, false,
325:                                    i_ids, resourceBundle);
326:                        } catch (Exception e) {
327:                        }
328:
329:                        boolean containsPattern = false;
330:                        if (ignoreCase)
331:                            containsPattern = (sa_contents[i].toLowerCase())
332:                                    .indexOf(pattern.toLowerCase()) > -1;
333:                        else
334:                            containsPattern = sa_contents[i].indexOf(pattern) > -1;
335:
336:                        if (containsPattern) {
337:                            String path = x_file.toString()
338:                                    .substring(i_prefix_length,
339:                                            x_file.toString().length());
340:                            if (x_file.isDirectory()) {
341:                                path += "/";
342:                            }
343:                            v_search_results.add(path);
344:                        }
345:                        if (x_file.isDirectory()) {
346:                            if (x_file.canRead()) {
347:                                search(x_file, ++i_directories_searched,
348:                                        maxsrchdir, i_prefix_length,
349:                                        v_search_results, pattern, ignoreCase,
350:                                        i_ids, resourceBundle);
351:                            } else {
352:                                v_search_results.add("Permission denied :"
353:                                        + x_file.toString().substring(
354:                                                i_prefix_length,
355:                                                x_file.toString().length()));
356:                            }
357:                        }
358:                    }
359:                }
360:            }
361:
362:            String delNFSFile(String username, String password, String VMSname,
363:                    String machname, String mainfilename, String dir_nam,
364:                    NetFileResource resourceBundle) throws NetFileException {
365:                if (!doAuthenticate(username, password, resourceBundle))
366:                    throw new NetFileException(
367:                            NetFileException.NETFILE_GENERROR_CODE,
368:                            resourceBundle.getString("nf.2"));
369:                try {
370:                    int[] i_ids = getUserIDs(username, password, resourceBundle);
371:                    com.sun.xfile.XFile xf_parent_directory = getXFile(VMSname,
372:                            machname, dir_nam, true,
373:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
374:                    if (!xf_parent_directory.canWrite()) {
375:                        throw new NetFileException(
376:                                NetFileException.NETFILE_GENERROR_CODE,
377:                                resourceBundle.getString("nf.3")
378:                                        + resourceBundle
379:                                                .getString(
380:                                                        "nf.7",
381:                                                        new Object[] { xf_parent_directory
382:                                                                .getPath() }));
383:                    }
384:                    com.sun.xfile.XFile xf_file = getXFile(VMSname, machname,
385:                            dir_nam + "/" + mainfilename, true,
386:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
387:                    if (!xf_file.canWrite()) {
388:                        throw new NetFileException(
389:                                NetFileException.NETFILE_GENERROR_CODE,
390:                                resourceBundle.getString("nf.3")
391:                                        + resourceBundle
392:                                                .getString(
393:                                                        "nf.7",
394:                                                        new Object[] { xf_parent_directory
395:                                                                .getPath() }));
396:                    }
397:                    xf_file.delete();
398:                } catch (NetFileException e) {
399:                    writeErrorDebug("Error in putting NFS File", e);
400:                    throw e;
401:                    //            return "ERROR:" + e.getMessage();
402:                }
403:                return resourceBundle.getString("info5");
404:            }
405:
406:            private String getFileURL(String VMSnam, String machname,
407:                    String dir_nam) {
408:                StringBuffer sb_file_pointer = new StringBuffer("nfs://");
409:                sb_file_pointer.append(machname);
410:                sb_file_pointer.append(VMSnam);
411:                sb_file_pointer.append(dir_nam);
412:                return sb_file_pointer.toString();
413:            }
414:
415:            public com.sun.xfile.XFileOutputStream getNFSOutputStream(
416:                    String username, String password, String machname,
417:                    String VMSname, String remotefil_arg, String dir_nam,
418:                    NetFileResource resourceBundle) throws Exception,
419:                    NetFileException {
420:
421:                return this .getNFSOutputStream(username, password, machname,
422:                        VMSname, remotefil_arg, dir_nam, false, resourceBundle);
423:            }
424:
425:            public com.sun.xfile.XFileOutputStream getNFSOutputStream(
426:                    String username, String password, String machname,
427:                    String VMSname, String remotefil_arg, String dir_nam,
428:                    boolean append, NetFileResource resourceBundle)
429:                    throws Exception, NetFileException {
430:                if (!doAuthenticate(username, password, resourceBundle))
431:                    throw new NetFileException(
432:                            NetFileException.NETFILE_GENERROR_CODE,
433:                            resourceBundle.getString("nf.2"));
434:
435:                int[] i_ids = getUserIDs(username, password, resourceBundle);
436:                com.sun.xfile.XFile xf_parent_dir = getXFile(VMSname, machname,
437:                        dir_nam, true, SHOULD_HAVE_READ_PERMISSION, i_ids,
438:                        resourceBundle);
439:
440:                if (!(xf_parent_dir.canWrite())) {
441:                    throw new NetFileException(
442:                            NetFileException.NETFILE_GENERROR_CODE,
443:                            resourceBundle.getString("nf.7",
444:                                    new Object[] { xf_parent_dir.getPath() }));
445:                }
446:
447:                com.sun.xfile.XFile xfile = getXFile(VMSname, machname, dir_nam
448:                        + "/" + remotefil_arg, false,
449:                        SHOULD_NOT_HAVE_READ_PERMISSION, i_ids, resourceBundle);
450:                if (append)
451:                    outstream = new XFileOutputStream(xfile, append);
452:                else
453:                    outstream = new XFileOutputStream(xfile);
454:                return outstream;
455:            }
456:
457:            public com.sun.xfile.XFileInputStream getNFSInputStream(
458:                    String username, String password, String VMSname,
459:                    String machname, String mainfilename, String dir_nam,
460:                    NetFileResource resourceBundle) throws Exception,
461:                    NetFileException {
462:                if (!doAuthenticate(username, password, resourceBundle))
463:                    throw new NetFileException(
464:                            NetFileException.NETFILE_GENERROR_CODE,
465:                            resourceBundle.getString("nf.2"));
466:
467:                int[] i_ids = getUserIDs(username, password, resourceBundle);
468:                writeDebug("Getting file " + machname + ":" + VMSname + dir_nam
469:                        + "/" + mainfilename);
470:                com.sun.xfile.XFile xfile = getXFile(VMSname, machname, dir_nam
471:                        + "/" + mainfilename, true,
472:                        SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
473:
474:                instream = new com.sun.xfile.XFileInputStream(xfile);
475:                return instream;
476:            }
477:
478:            public void closeNfsFile() throws IOException {
479:                if (instream != null)
480:                    instream.close();
481:                if (outstream != null)
482:                    outstream.close();
483:
484:                instream = null;
485:                outstream = null;
486:            }
487:
488:            private com.sun.xfile.XFile getXFile(String s_nfs_url,
489:                    boolean b_file_should_exist, boolean b_is_read_allowed,
490:                    int[] i_ids, NetFileResource resourceBundle)
491:                    throws NetFileException {
492:                com.sun.xfile.XFile xfile = new com.sun.xfile.XFile(s_nfs_url);
493:                com.sun.nfs.XFileExtensionAccessor nfsx = new com.sun.nfs.XFileExtensionAccessor(
494:                        xfile);
495:                int i_uid = i_ids[0];
496:                int i_gid = i_ids[1];
497:                int[] i_gids = new int[] { i_gid };
498:                nfsx.loginUGID(i_uid, i_gid, i_gids);
499:                if (b_file_should_exist) {
500:                    if (!(xfile.exists())) {
501:                        writeDebug(xfile.toString() + "," + xfile.getPath()
502:                                + " does not exist");
503:                        throw new NetFileException(
504:                                NetFileException.NETFILE_GENERROR_CODE,
505:                                resourceBundle.getString("nf.8",
506:                                        new Object[] { xfile.getPath() }));
507:                    } else {
508:                        writeDebug(xfile.getPath() + " exists");
509:                    }
510:                }
511:                if (b_is_read_allowed) {
512:                    if (!xfile.canRead()) {
513:                        throw new NetFileException(
514:                                NetFileException.NETFILE_GENERROR_CODE,
515:                                resourceBundle.getString("nf.9",
516:                                        new Object[] { xfile.getPath() }));
517:                    }
518:                }
519:                return xfile;
520:            }
521:
522:            private com.sun.xfile.XFile getXFile(String VMSName,
523:                    String machname, String file, boolean b_file_should_exist,
524:                    boolean b_is_read_allowed, int[] i_ids,
525:                    NetFileResource resourceBundle) throws NetFileException {
526:                writeDebug("Machine=" + machname + ",Share=" + VMSName
527:                        + ",file=" + file);
528:                if (!VMSName.startsWith("/")) {
529:                    VMSName = ("/" + VMSName);
530:                }
531:                if (!file.startsWith("/")) {
532:                    file = ("/" + file);
533:                }
534:                writeDebug("Machine=" + machname + ",Share=" + VMSName
535:                        + ",file=" + file);
536:                String s_nfs_url = getFileURL(VMSName, machname, file);
537:                writeDebug("File URL supplied to WebNFS is " + s_nfs_url);
538:                return getXFile(s_nfs_url, b_file_should_exist,
539:                        b_is_read_allowed, i_ids, resourceBundle);
540:            }
541:
542:            void rename(String username, String password, String machine,
543:                    String share, String directory, String old_file_name,
544:                    String new_file_name, NetFileResource resourceBundle)
545:                    throws NetFileException {
546:                if (!doAuthenticate(username, password, resourceBundle))
547:                    throw new NetFileException(
548:                            NetFileException.NETFILE_GENERROR_CODE,
549:                            resourceBundle.getString("nf.2"));
550:                try {
551:                    int[] i_ids = getUserIDs(username, password, resourceBundle);
552:                    com.sun.xfile.XFile xf_parent_directory = getXFile(share,
553:                            machine, directory, true,
554:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
555:                    if (!xf_parent_directory.canWrite()) {
556:                        throw new NetFileException(
557:                                NetFileException.NETFILE_GENERROR_CODE,
558:                                resourceBundle.getString("nf.10")
559:                                        + resourceBundle
560:                                                .getString(
561:                                                        "nf.7",
562:                                                        new Object[] { xf_parent_directory
563:                                                                .getPath() }));
564:                    }
565:                    com.sun.xfile.XFile xf_file = getXFile(share, machine,
566:                            directory + "/" + old_file_name, true,
567:                            SHOULD_HAVE_READ_PERMISSION, i_ids, resourceBundle);
568:                    if (!xf_file.canWrite()) {
569:                        throw new NetFileException(
570:                                NetFileException.NETFILE_GENERROR_CODE,
571:                                resourceBundle.getString("nf.10")
572:                                        + resourceBundle
573:                                                .getString(
574:                                                        "nf.7",
575:                                                        new Object[] { xf_parent_directory
576:                                                                .getPath() }));
577:                    }
578:                    XFile xf_renamed_file = new XFile(xf_parent_directory,
579:                            new_file_name);
580:                    if (xf_renamed_file.exists()) {
581:                        writeDebug(xf_renamed_file + " exists");
582:                        if (!xf_renamed_file.canWrite()) {
583:                            throw new NetFileException(
584:                                    NetFileException.NETFILE_GENERROR_CODE,
585:                                    resourceBundle.getString("nf.7",
586:                                            new Object[] { xf_parent_directory
587:                                                    .getPath() }));
588:                        }
589:                    }
590:                    xf_file.renameTo(xf_renamed_file);
591:                } catch (Exception e) {
592:                    writeErrorDebug("Error in putting NFS File", e);
593:                    if (e instanceof  NetFileException) {
594:                        throw (NetFileException) e;
595:                    }
596:                    throw new NetFileException(
597:                            NetFileException.NETFILE_GENERROR_CODE,
598:                            resourceBundle.getString("nf.10")
599:                                    + resourceBundle.getString("nf.7",
600:                                            new Object[] { directory }));
601:                }
602:            }
603:
604:            boolean doAuthenticate(String username, String passwd,
605:                    NetFileResource resourceBundle) throws NetFileException {
606:                try {
607:                    String osname = System.getProperty("os.name");
608:                    //            logger.info("OS detected is:" + osname);
609:                    Object[] params0 = { osname };
610:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2047", params0);
611:                    if (osname.indexOf("Linux") != -1
612:                            || osname.indexOf("SunOS") != -1
613:                            || osname.indexOf("HP-UX") != -1) {
614:                        //                logger.info("Trying to do Native UNIX Auth");
615:                        logger.info("PSSRNF_CSPNSJ2048");
616:                        boolean ret = false;
617:                        ret = doNativeAuth(username, passwd);
618:
619:                        //                logger.info("Native Auth code returned: " + ret);
620:                        Object[] params2 = { new Boolean(ret) };
621:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2049", params2);
622:                        return ret;
623:                    } else {
624:                        //TODO: use pcnfs for authentication for Windows
625:                        //                logger.info("Not UNIX OS, so not authenticating");
626:                        logger.info("PSSRNF_CSPNSJ2050");
627:                        return true;
628:                    }
629:                } catch (Exception e) {
630:                    writeErrorDebug(
631:                            "NfsFile, Exception while authenticating, ", e);
632:                    return false;
633:                }
634:            }
635:
636:            protected void writeDebug(String szMsg) {
637:                writeDebug(szMsg, null);
638:            }
639:
640:            protected void writeDebug(String szMsg, Exception e) {
641:                if (e != null) {
642:                    //            logger.log(Level.INFO, szMsg, e);
643:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2051");
644:                } else {
645:                    //            logger.info(szMsg);
646:                    logger.info("PSSRNF_CSPNSJ2052");
647:                }
648:            }
649:
650:            protected void writeErrorDebug(String szError, Exception e) {
651:                if (e != null)
652:                    //            logger.log(Level.SEVERE, szError, e);
653:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2053");
654:                else
655:                    //            logger.severe(szError);
656:                    logger.severe("PSSRNF_CSPNSJ2054");
657:            }
658:
659:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.