Exemplo n.º 1
0
 /** Receive notification of character data inside an element. */
 @Override
 public void characters(char ch[], int start, int len) {
   while (len > 0 && Character.isWhitespace(ch[start])) {
     ++start;
     --len;
   }
   while (len > 0 && Character.isWhitespace(ch[start + len - 1])) {
     --len;
   }
   if (len > 0) {
     if (_chars.length() > 0) {
       _chars.append(' ');
     }
     _chars.append(ch, start, len);
   }
 }
Exemplo n.º 2
0
 /**
  * Creates formatter using a message format style pattern.
  *
  * @param pattern the pattern.
  * @throws NullPointerException if pattern is null.
  * @throws IllegalArgumentException if pattern contains an ISO control character.
  */
 public SummaryNameFormatter(final String pattern) {
   for (int i = 0; i < pattern.length(); i++) {
     if (Character.isISOControl(pattern.charAt(i))) {
       throw new IllegalArgumentException("At index " + i);
     }
   }
   this.pattern = pattern;
 }
Exemplo n.º 3
0
 boolean isNMTOKEN(String token) {
   char[] chars = token.toCharArray();
   for (int i = 0; i < chars.length; ++i) {
     if (!(Character.isLetterOrDigit(chars[i]) || chars[i] == '_')) {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 4
0
  /**
   * Tokenizes a command string into a list.
   *
   * @throws Exception if the command cannot be tokenized
   */
  protected static LinkedList _tokenizeCommand(String cmd) throws Exception {

    LinkedList tokens = new LinkedList();
    int startIndex = 0;
    int dQuoteAt = cmd.indexOf('"');
    int sQuoteAt = cmd.indexOf('\'');

    if (dQuoteAt == -1 && sQuoteAt == -1) {
      StringTokenizer st = new StringTokenizer(cmd.trim());
      while (st.hasMoreTokens()) {
        tokens.add(st.nextToken());
      }
      return tokens;
    }

    char[] chArray = cmd.trim().toCharArray();

    int endIndex = 0;
    boolean inQuotes = false;
    char c = 0;
    char lastc = 0;
    char lastqc = 0;
    StringBuffer sb = new StringBuffer(80);

    while (endIndex < chArray.length) {
      c = chArray[endIndex];
      if (!Character.isWhitespace(c)) {
        if (c == '"' || c == '\'') {
          if (inQuotes && lastc != '\\' && lastqc == c) {
            tokens.add(sb.toString());
            inQuotes = false;
            sb.setLength(0);
          } else if (!inQuotes) {
            inQuotes = true;
            lastqc = c;
          } else {
            sb.append(c);
          }
        } else if (c == '\\') {
          if (lastc == '\\') sb.append(c);
        } else {
          sb.append(c);
        }
      } else {
        if (inQuotes) {
          sb.append(c);
        } else {
          if (sb.length() > 0) {
            tokens.add(sb.toString());
            sb.setLength(0);
          }
        }
      }
      lastc = c;
      ++endIndex;
    }

    if (inQuotes) {
      throw new Exception(
          WDExUtil.formatMessage(WDExConstants.UNTERMINATED_STRING, WDUtil.toArray(cmd)));
    }
    return tokens;
  }
Exemplo n.º 5
0
  /**
   * Create a new Item - reading the contents from the tab separated value set of columns. Loads it
   * into the Node object
   *
   * @param lang the Triceps context
   * @param sourceLine the line number within the source file (for debugging purposes)
   * @param sourceFile the name of the source file (for debugging purposes)
   * @param tsv the tab separated list of colums representing the node contents
   * @param numLanguage to know how many langauges to parsse?
   */
  Node(Triceps lang, int sourceLine, String sourceFile, String tsv, int numLanguages) {
    triceps = /*(lang == null) ? new Triceps() :*/ lang;
    String token;
    int field = 0;

    if (numLanguages < 1) {
      if (AUTHORABLE) {
        setParseError(triceps.get("numLanguages_must_be_greater_than_zero") + numLanguages);
      } else {
        setParseError("syntax error");
      }
      numLanguages = 1; // the default
    }

    this.sourceLine = sourceLine;
    this.sourceFile = sourceFile;
    this.numLanguages = numLanguages; // needs to be validated?

    int numLanguagesFound = 0;
    int numAnswersFound = 0;

    StringTokenizer ans = new StringTokenizer(tsv, "\t", true);

    while (ans.hasMoreTokens()) {
      String s = null;
      s = ans.nextToken();

      if (s.equals("\t")) {
        ++field;
        if (field == 7) {
          ++numLanguagesFound; // since once that field has been entered, has successfully coded a
          // language as present
        }
        if (field == 9 && numLanguagesFound < numLanguages) {
          field = 5; // so that next element is readback for the next language
        }
        continue;
      }

      switch (field) {
          /* there should be one copy of each of these */
        case 0:
          conceptName = (new ExcelDecoder()).decode(s);
          break;
        case 1:
          localName = (new ExcelDecoder()).decode(s);
          break;
        case 2:
          externalName = (new ExcelDecoder()).decode(s);
          break;
        case 3:
          dependencies = (new ExcelDecoder()).decode(s);
          break;
        case 4:
          questionOrEvalTypeField = (new ExcelDecoder()).decode(s);
          break;
          /* there are as many copies of each of these are there are languages */
        case 5:
          readback.addElement((new ExcelDecoder()).decode(s));
          break;
        case 6:
          questionOrEval.addElement((new ExcelDecoder()).decode(s));
          break;
        case 7:
          answerChoicesStr.addElement((new ExcelDecoder()).decode(s));
          break;
        case 8:
          helpURL.addElement((new ExcelDecoder()).decode(s));
          break;
          /* there are as many copies of each of these are there are answers - rudimentary support for arrays? */
        case 9:
          {
            int i = 0;
            try {
              i = Integer.parseInt((new ExcelDecoder()).decode(s));
            } catch (NumberFormatException t) {
              Logger.getLogger(LoggerName).log(Level.SEVERE, "", t);
              if (AUTHORABLE) {
                setParseError(triceps.get("languageNum_must_be_an_integer") + t.getMessage());
              } else {
                setParseError("syntax error");
              }
              i = 0; // default language
            }
            if (i < 0 || i >= numLanguages) {
              if (AUTHORABLE) {
                setParseError(
                    triceps.get("languageNum_must_be_in_range_zero_to")
                        + (numLanguages - 1)
                        + "): "
                        + i);
              } else {
                setParseError("syntax error");
              }
              i = 0; // default language
            }
            answerLanguageNum = i;
          }
          break;
        case 10:
          questionAsAsked = (new ExcelDecoder()).decode(s);
          break;
        case 11:
          answerGiven = (new ExcelDecoder()).decode(s);
          break;
        case 12:
          comment = (new ExcelDecoder()).decode(s);
          break;
        case 13:
          answerTimeStampStr = (new ExcelDecoder()).decode(s);
          break;
        default:
          break; // ignore extras
      }
    }
    if (dependencies == null || dependencies.trim().length() == 0) {
      if (AUTHORABLE) {
        setParseError(triceps.get("dependencies_column_is_missing"));
      } else {
        setParseError("syntax error");
      }
    }
    if (localName != null && localName.trim().length() > 0) {
      localName = localName.trim();
      if (Character.isDigit(localName.charAt(0))) {
        if (AUTHORABLE) {
          setNamingError(triceps.get("localName_may_not_begin_with_a_digit") + localName);
        } else {
          setParseError("syntax error");
        }
        localName = "_" + localName;
      }
      if (!isNMTOKEN(localName)) {
        if (AUTHORABLE) {
          setNamingError(
              triceps.get("localName_should_only_contain_letters_digits_and_underscores")
                  + localName);
        } else {
          setParseError("syntax error");
        }
      }
    } else {
      setNamingError(triceps.get("localName_must_be_specified"));
    }

    parseQuestionOrEvalTypeField();

    if (questionOrEvalType == BADTYPE) {
      if (AUTHORABLE) {
        setParseError(triceps.get("invalid_questionOrEvalType") + questionOrEvalTypeField);
      } else {
        setParseError("syntax error");
      }
    }

    for (int i = 0; i < answerChoicesStr.size(); ++i) {
      parseAnswerOptions(i, (String) answerChoicesStr.elementAt(i));
    }

    if (datumType == Datum.INVALID) {
      if (AUTHORABLE) {
        setParseError(triceps.get("invalid_dataType"));
      } else {
        setParseError("syntax error");
      }
    }
  }
Exemplo n.º 6
0
  private void printComponentTree(
      PrintWriter out, String errorId, FacesContext context, UIComponent comp, int depth) {
    for (int i = 0; i < depth; i++) out.print(' ');

    boolean isError = false;
    if (errorId != null && errorId.equals(comp.getClientId(context))) {
      isError = true;
      out.print("<span style='color:red'>");
    }

    out.print("&lt;" + comp.getClass().getSimpleName());
    if (comp.getId() != null) out.print(" id=\"" + comp.getId() + "\"");

    for (Method method : comp.getClass().getMethods()) {
      if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue;
      else if (method.getParameterTypes().length != 0) continue;

      String name;

      if (method.getName().startsWith("get")) name = method.getName().substring(3);
      else if (method.getName().startsWith("is")) name = method.getName().substring(2);
      else continue;

      // XXX: getURL
      name = Character.toLowerCase(name.charAt(0)) + name.substring(1);

      ValueExpression expr = comp.getValueExpression(name);

      Class type = method.getReturnType();

      if (expr != null) {
        out.print(" " + name + "=\"" + expr.getExpressionString() + "\"");
      } else if (method.getDeclaringClass().equals(UIComponent.class)
          || method.getDeclaringClass().equals(UIComponentBase.class)) {
      } else if (name.equals("family")) {
      } else if (String.class.equals(type)) {
        try {
          Object value = method.invoke(comp);

          if (value != null) out.print(" " + name + "=\"" + value + "\"");
        } catch (Exception e) {
        }
      }
    }

    int facetCount = comp.getFacetCount();
    int childCount = comp.getChildCount();

    if (facetCount == 0 && childCount == 0) {
      out.print("/>");

      if (isError) out.print("</span>");

      out.println();
      return;
    }
    out.println(">");

    if (isError) out.print("</span>");

    for (int i = 0; i < childCount; i++) {
      printComponentTree(out, errorId, context, comp.getChildren().get(i), depth + 1);
    }

    for (int i = 0; i < depth; i++) out.print(' ');

    if (isError) out.print("<span style='color:red'>");

    out.println("&lt;/" + comp.getClass().getSimpleName() + ">");

    if (isError) out.print("</span>");
  }