- if (res.indexOf('"') != -1 ||
- res.indexOf(' ') != -1 ||
- res.indexOf('\t') != -1 ||
- res.indexOf('=') != -1 ||
- res.indexOf('<') != -1 ||
- res.indexOf('>') != -1 ||
- res.indexOf('/') != -1 ||
- res.indexOf('(') != -1 ||
- res.indexOf(')') != -1) {
- res = '"' + res + '"';
+ String pos = "unanchored";
+ String text = term;
+ if (text.length() > 0 && text.substring(0, 1).equals("^")) {
+ text = text.substring(1);
+ pos = "anchored";
+ }
+ attr = config.getProperty("position." + pos);
+ if (attr == null)
+ throw new UnknownPositionException(pos);
+ attrs.add(attr);
+
+ attr = config.getProperty("structure." + rel);
+ if (attr == null)
+ attr = config.getProperty("structure.*");
+ attrs.add(attr);
+
+ attr = config.getProperty("always");
+ if (attr != null)
+ attrs.add(attr);
+
+ String s = "";
+ for (int i = 0; i < attrs.size(); i++) {
+ attr = (String) attrs.get(i);
+ s += "@attr " + Utils.replaceString(attr, " ", " @attr ") + " ";
+ }
+
+ return s + maybeQuote(text);
+ }
+
+ static String maybeQuote(String str) {
+ // There _must_ be a better way to make this test ...
+ if (str.length() == 0 ||
+ str.indexOf('"') != -1 ||
+ str.indexOf(' ') != -1 ||
+ str.indexOf('\t') != -1 ||
+ str.indexOf('=') != -1 ||
+ str.indexOf('<') != -1 ||
+ str.indexOf('>') != -1 ||
+ str.indexOf('/') != -1 ||
+ str.indexOf('(') != -1 ||
+ str.indexOf(')') != -1) {
+ str = '"' + Utils.replaceString(str, "\"", "\\\"") + '"';