From 6de0af4b68c47ccf0f0fbc8788b26c76359450e2 Mon Sep 17 00:00:00 2001 From: mkersten Date: Mon, 17 Jul 2006 03:33:10 +0000 Subject: Progress on: 150668: exceptions when Active Hierarchy is restored on launch https://bugs.eclipse.org/bugs/show_bug.cgi?id=150668 --- .../bugzilla/core/BugzillaReportSubmitForm.java | 6 +- .../bugzilla/core/BugzillaServerFacade.java | 6 +- .../internal/bugzilla/core/KeywordParser.java | 6 +- .../bugzilla/core/SaxBugReportContentHandler.java | 2 +- .../mylyn/internal/bugzilla/core/XmlCleaner.java | 6 +- org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF | 6 +- .../internal/tasks/core/HtmlStreamTokenizer.java | 1105 ++++++++++++++++++++ .../eclipse/mylyn/internal/tasks/core/HtmlTag.java | 362 +++++++ .../tasks/core/SaxRepositoriesContentHandler.java | 62 ++ .../internal/tasks/core/SaxRepositoriesWriter.java | 180 ++++ .../tasks/core/TaskRepositoriesExternalizer.java | 73 ++ .../mylyn/tasks/core/util/HtmlStreamTokenizer.java | 1105 -------------------- .../org/eclipse/mylyn/tasks/core/util/HtmlTag.java | 362 ------- .../core/util/SaxRepositoriesContentHandler.java | 62 -- .../tasks/core/util/SaxRepositoriesWriter.java | 180 ---- .../core/util/TaskRepositoriesExternalizer.java | 73 -- org.eclipse.mylyn.tasks.tests/plugin.xml | 4 +- .../tasks/tests/RepositorySettingsPageTest.java | 2 +- .../tests/RepositoryTaskSynchronizationTest.java | 6 +- .../mylyn/tasks/tests/TaskDataExportTest.java | 2 +- .../mylyn/tasks/tests/TaskDataImportTest.java | 2 +- .../mylyn/tasks/tests/TaskListManagerTest.java | 8 +- .../mylyn/tasks/tests/TaskListStandaloneTest.java | 2 +- .../tests/TaskRepositoriesExternalizerTest.java | 2 +- .../tasks/tests/TaskRepositoryManagerTest.java | 2 +- .../tests/connector/MockAttributeFactory.java | 45 + .../mylyn/tasks/tests/connector/MockQueryHit.java | 57 + .../tests/connector/MockRepositoryConnector.java | 138 +++ .../connector/MockRepositoryExternalizer.java | 60 ++ .../tasks/tests/connector/MockRepositoryQuery.java | 31 + .../tasks/tests/connector/MockRepositoryTask.java | 40 + .../tests/mockconnector/MockAttributeFactory.java | 45 - .../tasks/tests/mockconnector/MockQueryHit.java | 57 - .../mockconnector/MockRepositoryConnector.java | 138 --- .../mockconnector/MockRepositoryExternalizer.java | 60 -- .../tests/mockconnector/MockRepositoryQuery.java | 31 - .../tests/mockconnector/MockRepositoryTask.java | 40 - 37 files changed, 2185 insertions(+), 2183 deletions(-) create mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlStreamTokenizer.java create mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlTag.java create mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesContentHandler.java create mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesWriter.java create mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java delete mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlStreamTokenizer.java delete mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlTag.java delete mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesContentHandler.java delete mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesWriter.java delete mode 100644 org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/TaskRepositoriesExternalizer.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryQuery.java create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryTask.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockAttributeFactory.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockQueryHit.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryConnector.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryExternalizer.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryQuery.java delete mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryTask.java diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java index 72c77cd82..d014b5d43 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java @@ -36,13 +36,13 @@ import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; +import org.eclipse.mylar.internal.tasks.core.HtmlTag; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token; import org.eclipse.mylar.tasks.core.LocalAttachment; import org.eclipse.mylar.tasks.core.RepositoryOperation; import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer; -import org.eclipse.mylar.tasks.core.util.HtmlTag; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer.Token; /** * diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java index bdba1762d..5034304de 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java @@ -33,12 +33,12 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_OPERATION; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_REPORT_STATUS; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_RESOLUTION; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; +import org.eclipse.mylar.internal.tasks.core.HtmlTag; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token; import org.eclipse.mylar.tasks.core.RepositoryOperation; import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer; -import org.eclipse.mylar.tasks.core.util.HtmlTag; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer.Token; /** * @author Mik Kersten diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/KeywordParser.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/KeywordParser.java index a119b48e2..3abe0f225 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/KeywordParser.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/KeywordParser.java @@ -18,9 +18,9 @@ import java.util.List; import javax.security.auth.login.LoginException; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer; -import org.eclipse.mylar.tasks.core.util.HtmlTag; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer.Token; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; +import org.eclipse.mylar.internal.tasks.core.HtmlTag; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token; /** * Parses Bugzilla keywords page to determine keywords valid in this diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java index 43298e217..08c13a707 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java @@ -14,12 +14,12 @@ package org.eclipse.mylar.internal.bugzilla.core; import java.util.HashMap; import java.util.Map; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; import org.eclipse.mylar.tasks.core.AbstractAttributeFactory; import org.eclipse.mylar.tasks.core.TaskComment; import org.eclipse.mylar.tasks.core.RepositoryAttachment; import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/XmlCleaner.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/XmlCleaner.java index 6583efb00..20e3d531b 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/XmlCleaner.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/XmlCleaner.java @@ -15,9 +15,9 @@ import java.io.IOException; import java.io.Reader; import java.text.ParseException; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer; -import org.eclipse.mylar.tasks.core.util.HtmlTag; -import org.eclipse.mylar.tasks.core.util.HtmlStreamTokenizer.Token; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; +import org.eclipse.mylar.internal.tasks.core.HtmlTag; +import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token; /** * This is in place to escape & characters within the resource and rdf:about diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF index 0b085a2fd..a29790f09 100644 --- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF @@ -9,5 +9,7 @@ Bundle-Vendor: Eclipse.org Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylar.context.core -Export-Package: org.eclipse.mylar.tasks.core, - org.eclipse.mylar.tasks.core.util +Export-Package: org.eclipse.mylar.internal.tasks.core, + org.eclipse.mylar.tasks.core +Export-Package: org.eclipse.mylar.internal.tasks.core, + org.eclipse.mylar.tasks.core diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlStreamTokenizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlStreamTokenizer.java new file mode 100644 index 000000000..91c6d8439 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlStreamTokenizer.java @@ -0,0 +1,1105 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.internal.tasks.core; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.net.URL; +import java.text.ParseException; +import java.util.HashMap; + +public class HtmlStreamTokenizer { + + /** parser state */ + private State state; + + /** reader from which to parse the text */ + private BufferedReader in; + + /** base URL for resolving relative URLs */ + private URL base; + + /** buffer holding the text of the current token */ + private StringBuffer textBuffer; + + /** buffer holding whitespace preceding the current token */ + private StringBuffer whitespaceBuffer; + + /** + * holds a token that was read and then put back in the queue to be returned + * again on nextToken call + */ + private Token pushbackToken; + + /** + * holds a character that was read and then determined not to be part of the + * current token + */ + private int pushbackChar; + + /** current quote delimiter (single or double) */ + private int quoteChar; + + /** + * Constructor. + * + * @param in + * reader for the HTML document to tokenize + * @param base + * URL for resolving relative URLs + */ + public HtmlStreamTokenizer(Reader in, URL base) { + textBuffer = new StringBuffer(); + whitespaceBuffer = new StringBuffer(); + pushbackChar = 0; + state = State.TEXT; + this.in = new BufferedReader(in); + this.base = base; + } + + /** + * Returns the next token from the stream. + */ + public Token nextToken() throws IOException, ParseException { + if (pushbackToken != null) { + Token token = pushbackToken; + pushbackToken = null; + return token; + } + + int closingComment = 0; + + textBuffer.setLength(0); + whitespaceBuffer.setLength(0); + do { + int ch; + if (pushbackChar != 0) { + ch = pushbackChar; + pushbackChar = 0; + } else { + ch = in.read(); + } + if (ch < 0) { + State oldState = state; + state = State.EOF; + if (textBuffer.length() > 0 && oldState == State.TEXT) { + return new Token(textBuffer, whitespaceBuffer, false); + } else { + return new Token(); + } + } + if (state == State.TEXT) { + if (ch == '<') { + state = State.TAG; + if (textBuffer.length() > 0) + return new Token(textBuffer, whitespaceBuffer, false); + } else if (Character.isWhitespace((char) ch)) { + pushbackChar = ch; + state = State.WS; + if (textBuffer.length() > 0) + return new Token(textBuffer, whitespaceBuffer, false); + } else { + textBuffer.append((char) ch); + } + } else if (state == State.WS) { + if (!Character.isWhitespace((char) ch)) { + pushbackChar = ch; + state = State.TEXT; + } else { + whitespaceBuffer.append((char) ch); + } + } else if (state == State.TAG) { + if (ch == '>') { + state = State.TEXT; + HtmlTag tag = new HtmlTag(base); + parseTag(textBuffer.toString(), tag); + return new Token(tag, whitespaceBuffer); + } + if (ch == '<' && textBuffer.length() == 0) { + textBuffer.append("<<"); + state = State.TEXT; + } else if (ch == '-' && textBuffer.length() == 2 && textBuffer.charAt(1) == '-' + && textBuffer.charAt(0) == '!') { + textBuffer.setLength(0); + state = State.COMMENT; + } else if (ch == '\'' || ch == '"') { + quoteChar = ch; + textBuffer.append((char) ch); + state = State.TAG_QUOTE; + } else { + textBuffer.append((char) ch); + } + } else if (state == State.TAG_QUOTE) { + if (ch == '>') { + pushbackChar = ch; + state = State.TAG; + } else { + textBuffer.append((char) ch); + if (ch == quoteChar) + state = State.TAG; + } + } else if (state == State.COMMENT) { + if (ch == '>' && closingComment >= 2) { + textBuffer.setLength(textBuffer.length() - 2); + closingComment = 0; + state = State.TEXT; + return new Token(textBuffer, whitespaceBuffer, true); + } + if (ch == '-') { + closingComment++; + } else { + closingComment = 0; + } + textBuffer.append((char) ch); + } + } while (true); + } + + /** + * Pushes the token back into the queue, to be returned by the subsequent + * call to nextToken + */ + public void pushback(Token token) { + pushbackToken = token; + } + + /** + * Parses an HTML tag out of a string of characters. + */ + private static void parseTag(String s, HtmlTag tag) throws ParseException { + + int i = 0; + for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + if (i == s.length()) + throw new ParseException("parse empty tag", 0); + + int start = i; + for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + tag.setTagName(s.substring(start, i)); + + for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + if (i == s.length()) { + return; + } else { + parseAttributes(tag, s, i); + return; + } + } + + /** + * parses HTML tag attributes from a buffer and sets them in an HtmlTag + */ + private static void parseAttributes(HtmlTag tag, String s, int i) throws ParseException { + while (i < s.length()) { + // skip whitespace + while (i < s.length() && Character.isWhitespace(s.charAt(i))) + i++; + + if (i == s.length()) + return; + + // read the attribute name -- the rule might be looser than the RFC + // specifies: + // everything up to a space or an equal sign is included + int start = i; + for (; i < s.length() && !Character.isWhitespace(s.charAt(i)) && s.charAt(i) != '='; i++) { + // just move forward + } + String attributeName = s.substring(start, i).toLowerCase(); + + if(attributeName.equals("/")) { + tag.setSelfTerminating(true); + continue; + } + + for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + if (i == s.length() || s.charAt(i) != '=') { + // no attribute value + tag.setAttribute(attributeName, ""); + continue; + } + + // skip whitespace to the start of attribute value + for (i = i + 1; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + if (i == s.length()) + return; + + // read the attribute value -- the rule for unquoted attribute value + // is + // looser than the one in Conolly's W3C 1996 lexical analyzer draft: + // everything + // is included up to the next space + String attributeValue; + if (s.charAt(i) == '"') { + start = ++i; + for (; i < s.length() && s.charAt(i) != '"'; i++) { + // just move forward + } + if (i == s.length()) + return; // shouldn't happen if input returned by nextToken + attributeValue = unescape(s.substring(start, i)); + i++; + } else if (s.charAt(i) == '\'') { + start = ++i; + for (; i < s.length() && s.charAt(i) != '\''; i++) { + // just move forward + } + if (i == s.length()) + return; // shouldn't happen if input returned by nextToken + attributeValue = unescape(s.substring(start, i)); + i++; + } else { + start = i; + for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) { + // just move forward + } + attributeValue = s.substring(start, i); + } + tag.setAttribute(attributeName, attributeValue); + } + } + + /** + * Returns a string with HTML escapes changed into their corresponding + * characters. + */ + public static String unescape(String s) { + if (s.indexOf('&') == -1) { + return s; + } else { + StringBuffer sb = new StringBuffer(s); + unescape(sb); + return sb.toString(); + } + } + + /** + * Replaces (in-place) HTML escapes in a StringBuffer with their + * corresponding characters. + */ + public static StringBuffer unescape(StringBuffer sb) { + int i = 0; // index into the unprocessed section of the buffer + int j = 0; // index into the processed section of the buffer + + while (i < sb.length()) { + char ch = sb.charAt(i); + if (ch == '&') { + int start = i; + String escape = null; + for (i = i + 1; i < sb.length(); i++) { + ch = sb.charAt(i); + if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == (start + 1))) { + escape = sb.substring(start + 1, i); + break; + } + } + if (i == sb.length() && i != (start + 1)) { + escape = sb.substring(start + 1); + } + if (escape != null) { + Character character = parseReference(escape); + if (character != null) { + ch = character.charValue(); + } else { + // not an HTML escape; rewind + i = start; + ch = '&'; + } + } + } + sb.setCharAt(j, ch); + i++; + j++; + } + + sb.setLength(j); + return sb; + } + + /** + * Parses HTML character and entity references and returns the corresponding + * character. + */ + private static Character parseReference(String s) { + if (s.length() == 0) + return null; + + if (s.charAt(0) == '#') { + // character reference + if (s.length() == 1) + return null; + + try { + int value; + if (s.charAt(1) == 'x') { + // Hex reference + value = Integer.parseInt(s.substring(2), 16); + } else { + // Decimal reference + value = Integer.parseInt(s.substring(1)); + } + return new Character((char) value); + } catch (NumberFormatException e) { + return null; + } + } else { + return entities.get(s); + } + } + + /** + * Class for current token. + */ + public static class Token { + public static final Type EOF = new Type(); + + public static final Type TEXT = new Type(); + + public static final Type TAG = new Type(); + + public static final Type COMMENT = new Type(); + + /** token's type */ + private Type type; + + /** token's value */ + private Object value; + + /** whitespace preceding the token */ + private StringBuffer whitespace; + + /** + * Constructor for the EOF token. + */ + protected Token() { + type = EOF; + value = null; + whitespace = null; + } + + /** + * Constructor for the HTML tag tokens. + */ + protected Token(HtmlTag tag, StringBuffer whitespace) { + type = TAG; + value = tag; + this.whitespace = whitespace; + } + + /** + * Constructor for regular text and comments. + */ + protected Token(StringBuffer text, StringBuffer whitespace, boolean comment) { + if (comment) { + type = COMMENT; + } else { + type = TEXT; + } + this.value = text; + this.whitespace = whitespace; + } + + /** + * Returns the token's type. + */ + public Type getType() { + return type; + } + + /** + * Returns the whitespace preceding the token. + */ + public StringBuffer getWhitespace() { + return whitespace; + } + + /** + * Returns the token's value. This is an HtmlTag for tokens of type + * TAG and a StringBuffer for tokens of type + * TEXT and COMMENT. For tokens of type + * EOF, the value is null. + */ + public Object getValue() { + return value; + } + + /** + * Returns the string representation of the token, including the + * preceding whitespace. + */ + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + if (whitespace != null) { + sb.append(whitespace); + } + if (value != null) { + if (type == TAG) { + // sb.append('<'); + } else if (type == COMMENT) { + sb.append(""); + } + + } + return sb.toString(); + } + + /** + * Private enum class for token type. + */ + private static class Type { + private Type() { + // don't need to do anything + } + } + } + + /** + * Enum class for parser state. + */ + private static class State { + static final State EOF = new State(); + + static final State COMMENT = new State(); + + static final State TEXT = new State(); + + static final State TAG = new State(); + + static final State WS = new State(); + + static final State TAG_QUOTE = new State(); + + private State() { + // don't need to do anything + } + } + + /** names and values of HTML entity references */ + private static HashMap entities; + + /* + * Based on ISO 8879. + * + * Portions (c) International Organization for Standardization 1986 Permission + * to copy in any form is granted for use with conforming SGML systems and + * applications as defined in ISO 8879, provided this notice is included in + * all copies. + * + */ + static { + entities = new HashMap(); + entities.put(new String("nbsp"), new Character('\240')); // no-break + // space = + // non-breaking + // space + entities.put(new String("iexcl"), new Character('\241')); // inverted + // exclamation + // mark + entities.put(new String("cent"), new Character('\242')); // cent sign + entities.put(new String("pound"), new Character('\243')); // pound + // sign + entities.put(new String("curren"), new Character('\244')); // currency + // sign + entities.put(new String("yen"), new Character('\245')); // yen sign = + // yuan sign + entities.put(new String("brvbar"), new Character('\246')); // broken + // bar = + // broken + // vertical + // bar + entities.put(new String("sect"), new Character('\247')); // section + // sign + entities.put(new String("uml"), new Character('\250')); // diaeresis = + // spacing + // diaeresis + entities.put(new String("copy"), new Character('\251')); // copyright + // sign + entities.put(new String("ordf"), new Character('\252')); // feminine + // ordinal + // indicator + entities.put(new String("laquo"), new Character('\253')); // left-pointing + // double + // angle + // quotation + // mark = + // left + // pointing + // guillemet + entities.put(new String("not"), new Character('\254')); // not sign + entities.put(new String("shy"), new Character('\255')); // soft hyphen = + // discretionary + // hyphen + entities.put(new String("reg"), new Character('\256')); // registered + // sign = + // registered + // trade mark + // sign + entities.put(new String("macr"), new Character('\257')); // macron = + // spacing + // macron = + // overline + // = APL + // overbar + entities.put(new String("deg"), new Character('\260')); // degree sign + entities.put(new String("plusmn"), new Character('\261')); // plus-minus + // sign = + // plus-or-minus + // sign + entities.put(new String("sup2"), new Character('\262')); // superscript + // two = + // superscript + // digit two + // = squared + entities.put(new String("sup3"), new Character('\263')); // superscript + // three = + // superscript + // digit + // three = + // cubed + entities.put(new String("acute"), new Character('\264')); // acute + // accent = + // spacing + // acute + entities.put(new String("micro"), new Character('\265')); // micro + // sign + entities.put(new String("para"), new Character('\266')); // pilcrow + // sign = + // paragraph + // sign + entities.put(new String("middot"), new Character('\267')); // middle + // dot = + // Georgian + // comma = + // Greek + // middle + // dot + entities.put(new String("cedil"), new Character('\270')); // cedilla = + // spacing + // cedilla + entities.put(new String("sup1"), new Character('\271')); // superscript + // one = + // superscript + // digit one + entities.put(new String("ordm"), new Character('\272')); // masculine + // ordinal + // indicator + entities.put(new String("raquo"), new Character('\273')); // right-pointing + // double + // angle + // quotation + // mark = + // right + // pointing + // guillemet + entities.put(new String("frac14"), new Character('\274')); // vulgar + // fraction + // one + // quarter = + // fraction + // one + // quarter + entities.put(new String("frac12"), new Character('\275')); // vulgar + // fraction + // one half + // = + // fraction + // one half + entities.put(new String("frac34"), new Character('\276')); // vulgar + // fraction + // three + // quarters + // = + // fraction + // three + // quarters + entities.put(new String("iquest"), new Character('\277')); // inverted + // question + // mark = + // turned + // question + // mark + entities.put(new String("Agrave"), new Character('\300')); // latin + // capital + // letter A + // with + // grave = + // latin + // capital + // letter A + // grave + entities.put(new String("Aacute"), new Character('\301')); // latin + // capital + // letter A + // with + // acute + entities.put(new String("Acirc"), new Character('\302')); // latin + // capital + // letter A + // with + // circumflex + entities.put(new String("Atilde"), new Character('\303')); // latin + // capital + // letter A + // with + // tilde + entities.put(new String("Auml"), new Character('\304')); // latin + // capital + // letter A + // with + // diaeresis + entities.put(new String("Aring"), new Character('\305')); // latin + // capital + // letter A + // with ring + // above = + // latin + // capital + // letter A + // ring + entities.put(new String("AElig"), new Character('\306')); // latin + // capital + // letter AE + // = latin + // capital + // ligature + // AE + entities.put(new String("Ccedil"), new Character('\307')); // latin + // capital + // letter C + // with + // cedilla + entities.put(new String("Egrave"), new Character('\310')); // latin + // capital + // letter E + // with + // grave + entities.put(new String("Eacute"), new Character('\311')); // latin + // capital + // letter E + // with + // acute + entities.put(new String("Ecirc"), new Character('\312')); // latin + // capital + // letter E + // with + // circumflex + entities.put(new String("Euml"), new Character('\313')); // latin + // capital + // letter E + // with + // diaeresis + entities.put(new String("Igrave"), new Character('\314')); // latin + // capital + // letter I + // with + // grave + entities.put(new String("Iacute"), new Character('\315')); // latin + // capital + // letter I + // with + // acute + entities.put(new String("Icirc"), new Character('\316')); // latin + // capital + // letter I + // with + // circumflex + entities.put(new String("Iuml"), new Character('\317')); // latin + // capital + // letter I + // with + // diaeresis + entities.put(new String("ETH"), new Character('\320')); // latin capital + // letter ETH + entities.put(new String("Ntilde"), new Character('\321')); // latin + // capital + // letter N + // with + // tilde + entities.put(new String("Ograve"), new Character('\322')); // latin + // capital + // letter O + // with + // grave + entities.put(new String("Oacute"), new Character('\323')); // latin + // capital + // letter O + // with + // acute + entities.put(new String("Ocirc"), new Character('\324')); // latin + // capital + // letter O + // with + // circumflex + entities.put(new String("Otilde"), new Character('\325')); // latin + // capital + // letter O + // with + // tilde + entities.put(new String("Ouml"), new Character('\326')); // latin + // capital + // letter O + // with + // diaeresis + entities.put(new String("times"), new Character('\327')); // multiplication + // sign + entities.put(new String("Oslash"), new Character('\330')); // latin + // capital + // letter O + // with + // stroke = + // latin + // capital + // letter O + // slash + entities.put(new String("Ugrave"), new Character('\331')); // latin + // capital + // letter U + // with + // grave + entities.put(new String("Uacute"), new Character('\332')); // latin + // capital + // letter U + // with + // acute + entities.put(new String("Ucirc"), new Character('\333')); // latin + // capital + // letter U + // with + // circumflex + entities.put(new String("Uuml"), new Character('\334')); // latin + // capital + // letter U + // with + // diaeresis + entities.put(new String("Yacute"), new Character('\335')); // latin + // capital + // letter Y + // with + // acute + entities.put(new String("THORN"), new Character('\336')); // latin + // capital + // letter + // THORN + entities.put(new String("szlig"), new Character('\337')); // latin + // small + // letter + // sharp s = + // ess-zed + entities.put(new String("agrave"), new Character('\340')); // latin + // small + // letter a + // with + // grave = + // latin + // small + // letter a + // grave + entities.put(new String("aacute"), new Character('\341')); // latin + // small + // letter a + // with + // acute + entities.put(new String("acirc"), new Character('\342')); // latin + // small + // letter a + // with + // circumflex + entities.put(new String("atilde"), new Character('\343')); // latin + // small + // letter a + // with + // tilde + entities.put(new String("auml"), new Character('\344')); // latin + // small + // letter a + // with + // diaeresis + entities.put(new String("aring"), new Character('\345')); // latin + // small + // letter a + // with ring + // above = + // latin + // small + // letter a + // ring + entities.put(new String("aelig"), new Character('\346')); // latin + // small + // letter ae + // = latin + // small + // ligature + // ae + entities.put(new String("ccedil"), new Character('\347')); // latin + // small + // letter c + // with + // cedilla + entities.put(new String("egrave"), new Character('\350')); // latin + // small + // letter e + // with + // grave + entities.put(new String("eacute"), new Character('\351')); // latin + // small + // letter e + // with + // acute + entities.put(new String("ecirc"), new Character('\352')); // latin + // small + // letter e + // with + // circumflex + entities.put(new String("euml"), new Character('\353')); // latin + // small + // letter e + // with + // diaeresis + entities.put(new String("igrave"), new Character('\354')); // latin + // small + // letter i + // with + // grave + entities.put(new String("iacute"), new Character('\355')); // latin + // small + // letter i + // with + // acute + entities.put(new String("icirc"), new Character('\356')); // latin + // small + // letter i + // with + // circumflex + entities.put(new String("iuml"), new Character('\357')); // latin + // small + // letter i + // with + // diaeresis + entities.put(new String("eth"), new Character('\360')); // latin small + // letter eth + entities.put(new String("ntilde"), new Character('\361')); // latin + // small + // letter n + // with + // tilde + entities.put(new String("ograve"), new Character('\362')); // latin + // small + // letter o + // with + // grave + entities.put(new String("oacute"), new Character('\363')); // latin + // small + // letter o + // with + // acute + entities.put(new String("ocirc"), new Character('\364')); // latin + // small + // letter o + // with + // circumflex + entities.put(new String("otilde"), new Character('\365')); // latin + // small + // letter o + // with + // tilde + entities.put(new String("ouml"), new Character('\366')); // latin + // small + // letter o + // with + // diaeresis + entities.put(new String("divide"), new Character('\367')); // division + // sign + entities.put(new String("oslash"), new Character('\370')); // latin + // small + // letter o + // with + // stroke = + // latin + // small + // letter o + // slash + entities.put(new String("ugrave"), new Character('\371')); // latin + // small + // letter u + // with + // grave + entities.put(new String("uacute"), new Character('\372')); // latin + // small + // letter u + // with + // acute + entities.put(new String("ucirc"), new Character('\373')); // latin + // small + // letter u + // with + // circumflex + entities.put(new String("uuml"), new Character('\374')); // latin + // small + // letter u + // with + // diaeresis + entities.put(new String("yacute"), new Character('\375')); // latin + // small + // letter y + // with + // acute + entities.put(new String("thorn"), new Character('\376')); // latin + // small + // letter + // thorn + entities.put(new String("yuml"), new Character('\377')); // latin + // small + // letter y + // with + // diaeresis + + // Special characters + entities.put(new String("quot"), new Character('\42')); // quotation + // mark = APL + // quote + entities.put(new String("amp"), new Character('\46')); // ampersand + entities.put(new String("lt"), new Character('\74')); // less-than + // sign + entities.put(new String("gt"), new Character('\76')); // greater-than + // sign + // Latin Extended-A + entities.put(new String("OElig"), new Character('\u0152')); // latin + // capital + // ligature + // OE + entities.put(new String("oelig"), new Character('\u0153')); // latin + // small + // ligature + // oe, + // ligature + // is a + // misnomer, + // this is a + // separate + // character + // in some + // languages + entities.put(new String("Scaron"), new Character('\u0160')); // latin + // capital + // letter + // S + // with + // caron + entities.put(new String("scaron"), new Character('\u0161')); // latin + // small + // letter + // s + // with + // caron + entities.put(new String("Yuml"), new Character('\u0178')); // latin + // capital + // letter Y + // with + // diaeresis + // Spacing Modifier Letters + entities.put(new String("circ"), new Character('\u02c6')); // modifier + // letter + // circumflex + // accent + entities.put(new String("tilde"), new Character('\u02dc')); // small + // tilde + // General punctuation + entities.put(new String("ensp"), new Character('\u2002')); // en space + entities.put(new String("emsp"), new Character('\u2003')); // em space + entities.put(new String("thinsp"), new Character('\u2009')); // thin + // space + entities.put(new String("zwnj"), new Character('\u200c')); // zero + // width + // non-joiner + entities.put(new String("zwj"), new Character('\u200d')); // zero + // width + // joiner + entities.put(new String("lrm"), new Character('\u200e')); // left-to-right + // mark + entities.put(new String("rlm"), new Character('\u200f')); // right-to-left + // mark + entities.put(new String("ndash"), new Character('\u2013')); // en dash + entities.put(new String("mdash"), new Character('\u2014')); // em dash + entities.put(new String("lsquo"), new Character('\u2018')); // left + // single + // quotation + // mark + entities.put(new String("rsquo"), new Character('\u2019')); // right + // single + // quotation + // mark + entities.put(new String("sbquo"), new Character('\u201a')); // single + // low-9 + // quotation + // mark + entities.put(new String("ldquo"), new Character('\u201c')); // left + // double + // quotation + // mark + entities.put(new String("rdquo"), new Character('\u201d')); // right + // double + // quotation + // mark + entities.put(new String("bdquo"), new Character('\u201e')); // double + // low-9 + // quotation + // mark + entities.put(new String("dagger"), new Character('\u2020')); // dagger + entities.put(new String("Dagger"), new Character('\u2021')); // double + // dagger + entities.put(new String("permil"), new Character('\u2030')); // per + // mille + // sign + entities.put(new String("lsaquo"), new Character('\u2039')); // single + // left-pointing + // angle + // quotation + // mark, + // not + // yet + // standardized + entities.put(new String("rsaquo"), new Character('\u203a')); // single + // right-pointing + // angle + // quotation + // mark, + // not + // yet + // standardized + entities.put(new String("euro"), new Character('\u20ac')); // euro sign + } +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlTag.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlTag.java new file mode 100644 index 000000000..fc789480c --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/HtmlTag.java @@ -0,0 +1,362 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.internal.tasks.core; + +import java.net.URL; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Iterator; +import javax.swing.text.html.HTML.Tag; + +/** + * Class representing an HTML (3.2) tag and its attributes. + */ +public class HtmlTag { + /** tag's name */ + private String tagName; + + /** tag type enum */ + private Tag tagType; + + /** true if the tag is a closing tag */ + private boolean isEndTag; + + /** tag's attributes (keys are lowercase attribute names) */ + private HashMap attributes; + + /** tag's base url */ + private URL baseUrl; + + /** tag is self terminated */ + private boolean selfTerminating; + + /** + * Basic constructor. The tag is uninitialized. + */ + public HtmlTag() { + tagName = null; + tagType = Type.UNKNOWN; + isEndTag = false; + attributes = new HashMap(); + baseUrl = null; + } + + /** + * Copy constructor. + */ + @SuppressWarnings("unchecked") + public HtmlTag(HtmlTag htmltag) { + tagName = null; + tagType = Type.UNKNOWN; + isEndTag = false; + attributes = new HashMap(); + tagName = new String(htmltag.tagName); + baseUrl = htmltag.baseUrl; + tagType = htmltag.tagType; + isEndTag = htmltag.isEndTag; + attributes = (HashMap) htmltag.attributes.clone(); + } + + /** + * Constructor. + */ + public HtmlTag(String s) throws ParseException { + attributes = new HashMap(); + setTagName(s); + baseUrl = null; + } + + /** + * Constructor creating an otherwise empty tag, but with a given base url. + */ + public HtmlTag(URL url) { + tagName = null; + tagType = Type.UNKNOWN; + isEndTag = false; + attributes = new HashMap(); + baseUrl = url; + } + + /** + * Returns the tag's type (linked to the tag's name). + */ + public Tag getTagType() { + return tagType; + } + + /** + * Returns the tag's name (e.g., "HEAD", "P", etc.). + */ + public String getTagName() { + return tagName; + } + + /** + * Sets the tag's name and type, if known. + * + * @throws IllegalArgumentException + * if the argument is null or empty string + */ + public void setTagName(String s) throws IllegalArgumentException { + if (s == null || s.length() == 0) + throw new IllegalArgumentException("Empty tag name"); + if (s.charAt(0) == '/') { + isEndTag = true; + s = s.substring(1); + } + if (s.length() == 0) + throw new IllegalArgumentException("Empty tag name"); + tagName = s; + tagType = tags.get(s.toUpperCase()); + if (tagType == null) { + tagType = Type.UNKNOWN; + } + } + + /** + * Returns true if the tag is a closing tag. + */ + public boolean isEndTag() { + return isEndTag; + } + + /** + * Returns the value of a tag's attribute as an integer. + */ + public int getIntAttribute(String s) throws NumberFormatException { + return Integer.parseInt(getAttribute(s)); + } + + /** + * Returns the value of a tag's attribute, or NULL if it doesn't exist. + */ + public String getAttribute(String s) { + return attributes.get(s); + } + + /** + * Returns true if the tag contains attribute with the given + * name. + */ + public boolean hasAttribute(String s) { + return getAttribute(s) != null; + } + + /** + * Sets the value of a tag's attribute. + */ + public void setAttribute(String name, String value) { + attributes.put(name.toLowerCase(), value); + } + + public StringBuffer getURLs() { + StringBuffer sb = new StringBuffer(); + + Iterator attributeNames = attributes.keySet().iterator(); + Iterator attributeValues = attributes.values().iterator(); + while (attributeNames.hasNext()) { + String attributeName = attributeNames.next(); + if (attributeName.compareTo("href") == 0 || attributeName.compareTo("src") == 0) { + String target = attributeValues.next(); + if (!target.endsWith(".jpg") && !target.endsWith(".gif") && !target.endsWith(".css") + && !target.endsWith(".js") && !target.startsWith("mailto") && target.lastIndexOf("#") == -1 + && target.length() > 0) { + + for (int i = 0; i < target.length(); i++) { + char ch = target.charAt(i); + if (!Character.isWhitespace(ch)) { + if (i > 0) + target = target.substring(i + 1); + break; + } + } + target = target.replace('\\', '/'); + + if (target.startsWith("news:") || (target.indexOf("://") != -1 && target.length() >= 7)) { + // Absolute URL + if (target.substring(0, 7).compareToIgnoreCase("http://") == 0) + sb.append(target); + } else { + // Relative URL + + String baseDir = baseUrl.getPath(); + int lastSep = -1; + for (int i = 0; i < baseDir.length(); i++) { + char ch = baseDir.charAt(i); + if (ch == '/') + lastSep = i; + else if (ch == '?') + break; + } + if (lastSep >= 0) + baseDir = baseDir.substring(0, lastSep); + while (baseDir.length() > 1 && baseDir.endsWith("/.")) { + baseDir = baseDir.substring(0, baseDir.length() - 2); + } + + if (target.startsWith("//")) { + sb.append(baseUrl.getProtocol() + ":" + target); + } else if (target.startsWith("/")) { + sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + target); + } else { + while (target.startsWith("../")) { + if (baseDir.length() > 0) { + // can't go above root + baseDir = baseDir.substring(0, baseDir.lastIndexOf("/")); + } + target = target.substring(3); + } + sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + baseDir + "/" + target); + } + } + } + } else { + attributeValues.next(); + } + } + + return sb; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append('<'); + if (isEndTag) + sb.append('/'); + sb.append(tagName); + Iterator keys = attributes.keySet().iterator(); + Iterator values = attributes.values().iterator(); + while (keys.hasNext()) { + String name = keys.next(); + sb.append(' '); + sb.append(name); + String value = values.next(); + if (value.length() > 0) { + sb.append("=\""); + sb.append(value); + sb.append('"'); + } + } + if(selfTerminating) { + sb.append('/'); + } + sb.append('>'); + + return sb.toString(); + } + + /** + * Enum class for tag types. + */ + public static class Type extends Tag { + public static final Tag UNKNOWN = new Tag(); + + public static final Tag THEAD = new Type("THEAD"); + + public static final Tag DOCTYPE = new Type("!DOCTYPE"); + + public static final Tag LABEL = new Type("LABEL"); + + private Type(String name) { + super(name); + } + } + + private static HashMap tags; + static { + tags = new HashMap(); + tags.put(new String("A"), Tag.A); + tags.put(new String("ADDRESS"), Tag.ADDRESS); + tags.put(new String("APPLET"), Tag.APPLET); + tags.put(new String("AREA"), Tag.AREA); + tags.put(new String("B"), Tag.B); + tags.put(new String("BASE"), Tag.BASE); + tags.put(new String("BASEFONT"), Tag.BASEFONT); + tags.put(new String("BIG"), Tag.BIG); + tags.put(new String("BLOCKQUOTE"), Tag.BLOCKQUOTE); + tags.put(new String("BODY"), Tag.BODY); + tags.put(new String("BR"), Tag.BR); + tags.put(new String("CAPTION"), Tag.CAPTION); + tags.put(new String("CENTER"), Tag.CENTER); + tags.put(new String("CITE"), Tag.CITE); + tags.put(new String("CODE"), Tag.CODE); + tags.put(new String("DD"), Tag.DD); + tags.put(new String("DFN"), Tag.DFN); + tags.put(new String("DIR"), Tag.DIR); + tags.put(new String("DIV"), Tag.DIV); + tags.put(new String("DL"), Tag.DL); + tags.put(new String("!DOCTYPE"), Type.DOCTYPE); + tags.put(new String("DT"), Tag.DT); + tags.put(new String("EM"), Tag.EM); + tags.put(new String("FONT"), Tag.FONT); + tags.put(new String("FORM"), Tag.FORM); + tags.put(new String("FRAME"), Tag.FRAME); + tags.put(new String("FRAMESET"), Tag.FRAMESET); + tags.put(new String("H1"), Tag.H1); + tags.put(new String("H2"), Tag.H2); + tags.put(new String("H3"), Tag.H3); + tags.put(new String("H4"), Tag.H4); + tags.put(new String("H5"), Tag.H5); + tags.put(new String("H6"), Tag.H6); + tags.put(new String("HEAD"), Tag.HEAD); + tags.put(new String("HTML"), Tag.HTML); + tags.put(new String("HR"), Tag.HR); + tags.put(new String("I"), Tag.I); + tags.put(new String("IMG"), Tag.IMG); + tags.put(new String("INPUT"), Tag.INPUT); + tags.put(new String("ISINDEX"), Tag.ISINDEX); + tags.put(new String("KBD"), Tag.KBD); + tags.put(new String("LI"), Tag.LI); + tags.put(new String("LABEL"), Type.LABEL); + tags.put(new String("LINK"), Tag.LINK); + tags.put(new String("MAP"), Tag.MAP); + tags.put(new String("MENU"), Tag.MENU); + tags.put(new String("META"), Tag.META); + tags.put(new String("NOFRAMES"), Tag.NOFRAMES); + tags.put(new String("OBJECT"), Tag.OBJECT); + tags.put(new String("OL"), Tag.OL); + tags.put(new String("OPTION"), Tag.OPTION); + tags.put(new String("P"), Tag.P); + tags.put(new String("PARAM"), Tag.PARAM); + tags.put(new String("PRE"), Tag.PRE); + tags.put(new String("S"), Tag.S); + tags.put(new String("SAMP"), Tag.SAMP); + tags.put(new String("SCRIPT"), Tag.SCRIPT); + tags.put(new String("SELECT"), Tag.SELECT); + tags.put(new String("SMALL"), Tag.SMALL); + tags.put(new String("STRONG"), Tag.STRONG); + tags.put(new String("STYLE"), Tag.STYLE); + tags.put(new String("SUB"), Tag.SUB); + tags.put(new String("SUP"), Tag.SUP); + tags.put(new String("TABLE"), Tag.TABLE); + tags.put(new String("TD"), Tag.TD); + tags.put(new String("TEXTAREA"), Tag.TEXTAREA); + tags.put(new String("TH"), Tag.TH); + tags.put(new String("THEAD"), Type.THEAD); + tags.put(new String("TITLE"), Tag.TITLE); + tags.put(new String("TR"), Tag.TR); + tags.put(new String("TT"), Tag.TT); + tags.put(new String("U"), Tag.U); + tags.put(new String("UL"), Tag.UL); + tags.put(new String("VAR"), Tag.VAR); + } + + public void setSelfTerminating(boolean terminating) { + this.selfTerminating = terminating; + + } + + public boolean isSelfTerminating() { + return selfTerminating; + } +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesContentHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesContentHandler.java new file mode 100644 index 000000000..072b8ae85 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesContentHandler.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylar.internal.tasks.core; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.mylar.internal.context.core.util.XmlStringConverter; +import org.eclipse.mylar.tasks.core.IRepositoryConstants; +import org.eclipse.mylar.tasks.core.TaskRepository; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Adapted from SaxContextContentHandler + * + * @author Rob Elves + */ +public class SaxRepositoriesContentHandler extends DefaultHandler { + + + static final String ATTRIBUTE_INTERACTION_EVENT = "InteractionEvent"; + + private Set taskRepositories = new HashSet(); + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + try { + if (localName.equals(TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY) && attributes != null) { + String kind = XmlStringConverter.convertXmlToString(attributes + .getValue(IRepositoryConstants.PROPERTY_KIND)); + String url = XmlStringConverter.convertXmlToString(attributes + .getValue(IRepositoryConstants.PROPERTY_URL)); + if (kind != null && kind.length() > 0 && url != null && url.length() > 0) { + TaskRepository repository = new TaskRepository(kind, url); + for (int index = 0; index < attributes.getLength(); index++) { + String key = XmlStringConverter.convertXmlToString(attributes.getLocalName(index)); + String value = XmlStringConverter.convertXmlToString(attributes.getValue(index)); + repository.setProperty(key, value); + } + taskRepositories.add(repository); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public Set getRepositories() { + return taskRepositories; + } +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesWriter.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesWriter.java new file mode 100644 index 000000000..336582edb --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SaxRepositoriesWriter.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.internal.tasks.core; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.mylar.context.core.MylarStatusHandler; +import org.eclipse.mylar.internal.context.core.util.XmlStringConverter; +import org.eclipse.mylar.tasks.core.TaskRepository; +import org.xml.sax.ContentHandler; +import org.xml.sax.DTDHandler; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Adapted from SaxContextWriter + * + * @author Rob Elves + */ +public class SaxRepositoriesWriter { + + private OutputStream outputStream; + + public void setOutputStream(OutputStream outputStream) { + this.outputStream = outputStream; + } + + public void writeRepositoriesToStream(Collection repositories) throws IOException { + if (outputStream == null) { + IOException ioe = new IOException("OutputStream not set"); + throw ioe; + } + + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform( + new SAXSource(new RepositoriesWriter(), new TaskRepositoriesInputSource(repositories)), + new StreamResult(outputStream)); + } catch (TransformerException e) { + MylarStatusHandler.fail(e, "could not write repositories", false); + throw new IOException(e.getMessage()); + } + + } + + private static class TaskRepositoriesInputSource extends InputSource { + private Collection repositories; + + public TaskRepositoriesInputSource(Collection repositories) { + this.repositories = repositories; + } + + public Collection getRepositories() { + return this.repositories; + } + + } + + private static class RepositoriesWriter implements XMLReader { + +// private static final String ELEMENT_TASK_REPOSITORIES = "TaskRepositories"; +// +// public static final String ELEMENT_TASK_REPOSITORY = "TaskRepository"; +// +// private static final String ATTRIBUTE_VERSION = "xmlVersion"; + +// private static final String ATTRIBUTE_URL = "Url"; +// +// private static final String ATTRIBUTE_KIND = "Kind"; + + private ContentHandler handler; + + private ErrorHandler errorHandler; + + public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return false; + } + + public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { + + } + + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return null; + } + + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + } + + public void setEntityResolver(EntityResolver resolver) { + } + + public EntityResolver getEntityResolver() { + return null; + } + + public void setDTDHandler(DTDHandler handler) { + } + + public DTDHandler getDTDHandler() { + return null; + } + + public void setContentHandler(ContentHandler handler) { + this.handler = handler; + + } + + public ContentHandler getContentHandler() { + return handler; + } + + public void setErrorHandler(ErrorHandler handler) { + this.errorHandler = handler; + + } + + public ErrorHandler getErrorHandler() { + return errorHandler; + } + + public void parse(InputSource input) throws IOException, SAXException { + if (!(input instanceof TaskRepositoriesInputSource)) { + throw new SAXException("Can only parse writable input sources"); + } + + Collection repositories = ((TaskRepositoriesInputSource) input).getRepositories(); + + handler.startDocument(); + AttributesImpl rootAttributes = new AttributesImpl(); + rootAttributes.addAttribute("", TaskRepositoriesExternalizer.ATTRIBUTE_VERSION, TaskRepositoriesExternalizer.ATTRIBUTE_VERSION, "", "1"); + + handler.startElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, rootAttributes); + + for (TaskRepository repository : new ArrayList(repositories)) { + + AttributesImpl ieAttributes = new AttributesImpl(); + for (String key : repository.getProperties().keySet()) { + ieAttributes.addAttribute("", key, key, "", XmlStringConverter.convertToXmlString(repository + .getProperties().get(key))); + } + + handler.startElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, ieAttributes); + handler.endElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY); + } + handler.endElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES); + + handler.endDocument(); + } + + public void parse(String systemId) throws IOException, SAXException { + throw new SAXException("Can only parse writable input sources"); + } + + } +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java new file mode 100644 index 000000000..b679c9e39 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.internal.tasks.core; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collection; +import java.util.Set; + +import org.eclipse.mylar.context.core.MylarStatusHandler; +import org.eclipse.mylar.tasks.core.TaskRepository; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * Adapted from MylarContextExternalizer + * + * @author Rob Elves + */ +public class TaskRepositoriesExternalizer { + + private SaxRepositoriesWriter writer = new SaxRepositoriesWriter(); + + public static final String ELEMENT_TASK_REPOSITORIES = "TaskRepositories"; + + public static final String ELEMENT_TASK_REPOSITORY = "TaskRepository"; + + public static final String ATTRIBUTE_VERSION = "OutputVersion"; + + public void writeRepositoriesToXML(Collection repositories, File file) { + if (repositories.isEmpty()) + return; + try { + if (!file.exists()) + file.createNewFile(); + OutputStream stream = new FileOutputStream(file); + writer.setOutputStream(stream); + writer.writeRepositoriesToStream(repositories); + stream.close(); + } catch (IOException e) { + MylarStatusHandler.fail(e, "Could not write: " + file.getAbsolutePath(), true); + } + } + + public Set readRepositoriesFromXML(File file) { + + if (!file.exists()) + return null; + try { + SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler(); + XMLReader reader = XMLReaderFactory.createXMLReader(); + reader.setContentHandler(contentHandler); + reader.parse(new InputSource(new FileInputStream(file))); + return contentHandler.getRepositories(); + } catch (Exception e) { + file.renameTo(new File(file.getAbsolutePath() + "-save")); + return null; + } + } +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlStreamTokenizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlStreamTokenizer.java deleted file mode 100644 index 24dbf8109..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlStreamTokenizer.java +++ /dev/null @@ -1,1105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.core.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.net.URL; -import java.text.ParseException; -import java.util.HashMap; - -public class HtmlStreamTokenizer { - - /** parser state */ - private State state; - - /** reader from which to parse the text */ - private BufferedReader in; - - /** base URL for resolving relative URLs */ - private URL base; - - /** buffer holding the text of the current token */ - private StringBuffer textBuffer; - - /** buffer holding whitespace preceding the current token */ - private StringBuffer whitespaceBuffer; - - /** - * holds a token that was read and then put back in the queue to be returned - * again on nextToken call - */ - private Token pushbackToken; - - /** - * holds a character that was read and then determined not to be part of the - * current token - */ - private int pushbackChar; - - /** current quote delimiter (single or double) */ - private int quoteChar; - - /** - * Constructor. - * - * @param in - * reader for the HTML document to tokenize - * @param base - * URL for resolving relative URLs - */ - public HtmlStreamTokenizer(Reader in, URL base) { - textBuffer = new StringBuffer(); - whitespaceBuffer = new StringBuffer(); - pushbackChar = 0; - state = State.TEXT; - this.in = new BufferedReader(in); - this.base = base; - } - - /** - * Returns the next token from the stream. - */ - public Token nextToken() throws IOException, ParseException { - if (pushbackToken != null) { - Token token = pushbackToken; - pushbackToken = null; - return token; - } - - int closingComment = 0; - - textBuffer.setLength(0); - whitespaceBuffer.setLength(0); - do { - int ch; - if (pushbackChar != 0) { - ch = pushbackChar; - pushbackChar = 0; - } else { - ch = in.read(); - } - if (ch < 0) { - State oldState = state; - state = State.EOF; - if (textBuffer.length() > 0 && oldState == State.TEXT) { - return new Token(textBuffer, whitespaceBuffer, false); - } else { - return new Token(); - } - } - if (state == State.TEXT) { - if (ch == '<') { - state = State.TAG; - if (textBuffer.length() > 0) - return new Token(textBuffer, whitespaceBuffer, false); - } else if (Character.isWhitespace((char) ch)) { - pushbackChar = ch; - state = State.WS; - if (textBuffer.length() > 0) - return new Token(textBuffer, whitespaceBuffer, false); - } else { - textBuffer.append((char) ch); - } - } else if (state == State.WS) { - if (!Character.isWhitespace((char) ch)) { - pushbackChar = ch; - state = State.TEXT; - } else { - whitespaceBuffer.append((char) ch); - } - } else if (state == State.TAG) { - if (ch == '>') { - state = State.TEXT; - HtmlTag tag = new HtmlTag(base); - parseTag(textBuffer.toString(), tag); - return new Token(tag, whitespaceBuffer); - } - if (ch == '<' && textBuffer.length() == 0) { - textBuffer.append("<<"); - state = State.TEXT; - } else if (ch == '-' && textBuffer.length() == 2 && textBuffer.charAt(1) == '-' - && textBuffer.charAt(0) == '!') { - textBuffer.setLength(0); - state = State.COMMENT; - } else if (ch == '\'' || ch == '"') { - quoteChar = ch; - textBuffer.append((char) ch); - state = State.TAG_QUOTE; - } else { - textBuffer.append((char) ch); - } - } else if (state == State.TAG_QUOTE) { - if (ch == '>') { - pushbackChar = ch; - state = State.TAG; - } else { - textBuffer.append((char) ch); - if (ch == quoteChar) - state = State.TAG; - } - } else if (state == State.COMMENT) { - if (ch == '>' && closingComment >= 2) { - textBuffer.setLength(textBuffer.length() - 2); - closingComment = 0; - state = State.TEXT; - return new Token(textBuffer, whitespaceBuffer, true); - } - if (ch == '-') { - closingComment++; - } else { - closingComment = 0; - } - textBuffer.append((char) ch); - } - } while (true); - } - - /** - * Pushes the token back into the queue, to be returned by the subsequent - * call to nextToken - */ - public void pushback(Token token) { - pushbackToken = token; - } - - /** - * Parses an HTML tag out of a string of characters. - */ - private static void parseTag(String s, HtmlTag tag) throws ParseException { - - int i = 0; - for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - if (i == s.length()) - throw new ParseException("parse empty tag", 0); - - int start = i; - for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - tag.setTagName(s.substring(start, i)); - - for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - if (i == s.length()) { - return; - } else { - parseAttributes(tag, s, i); - return; - } - } - - /** - * parses HTML tag attributes from a buffer and sets them in an HtmlTag - */ - private static void parseAttributes(HtmlTag tag, String s, int i) throws ParseException { - while (i < s.length()) { - // skip whitespace - while (i < s.length() && Character.isWhitespace(s.charAt(i))) - i++; - - if (i == s.length()) - return; - - // read the attribute name -- the rule might be looser than the RFC - // specifies: - // everything up to a space or an equal sign is included - int start = i; - for (; i < s.length() && !Character.isWhitespace(s.charAt(i)) && s.charAt(i) != '='; i++) { - // just move forward - } - String attributeName = s.substring(start, i).toLowerCase(); - - if(attributeName.equals("/")) { - tag.setSelfTerminating(true); - continue; - } - - for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - if (i == s.length() || s.charAt(i) != '=') { - // no attribute value - tag.setAttribute(attributeName, ""); - continue; - } - - // skip whitespace to the start of attribute value - for (i = i + 1; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - if (i == s.length()) - return; - - // read the attribute value -- the rule for unquoted attribute value - // is - // looser than the one in Conolly's W3C 1996 lexical analyzer draft: - // everything - // is included up to the next space - String attributeValue; - if (s.charAt(i) == '"') { - start = ++i; - for (; i < s.length() && s.charAt(i) != '"'; i++) { - // just move forward - } - if (i == s.length()) - return; // shouldn't happen if input returned by nextToken - attributeValue = unescape(s.substring(start, i)); - i++; - } else if (s.charAt(i) == '\'') { - start = ++i; - for (; i < s.length() && s.charAt(i) != '\''; i++) { - // just move forward - } - if (i == s.length()) - return; // shouldn't happen if input returned by nextToken - attributeValue = unescape(s.substring(start, i)); - i++; - } else { - start = i; - for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) { - // just move forward - } - attributeValue = s.substring(start, i); - } - tag.setAttribute(attributeName, attributeValue); - } - } - - /** - * Returns a string with HTML escapes changed into their corresponding - * characters. - */ - public static String unescape(String s) { - if (s.indexOf('&') == -1) { - return s; - } else { - StringBuffer sb = new StringBuffer(s); - unescape(sb); - return sb.toString(); - } - } - - /** - * Replaces (in-place) HTML escapes in a StringBuffer with their - * corresponding characters. - */ - public static StringBuffer unescape(StringBuffer sb) { - int i = 0; // index into the unprocessed section of the buffer - int j = 0; // index into the processed section of the buffer - - while (i < sb.length()) { - char ch = sb.charAt(i); - if (ch == '&') { - int start = i; - String escape = null; - for (i = i + 1; i < sb.length(); i++) { - ch = sb.charAt(i); - if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == (start + 1))) { - escape = sb.substring(start + 1, i); - break; - } - } - if (i == sb.length() && i != (start + 1)) { - escape = sb.substring(start + 1); - } - if (escape != null) { - Character character = parseReference(escape); - if (character != null) { - ch = character.charValue(); - } else { - // not an HTML escape; rewind - i = start; - ch = '&'; - } - } - } - sb.setCharAt(j, ch); - i++; - j++; - } - - sb.setLength(j); - return sb; - } - - /** - * Parses HTML character and entity references and returns the corresponding - * character. - */ - private static Character parseReference(String s) { - if (s.length() == 0) - return null; - - if (s.charAt(0) == '#') { - // character reference - if (s.length() == 1) - return null; - - try { - int value; - if (s.charAt(1) == 'x') { - // Hex reference - value = Integer.parseInt(s.substring(2), 16); - } else { - // Decimal reference - value = Integer.parseInt(s.substring(1)); - } - return new Character((char) value); - } catch (NumberFormatException e) { - return null; - } - } else { - return entities.get(s); - } - } - - /** - * Class for current token. - */ - public static class Token { - public static final Type EOF = new Type(); - - public static final Type TEXT = new Type(); - - public static final Type TAG = new Type(); - - public static final Type COMMENT = new Type(); - - /** token's type */ - private Type type; - - /** token's value */ - private Object value; - - /** whitespace preceding the token */ - private StringBuffer whitespace; - - /** - * Constructor for the EOF token. - */ - protected Token() { - type = EOF; - value = null; - whitespace = null; - } - - /** - * Constructor for the HTML tag tokens. - */ - protected Token(HtmlTag tag, StringBuffer whitespace) { - type = TAG; - value = tag; - this.whitespace = whitespace; - } - - /** - * Constructor for regular text and comments. - */ - protected Token(StringBuffer text, StringBuffer whitespace, boolean comment) { - if (comment) { - type = COMMENT; - } else { - type = TEXT; - } - this.value = text; - this.whitespace = whitespace; - } - - /** - * Returns the token's type. - */ - public Type getType() { - return type; - } - - /** - * Returns the whitespace preceding the token. - */ - public StringBuffer getWhitespace() { - return whitespace; - } - - /** - * Returns the token's value. This is an HtmlTag for tokens of type - * TAG and a StringBuffer for tokens of type - * TEXT and COMMENT. For tokens of type - * EOF, the value is null. - */ - public Object getValue() { - return value; - } - - /** - * Returns the string representation of the token, including the - * preceding whitespace. - */ - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - if (whitespace != null) { - sb.append(whitespace); - } - if (value != null) { - if (type == TAG) { - // sb.append('<'); - } else if (type == COMMENT) { - sb.append(""); - } - - } - return sb.toString(); - } - - /** - * Private enum class for token type. - */ - private static class Type { - private Type() { - // don't need to do anything - } - } - } - - /** - * Enum class for parser state. - */ - private static class State { - static final State EOF = new State(); - - static final State COMMENT = new State(); - - static final State TEXT = new State(); - - static final State TAG = new State(); - - static final State WS = new State(); - - static final State TAG_QUOTE = new State(); - - private State() { - // don't need to do anything - } - } - - /** names and values of HTML entity references */ - private static HashMap entities; - - /* - * Based on ISO 8879. - * - * Portions (c) International Organization for Standardization 1986 Permission - * to copy in any form is granted for use with conforming SGML systems and - * applications as defined in ISO 8879, provided this notice is included in - * all copies. - * - */ - static { - entities = new HashMap(); - entities.put(new String("nbsp"), new Character('\240')); // no-break - // space = - // non-breaking - // space - entities.put(new String("iexcl"), new Character('\241')); // inverted - // exclamation - // mark - entities.put(new String("cent"), new Character('\242')); // cent sign - entities.put(new String("pound"), new Character('\243')); // pound - // sign - entities.put(new String("curren"), new Character('\244')); // currency - // sign - entities.put(new String("yen"), new Character('\245')); // yen sign = - // yuan sign - entities.put(new String("brvbar"), new Character('\246')); // broken - // bar = - // broken - // vertical - // bar - entities.put(new String("sect"), new Character('\247')); // section - // sign - entities.put(new String("uml"), new Character('\250')); // diaeresis = - // spacing - // diaeresis - entities.put(new String("copy"), new Character('\251')); // copyright - // sign - entities.put(new String("ordf"), new Character('\252')); // feminine - // ordinal - // indicator - entities.put(new String("laquo"), new Character('\253')); // left-pointing - // double - // angle - // quotation - // mark = - // left - // pointing - // guillemet - entities.put(new String("not"), new Character('\254')); // not sign - entities.put(new String("shy"), new Character('\255')); // soft hyphen = - // discretionary - // hyphen - entities.put(new String("reg"), new Character('\256')); // registered - // sign = - // registered - // trade mark - // sign - entities.put(new String("macr"), new Character('\257')); // macron = - // spacing - // macron = - // overline - // = APL - // overbar - entities.put(new String("deg"), new Character('\260')); // degree sign - entities.put(new String("plusmn"), new Character('\261')); // plus-minus - // sign = - // plus-or-minus - // sign - entities.put(new String("sup2"), new Character('\262')); // superscript - // two = - // superscript - // digit two - // = squared - entities.put(new String("sup3"), new Character('\263')); // superscript - // three = - // superscript - // digit - // three = - // cubed - entities.put(new String("acute"), new Character('\264')); // acute - // accent = - // spacing - // acute - entities.put(new String("micro"), new Character('\265')); // micro - // sign - entities.put(new String("para"), new Character('\266')); // pilcrow - // sign = - // paragraph - // sign - entities.put(new String("middot"), new Character('\267')); // middle - // dot = - // Georgian - // comma = - // Greek - // middle - // dot - entities.put(new String("cedil"), new Character('\270')); // cedilla = - // spacing - // cedilla - entities.put(new String("sup1"), new Character('\271')); // superscript - // one = - // superscript - // digit one - entities.put(new String("ordm"), new Character('\272')); // masculine - // ordinal - // indicator - entities.put(new String("raquo"), new Character('\273')); // right-pointing - // double - // angle - // quotation - // mark = - // right - // pointing - // guillemet - entities.put(new String("frac14"), new Character('\274')); // vulgar - // fraction - // one - // quarter = - // fraction - // one - // quarter - entities.put(new String("frac12"), new Character('\275')); // vulgar - // fraction - // one half - // = - // fraction - // one half - entities.put(new String("frac34"), new Character('\276')); // vulgar - // fraction - // three - // quarters - // = - // fraction - // three - // quarters - entities.put(new String("iquest"), new Character('\277')); // inverted - // question - // mark = - // turned - // question - // mark - entities.put(new String("Agrave"), new Character('\300')); // latin - // capital - // letter A - // with - // grave = - // latin - // capital - // letter A - // grave - entities.put(new String("Aacute"), new Character('\301')); // latin - // capital - // letter A - // with - // acute - entities.put(new String("Acirc"), new Character('\302')); // latin - // capital - // letter A - // with - // circumflex - entities.put(new String("Atilde"), new Character('\303')); // latin - // capital - // letter A - // with - // tilde - entities.put(new String("Auml"), new Character('\304')); // latin - // capital - // letter A - // with - // diaeresis - entities.put(new String("Aring"), new Character('\305')); // latin - // capital - // letter A - // with ring - // above = - // latin - // capital - // letter A - // ring - entities.put(new String("AElig"), new Character('\306')); // latin - // capital - // letter AE - // = latin - // capital - // ligature - // AE - entities.put(new String("Ccedil"), new Character('\307')); // latin - // capital - // letter C - // with - // cedilla - entities.put(new String("Egrave"), new Character('\310')); // latin - // capital - // letter E - // with - // grave - entities.put(new String("Eacute"), new Character('\311')); // latin - // capital - // letter E - // with - // acute - entities.put(new String("Ecirc"), new Character('\312')); // latin - // capital - // letter E - // with - // circumflex - entities.put(new String("Euml"), new Character('\313')); // latin - // capital - // letter E - // with - // diaeresis - entities.put(new String("Igrave"), new Character('\314')); // latin - // capital - // letter I - // with - // grave - entities.put(new String("Iacute"), new Character('\315')); // latin - // capital - // letter I - // with - // acute - entities.put(new String("Icirc"), new Character('\316')); // latin - // capital - // letter I - // with - // circumflex - entities.put(new String("Iuml"), new Character('\317')); // latin - // capital - // letter I - // with - // diaeresis - entities.put(new String("ETH"), new Character('\320')); // latin capital - // letter ETH - entities.put(new String("Ntilde"), new Character('\321')); // latin - // capital - // letter N - // with - // tilde - entities.put(new String("Ograve"), new Character('\322')); // latin - // capital - // letter O - // with - // grave - entities.put(new String("Oacute"), new Character('\323')); // latin - // capital - // letter O - // with - // acute - entities.put(new String("Ocirc"), new Character('\324')); // latin - // capital - // letter O - // with - // circumflex - entities.put(new String("Otilde"), new Character('\325')); // latin - // capital - // letter O - // with - // tilde - entities.put(new String("Ouml"), new Character('\326')); // latin - // capital - // letter O - // with - // diaeresis - entities.put(new String("times"), new Character('\327')); // multiplication - // sign - entities.put(new String("Oslash"), new Character('\330')); // latin - // capital - // letter O - // with - // stroke = - // latin - // capital - // letter O - // slash - entities.put(new String("Ugrave"), new Character('\331')); // latin - // capital - // letter U - // with - // grave - entities.put(new String("Uacute"), new Character('\332')); // latin - // capital - // letter U - // with - // acute - entities.put(new String("Ucirc"), new Character('\333')); // latin - // capital - // letter U - // with - // circumflex - entities.put(new String("Uuml"), new Character('\334')); // latin - // capital - // letter U - // with - // diaeresis - entities.put(new String("Yacute"), new Character('\335')); // latin - // capital - // letter Y - // with - // acute - entities.put(new String("THORN"), new Character('\336')); // latin - // capital - // letter - // THORN - entities.put(new String("szlig"), new Character('\337')); // latin - // small - // letter - // sharp s = - // ess-zed - entities.put(new String("agrave"), new Character('\340')); // latin - // small - // letter a - // with - // grave = - // latin - // small - // letter a - // grave - entities.put(new String("aacute"), new Character('\341')); // latin - // small - // letter a - // with - // acute - entities.put(new String("acirc"), new Character('\342')); // latin - // small - // letter a - // with - // circumflex - entities.put(new String("atilde"), new Character('\343')); // latin - // small - // letter a - // with - // tilde - entities.put(new String("auml"), new Character('\344')); // latin - // small - // letter a - // with - // diaeresis - entities.put(new String("aring"), new Character('\345')); // latin - // small - // letter a - // with ring - // above = - // latin - // small - // letter a - // ring - entities.put(new String("aelig"), new Character('\346')); // latin - // small - // letter ae - // = latin - // small - // ligature - // ae - entities.put(new String("ccedil"), new Character('\347')); // latin - // small - // letter c - // with - // cedilla - entities.put(new String("egrave"), new Character('\350')); // latin - // small - // letter e - // with - // grave - entities.put(new String("eacute"), new Character('\351')); // latin - // small - // letter e - // with - // acute - entities.put(new String("ecirc"), new Character('\352')); // latin - // small - // letter e - // with - // circumflex - entities.put(new String("euml"), new Character('\353')); // latin - // small - // letter e - // with - // diaeresis - entities.put(new String("igrave"), new Character('\354')); // latin - // small - // letter i - // with - // grave - entities.put(new String("iacute"), new Character('\355')); // latin - // small - // letter i - // with - // acute - entities.put(new String("icirc"), new Character('\356')); // latin - // small - // letter i - // with - // circumflex - entities.put(new String("iuml"), new Character('\357')); // latin - // small - // letter i - // with - // diaeresis - entities.put(new String("eth"), new Character('\360')); // latin small - // letter eth - entities.put(new String("ntilde"), new Character('\361')); // latin - // small - // letter n - // with - // tilde - entities.put(new String("ograve"), new Character('\362')); // latin - // small - // letter o - // with - // grave - entities.put(new String("oacute"), new Character('\363')); // latin - // small - // letter o - // with - // acute - entities.put(new String("ocirc"), new Character('\364')); // latin - // small - // letter o - // with - // circumflex - entities.put(new String("otilde"), new Character('\365')); // latin - // small - // letter o - // with - // tilde - entities.put(new String("ouml"), new Character('\366')); // latin - // small - // letter o - // with - // diaeresis - entities.put(new String("divide"), new Character('\367')); // division - // sign - entities.put(new String("oslash"), new Character('\370')); // latin - // small - // letter o - // with - // stroke = - // latin - // small - // letter o - // slash - entities.put(new String("ugrave"), new Character('\371')); // latin - // small - // letter u - // with - // grave - entities.put(new String("uacute"), new Character('\372')); // latin - // small - // letter u - // with - // acute - entities.put(new String("ucirc"), new Character('\373')); // latin - // small - // letter u - // with - // circumflex - entities.put(new String("uuml"), new Character('\374')); // latin - // small - // letter u - // with - // diaeresis - entities.put(new String("yacute"), new Character('\375')); // latin - // small - // letter y - // with - // acute - entities.put(new String("thorn"), new Character('\376')); // latin - // small - // letter - // thorn - entities.put(new String("yuml"), new Character('\377')); // latin - // small - // letter y - // with - // diaeresis - - // Special characters - entities.put(new String("quot"), new Character('\42')); // quotation - // mark = APL - // quote - entities.put(new String("amp"), new Character('\46')); // ampersand - entities.put(new String("lt"), new Character('\74')); // less-than - // sign - entities.put(new String("gt"), new Character('\76')); // greater-than - // sign - // Latin Extended-A - entities.put(new String("OElig"), new Character('\u0152')); // latin - // capital - // ligature - // OE - entities.put(new String("oelig"), new Character('\u0153')); // latin - // small - // ligature - // oe, - // ligature - // is a - // misnomer, - // this is a - // separate - // character - // in some - // languages - entities.put(new String("Scaron"), new Character('\u0160')); // latin - // capital - // letter - // S - // with - // caron - entities.put(new String("scaron"), new Character('\u0161')); // latin - // small - // letter - // s - // with - // caron - entities.put(new String("Yuml"), new Character('\u0178')); // latin - // capital - // letter Y - // with - // diaeresis - // Spacing Modifier Letters - entities.put(new String("circ"), new Character('\u02c6')); // modifier - // letter - // circumflex - // accent - entities.put(new String("tilde"), new Character('\u02dc')); // small - // tilde - // General punctuation - entities.put(new String("ensp"), new Character('\u2002')); // en space - entities.put(new String("emsp"), new Character('\u2003')); // em space - entities.put(new String("thinsp"), new Character('\u2009')); // thin - // space - entities.put(new String("zwnj"), new Character('\u200c')); // zero - // width - // non-joiner - entities.put(new String("zwj"), new Character('\u200d')); // zero - // width - // joiner - entities.put(new String("lrm"), new Character('\u200e')); // left-to-right - // mark - entities.put(new String("rlm"), new Character('\u200f')); // right-to-left - // mark - entities.put(new String("ndash"), new Character('\u2013')); // en dash - entities.put(new String("mdash"), new Character('\u2014')); // em dash - entities.put(new String("lsquo"), new Character('\u2018')); // left - // single - // quotation - // mark - entities.put(new String("rsquo"), new Character('\u2019')); // right - // single - // quotation - // mark - entities.put(new String("sbquo"), new Character('\u201a')); // single - // low-9 - // quotation - // mark - entities.put(new String("ldquo"), new Character('\u201c')); // left - // double - // quotation - // mark - entities.put(new String("rdquo"), new Character('\u201d')); // right - // double - // quotation - // mark - entities.put(new String("bdquo"), new Character('\u201e')); // double - // low-9 - // quotation - // mark - entities.put(new String("dagger"), new Character('\u2020')); // dagger - entities.put(new String("Dagger"), new Character('\u2021')); // double - // dagger - entities.put(new String("permil"), new Character('\u2030')); // per - // mille - // sign - entities.put(new String("lsaquo"), new Character('\u2039')); // single - // left-pointing - // angle - // quotation - // mark, - // not - // yet - // standardized - entities.put(new String("rsaquo"), new Character('\u203a')); // single - // right-pointing - // angle - // quotation - // mark, - // not - // yet - // standardized - entities.put(new String("euro"), new Character('\u20ac')); // euro sign - } -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlTag.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlTag.java deleted file mode 100644 index e5e99ca9c..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/HtmlTag.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.core.util; - -import java.net.URL; -import java.text.ParseException; -import java.util.HashMap; -import java.util.Iterator; -import javax.swing.text.html.HTML.Tag; - -/** - * Class representing an HTML (3.2) tag and its attributes. - */ -public class HtmlTag { - /** tag's name */ - private String tagName; - - /** tag type enum */ - private Tag tagType; - - /** true if the tag is a closing tag */ - private boolean isEndTag; - - /** tag's attributes (keys are lowercase attribute names) */ - private HashMap attributes; - - /** tag's base url */ - private URL baseUrl; - - /** tag is self terminated */ - private boolean selfTerminating; - - /** - * Basic constructor. The tag is uninitialized. - */ - public HtmlTag() { - tagName = null; - tagType = Type.UNKNOWN; - isEndTag = false; - attributes = new HashMap(); - baseUrl = null; - } - - /** - * Copy constructor. - */ - @SuppressWarnings("unchecked") - public HtmlTag(HtmlTag htmltag) { - tagName = null; - tagType = Type.UNKNOWN; - isEndTag = false; - attributes = new HashMap(); - tagName = new String(htmltag.tagName); - baseUrl = htmltag.baseUrl; - tagType = htmltag.tagType; - isEndTag = htmltag.isEndTag; - attributes = (HashMap) htmltag.attributes.clone(); - } - - /** - * Constructor. - */ - public HtmlTag(String s) throws ParseException { - attributes = new HashMap(); - setTagName(s); - baseUrl = null; - } - - /** - * Constructor creating an otherwise empty tag, but with a given base url. - */ - public HtmlTag(URL url) { - tagName = null; - tagType = Type.UNKNOWN; - isEndTag = false; - attributes = new HashMap(); - baseUrl = url; - } - - /** - * Returns the tag's type (linked to the tag's name). - */ - public Tag getTagType() { - return tagType; - } - - /** - * Returns the tag's name (e.g., "HEAD", "P", etc.). - */ - public String getTagName() { - return tagName; - } - - /** - * Sets the tag's name and type, if known. - * - * @throws IllegalArgumentException - * if the argument is null or empty string - */ - public void setTagName(String s) throws IllegalArgumentException { - if (s == null || s.length() == 0) - throw new IllegalArgumentException("Empty tag name"); - if (s.charAt(0) == '/') { - isEndTag = true; - s = s.substring(1); - } - if (s.length() == 0) - throw new IllegalArgumentException("Empty tag name"); - tagName = s; - tagType = tags.get(s.toUpperCase()); - if (tagType == null) { - tagType = Type.UNKNOWN; - } - } - - /** - * Returns true if the tag is a closing tag. - */ - public boolean isEndTag() { - return isEndTag; - } - - /** - * Returns the value of a tag's attribute as an integer. - */ - public int getIntAttribute(String s) throws NumberFormatException { - return Integer.parseInt(getAttribute(s)); - } - - /** - * Returns the value of a tag's attribute, or NULL if it doesn't exist. - */ - public String getAttribute(String s) { - return attributes.get(s); - } - - /** - * Returns true if the tag contains attribute with the given - * name. - */ - public boolean hasAttribute(String s) { - return getAttribute(s) != null; - } - - /** - * Sets the value of a tag's attribute. - */ - public void setAttribute(String name, String value) { - attributes.put(name.toLowerCase(), value); - } - - public StringBuffer getURLs() { - StringBuffer sb = new StringBuffer(); - - Iterator attributeNames = attributes.keySet().iterator(); - Iterator attributeValues = attributes.values().iterator(); - while (attributeNames.hasNext()) { - String attributeName = attributeNames.next(); - if (attributeName.compareTo("href") == 0 || attributeName.compareTo("src") == 0) { - String target = attributeValues.next(); - if (!target.endsWith(".jpg") && !target.endsWith(".gif") && !target.endsWith(".css") - && !target.endsWith(".js") && !target.startsWith("mailto") && target.lastIndexOf("#") == -1 - && target.length() > 0) { - - for (int i = 0; i < target.length(); i++) { - char ch = target.charAt(i); - if (!Character.isWhitespace(ch)) { - if (i > 0) - target = target.substring(i + 1); - break; - } - } - target = target.replace('\\', '/'); - - if (target.startsWith("news:") || (target.indexOf("://") != -1 && target.length() >= 7)) { - // Absolute URL - if (target.substring(0, 7).compareToIgnoreCase("http://") == 0) - sb.append(target); - } else { - // Relative URL - - String baseDir = baseUrl.getPath(); - int lastSep = -1; - for (int i = 0; i < baseDir.length(); i++) { - char ch = baseDir.charAt(i); - if (ch == '/') - lastSep = i; - else if (ch == '?') - break; - } - if (lastSep >= 0) - baseDir = baseDir.substring(0, lastSep); - while (baseDir.length() > 1 && baseDir.endsWith("/.")) { - baseDir = baseDir.substring(0, baseDir.length() - 2); - } - - if (target.startsWith("//")) { - sb.append(baseUrl.getProtocol() + ":" + target); - } else if (target.startsWith("/")) { - sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + target); - } else { - while (target.startsWith("../")) { - if (baseDir.length() > 0) { - // can't go above root - baseDir = baseDir.substring(0, baseDir.lastIndexOf("/")); - } - target = target.substring(3); - } - sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + baseDir + "/" + target); - } - } - } - } else { - attributeValues.next(); - } - } - - return sb; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append('<'); - if (isEndTag) - sb.append('/'); - sb.append(tagName); - Iterator keys = attributes.keySet().iterator(); - Iterator values = attributes.values().iterator(); - while (keys.hasNext()) { - String name = keys.next(); - sb.append(' '); - sb.append(name); - String value = values.next(); - if (value.length() > 0) { - sb.append("=\""); - sb.append(value); - sb.append('"'); - } - } - if(selfTerminating) { - sb.append('/'); - } - sb.append('>'); - - return sb.toString(); - } - - /** - * Enum class for tag types. - */ - public static class Type extends Tag { - public static final Tag UNKNOWN = new Tag(); - - public static final Tag THEAD = new Type("THEAD"); - - public static final Tag DOCTYPE = new Type("!DOCTYPE"); - - public static final Tag LABEL = new Type("LABEL"); - - private Type(String name) { - super(name); - } - } - - private static HashMap tags; - static { - tags = new HashMap(); - tags.put(new String("A"), Tag.A); - tags.put(new String("ADDRESS"), Tag.ADDRESS); - tags.put(new String("APPLET"), Tag.APPLET); - tags.put(new String("AREA"), Tag.AREA); - tags.put(new String("B"), Tag.B); - tags.put(new String("BASE"), Tag.BASE); - tags.put(new String("BASEFONT"), Tag.BASEFONT); - tags.put(new String("BIG"), Tag.BIG); - tags.put(new String("BLOCKQUOTE"), Tag.BLOCKQUOTE); - tags.put(new String("BODY"), Tag.BODY); - tags.put(new String("BR"), Tag.BR); - tags.put(new String("CAPTION"), Tag.CAPTION); - tags.put(new String("CENTER"), Tag.CENTER); - tags.put(new String("CITE"), Tag.CITE); - tags.put(new String("CODE"), Tag.CODE); - tags.put(new String("DD"), Tag.DD); - tags.put(new String("DFN"), Tag.DFN); - tags.put(new String("DIR"), Tag.DIR); - tags.put(new String("DIV"), Tag.DIV); - tags.put(new String("DL"), Tag.DL); - tags.put(new String("!DOCTYPE"), Type.DOCTYPE); - tags.put(new String("DT"), Tag.DT); - tags.put(new String("EM"), Tag.EM); - tags.put(new String("FONT"), Tag.FONT); - tags.put(new String("FORM"), Tag.FORM); - tags.put(new String("FRAME"), Tag.FRAME); - tags.put(new String("FRAMESET"), Tag.FRAMESET); - tags.put(new String("H1"), Tag.H1); - tags.put(new String("H2"), Tag.H2); - tags.put(new String("H3"), Tag.H3); - tags.put(new String("H4"), Tag.H4); - tags.put(new String("H5"), Tag.H5); - tags.put(new String("H6"), Tag.H6); - tags.put(new String("HEAD"), Tag.HEAD); - tags.put(new String("HTML"), Tag.HTML); - tags.put(new String("HR"), Tag.HR); - tags.put(new String("I"), Tag.I); - tags.put(new String("IMG"), Tag.IMG); - tags.put(new String("INPUT"), Tag.INPUT); - tags.put(new String("ISINDEX"), Tag.ISINDEX); - tags.put(new String("KBD"), Tag.KBD); - tags.put(new String("LI"), Tag.LI); - tags.put(new String("LABEL"), Type.LABEL); - tags.put(new String("LINK"), Tag.LINK); - tags.put(new String("MAP"), Tag.MAP); - tags.put(new String("MENU"), Tag.MENU); - tags.put(new String("META"), Tag.META); - tags.put(new String("NOFRAMES"), Tag.NOFRAMES); - tags.put(new String("OBJECT"), Tag.OBJECT); - tags.put(new String("OL"), Tag.OL); - tags.put(new String("OPTION"), Tag.OPTION); - tags.put(new String("P"), Tag.P); - tags.put(new String("PARAM"), Tag.PARAM); - tags.put(new String("PRE"), Tag.PRE); - tags.put(new String("S"), Tag.S); - tags.put(new String("SAMP"), Tag.SAMP); - tags.put(new String("SCRIPT"), Tag.SCRIPT); - tags.put(new String("SELECT"), Tag.SELECT); - tags.put(new String("SMALL"), Tag.SMALL); - tags.put(new String("STRONG"), Tag.STRONG); - tags.put(new String("STYLE"), Tag.STYLE); - tags.put(new String("SUB"), Tag.SUB); - tags.put(new String("SUP"), Tag.SUP); - tags.put(new String("TABLE"), Tag.TABLE); - tags.put(new String("TD"), Tag.TD); - tags.put(new String("TEXTAREA"), Tag.TEXTAREA); - tags.put(new String("TH"), Tag.TH); - tags.put(new String("THEAD"), Type.THEAD); - tags.put(new String("TITLE"), Tag.TITLE); - tags.put(new String("TR"), Tag.TR); - tags.put(new String("TT"), Tag.TT); - tags.put(new String("U"), Tag.U); - tags.put(new String("UL"), Tag.UL); - tags.put(new String("VAR"), Tag.VAR); - } - - public void setSelfTerminating(boolean terminating) { - this.selfTerminating = terminating; - - } - - public boolean isSelfTerminating() { - return selfTerminating; - } -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesContentHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesContentHandler.java deleted file mode 100644 index d3f3274a0..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesContentHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ -package org.eclipse.mylar.tasks.core.util; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.mylar.internal.context.core.util.XmlStringConverter; -import org.eclipse.mylar.tasks.core.IRepositoryConstants; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Adapted from SaxContextContentHandler - * - * @author Rob Elves - */ -public class SaxRepositoriesContentHandler extends DefaultHandler { - - - static final String ATTRIBUTE_INTERACTION_EVENT = "InteractionEvent"; - - private Set taskRepositories = new HashSet(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - try { - if (localName.equals(TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY) && attributes != null) { - String kind = XmlStringConverter.convertXmlToString(attributes - .getValue(IRepositoryConstants.PROPERTY_KIND)); - String url = XmlStringConverter.convertXmlToString(attributes - .getValue(IRepositoryConstants.PROPERTY_URL)); - if (kind != null && kind.length() > 0 && url != null && url.length() > 0) { - TaskRepository repository = new TaskRepository(kind, url); - for (int index = 0; index < attributes.getLength(); index++) { - String key = XmlStringConverter.convertXmlToString(attributes.getLocalName(index)); - String value = XmlStringConverter.convertXmlToString(attributes.getValue(index)); - repository.setProperty(key, value); - } - taskRepositories.add(repository); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - public Set getRepositories() { - return taskRepositories; - } -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesWriter.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesWriter.java deleted file mode 100644 index 5fd2f31f7..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/SaxRepositoriesWriter.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.core.util; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamResult; - -import org.eclipse.mylar.context.core.MylarStatusHandler; -import org.eclipse.mylar.internal.context.core.util.XmlStringConverter; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.xml.sax.ContentHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Adapted from SaxContextWriter - * - * @author Rob Elves - */ -public class SaxRepositoriesWriter { - - private OutputStream outputStream; - - public void setOutputStream(OutputStream outputStream) { - this.outputStream = outputStream; - } - - public void writeRepositoriesToStream(Collection repositories) throws IOException { - if (outputStream == null) { - IOException ioe = new IOException("OutputStream not set"); - throw ioe; - } - - try { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.transform( - new SAXSource(new RepositoriesWriter(), new TaskRepositoriesInputSource(repositories)), - new StreamResult(outputStream)); - } catch (TransformerException e) { - MylarStatusHandler.fail(e, "could not write repositories", false); - throw new IOException(e.getMessage()); - } - - } - - private static class TaskRepositoriesInputSource extends InputSource { - private Collection repositories; - - public TaskRepositoriesInputSource(Collection repositories) { - this.repositories = repositories; - } - - public Collection getRepositories() { - return this.repositories; - } - - } - - private static class RepositoriesWriter implements XMLReader { - -// private static final String ELEMENT_TASK_REPOSITORIES = "TaskRepositories"; -// -// public static final String ELEMENT_TASK_REPOSITORY = "TaskRepository"; -// -// private static final String ATTRIBUTE_VERSION = "xmlVersion"; - -// private static final String ATTRIBUTE_URL = "Url"; -// -// private static final String ATTRIBUTE_KIND = "Kind"; - - private ContentHandler handler; - - private ErrorHandler errorHandler; - - public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - return false; - } - - public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { - - } - - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - return null; - } - - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { - } - - public void setEntityResolver(EntityResolver resolver) { - } - - public EntityResolver getEntityResolver() { - return null; - } - - public void setDTDHandler(DTDHandler handler) { - } - - public DTDHandler getDTDHandler() { - return null; - } - - public void setContentHandler(ContentHandler handler) { - this.handler = handler; - - } - - public ContentHandler getContentHandler() { - return handler; - } - - public void setErrorHandler(ErrorHandler handler) { - this.errorHandler = handler; - - } - - public ErrorHandler getErrorHandler() { - return errorHandler; - } - - public void parse(InputSource input) throws IOException, SAXException { - if (!(input instanceof TaskRepositoriesInputSource)) { - throw new SAXException("Can only parse writable input sources"); - } - - Collection repositories = ((TaskRepositoriesInputSource) input).getRepositories(); - - handler.startDocument(); - AttributesImpl rootAttributes = new AttributesImpl(); - rootAttributes.addAttribute("", TaskRepositoriesExternalizer.ATTRIBUTE_VERSION, TaskRepositoriesExternalizer.ATTRIBUTE_VERSION, "", "1"); - - handler.startElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, rootAttributes); - - for (TaskRepository repository : new ArrayList(repositories)) { - - AttributesImpl ieAttributes = new AttributesImpl(); - for (String key : repository.getProperties().keySet()) { - ieAttributes.addAttribute("", key, key, "", XmlStringConverter.convertToXmlString(repository - .getProperties().get(key))); - } - - handler.startElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, ieAttributes); - handler.endElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY); - } - handler.endElement("", TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES, TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORIES); - - handler.endDocument(); - } - - public void parse(String systemId) throws IOException, SAXException { - throw new SAXException("Can only parse writable input sources"); - } - - } -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/TaskRepositoriesExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/TaskRepositoriesExternalizer.java deleted file mode 100644 index 2401d3151..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/util/TaskRepositoriesExternalizer.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.core.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Collection; -import java.util.Set; - -import org.eclipse.mylar.context.core.MylarStatusHandler; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -/** - * Adapted from MylarContextExternalizer - * - * @author Rob Elves - */ -public class TaskRepositoriesExternalizer { - - private SaxRepositoriesWriter writer = new SaxRepositoriesWriter(); - - public static final String ELEMENT_TASK_REPOSITORIES = "TaskRepositories"; - - public static final String ELEMENT_TASK_REPOSITORY = "TaskRepository"; - - public static final String ATTRIBUTE_VERSION = "OutputVersion"; - - public void writeRepositoriesToXML(Collection repositories, File file) { - if (repositories.isEmpty()) - return; - try { - if (!file.exists()) - file.createNewFile(); - OutputStream stream = new FileOutputStream(file); - writer.setOutputStream(stream); - writer.writeRepositoriesToStream(repositories); - stream.close(); - } catch (IOException e) { - MylarStatusHandler.fail(e, "Could not write: " + file.getAbsolutePath(), true); - } - } - - public Set readRepositoriesFromXML(File file) { - - if (!file.exists()) - return null; - try { - SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler(); - XMLReader reader = XMLReaderFactory.createXMLReader(); - reader.setContentHandler(contentHandler); - reader.parse(new InputSource(new FileInputStream(file))); - return contentHandler.getRepositories(); - } catch (Exception e) { - file.renameTo(new File(file.getAbsolutePath() + "-save")); - return null; - } - } -} diff --git a/org.eclipse.mylyn.tasks.tests/plugin.xml b/org.eclipse.mylyn.tasks.tests/plugin.xml index 6f104dd0d..4ccc91e0d 100644 --- a/org.eclipse.mylyn.tasks.tests/plugin.xml +++ b/org.eclipse.mylyn.tasks.tests/plugin.xml @@ -8,12 +8,12 @@ point="org.eclipse.mylar.tasks.ui.repositories"> diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java index cb4bba854..09b271ed5 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java @@ -13,7 +13,7 @@ import junit.framework.TestCase; import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage; import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryConnector; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryConnector; import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java index b55ed858a..a9796e93c 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java @@ -21,9 +21,9 @@ import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask.RepositoryTaskSyncState; -import org.eclipse.mylar.tasks.tests.mockconnector.MockAttributeFactory; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryConnector; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryTask; +import org.eclipse.mylar.tasks.tests.connector.MockAttributeFactory; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryConnector; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryTask; /** * @author Rob Elves diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java index 8ef221974..d66945130 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java @@ -14,7 +14,7 @@ import java.io.File; import org.eclipse.mylar.context.core.InteractionEvent; import org.eclipse.mylar.context.core.ContextCorePlugin; -import org.eclipse.mylar.core.tests.AbstractContextTest; +import org.eclipse.mylar.core.core.tests.AbstractContextTest; import org.eclipse.mylar.internal.context.core.MylarContext; import org.eclipse.mylar.internal.context.core.MylarContextManager; import org.eclipse.mylar.internal.tasks.ui.wizards.TaskDataExportWizard; diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java index 39817615e..947e100b8 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java @@ -14,7 +14,7 @@ import java.io.File; import java.util.Collection; import org.eclipse.mylar.context.core.ContextCorePlugin; -import org.eclipse.mylar.core.tests.AbstractContextTest; +import org.eclipse.mylar.core.core.tests.AbstractContextTest; import org.eclipse.mylar.internal.context.core.MylarContext; import org.eclipse.mylar.internal.tasks.ui.wizards.TaskDataImportWizard; import org.eclipse.mylar.internal.tasks.ui.wizards.TaskDataImportWizardPage; diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java index 0ff8472fc..3765dd565 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java @@ -43,10 +43,10 @@ import org.eclipse.mylar.tasks.core.Task; import org.eclipse.mylar.tasks.core.TaskCategory; import org.eclipse.mylar.tasks.core.TaskList; import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.tests.mockconnector.MockQueryHit; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryConnector; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryQuery; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryTask; +import org.eclipse.mylar.tasks.tests.connector.MockQueryHit; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryConnector; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryQuery; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryTask; import org.eclipse.mylar.tasks.ui.TaskListManager; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListStandaloneTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListStandaloneTest.java index 6bd9d0467..7ab66be2c 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListStandaloneTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListStandaloneTest.java @@ -54,7 +54,7 @@ public class TaskListStandaloneTest extends TestCase { file = new File("foo" + TasksUiPlugin.FILE_EXTENSION); file.deleteOnExit(); - manager = new TaskListManager(writer, file, 1); + manager = new TaskListManager(writer, file); manager.resetTaskList(); assertEquals("should be empty: " + manager.getTaskList().getRootTasks(), 0, manager.getTaskList() .getRootTasks().size()); diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoriesExternalizerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoriesExternalizerTest.java index 0614ff180..eb47c4dc1 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoriesExternalizerTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoriesExternalizerTest.java @@ -17,8 +17,8 @@ import java.util.Set; import junit.framework.TestCase; +import org.eclipse.mylar.internal.tasks.core.TaskRepositoriesExternalizer; import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.core.util.TaskRepositoriesExternalizer; /** * @author Rob Elves diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java index 0504ef7fa..15d732d8e 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java @@ -22,7 +22,7 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.tests.mockconnector.MockRepositoryConnector; +import org.eclipse.mylar.tasks.tests.connector.MockRepositoryConnector; import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.ui.TaskRepositoryManager; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java new file mode 100644 index 000000000..831ac5dd0 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 Mylar committers and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import org.eclipse.mylar.tasks.core.AbstractAttributeFactory; + + + +/** + * @author Rob Elves + */ +public class MockAttributeFactory extends AbstractAttributeFactory { + + private static final long serialVersionUID = 7713746838934802731L; + + @Override + public boolean getIsHidden(String key) { + // ignore + return false; + } + + @Override + public String getName(String key) { + // ignore + return key; + } + + @Override + public boolean isReadOnly(String key) { + // ignore + return false; + } + + @Override + public String mapCommonAttributeKey(String key) { + return key; + } + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java new file mode 100644 index 000000000..084060bfe --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 Mylar committers and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import org.eclipse.mylar.tasks.core.AbstractQueryHit; +import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; + +/** + * @author Rob Elves + */ +public class MockQueryHit extends AbstractQueryHit { + + AbstractRepositoryTask task = null; + + public MockQueryHit(String repositoryUrl, String description, String id) { + super(repositoryUrl, description, id); + } + + @Override + public AbstractRepositoryTask getCorrespondingTask() { + return task; + } + + @Override + public AbstractRepositoryTask getOrCreateCorrespondingTask() { + return task; + } + + @Override + public boolean isCompleted() { + return task.isCompleted(); + } + + @Override + public void setCorrespondingTask(AbstractRepositoryTask task) { + this.task = task; + } + + public String getDescription() { + return task.getDescription(); + } + + public String getPriority() { + return task.getPriority(); + } + + public void setHandleIdentifier(String id) { + // ignore + } + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java new file mode 100644 index 000000000..ec1ae5465 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage; +import org.eclipse.mylar.tasks.core.AbstractQueryHit; +import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; +import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; +import org.eclipse.mylar.tasks.core.IAttachmentHandler; +import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; +import org.eclipse.mylar.tasks.core.ITask; +import org.eclipse.mylar.tasks.core.TaskRepository; +import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector; + +/** + * @author Mik Kersten + * @author Rob Elves + */ +public class MockRepositoryConnector extends AbstractRepositoryConnector { + + public static final String REPOSITORY_TYPE = "mock"; + + @Override + public boolean canCreateNewTask() { + // ignore + return false; + } + + @Override + public boolean canCreateTaskFromKey() { + // ignore + return false; + } + + @Override + public ITask createTaskFromExistingKey(TaskRepository repository, String id) { + // ignore + return null; + } + + @Override + public Wizard getAddExistingTaskWizard(TaskRepository repository) { + // ignore + return null; + } + + @Override + public IAttachmentHandler getAttachmentHandler() { + // ignore + return null; + } + + @Override + public Set getChangedSinceLastSync(TaskRepository repository, Set tasks) throws Exception { + // ignore + return null; + } + + @Override + public String getLabel() { + return "Mock Repository (for unit tests)"; + } + + @Override + public IWizard getNewQueryWizard(TaskRepository repository, IStructuredSelection selection) { + // ignore + return null; + } + + @Override + public IWizard getNewTaskWizard(TaskRepository taskRepository, IStructuredSelection selection) { + // ignore + return null; + } + + @Override + public IOfflineTaskHandler getOfflineTaskHandler() { + // ignore + return null; + } + + @Override + public String getRepositoryType() { + return REPOSITORY_TYPE; + } + + @Override + public String getRepositoryUrlFromTaskUrl(String url) { + // ignore + return null; + } + + @Override + public AbstractRepositorySettingsPage getSettingsPage() { + // ignore + return null; + } + + @Override + public List getSupportedVersions() { + // ignore + return null; + } + + @Override + public void openEditQueryDialog(AbstractRepositoryQuery query) { + // ignore + } + + @Override + public List performQuery(AbstractRepositoryQuery query, IProgressMonitor monitor, MultiStatus queryStatus) { + return null; + } + + @Override + protected void updateTaskState(AbstractRepositoryTask repositoryTask) { + // ignore + } + + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java new file mode 100644 index 000000000..abcc319a5 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import org.eclipse.mylar.tasks.core.AbstractQueryHit; +import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; +import org.eclipse.mylar.tasks.core.DelegatingTaskExternalizer; +import org.eclipse.mylar.tasks.core.ITask; +import org.w3c.dom.Node; + +/** + * @author Mik Kersten + */ +public class MockRepositoryExternalizer extends DelegatingTaskExternalizer { + + @Override + public boolean canCreateElementFor(AbstractRepositoryQuery query) { + return query instanceof MockRepositoryQuery; + } + + @Override + public boolean canCreateElementFor(ITask task) { + return task instanceof MockRepositoryTask; + } + + @Override + public boolean canCreateElementFor(AbstractQueryHit queryHit) { + return false; + } + + @Override + public boolean canReadCategory(Node node) { + return false; + } + + @Override + public boolean canReadQuery(Node node) { + return false; + } + + @Override + public boolean canReadQueryHit(Node node) { + return false; + } + + @Override + public boolean canReadTask(Node node) { + return false; + } + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryQuery.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryQuery.java new file mode 100644 index 000000000..66d6d09c0 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryQuery.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; +import org.eclipse.mylar.tasks.core.TaskList; + +/** + * @author Mik Kersten + */ +public class MockRepositoryQuery extends AbstractRepositoryQuery { + + public MockRepositoryQuery(String description, TaskList taskList) { + super(description, taskList); + } + + @Override + public String getRepositoryKind() { + return "mock"; + } + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryTask.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryTask.java new file mode 100644 index 000000000..0acae7507 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryTask.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.tasks.tests.connector; + +import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; + +/** + * @author Mik Kersten + */ +public class MockRepositoryTask extends AbstractRepositoryTask { + + public MockRepositoryTask(String handle) { + super(handle, "label for " + handle, true); + } + + @Override + public String getRepositoryKind() { + return "mock"; + } + + @Override + public boolean isDownloaded() { + return false; + } + + @Override + public boolean isPersistentInWorkspace() { + return false; + } + +} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockAttributeFactory.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockAttributeFactory.java deleted file mode 100644 index 3d6d0b96a..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockAttributeFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 Mylar committers and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import org.eclipse.mylar.tasks.core.AbstractAttributeFactory; - - - -/** - * @author Rob Elves - */ -public class MockAttributeFactory extends AbstractAttributeFactory { - - private static final long serialVersionUID = 7713746838934802731L; - - @Override - public boolean getIsHidden(String key) { - // ignore - return false; - } - - @Override - public String getName(String key) { - // ignore - return key; - } - - @Override - public boolean isReadOnly(String key) { - // ignore - return false; - } - - @Override - public String mapCommonAttributeKey(String key) { - return key; - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockQueryHit.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockQueryHit.java deleted file mode 100644 index d2367337f..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockQueryHit.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 Mylar committers and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; - -/** - * @author Rob Elves - */ -public class MockQueryHit extends AbstractQueryHit { - - AbstractRepositoryTask task = null; - - public MockQueryHit(String repositoryUrl, String description, String id) { - super(repositoryUrl, description, id); - } - - @Override - public AbstractRepositoryTask getCorrespondingTask() { - return task; - } - - @Override - public AbstractRepositoryTask getOrCreateCorrespondingTask() { - return task; - } - - @Override - public boolean isCompleted() { - return task.isCompleted(); - } - - @Override - public void setCorrespondingTask(AbstractRepositoryTask task) { - this.task = task; - } - - public String getDescription() { - return task.getDescription(); - } - - public String getPriority() { - return task.getPriority(); - } - - public void setHandleIdentifier(String id) { - // ignore - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryConnector.java deleted file mode 100644 index 33bbc5f45..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryConnector.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage; -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; -import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; -import org.eclipse.mylar.tasks.core.IAttachmentHandler; -import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; -import org.eclipse.mylar.tasks.core.ITask; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector; - -/** - * @author Mik Kersten - * @author Rob Elves - */ -public class MockRepositoryConnector extends AbstractRepositoryConnector { - - public static final String REPOSITORY_TYPE = "mock"; - - @Override - public boolean canCreateNewTask() { - // ignore - return false; - } - - @Override - public boolean canCreateTaskFromKey() { - // ignore - return false; - } - - @Override - public ITask createTaskFromExistingKey(TaskRepository repository, String id) { - // ignore - return null; - } - - @Override - public Wizard getAddExistingTaskWizard(TaskRepository repository) { - // ignore - return null; - } - - @Override - public IAttachmentHandler getAttachmentHandler() { - // ignore - return null; - } - - @Override - public Set getChangedSinceLastSync(TaskRepository repository, Set tasks) throws Exception { - // ignore - return null; - } - - @Override - public String getLabel() { - return "Mock Repository (for unit tests)"; - } - - @Override - public IWizard getNewQueryWizard(TaskRepository repository, IStructuredSelection selection) { - // ignore - return null; - } - - @Override - public IWizard getNewTaskWizard(TaskRepository taskRepository, IStructuredSelection selection) { - // ignore - return null; - } - - @Override - public IOfflineTaskHandler getOfflineTaskHandler() { - // ignore - return null; - } - - @Override - public String getRepositoryType() { - return REPOSITORY_TYPE; - } - - @Override - public String getRepositoryUrlFromTaskUrl(String url) { - // ignore - return null; - } - - @Override - public AbstractRepositorySettingsPage getSettingsPage() { - // ignore - return null; - } - - @Override - public List getSupportedVersions() { - // ignore - return null; - } - - @Override - public void openEditQueryDialog(AbstractRepositoryQuery query) { - // ignore - } - - @Override - public List performQuery(AbstractRepositoryQuery query, IProgressMonitor monitor, MultiStatus queryStatus) { - return null; - } - - @Override - protected void updateTaskState(AbstractRepositoryTask repositoryTask) { - // ignore - } - - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryExternalizer.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryExternalizer.java deleted file mode 100644 index 57f818ce0..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryExternalizer.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; -import org.eclipse.mylar.tasks.core.DelegatingTaskExternalizer; -import org.eclipse.mylar.tasks.core.ITask; -import org.w3c.dom.Node; - -/** - * @author Mik Kersten - */ -public class MockRepositoryExternalizer extends DelegatingTaskExternalizer { - - @Override - public boolean canCreateElementFor(AbstractRepositoryQuery query) { - return query instanceof MockRepositoryQuery; - } - - @Override - public boolean canCreateElementFor(ITask task) { - return task instanceof MockRepositoryTask; - } - - @Override - public boolean canCreateElementFor(AbstractQueryHit queryHit) { - return false; - } - - @Override - public boolean canReadCategory(Node node) { - return false; - } - - @Override - public boolean canReadQuery(Node node) { - return false; - } - - @Override - public boolean canReadQueryHit(Node node) { - return false; - } - - @Override - public boolean canReadTask(Node node) { - return false; - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryQuery.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryQuery.java deleted file mode 100644 index 89dc79b52..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryQuery.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; -import org.eclipse.mylar.tasks.core.TaskList; - -/** - * @author Mik Kersten - */ -public class MockRepositoryQuery extends AbstractRepositoryQuery { - - public MockRepositoryQuery(String description, TaskList taskList) { - super(description, taskList); - } - - @Override - public String getRepositoryKind() { - return "mock"; - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryTask.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryTask.java deleted file mode 100644 index eefd29796..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/mockconnector/MockRepositoryTask.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.tests.mockconnector; - -import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; - -/** - * @author Mik Kersten - */ -public class MockRepositoryTask extends AbstractRepositoryTask { - - public MockRepositoryTask(String handle) { - super(handle, "label for " + handle, true); - } - - @Override - public String getRepositoryKind() { - return "mock"; - } - - @Override - public boolean isDownloaded() { - return false; - } - - @Override - public boolean isPersistentInWorkspace() { - return false; - } - -} -- cgit v1.2.3