- /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
- private int partitionAttributes(int left, int right) {
- int i, j, middle;
- middle = (left + right) / 2;
- String s = t.keys[right]; t.keys[right] = t.keys[middle]; t.keys[middle] = s;
- Object o = t.vals[right]; t.vals[right] = t.vals[middle]; t.vals[middle] = o;
- for (i = left - 1, j = right; ; ) {
- while (t.keys[++i].compareTo(t.keys[right]) < 0);
- while (j > left && t.keys[--j].compareTo(t.keys[right]) > 0);
- if (i >= j) break;
- s = t.keys[i]; t.keys[i] = t.keys[j]; t.keys[j] = s;
- o = t.vals[i]; t.vals[i] = t.vals[j]; t.vals[j] = o;
- }
- s = t.keys[right]; t.keys[right] = t.keys[i]; t.keys[i] = s;
- o = t.vals[right]; t.vals[right] = t.vals[i]; t.vals[i] = o;
- return i;
- }
-
- /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
- private void quickSortAttributes(int left, int right) {
- if (left >= right) return;
- int p = partitionAttributes(left, right);
- quickSortAttributes(left, p - 1);
- quickSortAttributes(p + 1, right);
- }
-
- public void endElement(String name, int line, int col) throws XML.SAXException {
-
- boolean hasNonWhitespace = false;
-
- int len = t == null || t.content == null ? 0 : t.content.length();
- for(int i=0; t.content != null && i<len; i++)
-
- // ignore double-slash comment blocks
- if (t.content.charAt(i) == '/' && t.content.charAt(i + 1) == '/') {
- while(t.content.charAt(i) != '\n' && i<len) i++;
- i--;
-
- // ignore /* .. */ comment blocks
- } else if (i<len - 1 && t.content.charAt(i) == '/' && t.content.charAt(i + 1) == '*') {
- i += 2;
- while(i<len - 1 && !(t.content.charAt(i) == '*' && t.content.charAt(i + 1) == '/')) i++;
- if (i<len - 1 && t.content.charAt(i) == '*' && t.content.charAt(i + 1) == '/') i += 2;
- i--;
-
- // check for named functions
- } else if (i + 8 <= len && t.content.charAt(i) == 'f' && t.content.charAt(i+1) == 'u' &&
- t.content.charAt(i+2) == 'n' && t.content.charAt(i+3) == 'c' && t.content.charAt(i+4) == 't' &&
- t.content.charAt(i+5) == 'i' && t.content.charAt(i+6) == 'o' && t.content.charAt(i+7) == 'n') {
- int j = i + 8;
- while(j<len && Character.isWhitespace(t.content.charAt(j))) j++;
- if (j<len && t.content.charAt(j) != '(')
- throw new XML.SAXException("named functions are not permitted in XWT -- instead of \"function foo() { ... }\"," +
- " use \"foo = function() { ... }\"");
-
- // replace " and " with " && "
- } else if (i + 5 < len && Character.isWhitespace(t.content.charAt(i)) &&
- t.content.charAt(i+1) == 'a' && t.content.charAt(i+2) == 'n' && t.content.charAt(i+3) == 'd' &&
- Character.isWhitespace(t.content.charAt(i + 4))) {
- t.content.setCharAt(i+1, '&');
- t.content.setCharAt(i+2, '&');
- t.content.setCharAt(i+3, ' ');
- hasNonWhitespace = true;
-
- // generic check for nonwhitespace
- } else if (!Character.isWhitespace(t.content.charAt(i))) {
- hasNonWhitespace = true;
-
- }
-
- if (rootNodeHasBeenEncountered && !templateNodeHasBeenEncountered) {
- if ("static".equals(nameOfHeaderNodeBeingProcessed) && hasNonWhitespace) t.staticscript = genscript(true);
- nameOfHeaderNodeBeingProcessed = null;
-
- } else if (templateNodeHasBeenEncountered && !templateNodeHasBeenFinished) {
-
- // turn our childvect into a Template[]
- t.childvect.copyInto(t.children = new Template[t.childvect.size()]);
- t.childvect = null;
- if (hasNonWhitespace) t.script = genscript(false);
-
- if (nodeStack.size() == 0) {
- // </template>
- templateNodeHasBeenFinished = true;
-
- } else {
- // add this template as a child of its parent