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

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

Introduction

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

Prototype

public static String right(String str, int len) 

Source Link

Document

Gets the rightmost len characters of a String.

Usage

From source file:org.fracturedatlas.athena.payments.model.CreditCard.java

public static String lastFour(String cardNumber) {
    return StringUtils.right(cardNumber, 4);
}

From source file:org.geopublishing.atlasViewer.swing.ClickInfoDialog.java

/**
 * Update with info-dialog with the new {@link ObjectSelectionEvent}
 *///www  .  j av a2 s .c  o  m
public void setSelectionEvent(final ObjectSelectionEvent<?> objectSelectionEvent) {

    clickInfoPanel.setSelectionEvent(objectSelectionEvent);

    XMapPane source = objectSelectionEvent.getSource();

    // Set the title of the dialog to the translated title the layer
    try {
        String title = objectSelectionEvent.getSourceLayer().getTitle();
        if (atlasConfig != null) {
            setTitle(atlasConfig.getDataPool().get(title).getTitle().toString());
        } else {
            title = StringUtils.right(title, 25);
            setTitle(title);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    XMapPane mapPane = objectSelectionEvent.getSource();
    // If it is a feature, let it blink for a moment
    if (source instanceof XMapPane && objectSelectionEvent instanceof FeatureSelectedEvent) {

        mapPane.blink(((FeatureSelectedEvent) objectSelectionEvent).getSelectionResult());
    } else {
        // Create a fake Feature and let it blink a moment
        final GridCoverageValueSelectedEvent gridSelection = (GridCoverageValueSelectedEvent) objectSelectionEvent;

        // TODO Help Martin, warum kann ich kein feake Feature mit correctem
        // CRS erstellen?
        Point2D selectionPoint = gridSelection.getSelectionPoint();

        CoordinateReferenceSystem crs = mapPane.getMapContext().getCoordinateReferenceSystem();

        SimpleFeatureType fakeFeatureType = FeatureUtil.createFeatureType(Point.class, crs);

        SimpleFeature fakeFeature = FeatureUtil.createFeatureInstance(fakeFeatureType, true,
                "fake raster selection",
                new DirectPosition2D(crs, selectionPoint.getX(), selectionPoint.getY()));

        System.out.println("crs = " + fakeFeature.getFeatureType().getCoordinateReferenceSystem());

        mapPane.blink(fakeFeature);
    }
}

From source file:org.jason.mapmaker.server.service.ShapefileMetadataServiceImpl.java

public void generateMetadata(String year) throws ServiceException {

    String host = "ftp2.census.gov";

    for (String geoId : GeographyUtils.stateGeoIdMap.keySet()) {
        String stateName = GeographyUtils.getStateForGeoId(geoId);

        // generate the working directory. String.format() used because it's cleaner than the old String
        // concats
        String workingDirectory = String.format(workingDirectoryFormat, year, geoId, stateName, geoId);

        List<String> fileNames = getRemoteFilenames(host, workingDirectory);
        List<ShapefileMetadata> shapefileMetadataList = new ArrayList<ShapefileMetadata>(fileNames.size());

        for (String mangledName : GeographyUtils.mangledNamesMap.inverse().keySet()) {
            String remoteFilename;
            String shortYear = StringUtils.right(year, 2); // need the last two digits of the year

            if (mangledName.equals("CD111")) {
                remoteFilename = String.format(cdUrlPostfix, year, geoId);
            } else {
                remoteFilename = String.format(urlPostfix, year, geoId, mangledName.toLowerCase(), shortYear);
            }/*from w ww  .ja  v a 2 s  .  co m*/

            String demangledName = GeographyUtils.demangleTypeName(mangledName); // i.e. COUSUB to COUNTY_SUBDIVISION
            String mtfcc = GeographyUtils.getMtfccForName(demangledName);

            ShapefileMetadata sm = new ShapefileMetadata();
            sm.setGeoId(geoId);
            sm.setMtfccCode(mtfcc);
            sm.setUrl("ftp://" + host + workingDirectory + remoteFilename);
            sm.setVersion(year);

            if (fileNames.contains(remoteFilename)) {
                sm.setCurrentStatus(GeographyUtils.Status.NOT_IMPORTED);
            } else {
                sm.setCurrentStatus(GeographyUtils.Status.NOT_AVAILABLE);
            }

            shapefileMetadataList.add(sm);
        }

        try {
            shapefileMetadataRepository.saveList(shapefileMetadataList);
        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }
}

From source file:org.jtalks.jcommune.web.filters.LoggingConfigurationFilter.java

/**
 * Register the user in the MDC under USER_KEY.
 *
 * @param userName the name of current user
 * @return true if the username was registered in MDC, false only if the user is anonymous and session id is empty.
 *         If true, you have to unregister the user at some point otherwise the memory will leak.
 *///w  ww.  j  a v a 2s  . com
private boolean registerCurrentUserName(String userName, String sessionId) {
    if (!StringUtils.isEmpty(userName)) {
        loggerMdc.registerUser(userName);
        return true;
    } else if (isSessionIdValid(sessionId)) {
        loggerMdc.registerUser(ANONYMOUS_PREFIX + StringUtils.right(sessionId, SESSION_ID_LENGTH));
        return true;
    } else {
        return false;
    }
}

From source file:org.jumpmind.metl.core.runtime.component.ModelAttributeScriptHelper.java

public String right(int length) {
    return StringUtils.right(value != null ? value.toString() : "", length);
}

From source file:org.kuali.kfs.fp.batch.service.impl.ProcurementCardCreateDocumentServiceImpl.java

/**
 * Set up PCDO document description as "cardholder name-card number (which is 4 digits)-chartOfAccountsCode-default account"
 *
 * @param pcardDocument/*w  w  w  . ja  v  a 2s. c  o m*/
 */
protected void setupDocumentDescription(ProcurementCardDocument pcardDocument) {
    ProcurementCardHolder cardHolder = pcardDocument.getProcurementCardHolder();

    if (ObjectUtils.isNotNull(cardHolder)) {
        String cardHolderName = StringUtils.left(cardHolder.getCardHolderName(), 23);
        String lastFourDigits = StringUtils.right(cardHolder.getTransactionCreditCardNumber(), 4);
        String chartOfAccountsCode = cardHolder.getChartOfAccountsCode();
        String accountNumber = cardHolder.getAccountNumber();

        String description = MessageFormat.format(DOCUMENT_DESCRIPTION_PATTERN, cardHolderName, lastFourDigits,
                chartOfAccountsCode, accountNumber);
        pcardDocument.getDocumentHeader().setDocumentDescription(description);
    }
}

From source file:org.kuali.kfs.fp.document.web.struts.VoucherForm.java

/**
 * util method to get postingYear out of selectedAccountingPeriod
 * //www. j  a v  a 2 s  .  c o  m
 * @return Integer
 */

protected Integer getSelectedPostingYear() {
    Integer postingYear = null;
    if (StringUtils.isNotBlank(getSelectedAccountingPeriod())) {
        postingYear = new Integer(StringUtils.right(getSelectedAccountingPeriod(), 4));
    }
    return postingYear;
}

From source file:org.kuali.kfs.module.cam.businessobject.AssetGlobal.java

/**
 * Gets the universityFiscalPeriodName attribute.
 * /*ww  w . j  a v a  2s .  c  o  m*/
 * @return Returns the universityFiscalPeriodName
 */

public String getUniversityFiscalPeriodName() {
    if (StringUtils.isNotBlank(universityFiscalPeriodName)) {
        this.setFinancialDocumentPostingPeriodCode(StringUtils.left(universityFiscalPeriodName, 2));
        this.setFinancialDocumentPostingYear(new Integer(StringUtils.right(universityFiscalPeriodName, 4)));
    }

    if (StringUtils.isBlank(universityFiscalPeriodName)) {
        if (this.financialDocumentPostingPeriodCode != null && this.financialDocumentPostingYear != null) {
            universityFiscalPeriodName = this.financialDocumentPostingPeriodCode
                    + this.financialDocumentPostingYear;
        }
    }

    return universityFiscalPeriodName;
}

From source file:org.kuali.kfs.module.cam.businessobject.AssetGlobal.java

/** 
 * Sets the universityFiscalPeriodName attribute.
 * /*from  w  w w.  j a v a2  s .  c o  m*/
 * @param universityFiscalPeriodName The universityFiscalPeriodName to set.
 */
public void setUniversityFiscalPeriodName(String universityFiscalPeriodName) {
    if (StringUtils.isBlank(universityFiscalPeriodName)) {
        if (this.financialDocumentPostingPeriodCode != null && this.financialDocumentPostingYear != null) {
            universityFiscalPeriodName = this.financialDocumentPostingPeriodCode
                    + this.financialDocumentPostingYear;
        }
    }

    String THIRTEEN = "13";
    if (StringUtils.isNotBlank(universityFiscalPeriodName)
            && StringUtils.left(universityFiscalPeriodName, 2).equals(THIRTEEN)) {
        String period = StringUtils.left(universityFiscalPeriodName, 2);
        Integer year = new Integer(StringUtils.right(universityFiscalPeriodName, 4));
        AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year);
        setAccountingPeriod(accountingPeriod);
    }

    this.universityFiscalPeriodName = universityFiscalPeriodName;
}

From source file:org.kuali.kfs.module.cam.businessobject.AssetGlobal.java

/**
 * Sets the accountingPeriod if in period 13
 * @param accountingPeriodString/*w ww .  ja  va2 s.  c om*/
 * TODO remove hardcoding
 */
public void setAccountingPeriodCompositeString(String accountingPeriodString) {
    String THIRTEEN = "13";
    if (StringUtils.isNotBlank(accountingPeriodString)
            && StringUtils.left(accountingPeriodString, 2).equals(THIRTEEN)) {
        String period = StringUtils.left(accountingPeriodString, 2);
        Integer year = new Integer(StringUtils.right(accountingPeriodString, 4));
        AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year);
        setAccountingPeriod(accountingPeriod);
    }
}