Source Code Cross Referenced for MRUList.java in  » Net » j2ssh » com » sshtools » common » mru » 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 » Net » j2ssh » com.sshtools.common.mru 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  SSHTools - Java SSH2 API
003:         *
004:         *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
005:         *
006:         *  Contributions made by:
007:         *
008:         *  Brett Smith
009:         *  Richard Pernavas
010:         *  Erwin Bolwidt
011:         *
012:         *  This program is free software; you can redistribute it and/or
013:         *  modify it under the terms of the GNU General Public License
014:         *  as published by the Free Software Foundation; either version 2
015:         *  of the License, or (at your option) any later version.
016:         *
017:         *  This program is distributed in the hope that it will be useful,
018:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:         *  GNU General Public License for more details.
021:         *
022:         *  You should have received a copy of the GNU General Public License
023:         *  along with this program; if not, write to the Free Software
024:         *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
025:         */
026:        package com.sshtools.common.mru;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:
031:        import org.xml.sax.Attributes;
032:        import org.xml.sax.SAXException;
033:        import org.xml.sax.helpers.DefaultHandler;
034:
035:        import java.io.File;
036:        import java.io.IOException;
037:        import java.io.InputStream;
038:
039:        import java.util.Iterator;
040:        import java.util.Stack;
041:        import java.util.Vector;
042:
043:        import javax.xml.parsers.ParserConfigurationException;
044:        import javax.xml.parsers.SAXParser;
045:        import javax.xml.parsers.SAXParserFactory;
046:
047:        /**
048:         *
049:         *
050:         * @author $author$
051:         * @version $Revision: 1.15 $
052:         */
053:        public class MRUList extends java.util.Vector {
054:            private static Log log = LogFactory.getLog(MRUList.class);
055:            private static final String MRU_LIST_ELEMENT = "MRUList";
056:            private static final String FILE_ELEMENT = "File";
057:            private String currentElement = null;
058:
059:            /**
060:             * Creates a new MRUList object.
061:             */
062:            public MRUList() {
063:                super ();
064:            }
065:
066:            /**
067:             * Creates a new MRUList object.
068:             *
069:             * @param in
070:             *
071:             * @throws SAXException
072:             * @throws ParserConfigurationException
073:             * @throws IOException
074:             */
075:            public MRUList(InputStream in) throws SAXException,
076:                    ParserConfigurationException, IOException {
077:                this ();
078:                reload(in);
079:            }
080:
081:            /**
082:             *
083:             *
084:             * @param in
085:             *
086:             * @throws SAXException
087:             * @throws ParserConfigurationException
088:             * @throws IOException
089:             */
090:            public void reload(InputStream in) throws SAXException,
091:                    ParserConfigurationException, IOException {
092:                SAXParserFactory saxFactory = SAXParserFactory.newInstance();
093:                SAXParser saxParser = saxFactory.newSAXParser();
094:                saxParser.parse(in, new MRUSAXHandler());
095:            }
096:
097:            /**
098:             *
099:             *
100:             * @return
101:             */
102:            public String toString() {
103:                String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
104:                xml += ("<!-- Most recently used -->\n<" + MRU_LIST_ELEMENT + ">\n");
105:
106:                Iterator it = iterator();
107:                File file = null;
108:
109:                while (it.hasNext()) {
110:                    file = (File) it.next();
111:                    xml += ("   " + "<" + FILE_ELEMENT + ">"
112:                            + file.getAbsolutePath() + "</" + FILE_ELEMENT + ">\n");
113:                }
114:
115:                xml += ("</" + MRU_LIST_ELEMENT + ">");
116:
117:                return xml;
118:            }
119:
120:            private class MRUSAXHandler extends DefaultHandler {
121:                private String MRU_LIST_ELEMENT = "MRUList";
122:                private String FILE_ELEMENT = "File";
123:                private File currentFile = null;
124:                private Stack tags = new Stack();
125:
126:                public void startElement(String uri, String localName,
127:                        String qname, Attributes attrs) throws SAXException {
128:                    ElementWrapper currentElement = (tags.size() == 0) ? null
129:                            : (ElementWrapper) tags.peek();
130:
131:                    if (currentElement == null) {
132:                        if (!qname.equals(MRU_LIST_ELEMENT)) {
133:                            throw new SAXException("Unexpected root element <"
134:                                    + qname + ">");
135:                        }
136:                    } else {
137:                        if (currentElement.element.equals(MRU_LIST_ELEMENT)) {
138:                            if (qname.equals(FILE_ELEMENT)) {
139:                            } else {
140:                                throw new SAXException("Unexpected element <"
141:                                        + qname + ">");
142:                            }
143:                        } else {
144:                            throw new SAXException("Unexpected element <"
145:                                    + qname + ">");
146:                        }
147:                    }
148:
149:                    ElementWrapper w = new ElementWrapper(qname);
150:                    tags.push(w);
151:                }
152:
153:                public void characters(char[] ch, int start, int len)
154:                        throws SAXException {
155:                    ElementWrapper currentElement = (tags.size() == 0) ? null
156:                            : (ElementWrapper) tags.peek();
157:
158:                    if (currentElement != null) {
159:                        currentElement.text.append(new String(ch, start, len));
160:                    } else {
161:                        throw new SAXException("Unexpected text at " + start
162:                                + " for " + len);
163:                    }
164:                }
165:
166:                public void endElement(String uri, String localName,
167:                        String qname) throws SAXException {
168:                    ElementWrapper currentElement = (tags.size() == 0) ? null
169:                            : (ElementWrapper) tags.peek();
170:
171:                    if (currentElement != null) {
172:                        if (!currentElement.element.equals(qname)) {
173:                            throw new SAXException(
174:                                    "Unexpected end element found <" + qname
175:                                            + ">");
176:                        }
177:
178:                        if (currentElement.element.equals(FILE_ELEMENT)) {
179:                            MRUList.this .add(new File(currentElement.text
180:                                    .toString()));
181:                        }
182:
183:                        tags.pop();
184:                    }
185:                }
186:            }
187:
188:            public class ElementWrapper {
189:                String element;
190:                StringBuffer text;
191:
192:                ElementWrapper(String element) {
193:                    this .element = element;
194:                    text = new StringBuffer();
195:                }
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.