KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > XMLEditingModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.text;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
17 import javax.xml.parsers.ParserConfigurationException JavaDoc;
18
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.pde.core.IModel;
21 import org.eclipse.pde.internal.core.util.SAXParserWrapper;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.DefaultHandler JavaDoc;
24
25 public abstract class XMLEditingModel extends AbstractEditingModel {
26     
27     public XMLEditingModel(IDocument document, boolean isReconciling) {
28         super(document, isReconciling);
29     }
30     
31     /* (non-Javadoc)
32      * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
33      */

34     public void load(InputStream JavaDoc source, boolean outOfSync) {
35         try {
36             fLoaded = true;
37             SAXParserWrapper parser = new SAXParserWrapper();
38             parser.parse(source, createDocumentHandler(this, true));
39         } catch (SAXException JavaDoc e) {
40             fLoaded = false;
41         } catch (IOException JavaDoc e) {
42         } catch (ParserConfigurationException JavaDoc e) {
43         } catch (FactoryConfigurationError JavaDoc e) {
44         }
45     }
46     
47     protected abstract DefaultHandler JavaDoc createDocumentHandler(IModel model, boolean reconciling);
48     
49     public void adjustOffsets(IDocument document) {
50         try {
51             SAXParserWrapper parser = new SAXParserWrapper();
52             parser.parse(getInputStream(document), createDocumentHandler(this, false));
53         } catch (SAXException JavaDoc e) {
54         } catch (IOException JavaDoc e) {
55         } catch (ParserConfigurationException JavaDoc e) {
56         } catch (FactoryConfigurationError JavaDoc e) {
57         }
58     }
59 }
60
Popular Tags