Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2006-11-09 19:25:11 +0000
committerCurtis D'Entremont2006-11-09 19:25:11 +0000
commitd8a5f4b7f039fb9781b94b26f7d716d5ccd2c315 (patch)
tree643bd1d0ac96c311f7680d1fc54f3a255e1b8626 /org.eclipse.ui.cheatsheets
parent493bb0871612962a7e466e855eaef8169589a796 (diff)
downloadeclipse.platform.ua-d8a5f4b7f039fb9781b94b26f7d716d5ccd2c315.tar.gz
eclipse.platform.ua-d8a5f4b7f039fb9781b94b26f7d716d5ccd2c315.tar.xz
eclipse.platform.ua-d8a5f4b7f039fb9781b94b26f7d716d5ccd2c315.zip
163558 Dynamic content support for all UA
Diffstat (limited to 'org.eclipse.ui.cheatsheets')
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java18
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java114
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserInput.java10
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/provisional/cheatsheets/IEditableTask.java8
5 files changed, 106 insertions, 46 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java
index cf760c034..df3f8c747 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java
@@ -17,10 +17,12 @@ import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.internal.cheatsheets.composite.parser.ITaskParseStrategy;
import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheet;
import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
+import org.osgi.framework.Bundle;
/**
* A single task within a composite cheatsheet. This class encapsulates the
@@ -167,8 +169,22 @@ public abstract class AbstractTask implements ICompositeCheatSheetTask {
model.stateChanged(this);
}
+ /*
+ * Resolves the given path to a URL. The path can either be fully qualified with
+ * the plugin id, e.g. "/plugin_id/path/file.xml" or relative to the composite cheat
+ * sheet file, e.g. "tasks/task1.xml".
+ */
public URL getInputUrl(String path) throws MalformedURLException {
- return new URL(model.getContentUrl(), path);
+ int index = path.indexOf('/', 1);
+ String bundleName = path.substring(1, index);
+ String relativePath = path.substring(index + 1);
+ Bundle bundle = Platform.getBundle(bundleName);
+ if (bundle != null) {
+ return bundle.getEntry(relativePath);
+ }
+ else {
+ return new URL(model.getContentUrl(), path);
+ }
}
public ICompositeCheatSheet getCompositeCheatSheet() {
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
index fdbe092b0..3d01f14ea 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
@@ -10,23 +10,43 @@
*******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.data;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
-import javax.xml.parsers.*;
-
-import org.eclipse.core.runtime.*;
+import javax.xml.parsers.DocumentBuilder;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.help.internal.dynamic.DocumentNode;
+import org.eclipse.help.internal.dynamic.ExtensionHandler;
+import org.eclipse.help.internal.dynamic.FilterHandler;
+import org.eclipse.help.internal.dynamic.IncludeHandler;
+import org.eclipse.help.internal.dynamic.NodeHandler;
+import org.eclipse.help.internal.dynamic.NodeProcessor;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.cheatsheets.AbstractItemExtensionElement;
-import org.eclipse.ui.internal.cheatsheets.*;
+import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
+import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
+import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.composite.model.CompositeCheatSheetModel;
import org.eclipse.ui.internal.cheatsheets.composite.parser.CompositeCheatSheetParser;
import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags;
import org.eclipse.ui.internal.cheatsheets.composite.parser.IStatusContainer;
-import org.eclipse.ui.internal.cheatsheets.registry.*;
-import org.w3c.dom.*;
-import org.xml.sax.*;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetItemExtensionElement;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
/**
* Parser for the cheatsheet content files.
@@ -44,6 +64,7 @@ public class CheatSheetParser implements IStatusContainer {
private static final String TRUE_STRING = "true"; //$NON-NLS-1$
private DocumentBuilder documentBuilder;
+ private NodeProcessor processor;
private ArrayList itemExtensionContainerList;
// Cheatsheet kinds that can be parsed
@@ -827,8 +848,8 @@ public class CheatSheetParser implements IStatusContainer {
return (AbstractItemExtensionElement[])al.toArray(new AbstractItemExtensionElement[al.size()]);
}
- public ICheatSheet parse(URL url, int cheatSheetKind) {
- return parse(new ParserInput(url), cheatSheetKind);
+ public ICheatSheet parse(URL url, String pluginId, int cheatSheetKind) {
+ return parse(new ParserInput(url, pluginId), cheatSheetKind);
}
public ICheatSheet parse(ParserInput input, int cheatSheetKind) {
@@ -890,6 +911,22 @@ public class CheatSheetParser implements IStatusContainer {
} catch (Exception e) {
}
}
+
+ // process dynamic content, normalize paths
+ if (processor == null) {
+ NodeReader reader = new NodeReader();
+ processor = new NodeProcessor(new NodeHandler[] {
+ new FilterHandler(),
+ new NormalizeHandler(),
+ new IncludeHandler(reader, Platform.getNL()),
+ new ExtensionHandler(reader, Platform.getNL())
+ });
+ }
+ String documentPath = null;
+ if (input.getPluginId() != null) {
+ documentPath = '/' + input.getPluginId() + input.getUrl().getPath();
+ }
+ processor.process(new DocumentNode(document), documentPath);
if ( cheatSheetKind == COMPOSITE_ONLY || (cheatSheetKind == ANY && isComposite(document))) {
CompositeCheatSheetParser compositeParser = new CompositeCheatSheetParser();
@@ -978,36 +1015,39 @@ public class CheatSheetParser implements IStatusContainer {
throw new CheatSheetParserException(Messages.ERROR_PARSING_CHEATSHEET_CONTENTS);
}
-/*
- private String getNormalizedText(String text) {
- int [] spaceCounter = new int[1];
- StringBuffer buf = new StringBuffer();
+ /*
+ * Normalizes composite cheat sheet-relative paths to simple cheat sheets into fully
+ * qualified paths, e.g. for the path "tasks/mySimpleCheatSheet.xml" in composite cheat
+ * sheet "/my.plugin/cheatsheets/myCompositeCheatSheet.xml", this normalizes to
+ * "/my.plugin/cheatsheets/tasks/mySimpleCheatSheet.xml".
+ *
+ * This is necessary because with dynamic content we are pulling in tasks from other
+ * plug-ins and those tasks have relative paths. It also only applies for cheat sheets
+ * located in running plug-ins.
+ */
+ private class NormalizeHandler extends NodeHandler {
- if (text==null) return null;
-
-
- for (int j=0; j<text.length(); j++) {
- char c = text.charAt(j);
- if (c==' ' || c=='\t') {
- // space
- if (++spaceCounter[0] == 1) {
- buf.append(c);
- }
- }
- else if (c=='\n' || c=='\r' || c=='\f') {
- // new line
- if (++spaceCounter[0]==1) {
- buf.append(' ');
+ private static final String ELEMENT_PARAM = "param"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
+ private static final String NAME_PATH = "path"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.internal.dynamic.NodeHandler#handle(org.eclipse.help.Node, java.lang.String)
+ */
+ public short handle(org.eclipse.help.Node node, String id) {
+ if (id != null && ELEMENT_PARAM.equals(node.getNodeName())) {
+ String name = node.getAttribute(ATTRIBUTE_NAME);
+ if (NAME_PATH.equals(name)) {
+ String value = node.getAttribute(ATTRIBUTE_VALUE);
+ if (value != null) {
+ int index = id.lastIndexOf('/');
+ node.setAttribute(ATTRIBUTE_VALUE, id.substring(0, index + 1) + value);
+ }
}
+ return HANDLED_CONTINUE;
}
- else {
- // other characters
- spaceCounter[0]=0;
- buf.append(c);
- }
+ return UNHANDLED;
}
-
- return buf.toString();
}
-*/
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserInput.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserInput.java
index a33831fa3..41f12e279 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserInput.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserInput.java
@@ -22,6 +22,7 @@ import java.net.URL;
public class ParserInput {
private URL url;
private String xml;
+ private String pluginId;
public ParserInput() {
url = null;
@@ -40,9 +41,10 @@ public class ParserInput {
}
}
- public ParserInput(URL url) {
+ public ParserInput(URL url, String pluginId) {
this.url = url;
this.xml = null;
+ this.pluginId = pluginId;
}
public URL getUrl() {
@@ -52,5 +54,9 @@ public class ParserInput {
public String getXml() {
return xml;
}
-
+
+ public String getPluginId() {
+ return pluginId;
+ }
+
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
index daf49e007..972ed91bd 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
@@ -1141,7 +1141,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
} catch (MalformedURLException mue) {
}
}
- parserInput = new ParserInput(contentURL);
+ parserInput = new ParserInput(contentURL, bundle != null ? bundle.getSymbolicName() : null);
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/provisional/cheatsheets/IEditableTask.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/provisional/cheatsheets/IEditableTask.java
index 0640af5d4..8348f5cb3 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/provisional/cheatsheets/IEditableTask.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/provisional/cheatsheets/IEditableTask.java
@@ -31,12 +31,10 @@ public interface IEditableTask extends ICompositeCheatSheetTask {
/**
* Gets a URL which can be used to open the content file for this
- * task if the content file can be specified by a path relative to
- * the content file for the composite cheat sheet which contains it.
- * @param path a relative path
+ * task if the content file is specified by a path.
+ * @param path the path to the content file
* @throws MalformedURLException
- * @return a URL which represents a location relative to the
- * location of the content file for the composite cheat sheet.
+ * @return a URL to the content file
*/
public URL getInputUrl(String path) throws MalformedURLException;

Back to the top