1 11 package org.eclipse.pde.internal.core.text.bundle; 12 13 import java.io.PrintWriter ; 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 fName; 32 protected String fValue; 33 34 protected transient IBundle fBundle; 35 protected String fLineDelimiter; 36 37 public ManifestHeader() { 38 } 39 40 public ManifestHeader(String name, String value, IBundle bundle, String lineDelimiter) { 41 fName = name; 42 fBundle = bundle; 43 fLineDelimiter = lineDelimiter; 44 processValue(value); 45 setModel(fBundle.getModel()); 46 } 47 48 protected void processValue(String value) { 49 fValue = value; 50 } 51 52 public String getLineLimiter() { 53 return fLineDelimiter; 54 } 55 56 59 public void setName(String name) { 60 fName = name; 61 } 62 65 public String getName() { 66 return fName; 67 } 68 69 public String getValue() { 70 return fValue; 71 } 72 73 public void setValue(String value) { 74 String old = fValue; 75 fValue = value; 76 fBundle.getModel().fireModelObjectChanged(this, getName(), old, value); 77 } 78 79 82 public void setOffset(int offset) { 83 fOffset = offset; 84 } 85 88 public int getOffset() { 89 return fOffset; 90 } 91 94 public void setLength(int length) { 95 fLength = length; 96 } 97 100 public int getLength() { 101 return fLength; 102 } 103 106 public String write() { 107 StringBuffer sb = new StringBuffer (fName); 108 sb.append(": "); 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 text = doc.get(fOffset, doc.getLineLength(line)).trim(); 116 if (text.length() == fName.length() + 1) { 119 sb.append(fLineDelimiter); 120 sb.append(" "); } 122 } 123 } 124 } catch (BadLocationException e) { 125 } 126 sb.append(getValue()); 127 sb.append(fLineDelimiter); 128 return sb.toString(); 129 } 130 133 public void write(String indent, PrintWriter 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 getKey() { 145 return getName(); 146 } 147 148 public void setKey(String key) throws CoreException { 149 setName(key); 150 } 151 152 protected int getManifestVersion() { 153 return BundlePluginBase.getBundleManifestVersion(fBundle); 154 } 155 156 public void update() { 157 } 161 162 public void update(boolean notify) { 163 } 164 } 165 166 | Popular Tags |