Example usage for org.apache.commons.lang3 StringEscapeUtils unescapeJava

List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeJava

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils unescapeJava.

Prototype

public static final String unescapeJava(final String input) 

Source Link

Document

Unescapes any Java literals found in the String .

Usage

From source file:com.thinkbiganalytics.discovery.parsers.csv.CSVFileSchemaParser.java

/**
 * Converts the specified string to a character.
 *
 * @param character the escaped string//from  w  w  w.j  a  va  2s.co m
 * @return the character
 */
@Nonnull
private String toChar(@Nonnull final String character) {
    if (character.length() == 1) {
        return character;
    } else if (character.length() == 2 && character.charAt(0) == '\\') {
        return StringEscapeUtils.unescapeJava(character);
    }
    throw new IllegalArgumentException("Not a valid character: " + character);
}

From source file:ca.hec.commons.utils.MergePropertiesUtils.java

private static String unescapeJava(String str) {
    return StringEscapeUtils.unescapeJava(str);
}

From source file:de.fraunhofer.sciencedataamanager.business.SearchExecutionManager.java

/**
 * Executes the search definition./*from ww  w  .  j a v a  2s . co m*/
 *
 * @param searchDefinitionID the search definition to be executed.
 * @throws Exception
 */
public void executeOnlyInformations(int searchDefinitionID) throws Exception {
    this.applicationConfiguration.getLoggingManager().log(
            "Entering methode (public void execute(int searchDefinitionID) throws Exception)", LogLevel.DEBUG);

    //get groovy code and compile it

    LinkedList<SearchDefinitonExecution> searchDefinitonExecutionList = new LinkedList<SearchDefinitonExecution>();
    SearchDefinitionDataManager searchDefinitionDataProvider = new SearchDefinitionDataManager(
            applicationConfiguration);
    SearchDefinition searchDefinition = searchDefinitionDataProvider
            .getSearchDefinitionByID(searchDefinitionID);

    SearchExecutionDataManager searchExecutionDataProvider = new SearchExecutionDataManager(
            applicationConfiguration);
    SearchExecution searchExecution = searchExecutionDataProvider
            .getSystemInstanceBySearchDefinition(searchDefinition);

    //construct search definition execution run object and set current timestamp

    SearchDefinitionExecutionRun searchDefinitionExecutionRun = new SearchDefinitionExecutionRun();
    searchDefinitionExecutionRun
            .setDescription(searchDefinition.getName() + " - " + Calendar.getInstance().getTime().toString());
    searchDefinitionExecutionRun
            .setStartExecutionTimestamp(new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()));
    searchDefinitionExecutionRun.setSearchExecution(searchExecution);
    searchDefinitionExecutionRun.setSearchDefinitionExecutionList(searchDefinitonExecutionList);

    SearchDefinitonExecutionRunDataManager searchDefinitonExecutionRunDataManager = new SearchDefinitonExecutionRunDataManager(
            applicationConfiguration);
    searchDefinitionExecutionRun = searchDefinitonExecutionRunDataManager
            .insertSearchDefinitionExecutionRunLastID(searchDefinitionExecutionRun);

    //loop through each system instance and compile connector code. 

    for (SystemInstance connectorLoop : searchExecution.getSystemInstances()) {
        SearchDefinitonExecution searchDefinitonExecution = null;
        try {
            //get groovy code and compile it

            GroovyClassLoader gcl = new GroovyClassLoader();
            Class parsedGroocyClass = gcl
                    .parseClass(StringEscapeUtils.unescapeJava(connectorLoop.getGroovyCode()));
            Class[] constructorParameterConnector = new Class[1];
            constructorParameterConnector[0] = this.applicationConfiguration.getClass();
            //Object groovyClassInstance = parsedGroocyClass.newInstance(constructorParameterConnector);
            Object groovyClassInstance = null;
            Constructor connectorConstructor = parsedGroocyClass
                    .getDeclaredConstructor(constructorParameterConnector);
            if (connectorConstructor != null) {
                groovyClassInstance = connectorConstructor.newInstance(this.applicationConfiguration);
            } else {
                groovyClassInstance = parsedGroocyClass.newInstance();
            }
            currentExecutedConnector = (ICloudPaperConnector) groovyClassInstance;
            //currentExecutedConnector = new ElsevierScienceDirectConnectorBufferAbstract(this.applicationConfiguration); 
            //currentExecutedConnector = new WebOfScienceLightConnector(this.applicationConfiguration); 
            searchExecution.getSearchDefiniton().setSystemInstance(connectorLoop);

            //set to 0 because no data should be downloaded

            searchExecution.getSearchDefiniton().setItemTreshhold(0);
            //execute search method and wait for return

            searchDefinitonExecution = currentExecutedConnector
                    .getCloudPapers(searchExecution.getSearchDefiniton());
            searchDefinitonExecution.setSearchState("Success");
            //set result
            searchDefinitonExecution.setSearch_Definiton_ID(searchDefinitionID);
            searchDefinitonExecution.setSystemInstance(connectorLoop);
            searchDefinitionExecutionRun.getSearchDefinitionExecutionList().add(searchDefinitonExecution);

        } catch (Exception ex) {
            searchDefinitonExecution = new SearchDefinitonExecution();
            searchDefinitonExecution.setSearch_Definiton_ID(searchDefinitionID);
            searchDefinitonExecution.setSystemInstance(connectorLoop);
            searchDefinitonExecution.setSearchState("Failure");
            searchDefinitonExecution.setMessage(ex.toString());
            searchDefinitonExecution.setFinishedExecutionTimestamp(
                    new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()));
            searchDefinitionExecutionRun.getSearchDefinitionExecutionList().add(searchDefinitonExecution);
            this.applicationConfiguration.getLoggingManager().logException(ex);
            continue;
        }
    }
    //write data to db

    searchDefinitionExecutionRun
            .setFinishedExecutionTimestamp(new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()));
    searchDefinitonExecutionRunDataManager.updateSearchDefinitionExecutionRun(searchDefinitionExecutionRun);

    for (SearchDefinitonExecution searchDefinitonExecution : searchDefinitionExecutionRun
            .getSearchDefinitionExecutionList()) {
        for (ScientificPaperMetaInformationParseException scientificPaperMetaInformationParseException : searchDefinitonExecution
                .getScientificPaperMetaInformationParseException()) {
            this.applicationConfiguration.getLoggingManager()
                    .logException(scientificPaperMetaInformationParseException.getParseException());
        }
    }

}

