01: package net.sf.saxon;
02:
03: /**
04: * Class containing utility methods for handling error messages
05: */
06:
07: public class Err {
08:
09: public static final int ELEMENT = 1;
10: public static final int ATTRIBUTE = 2;
11: public static final int FUNCTION = 3;
12: public static final int VALUE = 4;
13: public static final int VARIABLE = 5;
14: public static final int GENERAL = 6;
15: public static final int URI = 7;
16:
17: /**
18: * Add delimiters to represent variable information within an error message
19: * @param cs the variable information to be delimited
20: * @return the delimited variable information
21: */
22: public static String wrap(CharSequence cs) {
23: return wrap(cs, GENERAL);
24: }
25:
26: /**
27: * Add delimiters to represent variable information within an error message
28: * @param cs the variable information to be delimited
29: * @param valueType the type of value, e.g. element name or attribute name
30: * @return the delimited variable information
31: */
32: public static String wrap(CharSequence cs, int valueType) {
33: if (cs == null) {
34: return "(NULL)";
35: }
36: String s = cs.toString();
37: s = s.replace('\n', ' ');
38: s = s.replace('\t', ' ');
39: s = s.replace('\r', ' ');
40: if (s.length() > 30) {
41: if (valueType == URI) {
42: s = "..." + s.substring(s.length() - 30);
43: } else {
44: s = s.substring(0, 30) + "...";
45: }
46: }
47: switch (valueType) {
48: case ELEMENT:
49: return "<" + s + ">";
50: case ATTRIBUTE:
51: return "@" + s;
52: case FUNCTION:
53: return s + "()";
54: case VARIABLE:
55: return "$" + s;
56: case VALUE:
57: return "\"" + s + "\"";
58: default:
59: return "{" + s + "}";
60: }
61: }
62:
63: }
64: //
65: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
66: // you may not use this file except in compliance with the License. You may obtain a copy of the
67: // License at http://www.mozilla.org/MPL/
68: //
69: // Software distributed under the License is distributed on an "AS IS" basis,
70: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
71: // See the License for the specific language governing rights and limitations under the License.
72: //
73: // The Original Code is: all this file.
74: //
75: // The Initial Developer of the Original Code is Michael H. Kay.
76: //
77: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
78: //
79: // Contributor(s): none.
80: //
|