Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2007-01-03 23:49:52 +0000
committerChris Goldthorpe2007-01-03 23:49:52 +0000
commitebf25f1f30a0ebf3ad22c628787810255a2a2d1e (patch)
treef56c6eb4e7f554fffc42796a9161feb78dea9766 /org.eclipse.ui.cheatsheets
parent4d94b5dd213cd2cd2598cd43aebbfc42f6887a74 (diff)
downloadeclipse.platform.ua-ebf25f1f30a0ebf3ad22c628787810255a2a2d1e.tar.gz
eclipse.platform.ua-ebf25f1f30a0ebf3ad22c628787810255a2a2d1e.tar.xz
eclipse.platform.ua-ebf25f1f30a0ebf3ad22c628787810255a2a2d1e.zip
Extended markup parser to handle attributes in tags.
Diffstat (limited to 'org.eclipse.ui.cheatsheets')
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/MarkupParser.java42
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/DescriptionPanel.java35
2 files changed, 47 insertions, 30 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/MarkupParser.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/MarkupParser.java
index 25715fd5a..fd3ce0c2b 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/MarkupParser.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/MarkupParser.java
@@ -11,6 +11,7 @@
package org.eclipse.ui.internal.cheatsheets.composite.parser;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -30,6 +31,21 @@ public class MarkupParser {
} else if (childNode.getNodeType() == Node.ELEMENT_NODE) {
text.append('<');
text.append(childNode.getNodeName());
+ // Add the attributes
+ NamedNodeMap attributes = childNode.getAttributes();
+ if (attributes != null) {
+ for (int x = 0; x < attributes.getLength(); x++) {
+ Node attribute = attributes.item(x);
+ String attributeName = attribute.getNodeName();
+ if (attributeName == null)
+ continue;
+ text.append(' ');
+ text.append(attributeName);
+ text.append(" = \""); //$NON-NLS-1$
+ text.append(attribute.getNodeValue());
+ text.append('"');
+ }
+ }
text.append('>');
text.append(parseMarkup(childNode));
text.append("</"); //$NON-NLS-1$
@@ -71,5 +87,31 @@ public class MarkupParser {
}
return null;
}
+
+ /*
+ * Add paragraph tags if not already present
+ */
+ public static String createParagraph(String text, String imageTag) {
+ String result = ""; //$NON-NLS-1$
+ String trimmed = text.trim();
+ boolean addParagraphTags = trimmed.length() < 3 || trimmed.charAt(0)!='<' ||
+ (trimmed.charAt(1)!='p' && trimmed.charAt(1) != 'l');
+ if (addParagraphTags) {
+ result += "<p>"; //$NON-NLS-1$
+ }
+
+ if (imageTag != null) {
+ result += "<img href=\""; //$NON-NLS-1$
+ result += imageTag;
+ result += "\"/> "; //$NON-NLS-1$
+ }
+
+ result += trimmed;
+
+ if (addParagraphTags) {
+ result += "</p>"; //$NON-NLS-1$
+ }
+ return result;
+ }
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/DescriptionPanel.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/DescriptionPanel.java
index 3b9830add..71421d85c 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/DescriptionPanel.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/DescriptionPanel.java
@@ -123,7 +123,7 @@ public class DescriptionPanel {
upperMessage.append("<p><span color=\"title\" font=\"header\">"); //$NON-NLS-1$
upperMessage.append(MarkupParser.escapeText(task.getName()));
upperMessage.append("</span></p>"); //$NON-NLS-1$
- upperMessage.append(createParagraph(task.getDescription(), null));
+ upperMessage.append(MarkupParser.createParagraph(task.getDescription(), null));
upperMessage.append("</form>"); //$NON-NLS-1$
upperText.setText(upperMessage.toString(), true, false);
@@ -135,22 +135,22 @@ public class DescriptionPanel {
boolean isSkippable = ((AbstractTask)task).isSkippable();
if (task.getState() == ICompositeCheatSheetTask.COMPLETED) {
- buf.append(createParagraph(task.getCompletionMessage(), null));
+ buf.append(MarkupParser.createParagraph(task.getCompletionMessage(), null));
isSkippable = false;
} else if (task.getState() == ICompositeCheatSheetTask.SKIPPED) {
- buf.append(createParagraph(Messages.THIS_TASK_SKIPPED, INFORMATION_IMAGE));
+ buf.append(MarkupParser.createParagraph(Messages.THIS_TASK_SKIPPED, INFORMATION_IMAGE));
isSkippable = false;
} else if (TaskStateUtilities.findSkippedAncestor(task) != null) {
ICompositeCheatSheetTask skipped = TaskStateUtilities.findSkippedAncestor(task);
String skipParentMsg = NLS.bind(Messages.PARENT_SKIPPED,
(new Object[] {MarkupParser.escapeText((skipped.getName()))}));
- buf.append(createParagraph(skipParentMsg, WARNING_IMAGE));
+ buf.append(MarkupParser.createParagraph(skipParentMsg, WARNING_IMAGE));
isSkippable = false;
} else if (TaskStateUtilities.findCompletedAncestor(task) != null) {
ICompositeCheatSheetTask completed = TaskStateUtilities.findCompletedAncestor(task);
String completedParentMsg = NLS.bind(Messages.PARENT_COMPLETED,
(new Object[] {MarkupParser.escapeText(completed.getName())}));
- buf.append(createParagraph(completedParentMsg, WARNING_IMAGE));
+ buf.append(MarkupParser.createParagraph(completedParentMsg, WARNING_IMAGE));
isSkippable = false;
} else if (!task.requiredTasksCompleted()) {
isBlocked = true;
@@ -194,31 +194,6 @@ public class DescriptionPanel {
form.reflow(true);
}
- /*
- * Add paragraph tags if not already present
- */
- private String createParagraph(String text, String imageTag) {
- String result = ""; //$NON-NLS-1$
- String trimmed = text.trim();
- boolean addParagraphTags = trimmed.length() < 3 || trimmed.charAt(0)!='<' || trimmed.charAt(1)!='p';
- if (addParagraphTags) {
- result += "<p>"; //$NON-NLS-1$
- }
-
- if (imageTag != null) {
- result += "<img href=\""; //$NON-NLS-1$
- result += imageTag;
- result += "\"/> "; //$NON-NLS-1$
- }
-
- result += trimmed;
-
- if (addParagraphTags) {
- result += "</p>"; //$NON-NLS-1$
- }
- return result;
- }
-
private void showBlockingTasks(String message, final ICompositeCheatSheetTask task, StringBuffer buf) {
buf.append("<p/>"); //$NON-NLS-1$
buf.append("<p>"); //$NON-NLS-1$

Back to the top