From source file:com.streamsets.pipeline.stage.origin.udp.UDPSourceConfigBean.java

public boolean init(Stage.Context context, List<Stage.ConfigIssue> issues) {

    boolean valid = true;

    switch (dataFormat) {
    case SYSLOG://from w ww  .j  a v  a 2  s.  c o  m
        parserConfig.put(CHARSET, syslogCharset);
        break;
    case COLLECTD:
        parserConfig.put(CHARSET, collectdCharset);
        break;
    case RAW_DATA:
        parserConfig.put(CHARSET, rawDataCharset);
        parserConfig.put(RAW_DATA_MODE, rawDataMode);
        parserConfig.put(RAW_DATA_MULTIPLE_VALUES_BEHAVIOR, rawDataMultipleValuesBehavior);
        parserConfig.put(RAW_DATA_OUTPUT_FIELD_PATH, rawDataOutputField);
        parserConfig.put(RAW_DATA_SEPARATOR_BYTES,
                StringEscapeUtils.unescapeJava(rawDataSeparatorBytes).getBytes());
        break;
    case NETFLOW:
        parserConfig.put(NETFLOW_OUTPUT_VALUES_MODE, netflowOutputValuesMode);
        parserConfig.put(NETFLOW_MAX_TEMPLATE_CACHE_SIZE, maxTemplateCacheSize);
        parserConfig.put(NETFLOW_TEMPLATE_CACHE_TIMEOUT_MS, templateCacheTimeoutMs);
        break;
    default:
        // NOOP
    }

    parserConfig.put(CONVERT_TIME, convertTime);
    parserConfig.put(TYPES_DB_PATH, typesDbPath);
    parserConfig.put(EXCLUDE_INTERVAL, excludeInterval);
    parserConfig.put(AUTH_FILE_PATH, authFilePath);

    if (enableEpoll && !Epoll.isAvailable()) {
        issues.add(context.createConfigIssue(Groups.UDP.name(), "enableEpoll", Errors.UDP_08));
    }
    if (ports.isEmpty()) {
        issues.add(context.createConfigIssue(Groups.UDP.name(), "ports", Errors.UDP_02));
    } else {
        for (String candidatePort : ports) {
            try {
                int port = Integer.parseInt(candidatePort.trim());
                if (port > 0 && port < 65536) {
                    if (port < 1024) {
                        privilegedPortUsage = true; // only for error handling purposes
                    }
                    addresses.add(new InetSocketAddress(port));
                } else {
                    issues.add(context.createConfigIssue(Groups.UDP.name(), "ports", Errors.UDP_03, port));
                }
            } catch (NumberFormatException ex) {
                issues.add(context.createConfigIssue(Groups.UDP.name(), "ports", Errors.UDP_03, candidatePort));
            }
        }
    }

    Charset charset;
    switch (dataFormat) {
    case NETFLOW:
        final int maxTemplateCacheSize = parserConfig.getInteger(NETFLOW_MAX_TEMPLATE_CACHE_SIZE);
        final int templateCacheTimeoutMs = parserConfig.getInteger(NETFLOW_TEMPLATE_CACHE_TIMEOUT_MS);
        NetflowDataParserFactory.validateConfigs(context, issues, Groups.NETFLOW_V9.name(), "",
                maxTemplateCacheSize, templateCacheTimeoutMs);
        parser = new NetflowParser(context, (OutputValuesMode) parserConfig.get(NETFLOW_OUTPUT_VALUES_MODE),
                maxTemplateCacheSize, templateCacheTimeoutMs);
        break;
    case SYSLOG:
        charset = validateCharset(Groups.SYSLOG.name(), context, issues);
        parser = new SyslogParser(context, charset);
        break;
    case COLLECTD:
        charset = validateCharset(Groups.COLLECTD.name(), context, issues);
        checkCollectdParserConfigs(context, issues);
        if (issues.isEmpty()) {
            parser = new CollectdParser(context, parserConfig.getBoolean(CONVERT_TIME),
                    parserConfig.getString(TYPES_DB_PATH), parserConfig.getBoolean(EXCLUDE_INTERVAL),
                    parserConfig.getString(AUTH_FILE_PATH), charset);
        }
        break;
    case RAW_DATA:
        charset = validateCharset(Groups.RAW_DATA.name(), context, issues);
        parser = new SeparatedDataParser(context, (RawDataMode) parserConfig.get(RAW_DATA_MODE), charset,
                parserConfig.getString(RAW_DATA_OUTPUT_FIELD_PATH),
                (MultipleValuesBehavior) parserConfig.get(RAW_DATA_MULTIPLE_VALUES_BEHAVIOR),
                (byte[]) parserConfig.get(RAW_DATA_SEPARATOR_BYTES));
        break;
    default:
        issues.add(context.createConfigIssue(Groups.UDP.name(), "dataFormat", Errors.UDP_01, dataFormat));
        break;
    }

    return valid;

}

