⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmltextvalidator.java

📁 WAP ide 代码
💻 JAVA
字号:
package wapide;/** * Used to validate text to see if it conforms to wml standards. * Currently, items checked for include the following: *    " : quotation marks. *    ' : apostrophes. *    < : less than sign *    > : greater than sign *    = : not supported by all attributes */ /** * Copyright:    Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */import javax.swing.*;import java.awt.*;import java.lang.*;import java.util.*;public class WMLTextValidator {  /**   * Constructor - creates a new WMLTextValidator Object.   */  public WMLTextValidator() {  }  /**   * Constructor - creates a new WMLTextValidator Object and checks   * the text for restricted phrases and characters.  Will display a   * pop-up message if a restricted character or phrase is found.   * @param String text - the text to search in.   * @param Component component - the component being checked, can be null.   */  public WMLTextValidator(String text, Component c) {    boolean found = false;    String[] check = {"<", ">", "\"", "'", "="};    for (int x = 0; x < 5; x++) {      if ((!found) && (text.indexOf(check[x]) > -1))        found = true;    }    if (found) {      displayWarning(c);    }  }  /**   * Checks to see if the text contains any characters that are considered   * restricted by WML rules, such as quotation marks(").   * @param String text - the text to search in.   */  public boolean checkText(String text) {    boolean found = false;    try {      String[] check = {"<", ">", "\"", "'", "="};      for (int x = 0; x < 5; x++) {        if ((!found) && (text.indexOf(check[x]) > -1))          found = true;      }    }    catch (NullPointerException nullerr) {}    return found;  }  /**   * Checks to see if the text contains any characters that are considered   * restricted by WML rules, such as quotation marks(").   * @param String text - the text to search in.   * @param String[] items - custom items to check.   */  public boolean checkText(String text, String[] items) {    boolean found = false;    try {      String[] check = items;      for (int x = 0; x < 5; x++) {        if ((!found) && (text.indexOf(check[x]) > -1))          found = true;      }    }    catch (NullPointerException nullerr) {}    return found;  }  /**   * Displays a dialog with a default warning message.   * The message reads as follows:   * "One or more field(s) have one or more reserved character(s),   * be sure the following characters are not used:   *   <, >, ", ', and = (not supported by all attributes)   * See the WAP Developer's Manual for further information."   * @param Component component - the Component requesting the display of the dialog, can be null.   */  public void displayWarning(Component c) {    String title = "Warning: Illegal use of reserved characters";      int messageType = JOptionPane.WARNING_MESSAGE;      int optionType = JOptionPane.DEFAULT_OPTION;      String message = "One or more fields have one or more reserved character(s),\n";      message = message + "be sure the following characters are not used:\n";      message = message + "  <, >, \", ', = (not supported by all attributes)";      message = message + "\n\nSee the WAP Developer's Manual for further information.";      JOptionPane pane = new JOptionPane(message, messageType, optionType);      JDialog dlg = pane.createDialog(c, title);      dlg.show();  }  /**   * Displays a warning dialog with a custom message.   * @param Component component - the Component requesting the display of the dialog, can be null.   * @param String message - the warning message to display in the dialog.   */  public void displayWarning(Component c, String message) {    String title = "Warning: Illegal use of reserved characters";      int messageType = JOptionPane.WARNING_MESSAGE;      int optionType = JOptionPane.DEFAULT_OPTION;      JOptionPane pane = new JOptionPane(message, messageType, optionType);      JDialog dlg = pane.createDialog(c, title);      dlg.show();  }  //public static void main(String[] args) {  //  WMLTextValidator WMLTextValidator1 = new WMLTextValidator("test of try", null);  //}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -