Example usage for org.apache.commons.lang3 StringUtils trimToEmpty

List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trimToEmpty.

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .

Usage

From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java

private TransactionImpl reconstructTransaction(TransactionArchive archive) throws IllegalStateException {
    XidFactory xidFactory = this.beanFactory.getXidFactory();
    TransactionContext transactionContext = new TransactionContext();
    TransactionXid xid = (TransactionXid) archive.getXid();
    transactionContext.setXid(xidFactory.createGlobalXid(xid.getGlobalTransactionId()));
    transactionContext.setRecoveried(true);
    transactionContext.setCoordinator(archive.isCoordinator());
    transactionContext.setPropagatedBy(archive.getPropagatedBy());

    TransactionImpl transaction = new TransactionImpl(transactionContext);
    transaction.setBeanFactory(this.beanFactory);
    transaction.setTransactionStatus(archive.getStatus());

    List<XAResourceArchive> nativeResources = archive.getNativeResources();
    transaction.getNativeParticipantList().addAll(nativeResources);

    transaction.setParticipant(archive.getOptimizedResource());

    List<XAResourceArchive> remoteResources = archive.getRemoteResources();
    transaction.getRemoteParticipantList().addAll(remoteResources);

    List<XAResourceArchive> participants = transaction.getParticipantList();
    Map<String, XAResourceArchive> applicationMap = transaction.getApplicationMap();
    Map<String, XAResourceArchive> participantMap = transaction.getParticipantMap();
    if (archive.getOptimizedResource() != null) {
        participants.add(archive.getOptimizedResource());
    }/*from  w  w w .j ava 2 s  .c o  m*/
    participants.addAll(nativeResources);
    participants.addAll(remoteResources);

    for (int i = 0; i < participants.size(); i++) {
        XAResourceArchive element = participants.get(i);
        XAResourceDescriptor descriptor = element.getDescriptor();
        String identifier = StringUtils.trimToEmpty(descriptor.getIdentifier());

        if (RemoteResourceDescriptor.class.isInstance(descriptor)) {
            RemoteResourceDescriptor resourceDescriptor = (RemoteResourceDescriptor) descriptor;
            RemoteCoordinator remoteCoordinator = resourceDescriptor.getDelegate();
            applicationMap.put(remoteCoordinator.getApplication(), element);
        } // end-if (RemoteResourceDescriptor.class.isInstance(descriptor))

        participantMap.put(identifier, element);
    }

    transaction.recoverTransactionStrategy(archive.getTransactionStrategyType());

    if (archive.getVote() == XAResource.XA_RDONLY) {
        throw new IllegalStateException("Transaction has already been completed!");
    }

    return transaction;
}

From source file:org.bytesoft.bytetcc.logging.SampleCompensableLogger.java

public File getDefaultDirectory() {
    String address = StringUtils.trimToEmpty(this.endpoint);
    File directory = new File(String.format("bytetcc/%s", address.replaceAll("\\:|\\.", "_")));
    if (directory.exists() == false) {
        try {/* w w  w.  jav a  2  s. c o  m*/
            directory.mkdirs();
        } catch (SecurityException ex) {
            logger.error("Error occurred while creating directory {}!", directory.getAbsolutePath(), ex);
        }
    }
    return directory;
}

From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java

public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL);
            PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS);

            String protocol = null;
            String address = null;
            if (addrpv == null) {
                throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen
            } else if (protpv == null) {
                String value = String.valueOf(addrpv.getValue());
                try {
                    URL url = new URL(null, value, this);
                    protocol = url.getProtocol();
                    address = url.getAuthority();
                } catch (Exception ex) {
                    throw new FatalBeanException("Unsupported format!");
                }/*from   w  w w . j  a  v a 2 s . c o m*/
            } else {
                protocol = String.valueOf(protpv.getValue());
                String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue()));
                int index = value.indexOf(protocol);
                if (index == -1) {
                    address = value;
                } else if (index == 0) {
                    String str = StringUtils.trimToEmpty(value.substring(protocol.length()));
                    if (str.startsWith("://")) {
                        address = StringUtils.trimToEmpty(str.substring(3));
                    } else {
                        throw new FatalBeanException("Unsupported format!");
                    }
                } else {
                    throw new FatalBeanException("Unsupported format!");
                }
            }

            if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) {
                throw new FatalBeanException("Unsupported protocol!");
            }

            String addrKey = "zookeeperAddr";
            String[] watcherBeanArray = beanFactory
                    .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class);
            BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]);
            MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues();
            PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey);
            if (warcherPv == null) {
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            } else {
                warcherMpv.removePropertyValue(addrKey);
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            }

        }
    }
}

From source file:org.bytesoft.bytetcc.work.CleanupWork.java

