KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > plugin > NodeOffsetHandler


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.plugin;
12
13 import org.eclipse.pde.internal.ui.model.*;
14 import org.xml.sax.*;
15
16 public class NodeOffsetHandler extends AbstractPluginDocumentHandler {
17
18     /**
19      * @param model
20      */

21     public NodeOffsetHandler(PluginModelBase model) {
22         super(model);
23     }
24     
25     /* (non-Javadoc)
26      * @see org.eclipse.pde.internal.ui.model.DocumentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
27      */

28     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
29             Attributes attributes) throws SAXException {
30         super.startElement(uri, localName, qName, attributes);
31         IDocumentNode node = (IDocumentNode)fDocumentNodeStack.peek();
32         IDocumentAttribute[] attrs = node.getNodeAttributes();
33         for (int i = 0; i < attrs.length; i++) {
34             //if (attrs[i].getNameOffset() == -1)
35
//node.removeDocumentAttribute(attrs[i]);
36
}
37     }
38     /* (non-Javadoc)
39      * @see org.eclipse.pde.internal.ui.model.plugin.DocumentHandler#getDocumentNode(java.lang.String, org.eclipse.pde.internal.ui.model.IDocumentNode)
40      */

41     protected IDocumentNode getDocumentNode(String JavaDoc name, IDocumentNode parent) {
42         IDocumentNode node = null;
43         if (parent == null) {
44             node = (IDocumentNode)getModel().getPluginBase();
45             node.setOffset(-1);
46             node.setLength(-1);
47         } else {
48             IDocumentNode[] children = parent.getChildNodes();
49             for (int i = 0; i < children.length; i++) {
50                 if (children[i].getOffset() < 0) {
51                     node = children[i];
52                     break;
53                 }
54             }
55         }
56         
57         IDocumentAttribute[] attrs = node.getNodeAttributes();
58         for (int i = 0; i < attrs.length; i++) {
59             attrs[i].setNameOffset(-1);
60             attrs[i].setNameLength(-1);
61             attrs[i].setValueOffset(-1);
62             attrs[i].setValueLength(-1);
63         }
64         
65         for (int i = 0; i < node.getChildNodes().length; i++) {
66             IDocumentNode child = node.getChildAt(i);
67             child.setOffset(-1);
68             child.setLength(-1);
69         }
70         
71         return node;
72     }
73     
74     /* (non-Javadoc)
75      * @see org.eclipse.pde.internal.ui.model.DocumentHandler#appendChildToParent(org.eclipse.pde.internal.ui.model.IDocumentNode, org.eclipse.pde.internal.ui.model.IDocumentNode)
76      */

77     protected void appendChildToParent(IDocumentNode parent, IDocumentNode child) {
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.pde.internal.ui.model.plugin.DocumentHandler#getDocumentAttribute(java.lang.String, java.lang.String, org.eclipse.pde.internal.ui.model.IDocumentNode)
82      */

83     protected IDocumentAttribute getDocumentAttribute(String JavaDoc name,
84             String JavaDoc value, IDocumentNode parent) {
85         return parent.getDocumentAttribute(name);
86     }
87
88 }
89
Popular Tags