Esempio n. 1
1
  private boolean validate(String username, String email, String password) {
    String EMAIL_REGEX =
        "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    String USER_REGEX = "^[a-zA-Z0-9._-]{4,}$";

    if (!Pattern.matches(EMAIL_REGEX, email)) {
      Toast.makeText(this, "The email address is invalid", Toast.LENGTH_SHORT).show();
      return false;
    }

    if (!Pattern.matches(USER_REGEX, username)) {
      Toast.makeText(
              this, "Username have an invalid character or length less than 4", Toast.LENGTH_SHORT)
          .show();
      return false;
    }

    if (password == null || password.length() < 4) {
      Toast.makeText(this, "Password must have at least 4 characters", Toast.LENGTH_SHORT).show();
      return false;
    }

    return true;
  }
Esempio n. 2
0
  @Override
  public Links visitAndGetNextLinks(Page page) {
    System.out.println(page.getHtml());
    if (Pattern.matches(".*jpg$", page.getUrl())
        || Pattern.matches(".*png$", page.getUrl())
        || Pattern.matches(".*gif$", page.getUrl())) {
      try {
        FileUtils.writeFileWithParent(
            "download/" + id.incrementAndGet() + ".jpg", page.getContent());
        System.out.println("download:" + page.getUrl());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    MyLinks nextLinks = new MyLinks();
    RegexRule rr = new RegexRule();
    rr.addRule(".*meishij.*");
    nextLinks.addAllFromDocument(page.getDoc(), rr);
    nextLinks.filterImgUrl(page.getDoc(), rr);

    System.out.println(nextLinks.size());
    try {
      Thread.sleep(1500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    return nextLinks;
  }
Esempio n. 3
0
 /** @desc 初始化 */
 public void initMethods() {
   getMethods = new Hashtable<String, Method>();
   setMethods = new Hashtable<String, Method>();
   cls = obj.getClass();
   Method[] methods = cls.getMethods();
   // 定义正则表达式,从方法中过滤出getter / setter 函数.
   String gs = "get(\\w+)";
   Pattern getM = Pattern.compile(gs);
   String ss = "set(\\w+)";
   Pattern setM = Pattern.compile(ss);
   // 把方法中的"set" 或者 "get" 去掉
   String rapl = "$1";
   String param;
   for (int i = 0; i < methods.length; ++i) {
     Method m = methods[i];
     String methodName = m.getName();
     if (Pattern.matches(gs, methodName)) {
       param = getM.matcher(methodName).replaceAll(rapl).toLowerCase();
       getMethods.put(param, m);
     } else if (Pattern.matches(ss, methodName)) {
       param = setM.matcher(methodName).replaceAll(rapl).toLowerCase();
       setMethods.put(param, m);
     } else {
       // System.out.println(methodName + " 不是getter,setter方法!");
     }
   }
 }
Esempio n. 4
0
  public static boolean containsDifferentMethod(String line, String methodName) {

    boolean isDifferentMethod = false;

    if (line.contains(methodName)) {
      if (line.length() > 0) {
        int index = line.indexOf(methodName);
        if (index > 0) { // checking the character before the method name
          String prefix = String.valueOf(line.charAt(index - 1));
          isDifferentMethod = Pattern.matches("['_a-zA-Z0-9]", prefix);
          /*if(isDifferentMethod)
          	System.out.println("Line: "+ line+" contains a method different from "+methodName);
          else
          	System.out.println("Line: "+ line+" contains same method as "+methodName);*/
        } else if (line.length() > (index + methodName.length())) {
          String suffix = String.valueOf(line.charAt(index + methodName.length()));
          isDifferentMethod = Pattern.matches("['._a-zA-Z0-9]", suffix);
          /*if(isDifferentMethod)
          	System.out.println("Line: "+ line+" contains a method different from "+methodName);
          else
          	System.out.println("Line: "+ line+" contains same method as "+methodName);*/
        } else {
          // System.out.println("Line: "+ line+" contains same method as "+methodName);
          isDifferentMethod = true;
        }
      }
    }

    return isDifferentMethod;
  }
  @Test
  public void test() {

    assertTrue(Pattern.matches("(\\d|\\D)*&#[0-9]{2,3};(\\d|\\D)*", "동ac1232&#40;동해물")); // 숫자가 아니고
    assertFalse(Pattern.matches("(\\d|\\D)*&#[0-9]{2,3};(\\d|\\D)*", "동ac1232&#4사람 인;동해물"));
    assertFalse(Pattern.matches("\\w*", "동ac1232&#4사람 인;동해물"));
    assertTrue(Pattern.matches("\\w*", "동ac1234사람인동해물")); // [0-9A-Za-z_] 와 동
  }
    // starts the game and opens gameactivity
    public void startFoldit(View view) {
      if (isOnline()) {
        EditText add = (EditText) view.findViewById(R.id.editAddress);
        EditText key = (EditText) view.findViewById(R.id.editKey);
        int myPort = Constants.PORT;
        String myKey = key.getText().toString();
        String myAddress = add.getText().toString();
        if (myAddress.equals("")
            || !(Pattern.matches(
                    "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$",
                    myAddress)
                || Pattern.matches(
                    "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$",
                    myAddress))) {
          Toast toast =
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  "Enter a valid IP address.",
                  Toast.LENGTH_SHORT);
          toast.show();
          return;
        }
        if (!myKey.equals("") && myKey.length() != Constants.KEY_LENGTH) {
          Toast toast =
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  "Key should be " + Constants.KEY_LENGTH + " characters.",
                  Toast.LENGTH_SHORT);
          toast.show();
          return;
        }
        SharedPreferences myPrefs = getActivity().getSharedPreferences("myPrefs", MODE_PRIVATE);
        // "128.95.2.85";
        SharedPreferences.Editor e = myPrefs.edit();

        e.putString("address", myAddress);
        e.putString("key", myKey);

        e.putInt("port", myPort);

        e.commit();

        Intent intent = new Intent(getActivity(), GameActivity.class);
        intent.putExtra("address", myAddress);
        intent.putExtra("port", myPort);
        intent.putExtra("key", myKey);
        startActivity(intent);
      } else {
        Toast toast =
            Toast.makeText(
                getActivity().getApplicationContext(),
                "You are not connected to the internet.",
                Toast.LENGTH_SHORT);
        toast.show();
      }
    }
Esempio n. 7
0
 public boolean isUrl(String str) {
   boolean isUrl = false;
   if (Pattern.matches("(?:(?:www)|(?:WWW)|[a-zA-Z0-9])[\\.]?[a-z0-9_A-Z\\.\\?\\&\\=]*", str)) {
     isUrl = true;
   } else if (Pattern.matches(
       "http:\\/\\/(?:(?:www)|(?:WWW)|[a-zA-Z0-9])[\\.]?[a-z0-9_A-Z\\.\\/\\?\\&\\=]*", str)) {
     isUrl = true;
   }
   return isUrl;
 }
Esempio n. 8
0
  public static void run(String str) throws ProcessException {
    if (Pattern.matches("(?i)CREATE\\s+SCHEMA\\s+[a-zA-Z0-9]+", str)) // down!
    {
      String[] command = str.split("\\s+|;");
      Command cmd = new CreateSchemaCmd(command[2]);
      cmd.execute();
    } else if (Pattern.matches("(?i)SHOW\\s+SCHEMAS", str)) // done!
    {
      Command cmd = new ShowSchemasCmd();
      cmd.execute();
    } else if (Pattern.matches("(?i)USE\\s+[a-zA-Z0-9]+", str)) // done!
    {
      String[] command = str.split("\\s+|;");
      Command cmd = new UseCmd(command[1]);
      cmd.execute();
    } else if (Pattern.matches("(?i)SHOW\\s+TABLES", str)) // done!
    {
      Command cmd = new ShowTablesCmd();
      cmd.execute();
    } else if (Pattern.matches("(?i)CREATE\\s+TABLE\\s+[a-zA-Z0-9]+\\s*\\(\\s*.+\\s*\\)", str)) {
      String table_name = str.split("\\s")[2];
      String temp = str.replaceFirst("(?i)CREATE\\s+TABLE\\s+[a-zA-Z0-9]+\\s*\\(\\s*", "");
      if (Pattern.matches("(?i).+\\)\\s*\\)", temp)) temp = temp.replaceAll("\\)\\s*\\)", ")");
      String[] insertTuples = temp.split(",");
      Command cmd = new CreateTableCmd(table_name, insertTuples);
      cmd.execute();
    } else if (Pattern.matches(
        "(?i)INSERT\\s+INTO\\s+TABLE\\s+[a-zA-Z0-9]+\\s+VALUES\\s+\\(\\s*.+\\s*\\)", str)) {
      String table_name = str.split("\\s")[3];
      String temp =
          str.replaceFirst("(?i)INSERT\\s+INTO\\s+TABLE\\s+[a-zA-Z0-9]+\\s+VALUES\\s+\\(\\s*", "");
      temp = temp.replaceAll("\\s*\\)", "");
      temp = temp.replaceAll("\\s", "");
      String[] insertTuples = temp.split(",");
      Command cmd = new InsertCmd(table_name, insertTuples);
      cmd.execute();
    } else if (Pattern.matches("(?i)SELECT\\s+.+\\s+FROM\\s+[a-zA-Z0-9]+\\s+WHERE\\s+.+", str)) {
      String temp1 = str.replaceFirst("(?i).+FROM\\s+", "");
      String table_name = temp1.split("\\s")[0];
      temp1 = temp1.replaceFirst("(?i).+WHERE\\s+", "");
      String condition = temp1.split(";")[0];

      String temp2 = str.replaceFirst("(?i)\\s+FROM.+", "");
      temp2 = temp2.replaceFirst("(?i)SELECT\\s+", "");
      temp2 = temp2.replaceFirst("\\s", "");
      String[] columns = temp2.split(",");
      Command cmd = new SelectFromCmd(columns, table_name, condition);
      cmd.execute();
    } else if (Pattern.matches("(?i)DROP\\s+TABLE\\s+.+", str)) {
      String table_name = str.replaceFirst("(?i)DROP\\s+TABLE\\s+", "");
      Command cmd = new DropTableCmd(table_name);
      cmd.execute();
    } else if (Pattern.matches("(?i)\\s*exit\\s*", str)) System.out.println("Exiting...");
    else System.out.println("You have an error in your SQL syntax;");
  }
 @Override
 protected boolean ValidateXMLDocument(Element eElement) throws Exception {
   if (!eElement.hasAttribute(ATTNUM)) {
     PrintConsole.printErr(
         ATTNUM
             + " attribute in "
             + TAG
             + " tag is missing. the following template may help you."
             + "\n <Gateways Number=\"2\" TypeOfGeneration=\"Static\"> \n	"
             + "<Add x=\"114\" y=\"457\" />\n<Add x=\"12\" y=\"333\" /></Gateways>");
     System.exit(0);
   } else if (!Pattern.matches("-?[0-9]+", eElement.getAttribute(ATTNUM))) {
     PrintConsole.printErr(
         "The value of " + ATTNUM + " attribute  in " + TAG + " must be an interger value. \n\n");
     System.exit(0);
   }
   if (!eElement.hasAttribute(ATTTOG)) {
     PrintConsole.printErr(
         ATTTOG
             + " attribute in "
             + TAG
             + " tag is missing. this template may help you."
             + "\n <Gateways Number=\"2\" TypeOfGeneration=\"Static\"> \n	"
             + "<Add x=\"114\" y=\"457\" />\n<Add x=\"12\" y=\"333\" /></Gateways>");
     System.exit(0);
   } else if (!Pattern.matches(
       "random|static|file", eElement.getAttribute(ATTTOG).toLowerCase())) {
     PrintConsole.printErr(
         "the value of "
             + ATTTOG
             + " in "
             + TAG
             + " node must be on of the following item:"
             + " \n 1- File \n 2- Static \n 3- Random.\n\n");
     System.exit(0);
   }
   if (!eElement.hasAttribute(ATTRADIO)) {
     PrintConsole.printErr(
         ATTRADIO
             + " attribute in "
             + TAG
             + " tag is missing. the following template may help you."
             + "\n <Routers Number=\"20\" TypeOfGeneration=\"RANDOM\" MinDistance=\"50\" Seed=\" 12252554 \" "
             + "SaftyTest=\"50\" />\n\n");
     System.exit(0);
   }
   // check the value of tag
   else if (!Pattern.matches("-?[0-9]+", eElement.getAttribute(ATTRADIO))) {
     PrintConsole.printErr(
         "The value of " + ATTRADIO + " attribute must be an interger value. \n\n");
     System.exit(0);
   }
   return true;
 }
Esempio n. 10
0
 public static String normalizeID(String id) throws ProcessException {
   if (Pattern.matches("^[0-9]{3}\\.[0-9]{3}\\.[0-9]{3}-[0-9]{2}$", id)) {
     return id;
   } else if (Pattern.matches("^[0-9]{3}\\.[0-9]{3}\\.[0-9]{3}/[0-9]{4}-[0-9]{2}$", id)) {
     return id;
   } else if (Pattern.matches("^[0-9]{2}\\.[0-9]{3}\\.[0-9]{3}/[0-9]{4}-[0-9]{2}$", id)) {
     return "0" + id;
   } else {
     throw new ProcessException("ERROR: INVALID ID");
   }
 }
  /**
   * method to add a new room
   *
   * @param roomList : rooms are added to the list
   * @return: It will return the name of the room that is added
   */
  protected static String addRoom(ArrayList<Room> roomList) {
    try {
      System.out.println("Add a room:");
      String name = getRoomName().toLowerCase();
      if (Pattern.matches("[a-zA-Z]+", name)) {
        int count = 0;
        if (count == 0) {
          if (roomList.size() > 0) {
            for (Room room : roomList) {
              if (room.getName().contains(name)) {
                System.out.println("Room already exists");
                break;
              } else {
                count = 1;
              }
            }
          }
        }
        if (count == 1 || roomList.size() == 0) {
          // to check whether the room name is empty or not
          if (name != null && !name.isEmpty()) {
            System.out.println("Room capacity?");
            int capacity = keyboard.nextInt();
            System.out.println("Building?");
            String building = keyboard.next();
            if (Pattern.matches("[a-zA-Z\\s]+", building)) {
              if (building != null && !building.isEmpty()) {
                System.out.println("Location?");
                String location = keyboard.next();
                if (Pattern.matches("[a-zA-Z]+", location)) {
                  Room newRoom = new Room(name, capacity, building, location);
                  roomList.add(newRoom); // add room to the
                  // list
                  return "Room '" + newRoom.getName() + "' added successfully!";
                } else {
                  System.out.println("Please enter only alphabets");
                }
              }

            } else {
              System.out.println("Please enter only alphabets");
            }
          } else {
            System.out.println("Name should not be empty");
          }
        }
      } else {
        System.out.println("Please enter only alphabets");
      }
    } catch (InputMismatchException e) {
      logger.info("Please enter only numeric values");
    }
    return "";
  }
 public static String getOfficeHome() {
   String osName = System.getProperty("os.name");
   if (Pattern.matches("Linux.*", osName)) {
     return "/opt/openoffice.org3";
   } else if (Pattern.matches("Windows.*", osName)) {
     return "D:/Program Files (x86)/OpenOffice.org 3";
   } else if (Pattern.matches("Mac.*", osName)) {
     return "/Application/OpenOffice.org.app/Contents";
   }
   return null;
 }
Esempio n. 13
0
  public static boolean checkNickName(String value) {
    char[] aa = value.toCharArray();
    for (int i = 0, len = aa.length; i < len; i++) {
      String c = String.valueOf(aa[i]);
      if (!(java.util.regex.Pattern.matches("[\u4e00-\u9fa5]", c)
          || isDigits(c)
          || java.util.regex.Pattern.matches("[a-zA-Z]", c))) {
        return false;
      }
      ;
    }

    return true;
  }
Esempio n. 14
0
 /**
  * Tests that both RE2's and JDK's pattern class act as we expect them. The regular expression
  * {@code regexp} matches the string {@code match} and doesn't match {@code nonMatch}
  */
 public void testMatches(String regexp, String match, String nonMatch) {
   String errorString = "Pattern with regexp: " + regexp;
   assertTrue(
       "JDK " + errorString + " doesn't match: " + match,
       java.util.regex.Pattern.matches(regexp, match));
   assertFalse(
       "JDK " + errorString + " matches: " + nonMatch,
       java.util.regex.Pattern.matches(regexp, nonMatch));
   assertTrue(
       errorString + " doesn't match: " + match,
       Pattern.matches(regexp, utf8Slice(match), options));
   assertFalse(
       errorString + " matches: " + nonMatch,
       Pattern.matches(regexp, utf8Slice(nonMatch), options));
 }
  /** {@inheritDoc} */
  @Override
  public IPortTemplateDesc[] findTemplatesByRepId(final String repId, final String language) {
    final ArrayList<IPortTemplateDesc> codegens = new ArrayList<IPortTemplateDesc>();

    // Search all repId's
    for (final Entry<String, Set<String>> ent : this.repToIdMap.entrySet()) {
      final String key = ent.getKey();

      // We allow for patterns, check if the passed in repId matches
      if (Pattern.matches(key, repId)) {

        // Loop through all the generators registered for this repId
        for (final String id : ent.getValue()) {
          final IPortTemplateDesc codegen = this.templateMap.get(id);
          if (codegen != null) {

            // Check for a match
            for (final String lang : codegen.getLanguages()) {
              if (lang.equals(language)) {
                codegens.add(codegen);
                break;
              }
            }
          }
        }
      }
    }

    Collections.sort(codegens);
    codegens.size();
    return codegens.toArray(new IPortTemplateDesc[codegens.size()]);
  }
        @Override
        public void onOneShotClick(View v) {

          String emailRegex =
              "[a-zA-Z0-9]+(?:(\\.|_)[A-Za-z0-9!#$%&'*+/=?^`{|}~-]+)*@(?!([a-zA-Z0-9]*\\.[a-zA-Z0-9]*\\.[a-zA-Z0-9]*\\.))(?:[A-Za-z0-9](?:[a-zA-Z0-9-]*[A-Za-z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?";
          String inputEmail = edtEmailAddress.getText().toString();
          boolean matches = Pattern.matches(emailRegex, inputEmail);

          if (!inputEmail.equals("") && matches) {

            getMailRespone(sendRequestEmailCodeModel(inputEmail));

          } else {

            Toast toast =
                Toast.makeText(
                    getApplicationContext(),
                    "Lütfen kayıt olduğunuz e-posta adresini giriniz.",
                    Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
          }

          return;
          // String response=getForgotAccResponse();

        }
Esempio n. 17
0
  public static long getSeconds(String dhms) {

    if (Pattern.matches(".*[a-zA-Z].*", dhms)) {
      return (TimeTools.secondsFromDhms(dhms));
    }
    return Long.parseLong(dhms);
  }
 @Override
 protected void onValidate(IValidatable<String> validatable) {
   final String nodeName = (String) validatable.getValue();
   if (!Pattern.matches("[a-zA-Z0-9]*", nodeName)) {
     error(validatable, "NodeNameValidator.policyname");
   }
 }
        @Override
        public void onOneShotClick(View v) {
          String codeRegex = "_{1}?([a-z0-9]+(%))+";
          String inputEmailCode = edtEmailCode.getText().toString();
          Boolean matches = Pattern.matches(codeRegex, inputEmailCode);
          if (inputEmailCode.equals("") || !matches) {
            Toast toast =
                Toast.makeText(
                    getApplicationContext(),
                    "Lütfen e-posta adresinize gönderilen kodu giriniz.",
                    Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
          }
          String inputPassword = edtNewPassword.getText().toString();
          String inputRePassword = edtRePassword.getText().toString();

          if ((inputPassword.equals("") || inputRePassword.equals(""))
              || (!inputPassword.equals(inputRePassword))) {
            Toast toast =
                Toast.makeText(
                    getApplicationContext(), "Girdiğiniz şifreler eşleşmiyor.", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
          }
          getNewPassWithLogin(sendEmailCodeModel(inputEmailCode, inputPassword, inputRePassword));
        }
Esempio n. 20
0
  /**
   * Retrieve the value of the selected sip uri
   *
   * @return the contact to call as a ToCall object containing account to use and number to call
   */
  public ToCall getValue() {
    String userName = dialUser.getText().toString();
    String toCall = "";
    Long accountToUse = null;
    if (TextUtils.isEmpty(userName)) {
      return null;
    }
    userName = userName.replaceAll("[ \t]", "");
    SipProfile acc = accountChooserButtonText.getSelectedAccount();
    if (acc != null) {
      accountToUse = acc.id;
      // If this is a sip account
      if (accountToUse > SipProfile.INVALID_ID) {
        if (Pattern.matches(".*@.*", userName)) {
          toCall = "sip:" + userName + "";
        } else if (!TextUtils.isEmpty(acc.getDefaultDomain())) {
          toCall = "sip:" + userName + "@" + acc.getDefaultDomain();
        } else {
          toCall = "sip:" + userName;
        }
      } else {
        toCall = userName;
      }
    } else {
      toCall = userName;
    }

    return new ToCall(accountToUse, toCall);
  }
 /**
  * Check if the system property "pattern" matches (substring regular expression) the file name.
  * Empty pattern matches everything.
  *
  * @param fileName file name to check
  * @return true if the pattern matches, false otherwise
  */
 protected boolean patternMatches(String fileName) {
   String pattern = System.getProperty("pattern", "");
   if (pattern == null || pattern.equals("")) {
     return true;
   }
   return Pattern.matches(".*" + pattern + ".*", fileName);
 }
Esempio n. 22
0
 public static void validateRegExp(String arg, String regexp, String label) {
   validateNotBlank(arg, "The text value '" + label + "' should not be blank");
   if (!Pattern.matches(regexp, arg)) {
     throw new AchillesException(
         "The property '" + label + "' should match the pattern '" + regexp + "'");
   }
 }
Esempio n. 23
0
  public static String getFileExtensionFromPath(String path) {
    if (!TextUtils.isEmpty(path)) {
      int fragment = path.lastIndexOf('#');
      if (fragment > 0) {
        path = path.substring(0, fragment);
      }

      int query = path.lastIndexOf('?');
      if (query > 0) {
        path = path.substring(0, query);
      }

      int filenamePos = path.lastIndexOf('/');
      String filename = 0 <= filenamePos ? path.substring(filenamePos + 1) : path;

      // if the filename contains special characters, we don't
      // consider it valid for our matching purposes:
      if (filename != null
          && filename.length() > 0
          && Pattern.matches("[a-zA-Z_0-9\\.\\-\\(\\)\\%]+", filename)) {
        int dotPos = filename.lastIndexOf('.');
        if (0 <= dotPos) {
          return filename.substring(dotPos + 1);
        }
      }
    }

    return "";
  }
Esempio n. 24
0
  private String getSrc(String src) {
    if (Pattern.matches("^http.*", src)) {
      return src;
    }

    return TCP + HOST + src;
  }
Esempio n. 25
0
 public boolean isNameAccepted(String name) {
   if (null == nameFilter
       || Strings.isBlank(name)
       || "\"\"".equals(name)) // 用户不选择文件时,文件名会是"" 两个双引号
   return true;
   return Pattern.matches(nameFilter, name.toLowerCase());
 }
Esempio n. 26
0
 private static void getStudentPass(String facultyNumber)
     throws IOException, JAXBException, SAXException, TransformerException,
         ParserConfigurationException {
   if (Pattern.matches("\\d{5,6}", facultyNumber)) {
     InputStream inputStream = new FileInputStream(Constants.CONFIG_FILE_PATH.toString());
     properties.load(inputStream);
     File protocolFile = new File(properties.getProperty("protocol"));
     ReadWriteUtils utils = new ReadWriteUtils(Protocol.class);
     Protocol protocol = (Protocol) utils.readFromXml(protocolFile);
     StudentPass studentPass = protocol.getStudentPass(Integer.parseInt(facultyNumber));
     utils.setType(StudentPass.class);
     File outputFile =
         new File(properties.getProperty("output") + "\\StudentPass" + facultyNumber + ".xml");
     if (outputFile.createNewFile()) System.out.println("File created!");
     utils.writeXml(studentPass, outputFile);
     utils.writeXml(studentPass, System.out);
     System.out.println(
         "Do you want to open the generated XML Document with your default viewing program?");
     if (awaitResponse()) Desktop.getDesktop().open(outputFile);
     System.out.println(
         "Do you want to transform the generated XML Document to html file and open with your default viewing program?");
     if (awaitResponse()) {
       Desktop.getDesktop()
           .open(transformXML(outputFile, new File(Constants.STUDENT_STYLE.toString())));
     }
     inputStream.close();
   } else throw new IllegalArgumentException("Invalid faculty number is entered!");
 }
Esempio n. 27
0
 @Test
 public void testIllegalHTableNamesRegex() {
   for (String tn : illegalTableNames) {
     LOG.info("Testing: '" + tn + "'");
     assertFalse(Pattern.matches(HTableDescriptor.VALID_USER_TABLE_REGEX, tn));
   }
 }
 /**
  * @see
  *     org.kuali.kfs.module.cam.document.service.AssetPaymentService#adjustPaymentAmounts(org.kuali.kfs.module.cam.businessobject.AssetPayment,
  *     boolean, boolean)
  */
 public void adjustPaymentAmounts(
     AssetPayment assetPayment, boolean reverseAmount, boolean nullPeriodDepreciation)
     throws IllegalAccessException, InvocationTargetException {
   LOG.debug("Starting - adjustAmounts() ");
   PropertyDescriptor[] propertyDescriptors =
       PropertyUtils.getPropertyDescriptors(AssetPayment.class);
   for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
     Method readMethod = propertyDescriptor.getReadMethod();
     if (readMethod != null
         && propertyDescriptor.getPropertyType() != null
         && KualiDecimal.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
       KualiDecimal amount = (KualiDecimal) readMethod.invoke(assetPayment);
       Method writeMethod = propertyDescriptor.getWriteMethod();
       if (writeMethod != null && amount != null) {
         // Reset periodic depreciation expenses
         if (nullPeriodDepreciation
             && Pattern.matches(
                 CamsConstants.SET_PERIOD_DEPRECIATION_AMOUNT_REGEX,
                 writeMethod.getName().toLowerCase())) {
           Object[] nullVal = new Object[] {null};
           writeMethod.invoke(assetPayment, nullVal);
         } else if (reverseAmount) {
           // reverse the amounts
           writeMethod.invoke(assetPayment, (amount.negated()));
         }
       }
     }
   }
   LOG.debug("Finished - adjustAmounts()");
 }
Esempio n. 29
0
  public boolean processHelo(String data) {
    String response = "400 - ¡Las personas educadas saludan primero! \n";
    boolean temp;
    System.out.println("HELO");
    temp = Pattern.matches("(HELO|EHLO)(\\s)+(\\w)+", data);

    if (temp) {
      // extraer dominio
      String[] correoUsuario = data.split("\\s+");
      // extraer el segundo elemento

      if (correoUsuario.length > 1) {
        String nombreDominio = correoUsuario[1]; // nombre del dominio que escribe
        System.out.println(nombreDominio);
        sendResponse("220 - Saludos " + nombreDominio + ", estamos a las ordenes...\n");
        dominioHelo = nombreDominio; // para verificar despues que lo incluya
      } else {
        // error o poner comodin?
        String nombreDominio = "dummy";
        System.out.println(nombreDominio);
        sendResponse("220 - Saludos anonimo, estamos a las ordenes...\n");
      }
      heloOK = true;
      return true;
    } else {
      // error
      sendResponse(response);
      return false;
    }
  }
  /**
   * Validates that the parent parameter was acceptable.
   *
   * @return True if the parent parameter is valid for the current container.
   */
  private boolean validateParent(GadgetContext context) {
    String container = context.getContainer();
    String parent = context.getParameter("parent");

    if (parent == null) {
      // If there is no parent parameter, we are still safe because no
      // dependent code ever has to trust it anyway.
      return true;
    }

    List<Object> parents = containerConfig.getList(container, "gadgets.parent");
    if (parents.isEmpty()) {
      // Allow all.
      return true;
    }

    // We need to check each possible parent parameter against this regex.
    for (Object pattern : parents) {
      if (Pattern.matches(pattern.toString(), parent)) {
        return true;
      }
    }

    return false;
  }