public void initialize() {
    if (this.directory == null) {
        String address = StringUtils.trimToEmpty(this.endpoint);
        String dirName = address.replaceAll("\\:|\\.", "_");
        this.directory = new File(String.format("bytetcc/%s", dirName));
    }/*from  ww w . j  av a2  s.co  m*/

    if (this.directory.exists() == false) {
        if (this.directory.mkdirs() == false) {
            throw new RuntimeException();
        }
    }

    boolean created = false;
    File resource = new File(this.directory, CONSTANTS_RESOURCE_NAME);
    boolean exists = resource.exists();
    if (exists == false) {
        try {
            created = resource.createNewFile();
        } catch (IOException ex) {
            throw new RuntimeException(ex.getMessage());
        }

        if (created == false) {
            throw new RuntimeException();
        }
    }

    try {
        this.raf = new RandomAccessFile(resource, "rw");
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex.getMessage());
    }

    if (created) {
        try {
            this.raf.setLength(CONSTANTS_START_INDEX);
        } catch (IOException ex) {
            throw new RuntimeException(ex.getMessage());
        }
    }

    try {
        this.sizeOfRaf = (int) this.raf.length();
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage());
    }

    this.channel = raf.getChannel();
    try {
        this.header = this.channel.map(MapMode.READ_WRITE, 0, CONSTANTS_START_INDEX);
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage());
    }

    this.checkIdentifier();
    this.checkVersion();
    this.checkStartIndex();
    this.endIndex = this.checkEndIndex();

    this.compress();
}

From source file:org.displaytag.export.excel.ExcelUtils.java

/**
 * Escape certain values that are not permitted in excel cells.
 * @param rawValue the object value/* ww  w .j av  a  2  s . c  o m*/
 * @return the escaped value
 */
public static String escapeColumnValue(Object rawValue) {
    if (rawValue == null) {
        return null;
    }
    // str = Patterns.replaceAll(str, "(\\r\\n|\\r|\\n|\\n\\r)\\s*", "");
    String returnString = rawValue.toString();
    // escape the String to get the tabs, returns, newline explicit as \t \r \n
    returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString));
    // remove tabs, insert four whitespaces instead
    returnString = StringUtils.replace(StringUtils.trim(returnString), "\\t", "    ");
    // remove the return, only newline valid in excel
    returnString = StringUtils.replace(StringUtils.trim(returnString), "\\r", " ");
    // unescape so that \n gets back to newline
    returnString = StringEscapeUtils.unescapeJava(returnString);
    return returnString;
}

From source file:org.dspace.service.impl.ClientInfoServiceImpl.java

private String getXForwardedForIpValue(String remoteIp, String xForwardedForValue) {
    String ip = null;/*from  w  ww .  j a va2 s .com*/

    /* This header is a comma delimited list */
    String headerValue = StringUtils.trimToEmpty(xForwardedForValue);
    for (String xfip : headerValue.split(",")) {
        /* proxy itself will sometime populate this header with the same value in
           remote address. ordering in spec is vague, we'll just take the last
           not equal to the proxy
        */
        if (!StringUtils.equals(remoteIp, xfip) && StringUtils.isNotBlank(xfip)
        //if we have trusted proxies, we'll assume that they are not the client IP
                && (trustedProxies == null || !isRequestFromTrustedProxy(xfip))) {

            ip = xfip.trim();
        }
    }

    return ip;
}

From source file:org.fabrician.enabler.DockerContainer.java

private String resolveToString(String runtimeContextVariableName) throws Exception {
    String val = SpecialDirective.resolveStringValue(this,
            StringUtils.trimToEmpty(getStringVariableValue(runtimeContextVariableName)));
    return val;
}

From source file:org.fabrician.enabler.DockerContainer.java

private int resolveToInteger(String runtimeContextVariableName) throws Exception {
    String val = SpecialDirective.resolveStringValue(this,
            StringUtils.trimToEmpty(getStringVariableValue(runtimeContextVariableName)));
    return NumberUtils.toInt(val);
}

From source file:org.fabrician.enabler.DockerContainer.java

private boolean resolveToBoolean(String runtimeContextVariableName) throws Exception {
    String val = SpecialDirective.resolveStringValue(this,
            StringUtils.trimToEmpty(getStringVariableValue(runtimeContextVariableName)));
    return BooleanUtils.toBoolean(val);
}

From source file:org.fabrician.enabler.DockerContainer.java

private File resolveToFile(String runtimeContextVariableName) throws Exception {
    String val = SpecialDirective.resolveStringValue(this,
            StringUtils.trimToEmpty(getStringVariableValue(runtimeContextVariableName)));
    return new File(val).getCanonicalFile();
}