Beispiel #1
0
  public static Map<String, Properties> loadDBConfig(Properties p) {
    Map<String, Properties> dbConfigs = Maps.newHashMapWithExpectedSize(1);
    for (Object o : p.keySet()) {
      String _key = String.valueOf(o);
      String value = p.getProperty(_key);

      if (StringUtils.startsWithIgnoreCase(_key, "db")) {
        int last_idx = _key.lastIndexOf(StringPool.DOT);
        if (last_idx > 2) {
          // like db.second.url
          String config_name = _key.substring(_key.indexOf(StringPool.DOT) + 1, last_idx);
          if (logger.isDebugEnabled()) {
            logger.debug("the db config is {}", config_name);
          }
          Properties db_config_props = dbConfigs.get(config_name);
          if (db_config_props == null) {
            db_config_props = new Properties();
            dbConfigs.put(config_name, db_config_props);
          }
          _key = _key.replace(StringPool.DOT + config_name, StringPool.EMPTY);
          db_config_props.put(_key, value);
        } else {
          Properties db_main_props = dbConfigs.get("main");
          if (db_main_props == null) {
            db_main_props = new Properties();
            dbConfigs.put("main", db_main_props);
          }
          db_main_props.put(_key, value);
        }
      }
    }
    return dbConfigs;
  }
 public static boolean directoryContains(String canonicalParent, String canonicalChild) {
   canonicalParent = normalize(canonicalParent);
   canonicalChild = normalize(canonicalChild);
   return (!StringUtils.equalsIgnoreCase(canonicalParent, canonicalChild))
       && StringUtils.startsWithIgnoreCase(
           normalize(canonicalChild), normalize(canonicalParent) + SEPARATOR);
 }
 private boolean anyStarts(String word, List<String> subjectWords) {
   for (String subjectWord : subjectWords) {
     if (StringUtils.startsWithIgnoreCase(subjectWord, word)) {
       return true;
     }
   }
   return false;
 }
