Example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens

List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens.

Prototype

public static String[] splitPreserveAllTokens(String str, String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:org.kuali.kfs.module.purap.util.ItemParserBase.java

/**
 * Parses a line of item data from a csv file and retrieves the attributes as key-value string pairs into a map.
 * //from w  w  w  .j a  va2s . com
 * @param itemLine a string read from a line in the item import file
 * @return a map containing item attribute name-value string pairs
 */
protected Map<String, String> retrieveItemAttributes(String itemLine) {
    String[] attributeNames = getItemFormat();
    String[] attributeValues = StringUtils.splitPreserveAllTokens(itemLine, ',');
    if (attributeNames.length != attributeValues.length) {
        String[] errorParams = { "" + attributeNames.length, "" + attributeValues.length, "" + lineNo };
        GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERRORS,
                ERROR_ITEMPARSER_WRONG_PROPERTY_NUMBER, errorParams);
        throw new ItemParserException(
                "wrong number of item properties: " + attributeValues.length + " exist, "
                        + attributeNames.length + " expected (line " + lineNo + ")",
                ERROR_ITEMPARSER_WRONG_PROPERTY_NUMBER, errorParams);
    }

    Map<String, String> itemMap = new HashMap<String, String>();
    for (int i = 0; i < attributeNames.length; i++) {
        itemMap.put(attributeNames[i], attributeValues[i]);
    }
    return itemMap;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 *
 * This method retrieves the attributes as key-value string pairs into a map.
 * @param line//w  ww  .j a  va  2s . c  om
 * @param attributeNames
 * @param lineNo
 * @param tabErrorKey
 * @return
 */
protected Map<String, String> retrieveObjectAttributes(String line, String[] attributeNames,
        Map<String, List<String>> defaultValues, Integer[] attributeMaxLength, Integer lineNo,
        String tabErrorKey) {
    String[] attributeValues = StringUtils.splitPreserveAllTokens(line, ',');
    if (attributeNames.length != attributeValues.length) {
        String[] errorParams = { "" + attributeNames.length, "" + attributeValues.length, "" + lineNo };
        GlobalVariables.getMessageMap().putError(tabErrorKey, ERROR_UPLOADPARSER_WRONG_PROPERTY_NUMBER,
                errorParams);
        throw new UploadParserException(
                "wrong number of properties: " + attributeValues.length + " exist, " + attributeNames.length
                        + " expected (line " + lineNo + ")",
                ERROR_UPLOADPARSER_WRONG_PROPERTY_NUMBER, errorParams);
    }

    for (int i = 0; i < attributeNames.length; i++) {
        if (defaultValues != null && defaultValues.get(attributeNames[i]) != null) {
            List<String> defaultValue = defaultValues.get(attributeNames[i]);
            boolean found = false;
            for (String value : defaultValue) {
                if (attributeValues[i].equalsIgnoreCase(value)) {
                    found = true;
                }
            }
            if (!found) {
                GlobalVariables.getMessageMap().putWarning(tabErrorKey, MESSAGE_UPLOADPARSER_INVALID_VALUE,
                        attributeNames[i], attributeValues[i], (" " + lineNo));
                throw new UploadParserException(
                        "Invalid value " + attributeValues[i] + " exist, " + "in line (" + lineNo + ")",
                        ERROR_UPLOADPARSER_WRONG_PROPERTY_NUMBER);
            }
        }

        if (attributeMaxLength != null) {
            if (attributeValues[i] != null && attributeValues[i].length() > attributeMaxLength[i]) {
                attributeValues[i] = attributeValues[i].substring(0, attributeMaxLength[i]);
                String[] errorParams = { "" + attributeNames[i], "" + attributeMaxLength[i], "" + lineNo };
                GlobalVariables.getMessageMap().putWarning(tabErrorKey,
                        MESSAGE_UPLOADPARSER_EXCEEDED_MAX_LENGTH, errorParams);
            }
        }
    }

    Map<String, String> objectMap = new HashMap<String, String>();
    for (int i = 0; i < attributeNames.length; i++) {
        objectMap.put(attributeNames[i], attributeValues[i]);
    }

    return objectMap;
}

From source file:org.kuali.kfs.sys.batch.DelimitedFlatFileSpecification.java

/**
 * Splits the line based on the given delimiter and parses into properties
 * @see org.kuali.kfs.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object)
 *//*  w ww.ja  v  a  2s. co  m*/
@Override
public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse,
        Object parseIntoObject, int lineNumber) {
    String[] lineSegments = StringUtils.splitPreserveAllTokens(lineToParse, delimiter);
    for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
        try {
            propertySpecification
                    .setProperty(lineSegments[((DelimitedFlatFilePropertySpecification) propertySpecification)
                            .getLineSegmentIndex()], parseIntoObject, lineNumber);
        } catch (ArrayIndexOutOfBoundsException e) {
            LOG.debug("Unable to set property " + propertySpecification.getPropertyName()
                    + " since lineSegmentIndex does not exist for line");
        }
    }
}

From source file:org.kuali.kfs.sys.businessobject.AccountingLineParserBase.java

/**
 * Parses the csv line//from w  w  w.j a  va  2  s  .  c  o m
 * 
 * @param accountingLineClass
 * @param lineToParse
 * @return Map containing accounting line attribute,value pairs
 */
protected Map<String, String> parseAccountingLine(Class<? extends AccountingLine> accountingLineClass,
        String lineToParse) {
    if (StringUtils.isNotBlank(fileName) && !StringUtils.lowerCase(fileName).endsWith(".csv")) {
        throw new AccountingLineParserException("unsupported file format: " + fileName,
                ERROR_INVALID_FILE_FORMAT, fileName);
    }
    String[] attributes = chooseFormat(accountingLineClass);
    String[] attributeValues = StringUtils.splitPreserveAllTokens(lineToParse, ",");

    Map<String, String> attributeValueMap = new HashMap<String, String>();

    for (int i = 0; i < Math.min(attributeValues.length, attributes.length); i++) {
        attributeValueMap.put(attributes[i], attributeValues[i]);
    }

    return attributeValueMap;
}

From source file:org.medici.bia.common.search.AdvancedSearchDocument.java

/**
 * {@inheritDoc}/*from w w  w . j a va2s.co m*/
 */
