1 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 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 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 e) { 64 e.printStackTrace(); 65 } 66 return fParser; 67 } 68 69 } 70 | Popular Tags |