List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeJava
public static final String unescapeJava(final String input)
Unescapes any Java literals found in the String .
From source file:org.omnaest.utils.propertyfile.content.parser.PropertyFileContentParser.java
private static String unescapeJavaStyleIfNecessary(boolean useJavaStyleUnicodeEscaping, final String group) { return useJavaStyleUnicodeEscaping ? StringEscapeUtils.unescapeJava(group) : group; }
From source file:org.pentaho.reporting.engine.classic.core.testsupport.TestSetupModule.java
private void populateDatabase(Driver driver) throws SQLException, IOException { Properties p = new Properties(); p.setProperty("user", "sa"); p.setProperty("password", ""); final Connection connection = driver.connect("jdbc:hsqldb:mem:SampleData", p); connection.setAutoCommit(false);/*from w w w . j a v a 2s.c om*/ if (isValid(connection)) { // both the test-module here and the sample-data module try to initialize the database. // lets do it only once. return; } try { final InputStream in = new FileInputStream("target/test-classes/sql/sampledata.script"); final InputStreamReader inReader = new InputStreamReader(in, "ISO-8859-1"); final BufferedReader bin = new BufferedReader(inReader, 4096); try { final Statement statement = connection.createStatement(); try { String line; while ((line = bin.readLine()) != null) { if (line.startsWith("CREATE SCHEMA ") || line.startsWith("CREATE USER SA ") || line.startsWith("GRANT DBA TO SA")) { // ignore the error, HSQL sucks } else { statement.addBatch(StringEscapeUtils.unescapeJava(line)); } } statement.executeBatch(); } finally { statement.close(); } } finally { bin.close(); } connection.commit(); } catch (FileNotFoundException fe) { DebugLog.log("Unable to populate test database, no script at ./sql/sampledata.script"); } finally { connection.close(); } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.sampledata.SampleDataModuleInitializer.java
private void populateDatabase(Driver driver) throws SQLException, IOException { Properties p = new Properties(); p.setProperty("user", "sa"); p.setProperty("password", ""); final Connection connection = driver.connect("jdbc:hsqldb:mem:SampleData", p); connection.setAutoCommit(false);//from ww w.j a v a2 s . co m try { final Configuration config = ClassicEngineBoot.getInstance().getGlobalConfig(); final String location = config.getConfigProperty( "org.pentaho.reporting.engine.classic.extensions.datasources.sampledata.SampleDataLocation"); final InputStream in = SampleDataModule.class.getResourceAsStream(location); if (in == null) { logger.warn("Invalid database init-script specified. Sample database will be empty. [" + location + "]"); return; } final InputStreamReader inReader = new InputStreamReader(in); final BufferedReader bin = new BufferedReader(inReader); try { final Statement statement = connection.createStatement(); try { String line; while ((line = bin.readLine()) != null) { if (line.startsWith("CREATE SCHEMA ") || line.startsWith("CREATE USER SA ") || line.startsWith("GRANT DBA TO SA")) { // ignore the error, HSQL sucks } else { statement.addBatch(StringEscapeUtils.unescapeJava(line)); } } statement.executeBatch(); } finally { statement.close(); } } finally { bin.close(); } connection.commit(); } finally { connection.close(); } }
From source file:org.pepstock.jem.jppf.ExecuteManager.java
/** * Create a JPPF job that can be submitted for execution. * // www . j a va2s . c o m * @param runnable Class name of Runnable or JPPFTask to execute * @param parallelTaskNumber Number of parallel task to submit * @param xmlContext InitialContext, serialized in XML string * @return an instance of the {@link org.jppf.client.JPPFJob JPPFJob} class. * @throws NamingException * @throws IOException * @throws JPPFException * @throws JPFFException * if an error occurs while creating the job or adding tasks. */ private static JPPFJob createJob(String xmlContext) throws JPPFMessageException, NamingException, IOException, JPPFException { XStream xstream = new XStream(); // reads all properties String jobName = JPPFConfiguration.getProperties().getProperty(Keys.JEM_JOB_NAME); String taskName = JPPFConfiguration.getProperties().getProperty(Keys.JEM_TASK_NAME); String runnable = JPPFConfiguration.getProperties().getProperty(Keys.JEM_RUNNABLE); int parallelTaskNumber = JPPFConfiguration.getProperties().getInt(Keys.JEM_TASK_NUMBER); // creates a data provider to pass initial context and number of parallel task MemoryMapDataProvider provider = new MemoryMapDataProvider(); provider.setValue(Keys.JEM_CONTEXT, xmlContext); provider.setValue(Keys.JEM_TASK_NUMBER, String.valueOf(parallelTaskNumber)); // checks if CHUNK is set if (JPPFConfiguration.getProperties().containsKey(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION)) { // gets data description String dataDescription = JPPFConfiguration.getProperties() .getProperty(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION); File file = null; InitialContext ic = ContextUtils.getContext(); // lookup for JNDI reference // needs file name because chunk is based on RandomFileAccess // that wants a FILE and not inputstream // so gets data description implementation object // to get REAL FILE NamingEnumeration<NameClassPair> list = ic.list(dataDescription); while (list.hasMore()) { NameClassPair pair = list.next(); // checks if is datastream // only datastreams are searched if (pair.getName().equalsIgnoreCase(dataDescription) && pair instanceof DataStreamNameClassPair) { DataStreamNameClassPair dsPair = (DataStreamNameClassPair) pair; DataStreamReference prevReference = (DataStreamReference) dsPair.getObject(); // gets data description XML definition StringRefAddr sra = (StringRefAddr) prevReference.get(StringRefAddrKeys.DATASTREAMS_KEY); // creates datadescription implementatio to get file DataDescriptionImpl ddImpl = (DataDescriptionImpl) xstream.fromXML(sra.getContent().toString()); file = ddImpl.getDatasets().iterator().next().getRealFile(); // leaves while break; } } // if file is null // data description is not found if (file == null) { throw new JPPFMessageException(JPPFMessage.JEMJ019E, dataDescription); } // calculated buffersize long bufferSize = file.length() / parallelTaskNumber; // using delimiter, creates chunk list List<ChunkDefinition> chunks = null; String delimiter = JPPFConfiguration.getProperties().getProperty(Keys.JEM_DELIMITER); String delimiterString = JPPFConfiguration.getProperties().getProperty(Keys.JEM_DELIMITER_STRING); if (delimiter != null) { // delimiter default LF char splitter = CharUtils.LF; // if delimiter is defined in BYTE mode // calculate char if (delimiter.toLowerCase().startsWith("0x")) { delimiter = StringUtils.substringAfter(delimiter.toLowerCase(), "0x"); splitter = (char) Integer.parseInt(delimiter, 16); } else { // if uses a escape java char splitter = StringEscapeUtils.unescapeJava(delimiter).charAt(0); } String displayDelimiter = Integer.toHexString((byte) splitter) + "(" + splitter + ")"; LogAppl.getInstance().emit(JPPFMessage.JEMJ020I, displayDelimiter); // calculates chunks chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize, splitter); provider.setValue(Keys.JEM_DELIMITER, splitter); } else if (delimiterString != null) { LogAppl.getInstance().emit(JPPFMessage.JEMJ020I, delimiterString); // calculates chunks chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize, delimiterString); provider.setValue(Keys.JEM_DELIMITER, delimiterString); } else { // if delimiter and delimiterString are missing, uses default delimiter (System.getProperty("line.separator") chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize); } // changes parallel task // because chunk calculation tries to maintain the same // number of task but usually there are less after // chunk list creation parallelTaskNumber = chunks.size(); LogAppl.getInstance().emit(JPPFMessage.JEMJ021I, chunks); // serializes and saves on data provider all necessary data provider.setValue(Keys.JEM_TASK_NUMBER, String.valueOf(parallelTaskNumber)); provider.setValue(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION, dataDescription); provider.setValue(Keys.JEM_CHUNKS, xstream.toXML(chunks)); } LogAppl.getInstance().emit(JPPFMessage.JEMJ023I, parallelTaskNumber); // checks if merged data decritpion is an argument if (JPPFConfiguration.getProperties().containsKey(Keys.JEM_MERGED_DATA_DESCRIPTION)) { // loads a list with all temporary files for tasks // to use to write partial output for (int i = 0; i < parallelTaskNumber; i++) { File temp = File.createTempFile("task[" + i + "]-merge", ".jemjppf"); temp.deleteOnExit(); TEMPORARY_FILES.add(temp); LogAppl.getInstance().emit(JPPFMessage.JEMJ022I, temp.getAbsolutePath(), i); } // sets data provider provider.setValue(Keys.JEM_MERGED_DATA_DESCRIPTION, JPPFConfiguration.getProperties().getProperty(Keys.JEM_MERGED_DATA_DESCRIPTION)); provider.setValue(Keys.JEM_TEMPORARY_FILES, xstream.toXML(TEMPORARY_FILES)); } // create a JPPF job JPPFJob job = new JPPFJob(provider); // give this job a readable unique id that we can use to monitor and // manage it. job.setName(jobName + "." + taskName); // Checks what instance has been past to distribute on grid try { Object clazz = Class.forName(runnable).newInstance(); if (clazz instanceof JPPFTask) { for (int i = 0; i < parallelTaskNumber; i++) { JPPFTask t = new WrapperJPPFTask((JPPFTask) clazz); // add a task to the job. job.addTask(t); } } else if (clazz instanceof Runnable) { for (int i = 0; i < parallelTaskNumber; i++) { JPPFTask t = new RunnableTask((Runnable) clazz); // add a task to the job. job.addTask(t); } } else { throw new JPPFMessageException(JPPFMessage.JEMJ002E, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } } catch (InstantiationException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } catch (IllegalAccessException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } catch (ClassNotFoundException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } // there is no guarantee on the order of execution of the tasks, // however the results are guaranteed to be returned in the same order // as the tasks. return job; }
From source file:org.talend.core.model.utils.TalendTextUtils.java
public static String trimParameter(String value) { if (value == null) { return null; }/*w w w . ja v a 2 s. co m*/ int length = value.length(); String result = removeQuotes(value); if (length > 1 && (((value.startsWith("\"") && value.endsWith("\""))) //$NON-NLS-1$//$NON-NLS-2$ || (value.startsWith("\'") && value.endsWith("\'")))) { //$NON-NLS-1$ //$NON-NLS-2$ result = value.substring(1, length - 1); if (result.contains("\\")) { //$NON-NLS-1$ result = result.replaceAll("\\\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\b", "\b"); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\f", "\f"); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\r", "\r"); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\t", "\t"); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ result = result.replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$ // handle unicode if (result.contains("\\u")) { for (int indexStart = 0; result.indexOf("\\u", indexStart) >= 0; indexStart = result .indexOf("\\u", indexStart)) { if (result.indexOf("\\u", indexStart) + 5 <= result.length()) { //$NON-NLS-1$ //$NON-NLS-2$ int unicodeStart = result.indexOf("\\u"); //$NON-NLS-1$ int unicodeEnd = unicodeStart + 5; result = result.substring(0, Math.max(0, unicodeStart)) + StringEscapeUtils.unescapeJava(result.substring(unicodeStart, unicodeEnd + 1)) + result.substring(Math.min(unicodeEnd + 1, result.length()), result.length()); } } } } } return result; }
From source file:org.talend.core.runtime.evaluator.AbstractPropertyValueEvaluator.java
public Object getTypedValue(Property property, Object rawValue) { if (GenericTypeUtils.isSchemaType(property)) { return rawValue; }/*from w w w . java 2 s .c o m*/ String stringValue = String.valueOf(rawValue); if (GenericTypeUtils.isBooleanType(property)) { return new Boolean(stringValue); } if (GenericTypeUtils.isIntegerType(property) && rawValue != null) { if (stringValue.isEmpty()) { // regard empty value as null for Integer type. return null; } try { return Integer.valueOf(stringValue); } catch (Exception e) { // value not existing anymore // return any value to let the component work without exception return 0; } } if (GenericTypeUtils.isEnumType(property)) { List<?> possibleValues = property.getPossibleValues(); if (possibleValues != null) { Object firstValue = null; if (!possibleValues.isEmpty()) { firstValue = possibleValues.get(0); } String stringStoredValue = TalendQuoteUtils.removeQuotes(stringValue); for (Object possibleValue : possibleValues) { if (possibleValue.toString().equals(stringStoredValue)) { return possibleValue; } } if (firstValue != null) { return firstValue; } } } if (GenericTypeUtils.isStringType(property)) { return TalendQuoteUtils.removeQuotes(StringEscapeUtils.unescapeJava(stringValue)); } return rawValue; }
From source file:org.tinymediamanager.scraper.util.YoutubeLinkExtractor.java
private List<VideoDownload> extractJsonInfo() throws Exception { List<VideoDownload> sNextVideoURL = new ArrayList<>(); {//from ww w .j ava 2 s . c o m Matcher matcher = patternAge.matcher(jsonConfiguration); if (matcher.find()) return sNextVideoURL; } { Matcher matcher = patternUnavailable.matcher(jsonConfiguration); if (matcher.find()) return sNextVideoURL; } { Matcher matcher = patternUrlencod.matcher(jsonConfiguration); if (matcher.find()) { String url_encoded_fmt_stream_map; url_encoded_fmt_stream_map = matcher.group(1); // normal embedded video, unable to grab age restricted videos Matcher encodMatch = patternUrl.matcher(url_encoded_fmt_stream_map); if (encodMatch.find()) { String sline = encodMatch.group(1); sNextVideoURL.addAll(extractUrlEncodedVideos(sline, id)); } // stream video Matcher encodStreamMatch = patternStream.matcher(url_encoded_fmt_stream_map); if (encodStreamMatch.find()) { String sline = encodStreamMatch.group(1); String[] urlStrings = sline.split("stream="); for (String urlString : urlStrings) { urlString = StringEscapeUtils.unescapeJava(urlString); Matcher linkMatch = patternLink.matcher(urlString); if (linkMatch.find()) { String sparams = linkMatch.group(1); String itag = linkMatch.group(2); String url = linkMatch.group(3); url = "http" + url + "?" + sparams; url = URLDecoder.decode(url, "UTF-8"); addVideo(sNextVideoURL, itag, new URL(url)); } } } } } // adaptive trailer are kinda useless: die video stream is separated from the audio stream :( // { // Pattern urlencod = Pattern.compile("\"adaptive_fmts\": \"([^\"]*)\""); // Matcher urlencodMatch = urlencod.matcher(html); // if (urlencodMatch.find()) { // String adaptive_fmts; // adaptive_fmts = urlencodMatch.group(1); // // // normal embedded video, unable to grab age restricted videos // Pattern encod = Pattern.compile("url=(.*)"); // Matcher encodMatch = encod.matcher(adaptive_fmts); // if (encodMatch.find()) { // String sline = encodMatch.group(1); // // sNextVideoURL.addAll(extractUrlEncodedVideos(sline)); // } // } // } Collections.sort(sNextVideoURL, new VideoUrlComparator()); return sNextVideoURL; }
From source file:org.tinymediamanager.scraper.util.YoutubeLinkExtractor.java
private List<VideoDownload> extractUrlEncodedVideos(String sline, String id) throws Exception { List<VideoDownload> sNextVideoURL = new ArrayList<>(); String[] urlStrings = sline.split("url="); for (String urlString : urlStrings) { urlString = StringEscapeUtils.unescapeJava(urlString); String urlFull = URLDecoder.decode(urlString, "UTF-8"); // universal request {/* ww w . j a v a 2 s . c o m*/ String url = null; { Pattern link = Pattern.compile("([^&,]*)[&,]"); Matcher linkMatch = link.matcher(urlString); if (linkMatch.find()) { url = linkMatch.group(1); url = URLDecoder.decode(url, "UTF-8"); } } String itag = null; { Pattern link = Pattern.compile("itag=(\\d+)"); Matcher linkMatch = link.matcher(urlFull); if (linkMatch.find()) { itag = linkMatch.group(1); } } String sig = null; if (sig == null) { Pattern link = Pattern.compile("&signature=([^&,]*)"); Matcher linkMatch = link.matcher(urlFull); if (linkMatch.find()) { sig = linkMatch.group(1); } } if (sig == null) { Pattern link = Pattern.compile("sig=([^&,]*)"); Matcher linkMatch = link.matcher(urlFull); if (linkMatch.find()) { sig = linkMatch.group(1); } } if (sig == null) { Pattern link = Pattern.compile("[&,]s=([^&,]*)"); Matcher linkMatch = link.matcher(urlFull); if (linkMatch.find()) { sig = linkMatch.group(1); sig = decryptSignature(sig); } } if (url != null && itag != null && sig != null) { try { url += "&signature=" + sig; addVideo(sNextVideoURL, itag, new URL(url)); continue; } catch (MalformedURLException e) { // ignore bad urls } } } } return sNextVideoURL; }
From source file:org.wso2.ballerina.core.parser.antlr4.BLangAntlr4Listener.java
private void createBasicLiteral(BallerinaParser.LiteralValueContext ctx) { if (ctx.exception == null) { TerminalNode terminalNode = ctx.IntegerLiteral(); if (terminalNode != null) { if (terminalNode.getText().endsWith("l") || terminalNode.getText().endsWith("L")) { //dropping the last character L String longValue = terminalNode.getText().substring(0, terminalNode.getText().length() - 1); modelBuilder.createLongLiteral(longValue, getCurrentLocation(ctx)); } else { modelBuilder.createIntegerLiteral(terminalNode.getText(), getCurrentLocation(ctx)); }//from w ww . jav a 2 s.com } terminalNode = ctx.FloatingPointLiteral(); if (terminalNode != null) { if (terminalNode.getText().endsWith("d") || terminalNode.getText().endsWith("D")) { //dropping the last character D String doubleValue = terminalNode.getText().substring(0, terminalNode.getText().length() - 1); modelBuilder.createDoubleLiteral(doubleValue, getCurrentLocation(ctx)); } else { modelBuilder.createFloatLiteral(terminalNode.getText(), getCurrentLocation(ctx)); } } terminalNode = ctx.QuotedStringLiteral(); if (terminalNode != null) { String stringLiteral = terminalNode.getText(); stringLiteral = stringLiteral.substring(1, stringLiteral.length() - 1); stringLiteral = StringEscapeUtils.unescapeJava(stringLiteral); modelBuilder.createStringLiteral(stringLiteral, getCurrentLocation(ctx)); } terminalNode = ctx.BooleanLiteral(); if (terminalNode != null) { modelBuilder.createBooleanLiteral(terminalNode.getText(), getCurrentLocation(ctx)); } terminalNode = ctx.NullLiteral(); if (terminalNode != null) { modelBuilder.createNullLiteral(terminalNode.getText(), getCurrentLocation(ctx)); } } }
From source file:org.wso2.ballerinalang.compiler.parser.BLangPackageBuilder.java
private IdentifierNode createIdentifier(String value) { IdentifierNode node = TreeBuilder.createIdentifierNode(); if (value == null) { return node; }/* w w w. ja v a 2 s .co m*/ if (value.startsWith(IDENTIFIER_LITERAL_PREFIX) && value.endsWith(IDENTIFIER_LITERAL_SUFFIX)) { value = StringEscapeUtils.unescapeJava(value); node.setValue(value.substring(2, value.length() - 1)); node.setLiteral(true); } else { node.setValue(value); node.setLiteral(false); } return node; }