KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > bundle > ManifestHeader


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.bundle;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.pde.internal.core.bundle.BundleObject;
19 import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
20 import org.eclipse.pde.internal.core.ibundle.IBundle;
21 import org.eclipse.pde.internal.core.ibundle.IBundleModel;
22 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
23 import org.eclipse.pde.internal.core.text.IEditingModel;
24
25 public class ManifestHeader extends BundleObject implements IManifestHeader {
26     private static final long serialVersionUID = 1L;
27     
28     private int fOffset = -1;
29     private int fLength = -1;
30     
31     protected String JavaDoc fName;
32     protected String JavaDoc fValue;
33
34     protected transient IBundle fBundle;
35     protected String JavaDoc fLineDelimiter;
36     
37     public ManifestHeader() {
38     }
39     
40     public ManifestHeader(String JavaDoc name, String JavaDoc value, IBundle bundle, String JavaDoc lineDelimiter) {
41         fName = name;
42         fBundle = bundle;
43         fLineDelimiter = lineDelimiter;
44         processValue(value);
45         setModel(fBundle.getModel());
46     }
47     
48     protected void processValue(String JavaDoc value) {
49         fValue = value;
50     }
51
52     public String JavaDoc getLineLimiter() {
53         return fLineDelimiter;
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setName(java.lang.String)
58      */

59     public void setName(String JavaDoc name) {
60         fName = name;
61     }
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getName()
64      */

65     public String JavaDoc getName() {
66         return fName;
67     }
68     
69     public String JavaDoc getValue() {
70         return fValue;
71     }
72     
73     public void setValue(String JavaDoc value) {
74         String JavaDoc old = fValue;
75         fValue = value;
76         fBundle.getModel().fireModelObjectChanged(this, getName(), old, value);
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setOffset(int)
81      */

82     public void setOffset(int offset) {
83         fOffset = offset;
84     }
85     /* (non-Javadoc)
86      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getOffset()
87      */

88     public int getOffset() {
89         return fOffset;
90     }
91     /* (non-Javadoc)
92      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setLength(int)
93      */

94     public void setLength(int length) {
95         fLength = length;
96     }
97     /* (non-Javadoc)
98      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getLength()
99      */

100     public int getLength() {
101         return fLength;
102     }
103     /* (non-Javadoc)
104      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#write()
105      */

106     public String JavaDoc write() {
107         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(fName);
108         sb.append(": "); //$NON-NLS-1$
109
try {
110             if (fOffset != -1) {
111                 IBundleModel model = fBundle.getModel();
112                 if (model instanceof IEditingModel) {
113                     IDocument doc = ((IEditingModel)model).getDocument();
114                     int line = doc.getLineOfOffset(fOffset);
115                     String JavaDoc text = doc.get(fOffset, doc.getLineLength(line)).trim();
116                     // respect a line break after a ":", if the user had entered it
117
// bug 113098
118
if (text.length() == fName.length() + 1) {
119                         sb.append(fLineDelimiter);
120                         sb.append(" "); //$NON-NLS-1$
121
}
122                 }
123             }
124         } catch (BadLocationException e) {
125         }
126         sb.append(getValue());
127         sb.append(fLineDelimiter);
128         return sb.toString();
129     }
130     /* (non-Javadoc)
131      * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
132      */

133     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
134     }
135     
136     public void setBundle(IBundle bundle) {
137         fBundle = bundle;
138     }
139     
140     public IBundle getBundle() {
141         return fBundle;
142     }
143     
144     public String JavaDoc getKey() {
145         return getName();
146     }
147
148     public void setKey(String JavaDoc key) throws CoreException {
149         setName(key);
150     }
151     
152     protected int getManifestVersion() {
153         return BundlePluginBase.getBundleManifestVersion(fBundle);
154     }
155     
156     public void update() {
157         // TODO
158
// should do something for headers that don't have their own class
159
// (and don't override this method)
160
}
161
162     public void update(boolean notify) {
163     }
164 }
165
166
Popular Tags