@Override
public void initFromAdvancedSearchCommand(AdvancedSearchCommand command) {
    //Words
    if ((command.getWord() != null) && (command.getWord().size() > 0)) {
        wordsTypes = new ArrayList<WordType>(command.getWord().size());
        words = new ArrayList<String>(command.getWord().size());

        for (String singleWord : command.getWord()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 2) {
                    wordsTypes.add(WordType.valueOf(stringTokenizer.nextToken()));
                    StringBuffer tempString = new StringBuffer(
                            URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                    if (StringUtils.countMatches(tempString.toString(), "\"") % 2 != 0) {
                        tempString.setCharAt(tempString.lastIndexOf("\""), ' ');
                    }
                    words.add(tempString.toString());

                } else {
                    continue;
                }
            } catch (URIException uriException) {
                logger.debug(uriException);
                wordsTypes.remove(wordsTypes.size() - 1);
            }
        }
    } else {
        wordsTypes = new ArrayList<WordType>(0);
        words = new ArrayList<String>(0);
    }

    // Person
    if ((command.getPerson() != null) && (command.getPerson().size() > 0)) {
        personId = new ArrayList<Integer>(command.getPerson().size());
        person = new ArrayList<String>(command.getPerson().size());

        for (String singleWord : command.getPerson()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);

            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    personId.add(new Integer(0));
                    try {
                        person.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                    } catch (URIException uriException) {
                        logger.debug(uriException);
                    }
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text

                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        personId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty personId is equal to 0
                        personId.add(new Integer(0));
                    }
                    try {
                        person.add(URIUtil.decode(singleText, "UTF-8"));
                    } catch (URIException uriException) {
                        logger.debug(uriException);
                        personId.remove(personId.size() - 1);
                    }
                }
            } catch (NumberFormatException nex) {
                logger.error(nex);
            }
        }
    } else {
        personId = new ArrayList<Integer>(0);
        person = new ArrayList<String>(0);
    }

    // Place
    if ((command.getPlace() != null) && (command.getPlace().size() > 0)) {
        placeId = new ArrayList<Integer>(command.getPlace().size());
        place = new ArrayList<String>(command.getPlace().size());

        for (String singleWord : command.getPlace()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);

            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    placeId.add(new Integer(0));
                    place.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        placeId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty placeId is equal to 0
                        placeId.add(new Integer(0));
                    }
                    place.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException nex) {
                logger.debug(nex);
            } catch (URIException uriException) {
                logger.debug(uriException);
                placeId.remove(placeId.size() - 1);
            }
        }
    } else {
        placeId = new ArrayList<Integer>(0);
        place = new ArrayList<String>(0);
    }

    // Sender
    if ((command.getSender() != null) && (command.getSender().size() > 0)) {
        senderId = new ArrayList<Integer>(command.getSender().size());
        sender = new ArrayList<String>(command.getSender().size());

        for (String singleWord : command.getSender()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    senderId.add(new Integer(0));
                    sender.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        senderId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty senderId is equal to 0
                        senderId.add(new Integer(0));
                    }
                    sender.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException nex) {
                logger.debug(nex);
            } catch (URIException uriException) {
                logger.debug(uriException);
                senderId.remove(senderId.size() - 1);
            }
        }
    } else {
        senderId = new ArrayList<Integer>(0);
        sender = new ArrayList<String>(0);
    }

    // From
    if ((command.getFrom() != null) && (command.getFrom().size() > 0)) {
        fromId = new ArrayList<Integer>(command.getFrom().size());
        from = new ArrayList<String>(command.getFrom().size());

        for (String singleWord : command.getFrom()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);

            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    fromId.add(new Integer(0));
                    from.add(stringTokenizer.nextToken());
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        fromId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty fromId is equal to 0
                        fromId.add(new Integer(0));
                    }
                    from.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                fromId.remove(fromId.size() - 1);
            }
        }
    } else {
        fromId = new ArrayList<Integer>(0);
        from = new ArrayList<String>(0);
    }

    // Recipient
    if ((command.getRecipient() != null) && (command.getRecipient().size() > 0)) {
        recipientId = new ArrayList<Integer>(command.getRecipient().size());
        recipient = new ArrayList<String>(command.getRecipient().size());

        for (String singleWord : command.getRecipient()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    recipientId.add(new Integer(0));
                    recipient.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        recipientId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty recipientId is equal to 0
                        recipientId.add(new Integer(0));
                    }
                    recipient.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                recipientId.remove(recipientId.size() - 1);
            }
        }
    } else {
        recipientId = new ArrayList<Integer>(0);
        recipient = new ArrayList<String>(0);
    }

    // To
    if ((command.getTo() != null) && (command.getTo().size() > 0)) {
        toId = new ArrayList<Integer>(command.getTo().size());
        to = new ArrayList<String>(command.getTo().size());

        for (String singleWord : command.getTo()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);

            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    toId.add(new Integer(0));
                    to.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        toId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty toId is equal to 0
                        toId.add(new Integer(0));
                    }
                    to.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                toId.remove(toId.size() - 1);
            }
        }
    } else {
        toId = new ArrayList<Integer>(0);
        to = new ArrayList<String>(0);
    }

    // ResTo;
    if ((command.getRefersTo() != null) && (command.getRefersTo().size() > 0)) {
        refersToId = new ArrayList<Integer>(command.getRefersTo().size());
        refersTo = new ArrayList<String>(command.getRefersTo().size());

        for (String singleWord : command.getRefersTo()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            // string format is number|text
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is |text
                    refersToId.add(new Integer(0));
                    refersTo.add(stringTokenizer.nextToken());
                } else if (stringTokenizer.countTokens() == 2) {
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(singleId)) {
                        refersToId.add(NumberUtils.createInteger(singleId));
                    } else {
                        //Empty refersToId is equal to 0
                        refersToId.add(new Integer(0));
                    }
                    refersTo.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                refersToId.remove(refersToId.size() - 1);
            }
        }
    } else {
        refersToId = new ArrayList<Integer>(0);
        refersTo = new ArrayList<String>(0);
    }

    // Extract
    if ((command.getExtract() != null) && (command.getExtract().size() > 0)) {
        extract = new ArrayList<String>(command.getExtract().size());

        for (String singleWord : command.getExtract()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            //RR: And this is for replacing special characters with unicode values
            singleWord = URLTransformer.decode(singleWord);
            try {
                extract.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        extract = new ArrayList<String>(0);
    }

    // Synopsis
    if ((command.getSynopsis() != null) && (command.getSynopsis().size() > 0)) {
        synopsis = new ArrayList<String>(command.getSynopsis().size());

        for (String singleWord : command.getSynopsis()) {
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            singleWord = URLTransformer.decode(singleWord);
            try {
                synopsis.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        synopsis = new ArrayList<String>(0);
    }

    // Topics
    if ((command.getTopic() != null) && (command.getTopic().size() > 0)) {
        topicsId = new ArrayList<Integer>(command.getTopic().size());
        topics = new ArrayList<String>(command.getTopic().size());
        topicsPlaceId = new ArrayList<Integer>(command.getTopic().size());
        topicsPlace = new ArrayList<String>(command.getTopic().size());

        for (String singleWord : command.getTopic()) {
            singleWord = singleWord.replace("+", "%20");

            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    // string format is number
                    String topicId = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(topicId)) {
                        topicsId.add(NumberUtils.createInteger(topicId));
                    } else {
                        //Empty topicsId is equal to 0
                        topicsId.add(new Integer(0));
                    }
                    //                  topics.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    // string format is number|text
                    String topicId = stringTokenizer.nextToken();
                    String topicText = stringTokenizer.nextToken();
                    // Check if field is correct
                    if (NumberUtils.isNumber(topicId)) {
                        topicsId.add(NumberUtils.createInteger(topicId));
                    } else {
                        //Empty topicsId is equal to 0
                        topicsId.add(new Integer(0));
                    }
                    topics.add(URIUtil.decode(topicText, "UTF-8"));
                } else if (stringTokenizer.countTokens() == 3) {
                    //string format is number|text|number
                    String singleId = stringTokenizer.nextToken();
                    String topicText = stringTokenizer.nextToken();
                    String placeId = stringTokenizer.nextToken();

                    if (NumberUtils.isNumber(singleId)) {
                        topicsId.add(NumberUtils.createInteger(singleId));
                    } else {
                        topicsId.add(new Integer(0));
                    }
                    topics.add(URIUtil.decode(topicText, "UTF-8"));
                    if (NumberUtils.isNumber(placeId)) {
                        topicsPlaceId.add(NumberUtils.createInteger(placeId));
                    } else {
                        topicsPlaceId.add(new Integer(0));
                    }
                } else if (stringTokenizer.countTokens() == 4) {
                    //string format is number|text|number|text
                    String singleId = stringTokenizer.nextToken();
                    String topicText = stringTokenizer.nextToken();
                    String placeId = stringTokenizer.nextToken();
                    String placeText = stringTokenizer.nextToken();

                    if (NumberUtils.isNumber(singleId)) {
                        topicsId.add(NumberUtils.createInteger(singleId));
                    } else {
                        topicsId.add(new Integer(0));
                    }
                    topics.add(URIUtil.decode(topicText, "UTF-8"));
                    if (NumberUtils.isNumber(placeId)) {
                        topicsPlaceId.add(NumberUtils.createInteger(placeId));
                    } else {
                        topicsPlaceId.add(new Integer(0));
                    }
                    topicsPlace.add(URIUtil.decode(placeText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                topicsId.remove(topicsId.size() - 1);
                topicsPlaceId.remove(topicsPlaceId.size() - 1);
            }
        }
    } else {
        topicsId = new ArrayList<Integer>(0);
        topics = new ArrayList<String>(0);
    }

    //Topics Place
    // Place
    //      if ((command.getTopicPlace() != null) && (command.getTopicPlace().size() >0)) {
    //         topicsPlaceId = new ArrayList<Integer>(command.getTopicPlace().size());
    //         topicsPlace = new ArrayList<String>(command.getTopicPlace().size());
    //         
    //         for (String singleWord : command.getTopicPlace()) {
    //            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
    //            singleWord = singleWord.replace("+", "%20");
    //            singleWord = singleWord.replace("%E7", "\u00E7");
    //            
    //            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
    //            try {
    //               if (stringTokenizer.countTokens() == 0) {
    //                  continue;
    //               } else if (stringTokenizer.countTokens() == 1) {
    //                  // string format is |text
    //                  topicsPlaceId.add(new Integer(0));
    //                  topicsPlace.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
    //               } else if (stringTokenizer.countTokens() == 2) {
    //                  // string format is number|text
    //                  String singleId = stringTokenizer.nextToken();
    //                  String singleText = stringTokenizer.nextToken();
    //                  // Check if field is correct
    //                  if (NumberUtils.isNumber(singleId)) { 
    //                     topicsPlaceId.add(NumberUtils.createInteger(singleId));
    //                  } else {
    //                     //Empty placeId is equal to 0
    //                     topicsPlaceId.add(new Integer(0));
    //                  }
    //                  topicsPlace.add(URIUtil.decode(singleText, "UTF-8"));
    //               }
    //            } catch (NumberFormatException numberFormatException) {
    //               logger.debug(numberFormatException);
    //            } catch (URIException uriException) {
    //               logger.debug(uriException);
    //               topicsPlaceId.remove(topicsPlaceId.size()-1);
    //            }
    //         }
    //      } else {
    //         topicsPlaceId = new ArrayList<Integer>(0);
    //         topicsPlace = new ArrayList<String>(0);
    //      }

    //Date
    if ((command.getDate() != null) && (command.getDate().size() > 0)) {
        datesTypes = new ArrayList<DateType>(command.getDate().size());
        datesYear = new ArrayList<Integer>(command.getDate().size());
        datesMonth = new ArrayList<Integer>(command.getDate().size());
        datesDay = new ArrayList<Integer>(command.getDate().size());
        datesYearBetween = new ArrayList<Integer>(command.getDate().size());
        datesMonthBetween = new ArrayList<Integer>(command.getDate().size());
        datesDayBetween = new ArrayList<Integer>(command.getDate().size());

        for (String singleWord : command.getDate()) {
            //e.g. After|1222|01|12|1223|12|12
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesTypes.add(DateType.valueOf(fields[0]));
            datesYear.add(DateUtils.getDateYearFromString(fields[1]));
            datesMonth.add(DateUtils.getDateMonthFromString(fields[2]));
            datesDay.add(DateUtils.getDateDayFromString(fields[3]));
            datesYearBetween.add(DateUtils.getDateYearFromString(fields[4]));
            datesMonthBetween.add(DateUtils.getDateMonthFromString(fields[5]));
            datesDayBetween.add(DateUtils.getDateDayFromString(fields[6]));
        }
    } else {
        datesTypes = new ArrayList<DateType>(0);
        datesYear = new ArrayList<Integer>(0);
        datesMonth = new ArrayList<Integer>(0);
        datesDay = new ArrayList<Integer>(0);
        datesYearBetween = new ArrayList<Integer>(0);
        datesMonthBetween = new ArrayList<Integer>(0);
        datesDayBetween = new ArrayList<Integer>(0);
    }

    //Date Created
    if ((command.getDateCreated() != null) && (command.getDateCreated().size() > 0)) {
        datesCreatedTypes = new ArrayList<DateType>(command.getDateCreated().size());
        datesCreated = new ArrayList<Date>(command.getDateCreated().size());
        datesCreatedBetween = new ArrayList<Date>(command.getDateCreated().size());

        for (String singleWord : command.getDateCreated()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesCreatedTypes.add(DateType.valueOf(fields[0]));
            datesCreated.add(DateUtils.getDateFromString(fields[1]));
            datesCreatedBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesCreatedTypes = new ArrayList<DateType>(0);
        datesCreated = new ArrayList<Date>(0);
        datesCreatedBetween = new ArrayList<Date>(0);
    }

    //Date lastUpdate
    if ((command.getDateLastUpdate() != null) && (command.getDateLastUpdate().size() > 0)) {
        datesLastUpdateTypes = new ArrayList<DateType>(command.getDateLastUpdate().size());
        datesLastUpdate = new ArrayList<Date>(command.getDateLastUpdate().size());
        datesLastUpdateBetween = new ArrayList<Date>(command.getDateLastUpdate().size());

        for (String singleWord : command.getDateLastUpdate()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesLastUpdateTypes.add(DateType.valueOf(fields[0]));
            datesLastUpdate.add(DateUtils.getDateFromString(fields[1]));
            datesLastUpdateBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesLastUpdateTypes = new ArrayList<DateType>(0);
        datesLastUpdate = new ArrayList<Date>(0);
        datesLastUpdateBetween = new ArrayList<Date>(0);
    }

    //Volume
    if ((command.getVolume() != null) && (command.getVolume().size() > 0)) {
        volumesTypes = new ArrayList<VolumeType>(command.getVolume().size());
        volumes = new ArrayList<String>(command.getVolume().size());
        volumesBetween = new ArrayList<String>(command.getVolume().size());

        for (String singleWord : command.getVolume()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            if ((stringTokenizer.countTokens() == 0) || (stringTokenizer.countTokens() == 1)) {
                continue;
            } else if (stringTokenizer.countTokens() == 2) {
                // string format is Exactly|12
                volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken()));
                volumes.add(stringTokenizer.nextToken());
                volumesBetween.add("0");
            } else if (stringTokenizer.countTokens() == 3) {
                // string format is Exactly|12|16
                volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken()));
                volumes.add(stringTokenizer.nextToken());
                volumesBetween.add(stringTokenizer.nextToken());
            }
        }
    } else {
        volumesTypes = new ArrayList<VolumeType>(0);
        volumes = new ArrayList<String>(0);
        volumesBetween = new ArrayList<String>(0);
    }

    // Insert
    if ((command.getInsert() != null && command.getInsert().size() > 0)) {
        insertNums = new ArrayList<String>(command.getInsert().size());

        for (String insert : command.getInsert()) {
            insertNums.add(insert);
        }
    } else {
        insertNums = new ArrayList<String>(0);
    }

    //Folio
    if ((command.getFolio() != null) && (command.getFolio().size() > 0)) {
        foliosTypes = new ArrayList<AdvancedSearchAbstract.FolioType>(command.getFolio().size());
        folios = new ArrayList<String>(command.getFolio().size());
        foliosBetween = new ArrayList<String>(command.getFolio().size());

        for (String singleWord : command.getFolio()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            if ((stringTokenizer.countTokens() == 0) || (stringTokenizer.countTokens() == 1)) {
                continue;
            } else if (stringTokenizer.countTokens() == 2) {
                foliosTypes.add(FolioType.valueOf(stringTokenizer.nextToken()));
                folios.add(stringTokenizer.nextToken());
                foliosBetween.add("0");
            } else if (stringTokenizer.countTokens() == 3) {
                foliosTypes.add(FolioType.valueOf(stringTokenizer.nextToken()));
                folios.add(stringTokenizer.nextToken());
                foliosBetween.add(stringTokenizer.nextToken());
            }
        }
    } else {
        foliosTypes = new ArrayList<AdvancedSearchAbstract.FolioType>(0);
        folios = new ArrayList<String>(0);
        foliosBetween = new ArrayList<String>(0);
    }

    //FolioMod
    if (command.getFolioMod() != null && command.getFolioMod().size() > 0) {
        folioMods = new ArrayList<String>(command.getFolioMod().size());
        folioMods.addAll(command.getFolioMod());
    } else {
        folioMods = new ArrayList<String>(0);
    }

    //EntryId
    if ((command.getDocId() != null) && (command.getDocId().size() > 0)) {
        docIds = new ArrayList<String>(command.getDocId().size());

        for (String singleWord : command.getDocId()) {
            try {
                docIds.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        docIds = new ArrayList<String>(0);
    }

    //LogicalDelete
    if (command.getLogicalDelete() != null) {
        if (command.getLogicalDelete().equals("true")) {
            logicalDelete = Boolean.TRUE;
        } else {
            logicalDelete = Boolean.FALSE;
        }
    }

    //Users
    if (command.getUser() != null) {
        userActionTypes = new ArrayList<UserActionType>(command.getUser().size());
        users = new ArrayList<String>(command.getUser().size());

        for (String singleUser : command.getUser()) {
            //MD: This is for refine search when the URLencoder change the space in "+"
            singleUser = singleUser.replace("+", "%20");
            singleUser = singleUser.replace("\"", "%22");
            singleUser = singleUser.replace("'", "%27");
            //RR: And this is for replacing special characters with unicode values
            singleUser = URLTransformer.decode(singleUser);
            StringTokenizer stringTokenizer = new StringTokenizer(singleUser, "|");
            try {
                if (stringTokenizer.countTokens() == 2) {
                    userActionTypes.add(UserActionType.valueOf(stringTokenizer.nextToken()));
                    StringBuffer tempString = new StringBuffer(
                            URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                    if (StringUtils.countMatches(tempString.toString(), "\"") % 2 != 0) {
                        tempString.setCharAt(tempString.lastIndexOf("\""), ' ');
                    }
                    users.add(tempString.toString());

                } else {
                    continue;
                }
            } catch (URIException uriException) {
                logger.debug(uriException);
                wordsTypes.remove(wordsTypes.size() - 1);
            }
        }
    } else {
        userActionTypes = new ArrayList<UserActionType>(0);
        users = new ArrayList<String>(0);
    }

}

From source file:org.medici.bia.common.search.AdvancedSearchPeople.java

/**
 * {@inheritDoc} /*from w ww  .  ja  v  a  2  s.  co  m*/
 */
@Override
public void initFromAdvancedSearchCommand(AdvancedSearchCommand command) {
    //Names
    if ((command.getNameParts() != null) && (command.getNameParts().size() > 0)) {
        namesTypes = new ArrayList<NameType>(command.getNameParts().size());
        names = new ArrayList<String>(command.getNameParts().size());

        for (String singleWord : command.getNameParts()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 2) {
                    namesTypes.add(NameType.valueOf(stringTokenizer.nextToken().replace(" ", "")));
                    names.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else {
                    continue;
                }
            } catch (URIException uriException) {
                logger.debug(uriException);
                namesTypes.remove(namesTypes.size() - 1);
            }
        }
    } else {
        namesTypes = new ArrayList<AdvancedSearchAbstract.NameType>(0);
        names = new ArrayList<String>(0);
    }

    //Exact Name
    if ((command.getPerson() != null) && (command.getPerson().size() > 0)) {
        personId = new ArrayList<Integer>(command.getPerson().size());
        exactName = new ArrayList<String>(command.getPerson().size());

        for (String singleWord : command.getPerson()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    personId.add(new Integer(0));
                    exactName.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(singleId)) {
                        personId.add(NumberUtils.createInteger(singleId));
                    } else {
                        personId.add(new Integer(0));
                    }
                    exactName.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                personId.remove(personId.size() - 1);
            }
        }
    } else {
        exactName = new ArrayList<String>(0);
        personId = new ArrayList<Integer>(0);
    }

    //Words
    if ((command.getWord() != null) && (command.getWord().size() > 0)) {
        //wordsTypes = new ArrayList<WordType>(command.getWord().size());
        words = new ArrayList<String>(command.getWord().size());

        for (String singleWord : command.getWord()) {
            //StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                //if (stringTokenizer.countTokens() == 2) {
                //wordsTypes.add(WordType.valueOf(stringTokenizer.nextToken()));
                //words.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                words.add(URIUtil.decode(singleWord, "UTF-8"));
                //} else {
                //   continue;
                //}
            } catch (URIException uriException) {
                logger.debug(uriException);
                //wordsTypes.remove(wordsTypes.size()-1);
                words.remove(words.size() - 1);
            }
        }
    } else {
        wordsTypes = new ArrayList<WordType>(0);
        words = new ArrayList<String>(0);
    }

    //Date
    if ((command.getDate() != null) && (command.getDate().size() > 0)) {
        datesTypes = new ArrayList<String>(command.getDate().size());
        datesYear = new ArrayList<Integer>(command.getDate().size());
        datesMonth = new ArrayList<Integer>(command.getDate().size());
        datesDay = new ArrayList<Integer>(command.getDate().size());
        datesYearBetween = new ArrayList<Integer>(command.getDate().size());
        datesMonthBetween = new ArrayList<Integer>(command.getDate().size());
        datesDayBetween = new ArrayList<Integer>(command.getDate().size());

        for (String singleWord : command.getDate()) {
            //e.g. After|1222|01|12|1223|12|12
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            try {
                datesTypes.add(URIUtil.decode(fields[0], "UTF-8"));
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
            datesYear.add(DateUtils.getDateYearFromString(fields[1]));
            datesMonth.add(DateUtils.getDateMonthFromString(fields[2]));
            datesDay.add(DateUtils.getDateDayFromString(fields[3]));
            datesYearBetween.add(DateUtils.getDateYearFromString(fields[4]));
            datesMonthBetween.add(DateUtils.getDateMonthFromString(fields[5]));
            datesDayBetween.add(DateUtils.getDateDayFromString(fields[6]));
        }
    } else {
        datesTypes = new ArrayList<String>(0);
        datesYear = new ArrayList<Integer>(0);
        datesMonth = new ArrayList<Integer>(0);
        datesDay = new ArrayList<Integer>(0);
        datesYearBetween = new ArrayList<Integer>(0);
        datesMonthBetween = new ArrayList<Integer>(0);
        datesDayBetween = new ArrayList<Integer>(0);
    }

    //Date lastUpdate
    if ((command.getDateLastUpdate() != null) && (command.getDateLastUpdate().size() > 0)) {
        datesLastUpdateTypes = new ArrayList<DateType>(command.getDateLastUpdate().size());
        datesLastUpdate = new ArrayList<Date>(command.getDateLastUpdate().size());
        datesLastUpdateBetween = new ArrayList<Date>(command.getDateLastUpdate().size());

        for (String singleWord : command.getDateLastUpdate()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesLastUpdateTypes.add(DateType.valueOf(fields[0]));
            datesLastUpdate.add(DateUtils.getDateFromString(fields[1]));
            datesLastUpdateBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesLastUpdateTypes = new ArrayList<DateType>(0);
        datesLastUpdate = new ArrayList<Date>(0);
        datesLastUpdateBetween = new ArrayList<Date>(0);
    }

    //Date Created
    if ((command.getDateCreated() != null) && (command.getDateCreated().size() > 0)) {
        datesCreatedTypes = new ArrayList<DateType>(command.getDateCreated().size());
        datesCreated = new ArrayList<Date>(command.getDateCreated().size());
        datesCreatedBetween = new ArrayList<Date>(command.getDateCreated().size());

        for (String singleWord : command.getDateCreated()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesCreatedTypes.add(DateType.valueOf(fields[0]));
            datesCreated.add(DateUtils.getDateFromString(fields[1]));
            datesCreatedBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesCreatedTypes = new ArrayList<DateType>(0);
        datesCreated = new ArrayList<Date>(0);
        datesCreatedBetween = new ArrayList<Date>(0);
    }

    //Role Categories
    if ((command.getRoleCategory() != null) && (command.getRoleCategory().size() > 0)) {
        roleCategories = new ArrayList<String>(command.getRoleCategory().size());
        for (String singleWord : command.getRoleCategory()) {
            try {
                roleCategories.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (URIException uriException) {
                logger.debug(uriException);
                roleCategories.remove(roleCategories.size() - 1);
            }
        }
    } else {
        roleCategories = new ArrayList<String>(0);
    }

    //OccupationsWords
    if ((command.getOccupationWord() != null) && (command.getOccupationWord().size() > 0)) {
        titleOccWord = new ArrayList<String>(command.getOccupationWord().size());
        for (String singleWord : command.getOccupationWord()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            try {
                titleOccWord.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        titleOccWord = new ArrayList<String>(0);
    }

    //Occupations
    if ((command.getOccupation() != null) && (command.getOccupation().size() > 0)) {
        titlesOccId = new ArrayList<Integer>(command.getOccupation().size());
        titlesOcc = new ArrayList<String>(command.getOccupation().size());

        for (String singleWord : command.getOccupation()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    titlesOccId.add(new Integer(0));
                    titlesOcc.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(singleId)) {
                        titlesOccId.add(NumberUtils.createInteger(singleId));
                    } else {
                        titlesOccId.add(new Integer(0));
                    }
                    titlesOcc.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                titlesOccId.remove(titlesOccId.size() - 1);
            }
        }
    } else {
        titlesOcc = new ArrayList<String>(0);
        titlesOccId = new ArrayList<Integer>(0);
    }

    //Gender
    if ((command.getGender() != null) && (command.getGender().size() > 0)) {
        gender = new ArrayList<AdvancedSearchAbstract.Gender>(command.getGender().size());

        for (String singleWord : command.getGender()) {
            try {
                gender.add(Gender.valueOf(URIUtil.decode(singleWord, "UTF-8")));
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        gender = new ArrayList<AdvancedSearchAbstract.Gender>(0);
    }

    //Places
    if ((command.getPlace() != null) && (command.getPlace().size() > 0)) {
        placeId = new ArrayList<Integer>(command.getPlace().size());
        place = new ArrayList<String>(command.getPlace().size());
        placeType = new ArrayList<String>(command.getPlace().size());

        for (String singleWord : command.getPlace()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    placeId.add(new Integer(0));
                    place.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(singleId)) {
                        placeId.add(NumberUtils.createInteger(singleId));
                    } else {
                        placeId.add(new Integer(0));
                    }
                    place.add(URIUtil.decode(singleText, "UTF-8"));
                } else if (stringTokenizer.countTokens() == 3) {
                    placeType.add(stringTokenizer.nextToken());
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(singleId)) {
                        placeId.add(NumberUtils.createInteger(singleId));
                    } else {
                        placeId.add(new Integer(0));
                    }
                    place.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                placeId.remove(placeId.size() - 1);
            }
        }
    } else {
        placeId = new ArrayList<Integer>(0);
        place = new ArrayList<String>(0);
        placeType = new ArrayList<String>(0);
    }

    //Research Notes
    if ((command.getResearchNotes() != null) && (command.getResearchNotes().size() > 0)) {
        researchNotes = new ArrayList<String>(command.getResearchNotes().size());

        for (String singleWord : command.getResearchNotes()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            try {
                researchNotes.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (URIException uriException) {
                logger.debug(uriException);
                researchNotes.remove(researchNotes.size() - 1);
            }
        }
    } else {
        researchNotes = new ArrayList<String>(0);
    }

    //PersonId
    if ((command.getPersonId() != null) && (command.getPersonId().size() > 0)) {
        peopleId = new ArrayList<String>(command.getPersonId().size());

        for (String singleWord : command.getPersonId()) {
            try {
                peopleId.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        peopleId = new ArrayList<String>(0);
    }

    //Logical Delete
    if (command.getLogicalDelete() != null) {
        if (command.getLogicalDelete().equals("true")) {
            logicalDelete = Boolean.TRUE;
        } else {
            logicalDelete = Boolean.FALSE;
        }
    }
}

From source file:org.medici.bia.common.search.AdvancedSearchPlace.java

/**
 * {@inheritDoc}/*from   w  w  w. ja va 2s .co m*/
 */
@Override
public void initFromAdvancedSearchCommand(AdvancedSearchCommand command) {
    // Place Name
    if ((command.getPlaceName() != null) && (command.getPlaceName().size() > 0)) {
        placesName = new ArrayList<String>(command.getPlaceName().size());

        for (String singleWord : command.getPlaceName()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            try {
                placesName.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        placesName = new ArrayList<String>(0);
    }

    //Exact Place Name
    if ((command.getPlace() != null) && (command.getPlace().size() > 0)) {
        placeId = new ArrayList<Integer>(command.getPlace().size());
        exactPlaceName = new ArrayList<String>(command.getPlace().size());

        for (String singleWord : command.getPlace()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 0) {
                    continue;
                } else if (stringTokenizer.countTokens() == 1) {
                    placeId.add(new Integer(0));
                    exactPlaceName.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else if (stringTokenizer.countTokens() == 2) {
                    String singleId = stringTokenizer.nextToken();
                    String singleText = stringTokenizer.nextToken();
                    if (NumberUtils.isNumber(singleId)) {
                        placeId.add(NumberUtils.createInteger(singleId));
                    } else {
                        placeId.add(new Integer(0));
                    }
                    exactPlaceName.add(URIUtil.decode(singleText, "UTF-8"));
                }
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
                placeId.remove(placeId.size() - 1);
            }
        }
    } else {
        exactPlaceName = new ArrayList<String>(0);
        placeId = new ArrayList<Integer>(0);
    }

    //Place Type
    if ((command.getPlaceType() != null) && (command.getPlaceType().size() > 0)) {
        placeType = new ArrayList<String>(command.getPlaceType().size());

        for (String singleWord : command.getPlaceType()) {
            try {
                placeType.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        placeType = new ArrayList<String>(0);
    }

    //Linked To People
    if ((command.getLinkedToPeople() != null) && (command.getLinkedToPeople().size() > 0)) {
        linkedToPeople = new ArrayList<String>(command.getLinkedToPeople().size());

        for (String singleWord : command.getLinkedToPeople()) {
            try {
                linkedToPeople.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        linkedToPeople = new ArrayList<String>(0);
    }

    //Date lastUpdate
    if ((command.getDateLastUpdate() != null) && (command.getDateLastUpdate().size() > 0)) {
        datesLastUpdateTypes = new ArrayList<DateType>(command.getDateLastUpdate().size());
        datesLastUpdate = new ArrayList<Date>(command.getDateLastUpdate().size());
        datesLastUpdateBetween = new ArrayList<Date>(command.getDateLastUpdate().size());

        for (String singleWord : command.getDateLastUpdate()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesLastUpdateTypes.add(DateType.valueOf(fields[0]));
            datesLastUpdate.add(DateUtils.getDateFromString(fields[1]));
            datesLastUpdateBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesLastUpdateTypes = new ArrayList<DateType>(0);
        datesLastUpdate = new ArrayList<Date>(0);
        datesLastUpdateBetween = new ArrayList<Date>(0);
    }

    //Date Created
    if ((command.getDateCreated() != null) && (command.getDateCreated().size() > 0)) {
        datesCreatedTypes = new ArrayList<DateType>(command.getDateCreated().size());
        datesCreated = new ArrayList<Date>(command.getDateCreated().size());
        datesCreatedBetween = new ArrayList<Date>(command.getDateCreated().size());

        for (String singleWord : command.getDateCreated()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesCreatedTypes.add(DateType.valueOf(fields[0]));
            datesCreated.add(DateUtils.getDateFromString(fields[1]));
            datesCreatedBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesCreatedTypes = new ArrayList<DateType>(0);
        datesCreated = new ArrayList<Date>(0);
        datesCreatedBetween = new ArrayList<Date>(0);
    }

    //PlaceAllId
    if ((command.getPlaceId() != null) && (command.getPlaceId().size() > 0)) {
        placesId = new ArrayList<String>(command.getPlaceId().size());

        for (String singleWord : command.getPlaceId()) {
            try {
                placesId.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        placesId = new ArrayList<String>(0);
    }

    //LogicalDelete
    if (command.getLogicalDelete() != null) {
        if (command.getLogicalDelete().equals("true")) {
            logicalDelete = Boolean.TRUE;
        } else {
            logicalDelete = Boolean.FALSE;
        }
    }

}

From source file:org.medici.bia.common.search.AdvancedSearchVolume.java

/**
 * {@inheritDoc}/*from www. jav a2  s .co m*/
 */
@Override
public void initFromAdvancedSearchCommand(AdvancedSearchCommand command) {
    //Words
    if ((command.getWord() != null) && (command.getWord().size() > 0)) {
        wordsTypes = new ArrayList<WordType>(command.getWord().size());
        words = new ArrayList<String>(command.getWord().size());

        for (String singleWord : command.getWord()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            try {
                if (stringTokenizer.countTokens() == 2) {
                    wordsTypes.add(WordType.valueOf(stringTokenizer.nextToken()));
                    words.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8"));
                } else {
                    continue;
                }
            } catch (URIException uriException) {
                logger.debug(uriException);
                wordsTypes.remove(wordsTypes.size() - 1);
            }
        }
    } else {
        wordsTypes = new ArrayList<WordType>(0);
        words = new ArrayList<String>(0);
    }

    //Date
    if ((command.getDate() != null) && (command.getDate().size() > 0)) {
        datesTypes = new ArrayList<DateType>(command.getDate().size());
        datesYear = new ArrayList<Integer>(command.getDate().size());
        datesMonth = new ArrayList<Integer>(command.getDate().size());
        datesDay = new ArrayList<Integer>(command.getDate().size());
        datesYearBetween = new ArrayList<Integer>(command.getDate().size());
        datesMonthBetween = new ArrayList<Integer>(command.getDate().size());
        datesDayBetween = new ArrayList<Integer>(command.getDate().size());

        for (String singleWord : command.getDate()) {
            //e.g. After|1222|01|12|1223|12|12
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesTypes.add(DateType.valueOf(fields[0]));
            datesYear.add(DateUtils.getDateYearFromString(fields[1]));
            datesMonth.add(DateUtils.getDateMonthFromString(fields[2]));
            datesDay.add(DateUtils.getDateDayFromString(fields[3]));
            datesYearBetween.add(DateUtils.getDateYearFromString(fields[4]));
            datesMonthBetween.add(DateUtils.getDateMonthFromString(fields[5]));
            datesDayBetween.add(DateUtils.getDateDayFromString(fields[6]));
        }
    } else {
        datesTypes = new ArrayList<DateType>(0);
        datesYear = new ArrayList<Integer>(0);
        datesMonth = new ArrayList<Integer>(0);
        datesDay = new ArrayList<Integer>(0);
        datesYearBetween = new ArrayList<Integer>(0);
        datesMonthBetween = new ArrayList<Integer>(0);
        datesDayBetween = new ArrayList<Integer>(0);
    }

    //Date lastUpdate
    if ((command.getDateLastUpdate() != null) && (command.getDateLastUpdate().size() > 0)) {
        datesLastUpdateTypes = new ArrayList<DateType>(command.getDateLastUpdate().size());
        datesLastUpdate = new ArrayList<Date>(command.getDateLastUpdate().size());
        datesLastUpdateBetween = new ArrayList<Date>(command.getDateLastUpdate().size());

        for (String singleWord : command.getDateLastUpdate()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesLastUpdateTypes.add(DateType.valueOf(fields[0]));
            datesLastUpdate.add(DateUtils.getDateFromString(fields[1]));
            datesLastUpdateBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesLastUpdateTypes = new ArrayList<DateType>(0);
        datesLastUpdate = new ArrayList<Date>(0);
        datesLastUpdateBetween = new ArrayList<Date>(0);
    }

    //Date Created
    if ((command.getDateCreated() != null) && (command.getDateCreated().size() > 0)) {
        datesCreatedTypes = new ArrayList<DateType>(command.getDateCreated().size());
        datesCreated = new ArrayList<Date>(command.getDateCreated().size());
        datesCreatedBetween = new ArrayList<Date>(command.getDateCreated().size());

        for (String singleWord : command.getDateCreated()) {
            //e.g. After|20120112|20120112
            String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|");
            datesCreatedTypes.add(DateType.valueOf(fields[0]));
            datesCreated.add(DateUtils.getDateFromString(fields[1]));
            datesCreatedBetween.add(DateUtils.getDateFromString(fields[2]));
        }
    } else {
        datesCreatedTypes = new ArrayList<DateType>(0);
        datesCreated = new ArrayList<Date>(0);
        datesCreatedBetween = new ArrayList<Date>(0);
    }

    //Volume
    if ((command.getVolume() != null) && (command.getVolume().size() > 0)) {
        volumesTypes = new ArrayList<VolumeType>(command.getVolume().size());
        volumes = new ArrayList<String>(command.getVolume().size());
        volumesBetween = new ArrayList<String>(command.getVolume().size());

        for (String singleWord : command.getVolume()) {
            StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|");
            if ((stringTokenizer.countTokens() == 0) || (stringTokenizer.countTokens() == 1)) {
                continue;
            } else if (stringTokenizer.countTokens() == 2) {
                // string format is Exactly|12
                volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken()));
                volumes.add(stringTokenizer.nextToken());
                volumesBetween.add("0");
            } else if (stringTokenizer.countTokens() == 3) {
                // string format is Exactly|12|16
                volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken()));
                volumes.add(stringTokenizer.nextToken());
                volumesBetween.add(stringTokenizer.nextToken());
            }
        }
    } else {
        volumesTypes = new ArrayList<VolumeType>(0);
        volumes = new ArrayList<String>(0);
        volumesBetween = new ArrayList<String>(0);
    }

    //Insert
    if ((command.getInsert() != null && command.getInsert().size() > 0)) {
        insertNums = new ArrayList<String>(command.getInsert().size());

        for (String insert : command.getInsert()) {
            insertNums.add(insert);
        }
    } else {
        insertNums = new ArrayList<String>(0);
    }

    //Digitized
    if (command.getDigitized() != null) {
        if (command.getDigitized().equals("Yes")) {
            digitized = true;
        } else {
            digitized = false;
        }
    }

    //Languages
    if (command.getLanguages() != null && command.getLanguages().size() > 0) {
        languages = new ArrayList<String>(command.getLanguages().size());
        languages.addAll(command.getLanguages());
    } else {
        languages = new ArrayList<String>(0);
    }

    //Other Languages
    if (command.getOtherLang() != null && command.getOtherLang().size() > 0) {
        otherLang = new ArrayList<String>(command.getOtherLang().size());
        otherLang.addAll(command.getOtherLang());
    } else {
        otherLang = new ArrayList<String>(0);
    }

    //Cypher
    if (command.getCipher() != null) {
        cipher = new String(command.getCipher());
    } else {
        cipher = new String();
    }

    //Index
    if (command.getIndex() != null) {
        index = new String(command.getIndex());
    } else {
        index = new String();
    }

    //From
    if (command.getFromVolume() != null && command.getFromVolume().size() > 0) {
        fromVolume = new ArrayList<String>(command.getFromVolume().size());
        for (String singleWord : command.getFromVolume()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            try {
                fromVolume.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        fromVolume = new ArrayList<String>(0);
    }

    //To
    if (command.getToVolume() != null && command.getToVolume().size() > 0) {
        toVolume = new ArrayList<String>(command.getToVolume().size());
        for (String singleWord : command.getToVolume()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            try {
                toVolume.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        toVolume = new ArrayList<String>(0);
    }

    //Context
    if (command.getContext() != null && command.getContext().size() > 0) {
        context = new ArrayList<String>(command.getContext().size());
        for (String singleWord : command.getContext()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            try {
                context.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        context = new ArrayList<String>(0);
    }

    //Inventario Sommario
    if (command.getInventario() != null && command.getInventario().size() > 0) {
        inventario = new ArrayList<String>(command.getInventario().size());
        for (String singleWord : command.getInventario()) {
            //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7"
            singleWord = singleWord.replace("+", "%20");
            singleWord = singleWord.replace("%E7", "\u00E7");
            singleWord = singleWord.replace("\"", "%22");
            singleWord = singleWord.replace("'", "%27");
            try {
                inventario.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        inventario = new ArrayList<String>(0);
    }

    //SummaryId
    if ((command.getVolumeId() != null) && (command.getVolumeId().size() > 0)) {
        volumesId = new ArrayList<String>(command.getVolumeId().size());

        for (String singleWord : command.getVolumeId()) {
            try {
                volumesId.add(URIUtil.decode(singleWord, "UTF-8"));
            } catch (NumberFormatException numberFormatException) {
                logger.debug(numberFormatException);
            } catch (URIException uriException) {
                logger.debug(uriException);
            }
        }
    } else {
        volumesId = new ArrayList<String>(0);
    }

    //LogicalDelete
    if (command.getLogicalDelete() != null) {
        if (command.getLogicalDelete().equals("true")) {
            logicalDelete = Boolean.TRUE;
        } else {
            logicalDelete = Boolean.FALSE;
        }
    }
}

From source file:org.medici.bia.controller.manuscriptviewer.AjaxController.java

/**
 * This method update the annotations of the folio presented in the manuscript viewer.
 * //  w ww  .  ja v  a  2  s .  c  om
 * @param httpServletRequest the request
 * @return
 */
@RequestMapping(value = { "/src/mview/UpdateAnnotations.json",
        "/de/mview/UpdateAnnotations.json" }, method = RequestMethod.POST)
public Map<String, Object> updateAnnotations(HttpServletRequest httpServletRequest) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    String account = ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
            .getUsername();
    Boolean administrator = getUserService().isAccountAdministrator(account);

    try {
        // In this controller we get input parameter at low level because 
        // there is a bug in spring which construct a wrong list of 
        // annotations in case of client send 1 single annotation 
        //String imageName = httpServletRequest.getParameter("imageName");
        Integer imageId = NumberUtils.toInt(httpServletRequest.getParameter("imageId"));
        String[] annotationsFormView = httpServletRequest.getParameterValues("annotations");
        List<Annotation> annotationsList = new ArrayList<Annotation>(0);
        List<Object> resultList = new ArrayList<Object>();

        if (annotationsFormView != null) {
            for (String string : annotationsFormView) {
                //Next code is instructed on code of javascript IIPMooViewer.annotationsAsQueryParameterString
                String[] splitted = StringUtils.splitPreserveAllTokens(string, "");
                Annotation annotation = new Annotation();
                annotation.setAnnotationId(NumberUtils.toInt(splitted[0]));
                annotation.setX(NumberUtils.toDouble(splitted[2]));
                annotation.setY(NumberUtils.toDouble(splitted[3]));
                annotation.setWidth(NumberUtils.toDouble(splitted[4]));
                annotation.setHeight(NumberUtils.toDouble(splitted[5]));
                annotation.setType(Annotation.Type.valueOf(splitted[6].toUpperCase()));
                annotation.setTitle(splitted[7]);
                annotation.setText(splitted[8]);
                annotation.setVisible(Boolean.valueOf(splitted[11]));
                annotationsList.add(annotation);
            }
        }
        Map<Annotation, Integer> imageAnnotationsMap = getManuscriptViewerService().updateAnnotations(imageId,
                annotationsList, httpServletRequest.getRemoteAddr(), administrator);
        for (Annotation currentAnnotation : imageAnnotationsMap.keySet()) {
            Map<String, Object> singleRow = new HashMap<String, Object>(0);
            if (imageAnnotationsMap.get(currentAnnotation) > -1) {
                singleRow.put("forum",
                        ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
                                .getRequest().getContextPath()
                                + "/community/EditForumPostAnnotation.do?topicId="
                                + imageAnnotationsMap.get(currentAnnotation));
                resultList.add(singleRow);
            }
        }
        // links -> only new annotations associated to a forum 
        model.put("links", resultList);
        // annotation -> all of the annotations associated to the current image
        model.put("annotations", getAnnotationsForView(null, imageAnnotationsMap.keySet()));
        model.put("adminPrivileges", administrator);
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("operation", "KO");
        model.put("error", applicationThrowable.getMessage() != null ? applicationThrowable.toString()
                : applicationThrowable.getCause().toString());
        return model;
    }
    model.put("operation", "OK");
    return model;
}

From source file:org.onehippo.forge.content.exim.core.util.ContentPathUtils.java

/**
 * Returns encoded node path where each node name in the {@code nodePath} is encoded
 * by using Hippo CMS Default URI Encoding strategy.
 * @param nodePath node path//from  w  w  w .  j a v  a  2  s  .c  o m
 * @return encoded node path where each node name in the {@code nodePath} is encoded
 *         by using Hippo CMS Default URI Encoding strategy
 */
public static String encodeNodePath(final String nodePath) {
    String[] nodeNames = StringUtils.splitPreserveAllTokens(nodePath, '/');

    if (nodeNames == null) {
        return null;
    }

    // If the nodePath starts with typical Hippo content node path like '/content/documents/MyHippoProject/...',
    // DO NOT encode the first three path segments
    // because the third path segment might be in upper-cases unlike descendant nodes.

    int begin = 0;
    final Matcher m = HIPPO_CONTENT_PATH_PREFIX_PATTERN.matcher(nodePath);
    if (m.lookingAt()) {
        begin = 4;
    }

    for (int i = begin; i < nodeNames.length; i++) {
        nodeNames[i] = HippoNodeUtils.getDefaultUriEncoding().encode(nodeNames[i]);
    }

    return StringUtils.join(nodeNames, '/');
}