KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > 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.core.text.plugin;
12
13 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
14 import org.eclipse.pde.internal.core.text.IDocumentNode;
15 import org.xml.sax.Attributes JavaDoc;
16 import org.xml.sax.SAXException JavaDoc;
17
18 public class NodeOffsetHandler extends AbstractPluginDocumentHandler {
19
20     /**
21      * @param model
22      */

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

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

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

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

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