From source file:com.microsoftopentechnologies.azchat.web.servicesbus.AzureChatServiceBus.java

/**
 * This method populates the userMessageEntity values from the broker
 * message and MediaServiceOutputBean.//from  w  ww. j a  v a2 s.  c o  m
 * 
 * @param message
 * @param outputObject
 * @return userMessageEntity
 */
private UserMessageEntity prepareUserMessageEntity(BrokeredMessage message,
        MediaServiceOutputBean outputObject) {
    UserMessageEntity userMessageEntity = new UserMessageEntity(
            AzureChatUtils.toString(message.getProperty(AzureChatConstants.BROK_MSG_KEY_UID)),
            AzureChatUtils.toString(message.getProperty(AzureChatConstants.BROK_MSG_KEY_MSG_ID)));

    userMessageEntity.setTextContent(
            AzureChatUtils.toString(message.getProperty(AzureChatConstants.BROK_MSG_KEY_TEXT_MSG)));
    userMessageEntity.setMediaURL(outputObject.getStreamingUrl());
    userMessageEntity.setUserName(
            AzureChatUtils.toString(message.getProperty(AzureChatConstants.BROK_MSG_KEY_USER_NAME)));
    userMessageEntity.setUserPhotoBlobURL(StringEscapeUtils.unescapeJava(
            AzureChatUtils.toString(message.getProperty(AzureChatConstants.BROK_MSG_KEY_PHOTO_BLOB))));
    userMessageEntity.setMediaType(AzureChatConstants.BROK_MSG_KEY_MED_TYPE_VEDIO);
    userMessageEntity.setAssetID(outputObject.getAssetID());
    return userMessageEntity;
}

From source file:com.github.xbn.text.padchop.VzblPadChop.java

/**
   <p>Format a string as configured.</p>
        //  ww  w .  j  a v a2s  . c o m
   <p>This:<ol>
 <li>If {@code text} is {@code null}, this returns {@code null}.</li>
 <li>Otherwise, the string is<ol>
    <li>Trimmed <code>({@link #doTrimLeftRight() doTrimLeftRight}())</code></li>
    <li>Unescaped <code>(@code getConfig().{@link #getEscapeAction() getEscapeAction}())</code></li>
    <li>Padded/chopped <code>(getConfig().{@link #doPad() doPad}(), {@link #doChop() doChop}())</code></li>
 </ol></li>
   </ol></p>
        
 * @param  vpc  May not be {@code null}.
 * @param  to_appendTo  May not be {@code null}.
 * @param  text  The string to chop.
 * @param  goal_len  The goal length to chop to. May not be less than one.
 */
