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

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

Introduction

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

Prototype

public static String stripStart(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the start of a String.

Usage

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.por.PORFileReader.java

private void decodeNumberOfVariables(BufferedReader reader) throws IOException {
    if (reader == null) {
        throw new IllegalArgumentException("decodeNumberOfVariables: reader == null!");
    }//from w  ww.  j av a2s  . co m

    String temp = null;
    char[] tmp = new char[1];
    StringBuilder sb = new StringBuilder();

    while (reader.read(tmp) > 0) {
        temp = Character.toString(tmp[0]);
        if (temp.equals("/")) {
            break;
        } else {
            sb.append(temp);
        }
    }

    String rawNumberOfVariables = sb.toString();
    int rawLength = rawNumberOfVariables.length();

    String numberOfVariables = StringUtils.stripStart((StringUtils.strip(rawNumberOfVariables)), "0");

    if ((numberOfVariables.equals("")) && (numberOfVariables.length() == rawLength)) {
        numberOfVariables = "0";
    }

    varQnty = Integer.valueOf(numberOfVariables, 30);
    smd.getFileInformation().put("varQnty", varQnty);
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java

private void decodeNumberOfVariables(BufferedReader reader) throws IOException {
    if (reader == null) {
        throw new IllegalArgumentException("decodeNumberOfVariables: reader == null!");
    }//from  w  ww  . j av  a  2  s  . c  o  m

    String temp = null;
    char[] tmp = new char[1];
    StringBuilder sb = new StringBuilder();

    while (reader.read(tmp) > 0) {
        temp = Character.toString(tmp[0]);
        if (temp.equals("/")) {
            break;
        } else {
            sb.append(temp);
        }
    }

    String rawNumberOfVariables = sb.toString();
    int rawLength = rawNumberOfVariables.length();

    String numberOfVariables = StringUtils.stripStart((StringUtils.strip(rawNumberOfVariables)), "0");

    if ((numberOfVariables.equals("")) && (numberOfVariables.length() == rawLength)) {
        numberOfVariables = "0";
    }

    varQnty = Integer.valueOf(numberOfVariables, 30);
    dataTable.setVarQuantity(Long.valueOf(numberOfVariables, 30));
}

From source file:no.freecode.translator.business.MessageImporter.java

public void importData(InputStream input, String filename) throws IOException {
    MessageLocale locale = getLocale(filename);
    locale.persist();//from  w  w  w . j av a  2 s . c  om

    BufferedReader csvReader = new BufferedReader(new InputStreamReader(input));

    //        HashMap<String, MessageSection> sections = new HashMap<String, MessageSection>();

    //        MessageSection curSection = new MessageSection();
    String curSectionId;
    String curComment = null;

    String line;
    while ((line = StringEscapeUtils.unescapeJava(StringUtils.strip(csvReader.readLine()))) != null) {

        if (StringUtils.startsWith(line, "#")) {
            String comment = StringUtils.stripStart(line, "# ");
            if (StringUtils.isNotEmpty(comment)) {
                curComment = comment;
            }

        } else {
            // Proper line
            String[] entry = StringUtils.split(line, "=", 2);

            if (entry.length == 2) {
                String key = StringUtils.strip(entry[0]);
                String value = StringUtils.strip(entry[1]);

                String[] keyFragments = StringUtils.split(key, ".", 2);

                if (keyFragments.length < 2) {
                    // Root section
                    curSectionId = "root";

                } else {
                    // Split into sections based on what's before the first '.' in the key.
                    curSectionId = keyFragments[0];
                }

                MessageSection curSection = MessageSection.findMessageSection(curSectionId);
                //                    curSection = sections.get(curSectionId);

                if (curSection == null) {
                    curSection = new MessageSection();
                    curSection.setId(curSectionId);
                    //                        sections.put(curSectionId, curSection);
                }

                if (StringUtils.isNotBlank(curComment)) {
                    curSection.setDescription(curComment);
                    curComment = null;
                }

                Set<Message> messages = curSection.getMessages();
                if (messages == null) {
                    messages = new HashSet<Message>();
                    curSection.setMessages(messages);
                }

                // Does this message already have one or more translation? If not, create a new message.
                List<Message> res = Message.findMessagesByPropertyEquals(key).getResultList();
                Message message;
                if (res.size() > 0) {
                    message = res.get(0);
                    logger.trace("Yes, found an already persisted one: " + message);

                } else {
                    message = new Message();
                }

                message.setProperty(key);
                message.getTranslations().put(locale, value);

                messages.add(message);

                logger.trace("persisting curSection: " + curSection);
                curSection.persist();

            } else {
                // Could be an empty line, or an invalid line. Ignore it.
            }
        }
    }

    //        logger.info("sections: " + sections.size());
    //        for (MessageSection section : sections.values()) {
    //            System.out.println(": (id:" + section.getId() + ") " + section);
    //            
    //            for (Message message : section.getMessages()) {
    //                System.out.println("--: (id:" + message.getId() + ") " + message);
    //                
    //                for (Entry<MessageLocale, String> entry : message.getTranslations().entrySet()) {
    //                    System.out.println("-----: " + entry.getKey() + ": " + entry.getValue());
    //                }
    //            }
    //            
    //            section.persist();
    //        }
}

From source file:org.ala.dao.FulltextSearchDaoImplSolr.java

/**
* Populate a Wordpress from the data in the lucene index.
*
* @param doc/*from  w  w w.  j  a  v  a2  s. c o m*/
* @return
*/
private SearchWordpressDTO createWordpressFromIndex(QueryResponse qr, SolrDocument doc) {
    SearchWordpressDTO wordpress = new SearchWordpressDTO();
    wordpress.setIdxType(IndexedTypes.WORDPRESS.toString());
    wordpress.setScore((Float) doc.getFirstValue("score"));
    wordpress.setGuid((String) doc.getFirstValue("guid"));
    wordpress.setName((String) doc.getFirstValue("name"));
    wordpress.setScore((Float) doc.getFirstValue("score"));

    // add SOLR generated highlights
    String id = (String) doc.getFirstValue("id");
    if (qr.getHighlighting() != null && qr.getHighlighting().get(id) != null) {
        logger.debug("Got highlighting (" + id + "): " + qr.getHighlighting().get(id).size());
        Map<String, List<String>> highlightVal = qr.getHighlighting().get(id);
        for (Map.Entry<String, List<String>> entry : highlightVal.entrySet()) {
            List<String> newHls = new ArrayList<String>();

            for (String hl : entry.getValue()) {
                // Strip leading punctuation twice (which SOLR tends to include)
                String punctuation = ".,;:)]}>!?%-_";
                String hl2 = StringUtils.stripStart(hl, punctuation);
                hl2 = StringUtils.stripStart(hl2, punctuation);
                newHls.add(hl2.trim() + " ...");
            }

            wordpress.setHighlight(StringUtils.join(newHls, "<br/>"));
        }
    }

    return wordpress;
}

From source file:org.alfresco.repo.invitation.site.InviteModeratedSenderTest.java

@SuppressWarnings("rawtypes")
/**//from   w w w  .j  av  a2s . c  om
 * Test that the mail action is correctly constructed when sending notifications emails about users requesting access to a specific site
 * @throws Exception
 */
public void testSendModeratedEmail() throws Exception {
    Map<String, String> properties = buildDefaultProperties();
    inviteModeratedSender.sendMail(ENTERPRISE_EMAIL_TEMPLATE_PATH,
            SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY, properties);

    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_FROM), eq(requesterMail));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TO_MANY), eq(SiteManagerGroup));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT),
            eq(SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT_PARAMS),
            eq(new Object[] { fullSiteName }));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE), eq(emailTemplateNodeRef));

    ArgumentCaptor<Map> modelC = ArgumentCaptor.forClass(Map.class);
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE_MODEL),
            (Serializable) modelC.capture());

    String pendingInvitesLink = StringUtils.stripStart(MessageFormat
            .format(InviteModeratedSender.SHARE_PENDING_INVITES_LINK, StringUtils.EMPTY, shortSiteName), "/");

    // Check the model
    Map model = modelC.getValue();
    assertNotNull(model);
    assertEquals(false, model.isEmpty());
    assertNotNull(model.get("productName"));
    assertEquals(model.get("inviteeName"), requesterFirstName + " " + requesterLastName);
    assertEquals(model.get("siteName"), fullSiteName);
    assertEquals(model.get("sharePendingInvitesLink"), pendingInvitesLink);

}

