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:de.fraunhofer.sciencedataamanager.beans.DataExportInstanceManagement.java

/**
 * Returns the data export instance. //from  w ww  .  j a v a2s. c o  m
 * @return the data export instance. 
 */
public DataExportInstance getDataExportInstanceByID() {
    DataExportInstance dataExportInstance = null;
    try {
        if (selectedItem == null || "".equals(selectedItem)) {
            return null;
        }
        int id = Integer.parseInt(selectedItem);
        for (DataExportInstance currentDataExportInstance : loadedDataExportInstances) {
            if (currentDataExportInstance.getID() == id) {
                currentDataExportInstance.setGroovyCode(
                        StringEscapeUtils.unescapeJava(currentDataExportInstance.getGroovyCode()));
                return currentDataExportInstance;
            }
        }

    } catch (Exception ex) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage("The following error occured: " + ex.toString()));
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        this.applicationConfiguration.getLoggingManager().logException(ex);

    }
    return null;
}

From source file:ambroafb.general.GeneralConfig.java

/**
 * ? ??  ??  ??  //from  w  w w  .ja  v a 2 s  . c  o  m
 *
 * @param key - , ? ?? ?? ?
 * @param language - ?, ?? ? ?? 
 * ??  ? ? ? ??? ?? ?. ?:
 * English, ? ...
 * @return
 */
public String getTitleForLanguage(String key, String language) {
    String id = mapLanguageToId(language);
    ResourceBundle b = loadBundle(new Locale(id));
    return StringEscapeUtils.unescapeJava(b.getString(key));
}

From source file:de.fraunhofer.sciencedataamanager.beans.SearchDefinitionEdit.java

/**
 * The method is executed after page load.
 *
 * @param event the information of the page load.
 *///  w w  w  .  j  ava 2s  . c o  m
public void onLoad(ComponentSystemEvent event) {

    try {
        if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
                .get("SelectedSearchDefinition") == null) {
            return;
        }
        searchDefinitionID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext()
                .getRequestParameterMap().get("SelectedSearchDefinition"));
        this.setSelectedSystemInstanceList(new LinkedList());
        this.setSystemInstanceList(new LinkedList());
        SearchDefinitionDataManager searchDefinitionDataProvider = new SearchDefinitionDataManager(
                applicationConfiguration);
        SearchDefinition searchDefinition = searchDefinitionDataProvider
                .getSearchDefinitionByID(searchDefinitionID);
        this.setSearchDefinitionName(searchDefinition.getName());

        this.setSearchDefinitionItemTreshhold(searchDefinition.getItemTreshhold() + "");
        this.setSearchDefinitionExpertQuery(StringEscapeUtils.unescapeJava(searchDefinition.getExpertQuery()));
        this.setSearchDefinitionQueryMode(searchDefinition.getSearchQueryMode());

        this.getSystemInstanceList().addAll(this.getSystemInstances());
        this.getSelectedSystemInstanceList()
                .addAll(getSearchExecutionBySearchDefinition().getSystemInstances());
    } catch (Exception ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        this.applicationConfiguration.getLoggingManager().logException(ex);

    }
}

From source file:com.zack6849.alphabot.api.Utils.java

