Source Code Cross Referenced for XMLEditingModel.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » core » text » 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 » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.core.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.core.text;
011:
012:        import java.io.BufferedInputStream;
013:        import java.io.ByteArrayInputStream;
014:        import java.io.IOException;
015:        import java.io.InputStream;
016:        import java.io.PrintWriter;
017:        import java.io.StringWriter;
018:        import java.io.UnsupportedEncodingException;
019:
020:        import javax.xml.parsers.FactoryConfigurationError;
021:        import javax.xml.parsers.ParserConfigurationException;
022:
023:        import org.eclipse.core.resources.IFile;
024:        import org.eclipse.core.runtime.CoreException;
025:        import org.eclipse.jface.text.IDocument;
026:        import org.eclipse.pde.core.IModel;
027:        import org.eclipse.pde.core.IWritable;
028:        import org.eclipse.pde.internal.core.PDECore;
029:        import org.eclipse.pde.internal.core.util.SAXParserWrapper;
030:        import org.xml.sax.SAXException;
031:        import org.xml.sax.helpers.DefaultHandler;
032:
033:        public abstract class XMLEditingModel extends AbstractEditingModel {
034:
035:            public XMLEditingModel(IDocument document, boolean isReconciling) {
036:                super (document, isReconciling);
037:            }
038:
039:            /* (non-Javadoc)
040:             * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
041:             */
042:            public void load(InputStream source, boolean outOfSync) {
043:                try {
044:                    fLoaded = true;
045:                    SAXParserWrapper parser = new SAXParserWrapper();
046:                    parser.parse(source, createDocumentHandler(this , true));
047:                } catch (SAXException e) {
048:                    fLoaded = false;
049:                } catch (IOException e) {
050:                } catch (ParserConfigurationException e) {
051:                } catch (FactoryConfigurationError e) {
052:                }
053:            }
054:
055:            protected abstract DefaultHandler createDocumentHandler(
056:                    IModel model, boolean reconciling);
057:
058:            public void adjustOffsets(IDocument document) {
059:                try {
060:                    SAXParserWrapper parser = new SAXParserWrapper();
061:                    parser.parse(getInputStream(document),
062:                            createDocumentHandler(this , false));
063:                } catch (SAXException e) {
064:                } catch (IOException e) {
065:                } catch (ParserConfigurationException e) {
066:                } catch (FactoryConfigurationError e) {
067:                }
068:            }
069:
070:            /**
071:             * @return
072:             */
073:            private boolean isResourceFile() {
074:                if (getUnderlyingResource() == null) {
075:                    return false;
076:                } else if ((getUnderlyingResource() instanceof  IFile) == false) {
077:                    return false;
078:                }
079:                return true;
080:            }
081:
082:            public void save() {
083:                if (isResourceFile() == false) {
084:                    return;
085:                }
086:                try {
087:                    IFile file = (IFile) getUnderlyingResource();
088:                    String contents = getContents();
089:                    ByteArrayInputStream stream = new ByteArrayInputStream(
090:                            contents.getBytes("UTF8")); //$NON-NLS-1$
091:                    if (file.exists()) {
092:                        file.setContents(stream, false, false, null);
093:                    } else {
094:                        file.create(stream, false, null);
095:                    }
096:                    stream.close();
097:                } catch (CoreException e) {
098:                    PDECore.logException(e);
099:                } catch (IOException e) {
100:                }
101:            }
102:
103:            /* (non-Javadoc)
104:             * @see org.eclipse.pde.internal.core.IWorkspaceModel#reload()
105:             */
106:            public void reload() {
107:                if (isResourceFile() == false) {
108:                    return;
109:                }
110:                IFile file = (IFile) getUnderlyingResource();
111:                // Underlying file has to exist in order to reload the model
112:                if (file.exists()) {
113:                    InputStream stream = null;
114:                    try {
115:                        // Get the file contents
116:                        stream = new BufferedInputStream(file.getContents(true));
117:                        // Load the model using the last saved file contents
118:                        reload(stream, false);
119:                        // Remove the dirty (*) indicator from the editor window
120:                        setDirty(false);
121:                    } catch (CoreException e) {
122:                        // Ignore
123:                    }
124:                }
125:            }
126:
127:            public void reload(IDocument document) {
128:                // Get the document's text
129:                String text = document.get();
130:                InputStream stream = null;
131:
132:                try {
133:                    // Turn the document's text into a stream
134:                    stream = new ByteArrayInputStream(text.getBytes("UTF8")); //$NON-NLS-1$
135:                    // Reload the model using the stream
136:                    reload(stream, false);
137:                    // Remove the dirty (*) indicator from the editor window
138:                    setDirty(false);
139:                } catch (UnsupportedEncodingException e) {
140:                    PDECore.logException(e);
141:                } catch (CoreException e) {
142:                    // Ignore
143:                }
144:            }
145:
146:            public String getContents() {
147:                StringWriter swriter = new StringWriter();
148:                PrintWriter writer = new PrintWriter(swriter);
149:                setLoaded(true);
150:                save(writer);
151:                writer.flush();
152:                try {
153:                    swriter.close();
154:                } catch (IOException e) {
155:                }
156:                return swriter.toString();
157:            }
158:
159:            /* (non-Javadoc)
160:             * @see org.eclipse.pde.internal.core.text.AbstractEditingModel#save(java.io.PrintWriter)
161:             */
162:            public void save(PrintWriter writer) {
163:                if (isLoaded()) {
164:                    getRoot().write("", writer); //$NON-NLS-1$
165:                }
166:                setDirty(false);
167:            }
168:
169:            protected abstract IWritable getRoot();
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.