01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.text.bundle;
11:
12: import org.eclipse.osgi.util.ManifestElement;
13: import org.eclipse.pde.internal.core.ICoreConstants;
14: import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
15: import org.eclipse.pde.internal.core.ibundle.IBundle;
16: import org.osgi.framework.BundleException;
17: import org.osgi.framework.Constants;
18:
19: public abstract class BasePackageHeader extends CompositeManifestHeader {
20:
21: private static final long serialVersionUID = 1L;
22:
23: public BasePackageHeader(String name, String value, IBundle bundle,
24: String lineDelimiter) {
25: super (name, value, bundle, lineDelimiter, true);
26: }
27:
28: protected String getVersionAttribute() {
29: int manifestVersion = BundlePluginBase
30: .getBundleManifestVersion(getBundle());
31: return (manifestVersion < 2) ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION
32: : Constants.VERSION_ATTRIBUTE;
33: }
34:
35: public void addPackage(PackageObject object) {
36: addManifestElement(object);
37: }
38:
39: public Object removePackage(PackageObject object) {
40: return removeManifestElement(object);
41: }
42:
43: public boolean hasPackage(String packageName) {
44: return hasElement(packageName);
45: }
46:
47: public Object removePackage(String name) {
48: return removeManifestElement(name);
49: }
50:
51: public boolean renamePackage(String oldName, String newName) {
52: if (hasPackage(oldName)) {
53: PackageObject object = (PackageObject) removeManifestElement(oldName);
54: object.setName(newName);
55: addManifestElement(object);
56: return true;
57: }
58: return false;
59: }
60:
61: protected void processValue(String value) {
62: try {
63: ManifestElement[] elements = ManifestElement.parseHeader(
64: fName, value);
65: for (int i = 0; i < elements.length; i++) {
66: if (elements[i].getValueComponents().length > 1) {
67: // if package element has multiple value components, create a new Element to represent each value (bug 160233)
68: String[] values = elements[i].getValueComponents();
69: for (int j = 0; j < values.length; j++) {
70: PDEManifestElement elem = createElement(elements[i]);
71: elem
72: .setValueComponents(new String[] { values[j] });
73: addManifestElement(elem, false);
74: }
75: } else {
76: addManifestElement(createElement(elements[i]),
77: false);
78: }
79: }
80: } catch (BundleException e) {
81: }
82: }
83:
84: }
|