public static String google(String s) {
    try {//from www . jav  a 2s .c o m
        String temp = String.format("https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s",
                URLEncoder.encode(s, "UTF-8"));
        URL u = new URL(temp);
        URLConnection c = u.openConnection();
        c.setRequestProperty("User-Agent",
                "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17");
        BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
        String json = "";
        String tmp;
        while ((tmp = in.readLine()) != null) {
            json += tmp + "\n";
        }
        in.close();
        JsonElement jelement = new JsonParser().parse(json);
        JsonObject output = jelement.getAsJsonObject();
        output = output.getAsJsonObject("responseData").getAsJsonArray("results").get(0).getAsJsonObject();

        String title = StringEscapeUtils.unescapeJava(StringEscapeUtils
                .unescapeHtml4(output.get("titleNoFormatting").toString().replaceAll("\"", "")));
        String content = StringEscapeUtils.unescapeJava(StringEscapeUtils.unescapeHtml4(output.get("content")
                .toString().replaceAll("\\s+", " ").replaceAll("\\<.*?>", "").replaceAll("\"", "")));
        String url = StringEscapeUtils.unescapeJava(output.get("url").toString().replaceAll("\"", ""));
        String result = String.format("Google: %s | %s | (%s)", title, content, url);
        if (result != null) {
            return result;
        } else {
            return "No results found for query " + s;
        }
    } catch (IOException ex) {
        Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.jkoolcloud.tnt4j.logger.AppenderTools.java

/**
 * Parse a given message into a map of key/value pairs. Tags are identified by '#key=value .. #keyN=value'
 * sequence. String values should be enclosed in single quotes.
 *
 * @param tags//from   w  w w  .  j  a  va2  s.  c o  m
 *            a set of name/value pairs
 * @param msg
 *            string message to be parsed
 * @param delm
 *            tag eye catcher
 * @return a map of parsed name/value pairs from a given string message.
 */
public static Map<String, String> parseEventMessage(Map<String, String> tags, String msg, char delm) {
    int curPos = 0;
    while (curPos < msg.length()) {
        if (msg.charAt(curPos) != delm) {
            curPos++;
            continue;
        }

        int start = ++curPos;
        boolean inValue = false;
        boolean quotedValue = false;
        while (curPos < msg.length()) {
            char c = msg.charAt(curPos);
            if (c == '=') {
                inValue = true;
            } else if (c == '\'' && inValue) {
                // the double quote we just read was not escaped, so include it in value
                if (quotedValue) {
                    // found closing quote
                    curPos++;
                    break;
                } else {
                    quotedValue = true;
                }
            } else if (Character.isWhitespace(c) && !quotedValue) {
                break;
            }
            curPos++;
        }

        if (curPos > start) {
            String[] curTag = msg.substring(start, curPos).split("=");
            String name = curTag[0].trim().replace("'", "");
            String value = (curTag.length > 1 ? curTag[1] : "");
            if (value.startsWith("'") && value.endsWith("'"))
                value = StringEscapeUtils.unescapeJava(value.substring(1, value.length() - 1));
            tags.put(name, value);
        }
    }
    return tags;
}

From source file:dk.nodes.webservice.parser.JSONStringer.java

/**
 * Encodes {@code value}./*from  w  ww.j  a  va 2  s.  c om*/
 *
 * @param value a {@link NJSONObject}, {@link NJSONArray}, String, Boolean,
 *     Integer, Long, Double or null. May not be {@link Double#isNaN() NaNs}
 *     or {@link Double#isInfinite() infinities}.
 * @return this stringer.
 */
public JSONStringer value(Object value) throws JSONException {
    if (stack.isEmpty()) {
        throw new JSONException("Nesting problem");
    }

    if (value instanceof NJSONArray) {
        ((NJSONArray) value).writeTo(this);
        return this;

    } else if (value instanceof NJSONObject) {
        ((NJSONObject) value).writeTo(this);
        return this;
    }

    beforeValue();

    if (value == null || value instanceof Boolean || value == NJSONObject.NULL) {
        out.append(value);

    } else if (value instanceof Number) {
        out.append(NJSONObject.numberToString((Number) value));

    } else {
        string(StringEscapeUtils.unescapeJava(value.toString()));
    }

    return this;
}

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

/**
 * This method reads video messages from the service bus queue and perform
 * the media service operations on the video message.Finally it deletes the
 * blob from temporary storage.//from   w  w  w  .  j  av  a2 s.  c  o  m
 * 
 * @param
 * @return
 */
@Scheduled(fixedRate = 36000)
public void readmessage() {
    LOGGER.info("[AzureChatServiceBus][readmessage] start");
    try {
        ReceiveMessageOptions options = ReceiveMessageOptions.DEFAULT;
        options.setReceiveMode(ReceiveMode.RECEIVE_AND_DELETE);
        while (true) {
            ReceiveQueueMessageResult resultQM = service
                    .receiveQueueMessage(AzureChatConstants.SERVICE_BUS_QUEUENAME, options);
            BrokeredMessage message = resultQM.getValue();
            if (message != null && message.getMessageId() != null) {
                String url = (String) message.getProperty(AzureChatConstants.BROK_MSG_KEY_URL);
                url = StringEscapeUtils.unescapeJava(url);
                String expiryTime = String
                        .valueOf(message.getProperty(AzureChatConstants.BROK_MSG_KEY_EXPIRY_TIME));
                LOGGER.debug("Broker Message : URL : " + url + " Expiry time : " + expiryTime + " seconds.");
                // Media service call
                LOGGER.debug("Media service call start time : " + AzureChatUtils.getCurrentTimestamp());
                MediaServiceOutputBean outputObject = azureChatMediaService.performMediaServicesOperations(url,
                        Double.parseDouble(expiryTime));
                LOGGER.debug("Media service call end time : " + AzureChatUtils.getCurrentTimestamp());
                if (outputObject != null) {
                    LOGGER.debug("Asset ID : " + outputObject.getAssetID());
                    UserMessageEntity userMessageEntity = prepareUserMessageEntity(message, outputObject);
                    UserMessageEntityDAO dao = new UserMessageEntityDAOImpl();
                    dao.addUserMessageEntity(userMessageEntity);
                    LOGGER.debug("Video message added the user message table. Message id : "
                            + userMessageEntity.getMessageID());
                    QueueRequestDAO queueRequestDAO = new QueueRequestDAOImpl();
                    queueRequestDAO.postMessage(userMessageEntity.getMessageID(), Integer.parseInt(expiryTime));
                    LOGGER.debug("Video message added the user message expiry queue. Message id : "
                            + userMessageEntity.getMessageID());
                    // Remove temporary stored non encoded video from blob
                    String filename = AzureChatUtils.getFileName(url, AzureChatConstants.TEMP_UPLOAD_CONTAINER);
                    deleteblob(filename);
                    LOGGER.debug("Deleted " + filename + " blob from the "
                            + AzureChatConstants.TEMP_UPLOAD_CONTAINER + " storage.");
                }
            } else {
                LOGGER.debug("No more messages");
                break;
            }
        }
    } catch (ServiceException e) {
        LOGGER.error(
                "Exception occurred while reading message from queue in AzureChatServiceBus Timer Task. Exception Message : "
                        + e.getMessage());
    } catch (Exception e) {
        LOGGER.error(
                "Exception occurred while reading message from queue in AzureChatServiceBus Timer Task. Exception Message :  "
                        + e.getMessage());
    }
    LOGGER.info("[AzureChatServiceBus][readmessage] end");
}

From source file:de.citec.sc.corpus.CorpusLoader.java

private List<Document> getMicroTaggingDocs() {
    List<Document> docs = new ArrayList<>();

    List<String> annotations = readFileAsList(new File(datasetsPath + "dataset/microtag/dataset.in"));
    List<String> tweetDocs = readFileAsList(new File(datasetsPath + "dataset/microtag/dataset_tweets.out"));

    HashMap<String, Document> tweetsHashMap = new HashMap();

    for (String s : tweetDocs) {
        String docId = s.split("\t")[0];
        String content = s.replace(docId, "");
        content = content.trim();/*from   w w w.  j a v  a  2  s  .co  m*/

        Document d1 = new Document(content, docId);

        tweetsHashMap.put(docId, d1);
    }

    for (String s : annotations) {
        String docId = s.split("\t")[0];
        String ans = s.replace(docId, "");
        ans = ans.trim();

        if (!ans.equals("")) {

            String[] arrayOfAnnotations = ans.split("\t");
            List<Annotation> goldSet = new ArrayList<>();

            for (int i = 0; i < arrayOfAnnotations.length; i = i + 2) {

                String label = arrayOfAnnotations[i];
                String uri = arrayOfAnnotations[i + 1].replace("http://dbpedia.org/resource/", "");
                label = StringEscapeUtils.unescapeJava(label);
                uri = StringEscapeUtils.unescapeJava(uri);
                try {
                    uri = URLDecoder.decode(uri, "UTF-8");
                } catch (Exception e) {

                }

                try {
                    label = URLDecoder.decode(label, "UTF-8");
                } catch (Exception e) {

                }
                Annotation a1 = new Annotation(label, uri, 0, 0, new VariableID("S" + goldSet.size()));
                goldSet.add(a1);
            }

            if (tweetsHashMap.containsKey(docId)) {
                Document d = tweetsHashMap.get(docId);

                d.setGoldStandard(goldSet);

                docs.add(d);
            }
        }

    }

    return docs;
}

From source file:com.streamsets.pipeline.lib.el.StringEL.java

@ElFunction(prefix = "str", name = "unescapeJava", description = "Returns an unescaped string from a string with Java special characters (e.g. \\n will be converted to 0x0A).")
public static String java(@ElParam("string") String string) {
    return StringEscapeUtils.unescapeJava(string);
}

From source file:elh.eus.absa.CorpusReader.java

/**
 * @param sentences the sentences to set
 *//*from  w w  w. j av a 2 s.  c  o m*/
public void addSentence(String id, String text) {
    this.sentences.put(id, StringEscapeUtils.unescapeHtml4(StringEscapeUtils.unescapeJava(text)));
}