diff options
author | Frank Becker | 2012-01-18 18:46:37 +0000 |
---|---|---|
committer | Frank Becker | 2012-01-18 18:51:00 +0000 |
commit | 80ebd9ccbf1507bbe4ed81ef7edca1cb0926c428 (patch) | |
tree | 03a6018349b6e0480e6fe0c58d0d3ff03ab602b5 /org.eclipse.mylyn.bugzilla.core | |
parent | 0edb11b0e15636413f17b8e127a801f4fe8e20e8 (diff) | |
download | org.eclipse.mylyn.tasks-80ebd9ccbf1507bbe4ed81ef7edca1cb0926c428.tar.gz org.eclipse.mylyn.tasks-80ebd9ccbf1507bbe4ed81ef7edca1cb0926c428.tar.xz org.eclipse.mylyn.tasks-80ebd9ccbf1507bbe4ed81ef7edca1cb0926c428.zip |
ASSIGNED - bug 168204: [patch] support bugzilla's usermatchmode for
matching names to email addresses
https://bugs.eclipse.org/bugs/show_bug.cgi?id=168204
Change-Id: I32f702fa7e973c3f31c8609bea53c31d99cff2b4
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
5 files changed, 391 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java index 948fdabd7..e96d286e3 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java @@ -2015,6 +2015,35 @@ public class BugzillaClient { } } + for (Iterator<String> iterator = bugzillaLanguageSettings.getResponseForCommand( + BugzillaLanguageSettings.COMMAND_ERROR_CONFIRM_MATCH).iterator(); iterator.hasNext() + && !found;) { + String value = iterator.next().toLowerCase(Locale.ENGLISH); + found = found || title.indexOf(value) != -1; + } + if (found) { + BugzillaVersion bugzillaVersion = null; + if (repositoryConfiguration != null) { + bugzillaVersion = repositoryConfiguration.getInstallVersion(); + } else { + bugzillaVersion = BugzillaVersion.MIN_VERSION; + } + BugzillaUserMatchResponse matchResponse = new BugzillaUserMatchResponse(); + matchResponse.parseResultConfirmMatch(tokenizer, repositoryUrl.toString(), body, + bugzillaVersion.isSmaller(BugzillaVersion.BUGZILLA_4_0)); + } + + found = false; + for (Iterator<String> iterator = bugzillaLanguageSettings.getResponseForCommand( + BugzillaLanguageSettings.COMMAND_ERROR_MATCH_FAILED).iterator(); iterator.hasNext() + && !found;) { + String value = iterator.next().toLowerCase(Locale.ENGLISH); + found = found || title.indexOf(value) != -1; + } + if (found) { + BugzillaUserMatchResponse matchResponse = new BugzillaUserMatchResponse(); + matchResponse.parseResultMatchFailed(tokenizer, repositoryUrl.toString(), body); + } isTitle = false; } } else { diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaLanguageSettings.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaLanguageSettings.java index 214410b5e..e14a0f687 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaLanguageSettings.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaLanguageSettings.java @@ -46,6 +46,10 @@ public class BugzillaLanguageSettings { public static final String COMMAND_SUBMITTED = "submitted"; //$NON-NLS-1$ + public static final String COMMAND_ERROR_CONFIRM_MATCH = "error_confirm_match"; //$NON-NLS-1$ + + public static final String COMMAND_ERROR_MATCH_FAILED = "error_match_failed"; //$NON-NLS-1$ + private final Map<String, List<String>> languageAttributes = new LinkedHashMap<String, List<String>>(); public BugzillaLanguageSettings(String languageName) { diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java index bd59cdf71..83eacf15c 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java @@ -131,6 +131,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { enSetting.addLanguageAttribute("submitted", "Submitted"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("submitted", "posted"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("suspicious_action", "Suspicious action"); //$NON-NLS-1$ //$NON-NLS-2$ + enSetting.addLanguageAttribute("error_confirm_match", "confirm match"); //$NON-NLS-1$//$NON-NLS-2$ + enSetting.addLanguageAttribute("error_match_failed", "match failed"); //$NON-NLS-1$ //$NON-NLS-2$ languages.add(enSetting); java2buzillaPlatformMap.put("x86", "PC"); // can be PC or Macintosh! //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaStatus.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaStatus.java index 344f658cc..ab40d7e1d 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaStatus.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaStatus.java @@ -24,26 +24,42 @@ public class BugzillaStatus extends Status { private String repositoryUrl = ""; //$NON-NLS-1$ + public final static int ERROR_CONFIRM_MATCH = 1024; + + public final static int ERROR_MATCH_FAILED = 1025; + + private final String htmlMessage; + + private final BugzillaUserMatchResponse userMatchResponse; + public BugzillaStatus(int severity, String pluginId, int code) { super(severity, pluginId, code, "MylynStatus", null); //$NON-NLS-1$ this.errorMessage = null; + this.htmlMessage = null; + this.userMatchResponse = null; } public BugzillaStatus(int severity, String pluginId, int code, String errorMessage) { super(severity, pluginId, code, "MylynStatus", null); //$NON-NLS-1$ this.errorMessage = errorMessage; + this.htmlMessage = null; + this.userMatchResponse = null; } public BugzillaStatus(int severity, String pluginId, int code, String repositoryUrl, Throwable e) { super(severity, pluginId, code, "MylynStatus", e); //$NON-NLS-1$ this.repositoryUrl = repositoryUrl; this.errorMessage = e.getMessage(); + this.htmlMessage = null; + this.userMatchResponse = null; } public BugzillaStatus(int severity, String pluginId, int code, String repositoryUrl, String errorMessage) { super(severity, pluginId, code, "MylynStatus", null); //$NON-NLS-1$ this.errorMessage = errorMessage; this.repositoryUrl = repositoryUrl; + this.htmlMessage = null; + this.userMatchResponse = null; } public BugzillaStatus(int severity, String pluginId, int code, String repositoryUrl, String errorMessage, @@ -51,6 +67,26 @@ public class BugzillaStatus extends Status { super(severity, pluginId, code, "MylynStatus", e); //$NON-NLS-1$ this.errorMessage = errorMessage; this.repositoryUrl = repositoryUrl; + this.htmlMessage = null; + this.userMatchResponse = null; + } + + public BugzillaStatus(int severity, String pluginId, int code, String repositoryUrl, String errorMessage, + String body) { + super(severity, pluginId, code, "MylynStatus", null); //$NON-NLS-1$ + this.errorMessage = errorMessage; + this.repositoryUrl = repositoryUrl; + this.htmlMessage = body; + this.userMatchResponse = null; + } + + public BugzillaStatus(int severity, String pluginId, int code, String repositoryUrl, String errorMessage, + String body, BugzillaUserMatchResponse userMatchResponse) { + super(severity, pluginId, code, "MylynStatus", null); //$NON-NLS-1$ + this.errorMessage = errorMessage; + this.repositoryUrl = repositoryUrl; + this.htmlMessage = body; + this.userMatchResponse = userMatchResponse; } /** @@ -112,4 +148,12 @@ public class BugzillaStatus extends Status { public void setRepositoryUrl(String repositoryUrl) { this.repositoryUrl = repositoryUrl; } + + public String getHtmlMessage() { + return htmlMessage; + } + + public BugzillaUserMatchResponse getUserMatchResponse() { + return userMatchResponse; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaUserMatchResponse.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaUserMatchResponse.java new file mode 100644 index 000000000..e35eb2dde --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaUserMatchResponse.java @@ -0,0 +1,312 @@ +/******************************************************************************* + * Copyright (c) 2011 Tasktop Technologies 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.core; + +import java.io.IOException; +import java.text.ParseException; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.text.html.HTML.Tag; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer; +import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token; +import org.eclipse.mylyn.commons.net.HtmlTag; +import org.eclipse.mylyn.tasks.core.RepositoryStatus; + +public class BugzillaUserMatchResponse { + private final List<String> newCCProposals = new LinkedList<String>(); + + private final List<String> assignedToProposals = new LinkedList<String>(); + + private final List<String> qaContactProposals = new LinkedList<String>(); + + private String newCCMsg; + + private String assignedToMsg; + + private String qaContactMsg; + + public List<String> getNewCCProposals() { + return newCCProposals; + } + + public List<String> getAssignedToProposals() { + return assignedToProposals; + } + + public List<String> getQaContactProposals() { + return qaContactProposals; + } + + public String getNewCCMsg() { + return newCCMsg; + } + + public String getAssignedToMsg() { + return assignedToMsg; + } + + public String getQaContactMsg() { + return qaContactMsg; + } + + public void parseResultConfirmMatch(HtmlStreamTokenizer tokenizer, String repositoryURL, String body, + boolean oldStyle) throws IOException, CoreException { + if (oldStyle) { + parseConfirmMatchOld(tokenizer, repositoryURL, body); + } else { + parseConfirmMatchNew(tokenizer, repositoryURL, body); + } + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + BugzillaStatus.ERROR_CONFIRM_MATCH, repositoryURL, "Confirm Match", body, this)); //$NON-NLS-1$ + } + + private void parseConfirmMatchNew(HtmlStreamTokenizer tokenizer, String repositoryURL, String body) + throws IOException, CoreException { + String name = ""; //$NON-NLS-1$ + String value = ""; //$NON-NLS-1$ + String divClass = null; + try { + for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) { + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && !((HtmlTag) (token.getValue())).isEndTag()) { + divClass = ((HtmlTag) (token.getValue())).getAttribute("class"); //$NON-NLS-1$ + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && ((HtmlTag) (token.getValue())).isEndTag()) { + divClass = null; + } + + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.INPUT + && !((HtmlTag) (token.getValue())).isEndTag() && divClass != null + && divClass.equals("user_match")) { //$NON-NLS-1$ + value = ((HtmlTag) (token.getValue())).getAttribute("value"); //$NON-NLS-1$ + name = ((HtmlTag) (token.getValue())).getAttribute("name"); //$NON-NLS-1$ + if (name.equals("newcc")) { //$NON-NLS-1$ + newCCProposals.add(value); + } else if (name.equals("assigned_to")) { //$NON-NLS-1$ + assignedToProposals.add(value); + } else if (name.equals("qa_contact")) { //$NON-NLS-1$ + qaContactProposals.add(value); + } + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.SELECT + && !((HtmlTag) (token.getValue())).isEndTag()) { + name = ((HtmlTag) (token.getValue())).getAttribute("id"); //$NON-NLS-1$ + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.OPTION + && !((HtmlTag) (token.getValue())).isEndTag() && divClass != null + && divClass.equals("user_match")) { //$NON-NLS-1$ + value = ((HtmlTag) (token.getValue())).getAttribute("value"); //$NON-NLS-1$ + if (name.equals("newcc")) { //$NON-NLS-1$ + newCCProposals.add(value); + } else if (name.equals("assigned_to")) { //$NON-NLS-1$ + assignedToProposals.add(value); + } else if (name.equals("qa_contact")) { //$NON-NLS-1$ + qaContactProposals.add(value); + } + } + } + } catch (ParseException e) { + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_INTERNAL, "Unable to parse response from " + repositoryURL + ".")); //$NON-NLS-1$//$NON-NLS-2$ + } + } + + private void parseConfirmMatchOld(HtmlStreamTokenizer tokenizer, String repositoryURL, String body) + throws IOException, CoreException { + boolean isDT = false; + String dtString = ""; //$NON-NLS-1$ + String lastDTValue = ""; //$NON-NLS-1$ + boolean isDiv = false; + String divString = ""; //$NON-NLS-1$ + try { + for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) { + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.TD + && ((HtmlTag) (token.getValue())).isEndTag()) { + isDT = false; + if (!dtString.equals("")) { //$NON-NLS-1$ + lastDTValue = dtString; + } + dtString = ""; //$NON-NLS-1$ + continue; + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && ((HtmlTag) (token.getValue())).isEndTag()) { + isDiv = false; + if (divString.length() > 4) { + if (lastDTValue.equals("CC:")) { //$NON-NLS-1$ + lastDTValue = "newcc"; //$NON-NLS-1$ + } + if (lastDTValue.equals("Assignee:")) { //$NON-NLS-1$ + lastDTValue = "assigned_to"; //$NON-NLS-1$ + } + if (lastDTValue.equals("QAContact:")) { //$NON-NLS-1$ + lastDTValue = "qa_contact"; //$NON-NLS-1$ + } + + int start = divString.indexOf("</b>"); //$NON-NLS-1$ + int optionValue = divString.indexOf("<option value=\"", start + 4); //$NON-NLS-1$ + String value = ""; //$NON-NLS-1$ + if (optionValue == -1) { + int startText = divString.indexOf("<", start + 4) + 1; //$NON-NLS-1$ + int endText = divString.indexOf(">", startText + 1); //$NON-NLS-1$ + String temp = divString.substring(startText + 3, endText); + value = temp.replace("@", "@"); //$NON-NLS-1$ //$NON-NLS-2$ + if (lastDTValue.equals("newcc")) { //$NON-NLS-1$ + newCCProposals.add(value); + } else if (lastDTValue.equals("assigned_to")) { //$NON-NLS-1$ + assignedToProposals.add(value); + } else if (lastDTValue.equals("qa_contact")) { //$NON-NLS-1$ + qaContactProposals.add(value); + } + } else { + while (optionValue != -1) { + int endText = divString.indexOf("\">", optionValue + 1); //$NON-NLS-1$ + value = divString.substring(optionValue + 15, endText); + value = value.replace("@", "@"); //$NON-NLS-1$ //$NON-NLS-2$ + if (lastDTValue.equals("newcc")) { //$NON-NLS-1$ + newCCProposals.add(value); + } else if (lastDTValue.equals("assigned_to")) { //$NON-NLS-1$ + assignedToProposals.add(value); + } else if (lastDTValue.equals("qa_contact")) { //$NON-NLS-1$ + qaContactProposals.add(value); + } + optionValue = divString.indexOf("<option value=\"", endText + 1); //$NON-NLS-1$ + } + } + } + dtString = ""; //$NON-NLS-1$ + divString = ""; //$NON-NLS-1$ + continue; + } + if (isDiv) { + divString += (" " + token.getValue()); //$NON-NLS-1$ + } + if (isDT) { + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && !((HtmlTag) (token.getValue())).isEndTag()) { + isDiv = true; + divString = ""; //$NON-NLS-1$ + } else { + dtString += token.getValue(); + } + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.TD + && !((HtmlTag) (token.getValue())).isEndTag()) { + isDT = true; + continue; + } + } + } catch (ParseException e) { + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_INTERNAL, "Unable to parse response from " + repositoryURL + ".")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + } + + public void parseResultMatchFailed(HtmlStreamTokenizer tokenizer, String repositoryURL, String body) + throws IOException, CoreException { + boolean isDT = false; + String dtString = ""; //$NON-NLS-1$ + String lastDTValue = ""; //$NON-NLS-1$ + boolean isDiv = false; + String divString = ""; //$NON-NLS-1$ + try { + for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) { + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.TD + && ((HtmlTag) (token.getValue())).isEndTag()) { + isDT = false; + if (!dtString.equals("")) { //$NON-NLS-1$ + lastDTValue = dtString; + } + dtString = ""; //$NON-NLS-1$ + continue; + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && ((HtmlTag) (token.getValue())).isEndTag()) { + isDiv = false; + if (divString.length() > 4) { + if (lastDTValue.equals("CC:")) { //$NON-NLS-1$ + lastDTValue = "newcc"; //$NON-NLS-1$ + } + if (lastDTValue.equals("Assignee:")) { //$NON-NLS-1$ + lastDTValue = "assigned_to"; //$NON-NLS-1$ + } + if (lastDTValue.equals("QAContact:")) { //$NON-NLS-1$ + lastDTValue = "qa_contact"; //$NON-NLS-1$ + } + + int start = divString.indexOf("</b>"); //$NON-NLS-1$ + int optionValue = divString.indexOf("<option value=\"", start + 4); //$NON-NLS-1$ + String value = ""; //$NON-NLS-1$ + if (optionValue == -1) { + int startText = divString.indexOf(">", start + 4) + 1; //$NON-NLS-1$ + int endText = divString.indexOf("<", startText + 1); //$NON-NLS-1$ + String temp = divString.substring(startText, endText); + value = divString.substring(5, start) + temp; + if (lastDTValue.equals("newcc")) { //$NON-NLS-1$ + newCCMsg = value; + } else if (lastDTValue.equals("assigned_to")) { //$NON-NLS-1$ + assignedToMsg = value; + } else if (lastDTValue.equals("qa_contact")) { //$NON-NLS-1$ + qaContactMsg = value; + } + } else { + while (optionValue != -1) { + int endText = divString.indexOf("\">", optionValue + 1); //$NON-NLS-1$ + value = divString.substring(optionValue + 15, endText); + value = value.replace("@", "@"); //$NON-NLS-1$ //$NON-NLS-2$ + if (lastDTValue.equals("newcc")) { //$NON-NLS-1$ + newCCProposals.add(value); + } else if (lastDTValue.equals("assigned_to")) { //$NON-NLS-1$ + assignedToProposals.add(value); + } else if (lastDTValue.equals("qa_contact")) { //$NON-NLS-1$ + qaContactProposals.add(value); + } + optionValue = divString.indexOf("<option value=\"", endText + 1); //$NON-NLS-1$ + } + } + } + dtString = ""; //$NON-NLS-1$ + divString = ""; //$NON-NLS-1$ + continue; + } + if (isDiv) { + divString += (" " + token.getValue()); //$NON-NLS-1$ + } + if (isDT) { + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.DIV + && !((HtmlTag) (token.getValue())).isEndTag()) { + isDiv = true; + divString = ""; //$NON-NLS-1$ + } else { + dtString += token.getValue(); + } + } + if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == Tag.TD + && !((HtmlTag) (token.getValue())).isEndTag()) { + isDT = true; + continue; + } + } + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + BugzillaStatus.ERROR_MATCH_FAILED, repositoryURL, "Match Failed", body, this)); + } catch (ParseException e) { + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_INTERNAL, "Unable to parse response from " + repositoryURL + ".")); //$NON-NLS-1$ //$NON-NLS-2$ + } + } +} |