blob: 101658342ca9b2a95914486b8caa26fbf23efdea (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*******************************************************************************
* Copyright (c) 2001, 2006 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsd.core.internal.validation.eclipse;
/**
* The XSDMessageInfoHelper creates a string with the
*/
public class XSDMessageInfoHelper
{
public XSDMessageInfoHelper()
{ super();
}
public String[] createMessageInfo(String errorKey, String errorMessage)
{
//Now map the error key to what we would want to underline:
String nameOrValue = "";
String selectionStrategy = "";
if(errorKey != null)
{
if (errorKey.equals("s4s-elt-invalid-content.1") || errorKey.equals("s4s-elt-must-match.1") ||
errorKey.equals("s4s-att-must-appear") || errorKey.equals("s4s-elt-invalid-content.2"))
{
selectionStrategy = "START_TAG";
}
else if (errorKey.equals("s4s-att-not-allowed"))
{
selectionStrategy = "ATTRIBUTE_NAME";
nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
}
else if (errorKey.equals("s4s-att-invalid-value"))
{
selectionStrategy = "ATTRIBUTE_VALUE";
nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
}
else if (errorKey.equals("s4s-elt-character"))
{
selectionStrategy = "TEXT";
}
else if (errorKey.equals("src-resolve.4.2") || errorKey.equals("src-resolve"))
{
selectionStrategy = "VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE";
nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
}
}
String messageInfo[] = new String[2];
messageInfo[0] = selectionStrategy;
messageInfo[1] = nameOrValue;
return messageInfo;
}
/**
* This method is used to get the value between the first pair of single quotes
* It is used to extract information from the error Message (for example
* an attribute name)
*
* @param s
* The string to extract the value from.
*/
protected String getFirstStringBetweenSingleQuotes(String s)
{
int first = s.indexOf("'");
int second = s.indexOf("'", first + 1);
String betweenQuotes = null;
if (first != -1 && second != -1)
{ betweenQuotes = s.substring(first + 1, second);
}
return betweenQuotes;
}
}
|