Beispiel #1
0
  public CSVParser(Reader input) throws IOException {
    count = 0;
    parsedValues = new ArrayList<>();

    BufferedReader bufferedReader = null;

    try {
      String sCurrentLine;
      bufferedReader = new BufferedReader(input);

      bufferedReader.readLine(); // Discard title line

      while ((sCurrentLine = bufferedReader.readLine()) != null) {
        count++;
        String[] split = sCurrentLine.split("\",\"");
        if (split.length > 1) {
          split[0] = StringUtils.strip(split[0], "\"");
          split[split.length - 1] = StringUtils.strip(split[split.length - 1], "\"");
          parsedValues.add(split);
        }
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    } finally {
      assert bufferedReader != null;
      bufferedReader.close();
    }
  }
 /**
  * *
  * <li><b>Trim/Strip</b> - removes leading and trailing whitespace Strip-->Strips any of a set of
  *     characters from the start and end of a String
  */
 @Test
 public void testTrimStripStringUtils() {
   System.out.println(strOne + ":" + strOne.length());
   System.out.println(StringUtils.trim("    " + strOne + "    ").length());
   System.out.println(StringUtils.strip("    " + strOne + "    ").length());
   System.out.println(StringUtils.strip("zabcyx", "xyz"));
 }
Beispiel #3
0
  /**
   * Creates a internal molgenis id from a vcf entity
   *
   * @param vcfEntity
   * @return the id
   */
  public static String createId(Entity vcfEntity) {
    StringBuilder id = new StringBuilder();
    id.append(StringUtils.strip(vcfEntity.get(CHROM).toString()));
    id.append("_");
    id.append(StringUtils.strip(vcfEntity.get(POS).toString()));
    id.append("_");
    id.append(StringUtils.strip(vcfEntity.get(REF).toString()));
    id.append("_");
    id.append(StringUtils.strip(vcfEntity.get(ALT).toString()));

    return id.toString();
  }
Beispiel #4
0
  /**
   * Returns the annotations to which should be displayed together with their namespace.
   *
   * <p>This will check the "show_ns" paramter for determining. the annotations to display. It also
   * iterates over all nodes of the graph matching the type.
   *
   * @param input The input for the visualizer.
   * @param types Which types of nodes to include
   * @return
   */
  public static Set<String> computeDisplayedNamespace(
      VisualizerInput input, List<Class<? extends SNode>> types) {
    if (input == null) {
      return new HashSet<>();
    }

    String showNamespaceConfig =
        input.getMappings().getProperty(GridComponent.MAPPING_SHOW_NAMESPACE);

    if (showNamespaceConfig != null) {

      SDocumentGraph graph = input.getDocument().getDocumentGraph();

      Set<String> annoPool = new LinkedHashSet<>();
      for (Class<? extends SNode> t : types) {
        annoPool.addAll(
            SToken.class.isAssignableFrom(t)
                ? getAnnotationLevelSet(graph, null, t)
                : getAnnotationLevelSet(graph, input.getNamespace(), t));
      }

      if ("true".equalsIgnoreCase(showNamespaceConfig)) {
        // all annotations should be displayed with a namespace
        return annoPool;
      } else if ("false".equalsIgnoreCase(showNamespaceConfig)) {
        return new LinkedHashSet<>();
      } else {
        Set<String> annos = new LinkedHashSet<>();

        List<String> defs =
            Splitter.on(',').omitEmptyStrings().trimResults().splitToList(showNamespaceConfig);
        for (String s : defs) {
          // is regular expression?
          if (s.startsWith("/") && s.endsWith("/")) {
            // go over all remaining items in our pool of all annotations and
            // check if they match
            Pattern regex = Pattern.compile(StringUtils.strip(s, "/"));

            LinkedList<String> matchingAnnos = new LinkedList<>();
            for (String a : annoPool) {
              if (regex.matcher(a).matches()) {
                matchingAnnos.add(a);
              }
            }

            annos.addAll(matchingAnnos);
            annoPool.removeAll(matchingAnnos);

          } else {
            annos.add(s);
            annoPool.remove(s);
          }
        }

        return annos;
      }
    }

    return new LinkedHashSet<>();
  }
 private static String validateName(String name) {
   name = StringUtils.strip(name);
   byte[] nameBytes = name.getBytes();
   for (byte b : nameBytes) {
     if ((b >= 0 && b <= 31) || (b == 127)) {
       throw new IllegalArgumentException("name contains unprintable character(s)");
     }
   }
   if (name.startsWith(".")) {
     throw new IllegalArgumentException("name starts with a dot");
   }
   name = StringUtils.strip(name, ".");
   if (StringUtils.contains(name, "\"*/:<>?\\|")) {
     throw new IllegalArgumentException("name contains illegal character(s)");
   }
   return name;
 }
Beispiel #6
0
 private void addToQuote(String value) {
   value = StringUtils.strip(value, QuoteRequest.garbageToStrip);
   value = StringUtils.remove(value, "<br");
   boolean hasSpecialChar = QuoteRequest.goodPattern.matcher(value).find();
   if (!hasSpecialChar) {
     if (value.length() > 0) {
       this.quoteSet.add(value);
     }
   }
 }
  public static void main(String[] args) {
    PasswordEncoder enc = new BCryptPasswordEncoder();

    Arrays.asList("root", "admin", "usuario")
        .stream()
        .forEach(
            pass -> {
              System.out.println(
                  String.format(
                      "'%s', '%s'", pass, StringUtils.strip(enc.encode(pass).substring(10))));
            });
  }
  private void extractDescription(
      @NotNull Element element, String queryString, DictionaryObjectBuilder objectBuilder) {
    Element descriptionNode = element.getElementsByClass("info").first();
    if (descriptionNode != null) {
      String description = descriptionNode.text();

      description = StringUtils.removeStart(description, "(");
      description = StringUtils.removeEnd(description, ")");

      if (!StringUtils.equalsIgnoreCase(
          description, queryString)) // Set description only if it is different from request string
      objectBuilder.setDescription(StringUtils.strip(description));
    }
  }
Beispiel #9
0
  public String getDockerHostIpAddress(Map<String, String> environment) {
    String ipAddress = LOCALHOST; // Default of localhost
    String dockerMachineName = getDockerMachineName(environment);

    if (!dockerMachineName.isEmpty()) {
      LOG.debug("Docker machine name = " + dockerMachineName);
      CommandLine commandline = CommandLine.parse(DOCKER_MACHINE_IP);
      commandline.addArgument(dockerMachineName);
      LOG.debug("Running exec: " + commandline.toString());
      try {
        ipAddress = StringUtils.strip(runCommand(commandline));
      } catch (IOException e) {
        LOG.error("Unable to run exec command to find ip address.", e);
      }
    } else {
      ipAddress = getDocker0AdapterIPAddress();
    }
    LOG.debug("Returned IP address: " + ipAddress);
    return ipAddress;
  }
Beispiel #10
0
  @NotNull
  private DictionaryObject processSingleNode(
      @NotNull Element element, @NotNull Language language, String queryString) {
    DictionaryObjectBuilder objectBuilder = ImmutableDictionaryObject.builder();
    objectBuilder.setLanguage(language);

    // Extract entry text:
    String context =
        StringUtils.substringBefore(element.text(), element.getElementsByTag("a").first().text());
    String generalForm = context + element.getElementsByTag("a").first().text();
    objectBuilder.setGeneralForm(StringUtils.strip(generalForm));

    // Extract description:
    extractDescription(element, queryString, objectBuilder);

    // Extract gender:
    extractGender(element, objectBuilder);

    return objectBuilder.build();
  }
Beispiel #11
0
 /**
  * Looks for a cat with a label under a given parent
  *
  * @param label
  * @param parentId
  * @return id or -1 if not found
  */
 public static long find(String label, Long parentId) {
   label = StringUtils.strip(label);
   String selection;
   String[] selectionArgs;
   if (parentId == null) {
     selection = KEY_PARENTID + " is null";
     selectionArgs = new String[] {label};
   } else {
     selection = KEY_PARENTID + " = ?";
     selectionArgs = new String[] {String.valueOf(parentId), label};
   }
   selection += " and " + KEY_LABEL + " = ?";
   Cursor mCursor =
       cr().query(CONTENT_URI, new String[] {KEY_ROWID}, selection, selectionArgs, null);
   if (mCursor.getCount() == 0) {
     mCursor.close();
     return -1;
   } else {
     mCursor.moveToFirst();
     long result = mCursor.getLong(0);
     mCursor.close();
     return result;
   }
 }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 1) {
      if ("list".equalsIgnoreCase(args[0])) {
        playerMsg("Tags for all online players:");

        for (final Player player : server.getOnlinePlayers()) {
          final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
          if (playerdata.getTag() != null) {
            playerMsg(player.getName() + ": " + playerdata.getTag());
          }
        }

        return true;
      } else if ("clearall".equalsIgnoreCase(args[0])) {
        if (!TFM_AdminList.isSuperAdmin(sender)) {
          playerMsg(TFM_Command.MSG_NO_PERMS);
          return true;
        }

        TFM_Util.adminAction(sender.getName(), "Removing all tags", false);

        int count = 0;
        for (final Player player : server.getOnlinePlayers()) {
          final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
          if (playerdata.getTag() != null) {
            count++;
            playerdata.setTag(null);
          }
        }

        playerMsg(count + " tag(s) removed.");

        return true;
      } else if ("off".equalsIgnoreCase(args[0])) {
        if (senderIsConsole) {
          playerMsg(
              "\"/tag off\" can't be used from the console. Use \"/tag clear <player>\" or \"/tag clearall\" instead.");
        } else {
          TFM_PlayerData.getPlayerData(sender_p).setTag(null);
          playerMsg("Your tag has been removed.");
        }

        return true;
      } else {
        return false;
      }
    } else if (args.length >= 2) {
      if ("clear".equalsIgnoreCase(args[0])) {
        if (!TFM_AdminList.isSuperAdmin(sender)) {
          playerMsg(TFM_Command.MSG_NO_PERMS);
          return true;
        }

        final Player player = getPlayer(args[1]);

        if (player == null) {
          playerMsg(TFM_Command.PLAYER_NOT_FOUND);
          return true;
        }

        TFM_PlayerData.getPlayerData(player).setTag(null);
        playerMsg("Removed " + player.getName() + "'s tag.");

        return true;
      } else if ("set".equalsIgnoreCase(args[0])) {
        final String inputTag = StringUtils.join(args, " ", 1, args.length);
        final String outputTag =
            TFM_Util.colorize(
                    StringUtils.replaceEachRepeatedly(
                        StringUtils.strip(inputTag),
                        new String[] {"" + ChatColor.COLOR_CHAR, "&k"},
                        new String[] {"", ""}))
                + ChatColor.RESET;

        if (!TFM_AdminList.isSuperAdmin(sender)) {
          final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();

          if (rawTag.length() > 20) {
            playerMsg("That tag is too long (Max is 20 characters).");
            return true;
          }

          String vartag = outputTag.toLowerCase();

          if (vartag.contains("admin")
              && vartag.contains("mod")
              && vartag.contains("owner")
              && vartag.contains("moderator")
              && vartag.contains("developer")
              && vartag.contains("console")
              && vartag.contains("super admin")
              && vartag.contains("telnet admin")
              && vartag.contains("senior admin")) {
            Command_smite.smite(sender_p, "[AutoSmite] You are not an administrator");
            return true;
          }
        }

        TFM_PlayerData.getPlayerData(sender_p).setTag(outputTag);
        playerMsg("Tag set to '" + outputTag + "'.");

        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
Beispiel #13
0
  /**
   * Returns the annotations to display according to the mappings configuration.
   *
   * <p>This will check the "annos" and "annos_regex" paramters for determining. the annotations to
   * display. It also iterates over all nodes of the graph matching the type.
   *
   * @param input The input for the visualizer.
   * @param type Which type of nodes to include
   * @return
   */
  public static List<String> computeDisplayAnnotations(
      VisualizerInput input, Class<? extends SNode> type) {
    if (input == null) {
      return new LinkedList<>();
    }

    SDocumentGraph graph = input.getDocument().getDocumentGraph();

    Set<String> annoPool =
        SToken.class.isAssignableFrom(type)
            ? getAnnotationLevelSet(graph, null, type)
            : getAnnotationLevelSet(graph, input.getNamespace(), type);
    List<String> annos = new LinkedList<>(annoPool);

    String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY);
    if (annosConfiguration != null && annosConfiguration.trim().length() > 0) {
      String[] split = annosConfiguration.split(",");
      annos.clear();
      for (String s : split) {
        s = s.trim();
        // is regular expression?
        if (s.startsWith("/") && s.endsWith("/")) {
          // go over all remaining items in our pool of all annotations and
          // check if they match
          Pattern regex = Pattern.compile(StringUtils.strip(s, "/"));

          LinkedList<String> matchingAnnos = new LinkedList<>();
          for (String a : annoPool) {
            if (regex.matcher(a).matches()) {
              matchingAnnos.add(a);
            }
          }

          annos.addAll(matchingAnnos);
          annoPool.removeAll(matchingAnnos);

        } else {
          annos.add(s);
          annoPool.remove(s);
        }
      }
    }

    // filter already found annotation names by regular expression
    // if this was given as mapping
    String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY);
    if (regexFilterRaw != null) {
      try {
        Pattern regexFilter = Pattern.compile(regexFilterRaw);
        ListIterator<String> itAnnos = annos.listIterator();
        while (itAnnos.hasNext()) {
          String a = itAnnos.next();
          // remove entry if not matching
          if (!regexFilter.matcher(a).matches()) {
            itAnnos.remove();
          }
        }
      } catch (PatternSyntaxException ex) {
        log.warn("invalid regular expression in mapping for grid visualizer", ex);
      }
    }
    return annos;
  }
Beispiel #14
0
 /**
  * we currently do not need a full representation of a category as an object when we create an
  * instance with an id, we only want to alter its label and are not interested in its parentId
  * when we create an instance with a parentId, it is a new instance
  *
  * @param id
  * @param label
  * @param parentId
  */
 public Category(Long id, String label, Long parentId) {
   this.setId(id);
   this.label = StringUtils.strip(label);
   this.parentId = parentId;
 }
 String extractTextFromPageArea(PDPage page, TopLeftRectangularBox area) throws TaskIOException {
   String text = new PdfTextExtractorByArea().extractTextFromArea(page, area.asRectangle());
   String result = defaultIfBlank(text, "");
   result = StringUtils.strip(result);
   return result;
 }