Beispiel #4
0
 @Override
 URL toUrlUnsafeClassic(final String url) throws MalformedURLException {
   if (WebClient.URL_ABOUT_BLANK != null
       && org.apache.commons.lang3.StringUtils.equalsIgnoreCase(
           WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) {
     return WebClient.URL_ABOUT_BLANK;
   } else if (org.apache.commons.lang3.StringUtils.startsWithIgnoreCase(
       url, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
     return new URL("http://gaeHack_" + url.replaceFirst(":", "/"));
   } else if (org.apache.commons.lang3.StringUtils.startsWithIgnoreCase(url, "about:")) {
     return new URL("http://gaeHack_" + url.replaceFirst(":", "/"));
   } else if (org.apache.commons.lang3.StringUtils.startsWithIgnoreCase(url, "data:")) {
     return new URL("http://gaeHack_" + url.replaceFirst(":", "/"));
   } else {
     return toNormalUrl(url);
   }
 }
Beispiel #5
0
 @Override
 public Object exec(@SuppressWarnings("rawtypes") List list) throws TemplateModelException {
   // Checks
   Validate.notNull(list, "List of arguments is required");
   Validate.notEmpty(list, "List of arguments must not be empty");
   // Gets the value
   String value = (String) list.get(0);
   // Gets the current locale value
   String currentValue = currentLocale.getCurrentLocale().toString();
   // OK?
   return StringUtils.startsWithIgnoreCase(currentValue, value);
 }
 public String getUrl() {
   if (StringUtils.startsWithIgnoreCase(geocode, "GK")) {
     String hex = geocode.substring(3);
     try {
       int id = Integer.parseInt(hex, 16);
       return "http://geokrety.org/konkret.php?id=" + id;
     } catch (NumberFormatException e) {
       Log.e(Settings.tag, "cgTrackable.getUrl", e);
       return null;
     }
   }
   return "http://coord.info/" + geocode.toUpperCase();
 }
Beispiel #7
0
  /**
   * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN
   * RISK.</span><br>
   *
   * <p>Submits this form to the server. If <tt>submitElement</tt> is <tt>null</tt>, then the
   * submission is treated as if it was triggered by JavaScript, and the <tt>onsubmit</tt> handler
   * will not be executed.
   *
   * <p><b>IMPORTANT:</b> Using this method directly is not the preferred way of submitting forms.
   * Most consumers should emulate the user's actions instead, probably by using something like
   * {@link HtmlElement#click()} or {@link HtmlElement#dblClick()}.
   *
   * @param submitElement the element that caused the submit to occur
   * @return a new page that reflects the results of this submission
   */
  Page submit(final SubmittableElement submitElement) {
    final HtmlPage htmlPage = (HtmlPage) getPage();
    final WebClient webClient = htmlPage.getWebClient();
    if (webClient.getOptions().isJavaScriptEnabled()) {
      if (submitElement != null) {
        isPreventDefault_ = false;
        final ScriptResult scriptResult = fireEvent(Event.TYPE_SUBMIT);
        if (isPreventDefault_) {
          // null means 'nothing executed'
          if (scriptResult == null) {
            return htmlPage;
          }
          return scriptResult.getNewPage();
        }
      }

      final String action = getActionAttribute().trim();
      if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
        return htmlPage
            .executeJavaScriptIfPossible(action, "Form action", getStartLineNumber())
            .getNewPage();
      }
    } else {
      if (StringUtils.startsWithIgnoreCase(
          getActionAttribute(), JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
        // The action is JavaScript but JavaScript isn't enabled.
        // Return the current page.
        return htmlPage;
      }
    }

    final WebRequest request = getWebRequest(submitElement);
    final String target = htmlPage.getResolvedTarget(getTargetAttribute());

    final WebWindow webWindow = htmlPage.getEnclosingWindow();
    webClient.download(webWindow, target, request, false, "JS form.submit()");
    return htmlPage;
  }
  public HtmlElement getItinerarySubSection(ItineraryRows subSection) {
    if (table_rows.size() == 0) {
      table_rows = itineraryCompareTable().findElements(By.tagName("tr"));
    }
    for (HtmlElement row : table_rows) {
      String text = row.findElement(By.tagName("th")).getText();
      String textContent = row.getWrappedElement().getAttribute("textContent");
      if (StringUtils.startsWithIgnoreCase(text, subSection.name())) {
        row.scrollIntoView(false);
        return row;
      } else if (StringUtils.containsIgnoreCase(textContent, subSection.name())) {
        row.scrollIntoView(false);
        return row;
      }
    }

    return null;
  }
  private boolean validateRequest() throws LoginException {

    HttpServletRequest request = fromPolicyContext(HttpServletRequest.class);
    if (request != null && request.getUserPrincipal() != null) {
      return false;
    }

    AuthorizationRequest authorizationRequest = fromPolicyContext(AuthorizationRequest.class);
    if (authorizationRequest == null) {
      return false;
    }

    ClientID clientID = authorizationRequest.getClientID();

    String redirectionURIs = System.getProperty("oauth.clients." + clientID + ".redirectionURIs");
    if (redirectionURIs == null) {
      LOG.warn(
          "Unknow OAUTH ClientID {} requested a token. Please define system property 'oauth.clients.{}.redirectionURIs'.",
          clientID,
          clientID);
      throw new LoginException(
          "Unknow OAUTH ClientID {} requested a token. Please define system property 'oauth.clients.{}.redirectionURIs'.");
    }

    String redirectUri = authorizationRequest.getRedirectionURI().toString();

    for (String allowedUri : Arrays.asList(redirectionURIs.split(","))) {
      if (StringUtils.startsWithIgnoreCase(redirectUri, allowedUri)) {
        return true;
      }
    }

    LOG.warn(
        "OAUTH ClientID {} requested a token but the redirect urls does not match. Actual redirectionurl {} is not defined in {}.",
        clientID,
        authorizationRequest.getRedirectionURI(),
        redirectionURIs);
    throw new LoginException(
        "OAUTH ClientID {} requested a token but the redirect urls does not match. Actual redirectionurl {} is not defined in {}.");
  }
  public void apply(ICompletionReporter reporter) throws BadLocationException {
    ICompletionContext context = getContext();
    if (!(context instanceof NamespaceMemberContext)) {
      return;
    }

    NamespaceMemberContext concreteContext = (NamespaceMemberContext) context;
    String prefix = concreteContext.getPrefix();
    String suffix = getSuffix(concreteContext);
    ISourceRange replaceRange = getReplacementRange(concreteContext);

    for (IType ns : concreteContext.getNamespaces()) {
      try {
        for (IMethod method : ns.getMethods()) {
          if (StringUtils.startsWithIgnoreCase(method.getElementName(), prefix)) {
            reporter.reportMethod(method, suffix, replaceRange);
          }
        }
      } catch (ModelException e) {
        PHPCorePlugin.log(e);
      }
    }
  }
 @Override
 public boolean canHandle(final @NonNull String geocode) {
   return (StringUtils.startsWithIgnoreCase(geocode, "GA")
           || StringUtils.startsWithIgnoreCase(geocode, "TP"))
       && isNumericId(geocode.substring(2));
 }
 public boolean isLoggable() {
   if (StringUtils.startsWithIgnoreCase(geocode, "GK")) {
     return false;
   }
   return true;
 }
Beispiel #13
0
 public boolean supportsGCVote() {
   return StringUtils.startsWithIgnoreCase(geocode, "GC");
 }
Beispiel #14
0
  protected void runCLI(String[] args) {
    // prepare CLI and parse arguments
    Options options = createOptions();
    CommandLineParser parser = new PosixParser();
    CommandLine line = null;
    try {
      line = parser.parse(options, args);
    } catch (ParseException ex) {
      usage(options);
      System.err.println();
      System.err.println(ex.getMessage());
      log.fatal(ex);
      System.exit(1);
    }

    String[] remainingArgs = line.getArgs();
    if (remainingArgs.length > 0) {
      this.usage(options);
      System.err.println();
      StringBuilder builder = new StringBuilder(100);
      for (String argument : remainingArgs) {
        if (builder.length() > 0) builder.append(", ");
        builder.append(argument);
      }
      String argumentsLine = builder.toString().trim();
      System.err.print("Cannot recognize the following argument");
      if (remainingArgs.length >= 2) System.err.print("s");
      System.err.println(": " + argumentsLine + ".");
      System.exit(1);
    }

    // set member variables depending on CLI arguments.
    if (line.hasOption("verbose")) {
      setVerbose(true);
    }

    if (line.hasOption("dry-run")) {
      setDryrun(true);
    }

    if (line.hasOption("stdout")) {
      setStdout(true);
    }

    // check mutual exclusive arguments
    if (line.hasOption("delete") && line.hasOption("delete-all")) {
      usage(options);
      System.err.println(
          "\n\nYou cannot use the options --delete <handle> " + "and --delete-all together.");
      System.exit(1);
    }

    if (line.hasOption("convert-all")
        && (line.hasOption("delete") || line.hasOption("delete-all"))) {
      usage(options);
      System.err.println(
          "\n\nYou cannot use the option --convert-all "
              + "together with --delete or --delete-all.");
      System.exit(1);
    }
    if (line.hasOption("identifiers")
        && (line.hasOption("delete") || line.hasOption("delete-all"))) {
      usage(options);
      System.err.println(
          "\n\nYou cannot use the option --identifiers <handle> "
              + "together with --delete or --delete-all.");
      System.exit(1);
    }
    if (line.hasOption("stdout") && (line.hasOption("delete") || line.hasOption("delete-all"))) {
      usage(options);
      System.err.println(
          "\n\nYou cannot use the option --stdout together " + "with --delete or --deleta-all.");
      System.exit(1);
    }

    // Run commands depending on CLI arguments.
    // process help first to prevent further evaluation of given options.
    if (line.hasOption('h')) {
      usage(options);
      System.exit(0);
    }

    if (line.hasOption("delete")) {
      String[] identifiers = line.getOptionValues("delete");
      for (String identifier : identifiers) {
        if (!StringUtils.startsWithIgnoreCase(identifier, "hdl:")) {
          if (!this.dryrun) {
            storage.delete(identifier);
          }
          if (this.verbose) {
            System.err.println("Deleted " + identifier + ".");
          }
          continue;
        }
        String handle = identifier.substring(4);

        log.debug("Trying to resolve identifier " + handle + ".");

        DSpaceObject dso = resolveHandle(handle);
        if (dso == null) {
          // resolveHandle reports problems and return null in case
          // of an error or an unresolvable handle.
          // Don't report it a second time, just continue...
          continue;
        }

        log.debug(
            "Resolved identifier "
                + handle
                + " as "
                + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso)
                + " "
                + dso.getID());

        try {
          this.delete(dso, true);
        } catch (SQLException ex) {
          log.error(ex);
          System.err.println(
              "A problem with the database connection " + "occurred. Canceled pending actions.");
          System.err.println(ex.getMessage());
          ex.printStackTrace(System.err);
          System.exit(1);
        }
      }
      System.exit(0);
    }

    if (line.hasOption("delete-all")) {
      this.deleteAll();
      System.exit(0);
    }

    if (line.hasOption("identifiers")) {
      String[] identifiers = line.getOptionValues("identifiers");
      report("Starting conversion of specified DSpaceObjects...");

      this.processed.clear();
      for (String handle : identifiers) {
        log.debug("Trying to resolve identifier " + handle + ".");

        DSpaceObject dso = resolveHandle(handle);
        if (dso == null) {
          // resolveHandle reports problems and return null in case
          // of an error or an unresolvable handle.
          // Don't report it a second time, just continue...
          continue;
        }

        try {
          this.convert(dso, false);
        } catch (SQLException ex) {
          log.error(ex);
          System.err.println(
              "A problem with the database connection " + "occurred. Canceled pending actions.");
          System.err.println(ex.getMessage());
          ex.printStackTrace(System.err);
          System.exit(1);
        }
      }
      report("Conversion ended.");
      System.exit(0);
    }

    if (line.hasOption("convert-all")) {
      try {
        this.convertAll();
      } catch (SQLException ex) {
        log.error(ex);
        System.err.println(
            "A problem with the database connection " + "occurred. Canceled pending actions.");
        System.err.println(ex.getMessage());
        ex.printStackTrace(System.err);
        System.exit(1);
      }
      System.exit(0);
    }

    this.usage(options);
    System.exit(0);
  }
  /**
   * Reads the data from the given node and generates an AmazonResult from it.
   *
   * @param nodeObj
   * @return
   */
  private static AmazonResult getResultFromNode(final Object nodeObj) {

    Node itemAttrNode = XPath.selectNode("./ItemAttributes", nodeObj);

    String title = getNodeContent(itemAttrNode, "./Title");

    String copyType = getNodeContent(itemAttrNode, "./Binding");
    if (copyTypeMatches.containsKey(copyType) == false) {
      if (Logger.isErrorEnabled() == true) {
        Logger.error("No copytype matching configured for amazon copytype: " + copyType);
      }
      return null;
    }
    copyType = copyTypeMatches.get(copyType);
    if (copyType.equals("BLURAY") == true && StringUtils.contains(title, "[Blu-ray 3D]") == true) {
      copyType = "BLURAY3D";
    }

    title = StringUtils.substringBefore(title, "(");

    if (CollectionUtils.isEmpty(removeFromTitleList) == false) {
      for (String removeFromTitle : removeFromTitleList) {
        title = StringUtils.remove(title, removeFromTitle);
      }
    }
    title = StringUtils.trim(title);

    String asin = getNodeContent(nodeObj, "./ASIN");
    String ean = getNodeContent(itemAttrNode, "./EAN");
    String rating = getNodeContent(itemAttrNode, "./AudienceRating");
    if (ageRatingMatches.containsKey(rating) == false) {
      if (Logger.isErrorEnabled() == true) {
        Logger.error("No agerating matching configured for amazon rating: " + rating);
      }
    } else {
      rating = ageRatingMatches.get(rating);
    }

    final Set<String> audioTypes = new HashSet<String>();

    final NodeList audioTypeNodes =
        XPath.selectNodes("./Languages/Language[AudioFormat and Type = 'Original']", itemAttrNode);
    for (int i = 0; i < audioTypeNodes.getLength(); i++) {
      Node langItem = audioTypeNodes.item(i);
      final Node nameNode = XPath.selectNode("./Name", langItem);
      final Node formatNode = XPath.selectNode("./AudioFormat", langItem);
      String audioType = StringUtils.EMPTY;
      if (nameNode != null && StringUtils.isEmpty(nameNode.getTextContent()) == false) {
        audioType = nameNode.getTextContent();
      }

      if (formatNode != null && StringUtils.isEmpty(formatNode.getTextContent()) == false) {
        if (StringUtils.isEmpty(audioType) == false) {
          audioType += " - ";
        }
        audioType += formatNode.getTextContent();
      }

      audioTypes.add(audioType);
    }

    final NodeList otherLanguageNodes =
        XPath.selectNodes("./Languages/Language[Type = 'Published']/Name", itemAttrNode);
    for (int i = 0; i < otherLanguageNodes.getLength(); i++) {
      String language = otherLanguageNodes.item(i).getTextContent();

      // check if the language is already known :)
      boolean alreadyKnown = false;

      for (final String audioType : audioTypes) {
        if (StringUtils.startsWithIgnoreCase(audioType, language) == true) {
          alreadyKnown = true;
          break;
        }
      }

      if (alreadyKnown == false) {
        audioTypes.add(language);
      }
    }

    final String imageUrl = getNodeContent(nodeObj, "./MediumImage/URL");

    final AmazonResult result =
        new AmazonResult(title, rating, copyType, asin, ean, audioTypes, imageUrl);

    return result;
  }