From source file:org.apache.geode.internal.security.IntegratedSecurityService.java

public void authorize(String resource, String operation, String regionName, String key) {
    regionName = StringUtils.stripStart(regionName, "/");
    authorize(new ResourcePermission(resource, operation, regionName, key));
}

From source file:org.apache.geode.internal.security.IntegratedSecurityService.java

public Object postProcess(Object principal, String regionPath, Object key, Object value,
        boolean valueIsSerialized) {
    if (!needPostProcess())
        return value;

    if (principal == null) {
        Subject subject = getSubject();
        if (subject == null)
            return value;
        principal = (Serializable) subject.getPrincipal();
    }// ww w .  j av a2s  . co m

    String regionName = StringUtils.stripStart(regionPath, "/");
    Object newValue = null;

    // if the data is a byte array, but the data itself is supposed to be an object, we need to
    // desearized it before we pass
    // it to the callback.
    if (valueIsSerialized && value instanceof byte[]) {
        try {
            Object oldObj = EntryEventImpl.deserialize((byte[]) value);
            Object newObj = postProcessor.processRegionValue(principal, regionName, key, oldObj);
            newValue = BlobHelper.serializeToBlob(newObj);
        } catch (IOException | SerializationException e) {
            throw new GemFireIOException("Exception de/serializing entry value", e);
        }
    } else {
        newValue = postProcessor.processRegionValue(principal, regionName, key, value);
    }

    return newValue;
}

From source file:org.apache.geode.security.ResourcePermission.java

public ResourcePermission(Resource resource, Operation operation, String target, String key) {
    if (resource != null) {
        this.resource = resource;
    }//from w  w w . j  av a2  s .  co  m
    if (operation != null) {
        this.operation = operation;
    }
    if (target != null) {
        this.target = StringUtils.stripStart(target, Region.SEPARATOR);
    }
    if (key != null) {
        this.key = key;
    }

    setParts(this.resource + ":" + this.operation + ":" + this.target + ":" + this.key, true);
}

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFLTrim.java

@Override
protected String performOp(String val) {
    return StringUtils.stripStart(val, " ");
}

From source file:org.apache.hadoop.hive.ql.udf.UDFLTrim.java

public Text evaluate(Text s) {
    if (s == null) {
        return null;
    }//ww  w .j  a  v  a2 s.c  om
    result.set(StringUtils.stripStart(s.toString(), " "));
    return result;
}