public static final Appendable appendX(VzblPadChop vpc, Appendable to_appendTo, int goal_len, Object text)
        throws IOException {

    if (text == null) {
        text = "null";
    }
    String s = text.toString();
    try {
        if (vpc.isDebugOn()) {
            vpc.getDebugAptr().appentln("<VPC> goal_len=" + goal_len + ", text:" + s.length());
        }
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(vpc, "vpc", null, rx);
    }

    //System.out.println("vpc1 text=" + text + "");

    if (vpc.doTrimLeftRight()) {
        //System.out.println("vpc2");
        s = s.trim();
    } else if (vpc.doTrimLeft()) {
        //System.out.println("vpc3");
        s = StringUtil.ltrim(s);
    } else if (vpc.doTrimRight()) {
        //System.out.println("vpc4");
        s = StringUtil.rtrim(s);
    }
    //System.out.println("vpc5");

    if (vpc.getEscapeAction().isEscape()) {
        s = StringEscapeUtils.escapeJava(s);
    } else if (vpc.getEscapeAction().isUnescape()) {
        s = StringEscapeUtils.unescapeJava(s);
    }

    if (vpc.doPadChop()) {
        if (vpc.isDebugOn()) {
            appendPadChoppedXWDbg(vpc, to_appendTo, goal_len, s);
        } else {
            if (vpc.doPadFirst()) {
                vpc.getChop().appendChoppedX(to_appendTo, vpc.getPad().getPadded(goal_len, s));
            } else {
                vpc.getPad().appendPaddedX(to_appendTo, vpc.getChop().getChopped(goal_len, s));
            }
        }
        return to_appendTo;
    }

    if (vpc.doPad()) {
        vpc.getPad().appendPaddedX(to_appendTo, goal_len, s);
    } else if (vpc.doChop()) {
        vpc.getChop().appendChoppedX(to_appendTo, goal_len, s);
    }
    return to_appendTo;
}

From source file:com.wegas.core.Helper.java

/**
 * Unescapes a string that contains standard Java escape sequences.
 * <ul>/*from   w  w w .  ja  v  a 2  s  .  com*/
 * <li><strong>&#92;b &#92;f &#92;n &#92;r &#92;t &#92;" &#92;'</strong> :
 * BS, FF, NL, CR, TAB, double and single quote.</li>
 * <li><strong>&#92;X &#92;XX &#92;XXX</strong> : Octal character
 * specification (0 - 377, 0x00 - 0xFF).</li>
 * <li><strong>&#92;uXXXX</strong> : Hexadecimal based Unicode
 * character.</li>
 * </ul>
 * https://gist.github.com/uklimaschewski/6741769
 *
 * @param st A string optionally containing standard java escape sequences.
 * @return The translated string.
 */
public static String unescape(String st) {
    return StringEscapeUtils.unescapeJava(st);
}

From source file:com.taobao.android.BasePatchTool.java

protected File getLastPatchFile(String baseApkVersion, String productName, File outPatchDir)
        throws IOException {
    try {//from   w w  w. j  a  va  2  s . c o  m
        String httpUrl = LAST_PATCH_URL + "baseVersion=" + baseApkVersion + "&productIdentifier=" + productName;
        String response = HttpClientUtils.getUrl(httpUrl);
        if (StringUtils.isBlank(response) || response.equals("\"\"") || !productName.equals("taobao4android")) {
            return null;
        }
        File downLoadFolder = new File(outPatchDir, "LastPatch");
        downLoadFolder.mkdirs();
        File downLoadFile = new File(downLoadFolder, "lastpatch.tpatch");
        String downLoadUrl = StringEscapeUtils.unescapeJava(response);
        downloadTPath(downLoadUrl.substring(1, downLoadUrl.length() - 1), downLoadFile);
        return downLoadFile;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.sri.ai.grinder.parser.antlr.ExpressionVisitor.java

protected Expression newSymbol(String text) {
    // Remove quotes from around quoted strings
    if ((text.startsWith("'") && text.endsWith("'")) || (text.startsWith("\"") && text.endsWith("\""))) {
        text = text.substring(1, text.length() - 1);
    }/*from  ww  w. ja v  a  2 s  . c o m*/

    // Ensure escapes are applied.
    text = StringEscapeUtils.unescapeJava(text);

    text = new String(text);

    Expression result = Expressions.makeSymbol(text);
    return result;
}

From source file:com.streamsets.pipeline.stage.origin.tcp.TCPServerSource.java

private void validateDelimiterBasedFrameDecoder(List<ConfigIssue> issues, String recordSeparatorStr,
        String recordSeparatorStrField) {
    if (recordSeparatorStr == null) {
        issues.add(getContext().createConfigIssue(Groups.TCP.name(), CONF_PREFIX + recordSeparatorStrField,
                Errors.TCP_41));/*from  w  w w .  j av  a  2s  . co m*/
        return;
    }
    final byte[] delimiterBytes = StringEscapeUtils.unescapeJava(recordSeparatorStr).getBytes();
    if (delimiterBytes.length == 0) {
        issues.add(getContext().createConfigIssue(Groups.TCP.name(), CONF_PREFIX + recordSeparatorStrField,
                Errors.TCP_40));
    }
}