1 11 12 package org.eclipse.ant.internal.ui.editor.outline; 13 14 import org.eclipse.ant.internal.ui.model.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.text.Region; 18 19 public class XMLProblem extends Region implements IProblem { 20 21 public static final int NO_PROBLEM= -1; 22 public static final int SEVERITY_WARNING= 0; 23 public static final int SEVERITY_ERROR= 1; 24 public static final int SEVERITY_FATAL_ERROR= 2; 25 26 private String fMessage; 27 private String fEscapedMessage; 28 private int fSeverity; 29 private int fAdjustedLength= -1; 30 private int fLineNumber= -1; 31 32 public XMLProblem(String message, int severity, int offset, int length, int lineNumber) { 33 super(offset, length); 34 fMessage= message; 35 fEscapedMessage= getEscaped(message); 36 fSeverity= severity; 37 fLineNumber= lineNumber; 38 } 39 40 43 public String getMessage() { 44 return fEscapedMessage; 45 } 46 47 50 public boolean isError() { 51 return fSeverity == SEVERITY_ERROR || fSeverity == SEVERITY_FATAL_ERROR; 52 } 53 54 57 public boolean isWarning() { 58 return fSeverity == SEVERITY_WARNING; 59 } 60 61 64 public int getLength() { 65 if (fAdjustedLength != -1) { 66 return fAdjustedLength; 67 } 68 return super.getLength(); 69 } 70 71 74 public void setLength(int adjustedLength) { 75 fAdjustedLength= adjustedLength; 76 } 77 78 81 public int getLineNumber() { 82 return fLineNumber; 83 } 84 85 private void appendEscapedChar(StringBuffer buffer, char c) { 86 String replacement= getReplacement(c); 87 if (replacement != null) { 88 buffer.append(replacement); 89 } else { 90 buffer.append(c); 91 } 92 } 93 94 private String getEscaped(String s) { 95 StringBuffer result= new StringBuffer (s.length() + 10); 96 for (int i= 0; i < s.length(); ++i) { 97 appendEscapedChar(result, s.charAt(i)); 98 } 99 return result.toString(); 100 } 101 102 private String getReplacement(char c) { 103 switch (c) { 107 case '<' : 108 return "<"; case '>' : 110 return ">"; case '"' : 112 return """; case '\'' : 114 return "'"; case '&' : 116 return "&"; } 118 return null; 119 } 120 121 124 public String getUnmodifiedMessage() { 125 return fMessage; 126 } 127 128 public static int getSeverity(String preferenceKey) { 129 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 130 String severityLevel= store.getString(preferenceKey); 131 if (severityLevel.length() == 0 || severityLevel.equals(AntEditorPreferenceConstants.BUILDFILE_ERROR)) { 132 return SEVERITY_ERROR; 133 } else if (severityLevel.equals(AntEditorPreferenceConstants.BUILDFILE_WARNING)) { 134 return SEVERITY_WARNING; 135 } else { 136 return NO_PROBLEM; 137 } 138 } 139 140 143 public boolean equals(Object o) { 144 boolean equal= super.equals(o); 145 if (equal) { 146 return ((XMLProblem)o).getUnmodifiedMessage().equals(getUnmodifiedMessage()); 147 } 148 return false; 149 } 150 }
| Popular Tags
|