Source Code Cross Referenced for ModeProvider.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » syntax » 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 » Swing Library » jEdit » org.gjt.sp.jedit.syntax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ModeProvider.java - An edit mode provider.
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2003 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:        package org.gjt.sp.jedit.syntax;
023:
024:        //{{{ Imports
025:
026:        import org.gjt.sp.jedit.GUIUtilities;
027:        import org.gjt.sp.jedit.Mode;
028:        import org.gjt.sp.jedit.jEdit;
029:        import org.gjt.sp.util.IOUtilities;
030:        import org.gjt.sp.util.Log;
031:        import org.xml.sax.InputSource;
032:        import org.xml.sax.SAXException;
033:        import org.xml.sax.SAXParseException;
034:        import org.xml.sax.XMLReader;
035:        import org.xml.sax.helpers.XMLReaderFactory;
036:
037:        import java.io.BufferedInputStream;
038:        import java.io.FileInputStream;
039:        import java.io.InputStream;
040:        import java.util.ArrayList;
041:        import java.util.List;
042:
043:        //}}}
044:
045:        /**
046:         * @author Matthieu Casanova
047:         * @version $Id: Buffer.java 8190 2006-12-07 07:58:34Z kpouer $
048:         * @since jEdit 4.3pre10
049:         */
050:        public class ModeProvider {
051:            public static final ModeProvider instance = new ModeProvider();
052:
053:            private List<Mode> modes = new ArrayList<Mode>(160);
054:
055:            //{{{ ModeProvider constructor
056:            private ModeProvider() {
057:            } //}}}
058:
059:            //{{{ removeAll() method
060:            public void removeAll() {
061:                modes = new ArrayList<Mode>(160);
062:            } //}}}
063:
064:            //{{{ getMode() method
065:            /**
066:             * Returns the edit mode with the specified name.
067:             * @param name The edit mode
068:             * @since jEdit 4.3pre10
069:             */
070:            public Mode getMode(String name) {
071:                for (int i = 0; i < modes.size(); i++) {
072:                    Mode mode = modes.get(i);
073:                    if (mode.getName().equals(name))
074:                        return mode;
075:                }
076:                return null;
077:            } //}}}
078:
079:            //{{{ getModeForFile() method
080:            /**
081:             * Get the appropriate mode that must be used for the file
082:             * @param filename the filename
083:             * @param firstLine the first line of the file
084:             * @return the edit mode, or null if no mode match the file
085:             * @since jEdit 4.3pre12
086:             */
087:            public Mode getModeForFile(String filename, String firstLine) {
088:                String nogzName = filename.substring(0, filename.length()
089:                        - (filename.endsWith(".gz") ? 3 : 0));
090:                Mode[] modes = getModes();
091:
092:                // this must be in reverse order so that modes from the user
093:                // catalog get checked first!
094:                for (int i = modes.length - 1; i >= 0; i--) {
095:                    if (modes[i].accept(nogzName, firstLine)) {
096:                        return modes[i];
097:                    }
098:                }
099:                return null;
100:            } //}}}
101:
102:            //{{{ getModes() method
103:            /**
104:             * Returns an array of installed edit modes.
105:             * @since jEdit 4.3pre10
106:             */
107:            public Mode[] getModes() {
108:                Mode[] array = new Mode[modes.size()];
109:                modes.toArray(array);
110:                return array;
111:            } //}}}
112:
113:            //{{{ addMode() method
114:            /**
115:             * Do not call this method. It is only public so that classes
116:             * in the org.gjt.sp.jedit.syntax package can access it.
117:             * @since jEdit 4.3pre10
118:             * @param mode The edit mode
119:             */
120:            public void addMode(Mode mode) {
121:                modes.add(mode);
122:            } //}}}
123:
124:            //{{{ loadMode() method
125:            public void loadMode(Mode mode, XModeHandler xmh) {
126:                String fileName = (String) mode.getProperty("file");
127:
128:                Log.log(Log.NOTICE, jEdit.class, "Loading edit mode "
129:                        + fileName);
130:
131:                XMLReader parser = null;
132:                try {
133:                    parser = XMLReaderFactory.createXMLReader();
134:                } catch (SAXException saxe) {
135:                    Log.log(Log.ERROR, jEdit.class, saxe);
136:                    return;
137:                }
138:                mode.setTokenMarker(xmh.getTokenMarker());
139:
140:                InputStream grammar = null;
141:
142:                try {
143:                    grammar = new BufferedInputStream(new FileInputStream(
144:                            fileName));
145:
146:                    InputSource isrc = new InputSource(grammar);
147:                    isrc.setSystemId("jedit.jar");
148:                    parser.setContentHandler(xmh);
149:                    parser.setDTDHandler(xmh);
150:                    parser.setEntityResolver(xmh);
151:                    parser.setErrorHandler(xmh);
152:                    parser.parse(isrc);
153:
154:                    mode.setProperties(xmh.getModeProperties());
155:                } catch (Throwable e) {
156:                    Log.log(Log.ERROR, jEdit.class, e);
157:
158:                    if (e instanceof  SAXParseException) {
159:                        String message = e.getMessage();
160:                        int line = ((SAXParseException) e).getLineNumber();
161:                        int col = ((SAXParseException) e).getColumnNumber();
162:
163:                        Object[] args = { fileName, line, col, message };
164:                        GUIUtilities.error(null, "xmode-error", args);
165:                    }
166:                } finally {
167:                    IOUtilities.closeQuietly(grammar);
168:                }
169:            } //}}}
170:
171:            //{{{ loadMode() method
172:            public void loadMode(Mode mode) {
173:                XModeHandler xmh = new XModeHandler(mode.getName()) {
174:                    public void error(String what, Object subst) {
175:                        Log.log(Log.ERROR, this , subst);
176:                    }
177:
178:                    public TokenMarker getTokenMarker(String modeName) {
179:                        Mode mode = getMode(modeName);
180:                        if (mode == null)
181:                            return null;
182:                        else
183:                            return mode.getTokenMarker();
184:                    }
185:                };
186:                loadMode(mode, xmh);
187:            } //}}}
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.