Package com.knowgate.jcifs.smb

Examples of com.knowgate.jcifs.smb.SmbFile


        return f1.lastModified() > f2.lastModified() ? -1 : 1;
    }
    protected void doDirectory( HttpServletRequest req, HttpServletResponse resp, SmbFile dir ) throws IOException {
        PrintWriter out;
        SmbFile[] dirents;
        SmbFile f;
        int i, j, len, maxLen, dirCount, fileCount, sort;
        String str, name, path, fmt;
        LinkedList sorted;
        ListIterator iter;
        SimpleDateFormat sdf = new SimpleDateFormat( "MM/d/yy h:mm a" );
        GregorianCalendar cal = new GregorianCalendar();

        sdf.setCalendar( cal );

        dirents = dir.listFiles();
        sorted = new LinkedList();
        if(( fmt = req.getParameter( "fmt" )) == null ) {
            fmt = "col";
        }
        sort = 0;
        if(( str = req.getParameter( "sort" )) == null || str.equals( "name" )) {
            sort = 0;
        } else if( str.equals( "size" )) {
            sort = 1;
        } else if( str.equals( "type" )) {
            sort = 2;
        } else if( str.equals( "date" )) {
            sort = 3;
        }
        dirCount = fileCount = 0;
        maxLen = 28;
        for( i = 0; i < dirents.length; i++ ) {
            try {
                if( dirents[i].getType() == SmbFile.TYPE_NAMED_PIPE ) {
                    continue;
                }
            } catch( SmbAuthException sae ) {
            } catch( SmbException se ) {
                if( se.getNtStatus() != se.NT_STATUS_UNSUCCESSFUL ) {
                    throw se;
                }
            }
            if( dirents[i].isDirectory() ) {
                dirCount++;
            } else {
                fileCount++;
            }

            name = dirents[i].getName();
            len = name.length();
            if( len > maxLen ) {
                maxLen = len;
            }

            iter = sorted.listIterator();
            for( j = 0; iter.hasNext(); j++ ) {
                if( sort == 0 ) {
                    if( compareNames( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 1 ) {
                    if( compareSizes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 2 ) {
                    if( compareTypes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 3 ) {
                    if( compareDates( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                }
            }
            sorted.add( j, dirents[i] );
        }
        if( maxLen > 50 ) {
            maxLen = 50;
        }
        maxLen *= 9; /* convert to px */

        out = resp.getWriter();

        resp.setContentType( "text/html" );

        out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" );
        out.println( "<html><head><title>Network Explorer</title>" );
        out.println( "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" );
        out.println( "<style TYPE=\"text/css\">" );

        out.println( style );

        if( dirents.length < 200 ) {
            out.println( "    a:hover {" );
            out.println( "        background: #a2ff01;" );
            out.println( "    }" );
        }

        out.println( "</STYLE>" );
        out.println( "</head><body>" );

        out.print( "<a class=\"sort\" style=\"width: " + maxLen + ";\" href=\"?fmt=detail&sort=name\">Name</a>" );
        out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=size\">Size</a>" );
        out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=type\">Type</a>" );
        out.println( "<a class=\"sort\" style=\"width: 180\" href=\"?fmt=detail&sort=date\">Modified</a><br clear='all'><p>" );

        path = dir.getCanonicalPath();

        if( path.length() < 7 ) {
            out.println( "<b><big>smb://</big></b><br>" );
            path = ".";
        } else {
            out.println( "<b><big>" + path + "</big></b><br>" );
            path = "../";
        }
        out.println( (dirCount + fileCount) + " objects (" + dirCount + " directories, " + fileCount + " files)<br>" );
        out.println( "<b><a class=\"plain\" href=\".\">normal</a> | <a class=\"plain\" href=\"?fmt=detail\">detailed</a></b>" );
        out.println( "<p><table border='0' cellspacing='0' cellpadding='0'><tr><td>" );

        out.print( "<A style=\"width: " + maxLen );
        out.print( "; height: 18;\" HREF=\"" );
        out.print( path );
        out.println( "\"><b>&uarr;</b></a>" );
        if( fmt.equals( "detail" )) {
            out.println( "<br clear='all'>" );
        }

        if( path.length() == 1 || dir.getType() != SmbFile.TYPE_WORKGROUP ) {
            path = "";
        }

        iter = sorted.listIterator();
        while( iter.hasNext() ) {
            f = (SmbFile)iter.next();
            name = f.getName();

            if( fmt.equals( "detail" )) {
                out.print( "<A style=\"width: " + maxLen );
                out.print( "; height: 18;\" HREF=\"" );
                out.print( path );
                out.print( name );

                if( f.isDirectory() ) {
                    out.print( "?fmt=detail\"><b>" );
                    out.print( name );
                    out.print( "</b></a>" );
                } else {
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b></a><div align='right'>" );
                    out.print( (f.length() / 1024) + " KB </div><div>" );
                    i = name.lastIndexOf( '.' ) + 1;
                    if( i > 1 && (name.length() - i) < 6 ) {
                        out.print( name.substring( i ).toUpperCase() + "</div class='ext'>" );
                    } else {
                        out.print( "&nbsp;</div>" );
                    }
                    out.print( "<div style='width: 180'>" );
                    out.print( sdf.format( new Date( f.lastModified() )));
                    out.print( "</div>" );
                }
                out.println( "<br clear='all'>" );
            } else {
                out.print( "<A style=\"width: " + maxLen );
                if( f.isDirectory() ) {
                    out.print( "; height: 18;\" HREF=\"" );
                    out.print( path );
                    out.print( name );
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b></a>" );
                } else {
                    out.print( ";\" HREF=\"" );
                    out.print( path );
                    out.print( name );
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b><br><small>" );
                    out.print( (f.length() / 1024) + "KB <br>" );
                    out.print( sdf.format( new Date( f.lastModified() )));
                    out.print( "</small>" );
                    out.println( "</a>" );
                }
            }
        }
View Full Code Here


                return;
            }
        }

        try {
            SmbFile file;

            if( ntlm != null ) {
                file = new SmbFile( "smb:/" + pathInfo , ntlm );
            } else if( server == null ) {
                file = new SmbFile( "smb://" );
            } else {
                file = new SmbFile( "smb:/" + pathInfo );
            }

            if( file.isDirectory() ) {
                doDirectory( req, resp, file );
            } else {
                doFile( req, resp, file );
            }
        } catch( SmbAuthException sae ) {
View Full Code Here

TOP

Related Classes of com.knowgate.jcifs.smb.SmbFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.