Пример #1
0
  /** @param scheme scheme-element which contains the mask-definition */
  public Mask(SchemeElement scheme) {

    this.scheme = scheme;

    if (scheme.getMap() != null) {
      names = scheme.getMap().split(","); // $NON-NLS-1$

      outputLength = -1; // variable, because name lengths can be variable

      regularMask = scheme.getMap().replace(',', '|');
      pre = ""; // $NON-NLS-1$
      post = ""; // $NON-NLS-1$
      maskString = ""; // $NON-NLS-1$

    } else {
      names = null;

      maskString = scheme.getMask();
      // regular expression in xsd
      // (([^%])*%(\-|\+|\s|\#)*0(\-|\+|\s|\#)*(\d)+d([^%])*)|(([^%])*%(\-|\+|\s|\#)*d([^%])+)
      if (maskString.matches("([^%])*%(\\-|\\+|\\s|\\#)*d([^%])+")) { // $NON-NLS-1$
        // length is unknown but there is a separator specified
        outputLength = -1;
      } else {
        // there must be given a length within the mask
        // Find length by printing out the number 1 with that mask
        outputLength = String.format(maskString, 1).length();
      }

      // create regular expression for this mask
      final int perCent = maskString.indexOf('%');
      // Search the first 'd'-character after the '%' character
      final int dPos = maskString.indexOf('d', perCent);

      pre = maskString.substring(0, perCent);
      post = maskString.substring(dPos + 1, maskString.length());
      regularMask = pre + number + post;
    }
  }