KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > XMLEditingModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.model;
12
13 import java.io.*;
14
15 import javax.xml.parsers.*;
16
17 import org.eclipse.jface.text.*;
18 import org.eclipse.pde.core.*;
19 import org.xml.sax.*;
20 import org.xml.sax.helpers.*;
21
22 public abstract class XMLEditingModel extends AbstractEditingModel {
23     
24     private SAXParser fParser;
25
26     public XMLEditingModel(IDocument document, boolean isReconciling) {
27         super(document, isReconciling);
28     }
29     
30     /* (non-Javadoc)
31      * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
32      */

33     public void load(InputStream source, boolean outOfSync) {
34         try {
35             fLoaded = true;
36             getParser().parse(source, createDocumentHandler(this));
37         } catch (SAXException e) {
38             fLoaded = false;
39         } catch (IOException e) {
40         }
41     }
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#adjustOffsets(org.eclipse.jface.text.IDocument)
45      */

46     protected void adjustOffsets(IDocument document) {
47         try {
48             getParser().parse(getInputStream(document), createNodeOffsetHandler(this));
49         } catch (SAXException e) {
50         } catch (IOException e) {
51         }
52     }
53     
54     protected abstract DefaultHandler createNodeOffsetHandler(IModel model);
55         
56     protected abstract DefaultHandler createDocumentHandler(IModel model);
57     
58     private SAXParser getParser() {
59         try {
60             if (fParser == null) {
61                 fParser = SAXParserFactory.newInstance().newSAXParser();
62             }
63         } catch (Exception JavaDoc e) {
64             e.printStackTrace();
65         }
66         return fParser;
67     }
68     
69 }
70
Popular Tags