List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:com.willowtreeapps.androidcontentprovidergenerator.Main.java
private void loadModel(File inputDir) throws IOException, JSONException { File[] entityFiles = inputDir.listFiles(new FileFilter() { @Override/*from w ww . jav a 2 s . c o m*/ public boolean accept(File pathname) { return !pathname.getName().startsWith("_") && pathname.getName().endsWith(".json"); } }); for (File entityFile : entityFiles) { if (Config.LOGD) Log.d(TAG, entityFile.getCanonicalPath()); String entityName = FilenameUtils.getBaseName(entityFile.getCanonicalPath()); if (Config.LOGD) Log.d(TAG, "entityName=" + entityName); Entity entity = new Entity(entityName); String fileContents = FileUtils.readFileToString(entityFile); JSONObject entityJson = new JSONObject(fileContents); entity.setUrl(entityJson.optString("urlPath")); // Fields JSONArray fieldsJson = entityJson.getJSONArray("fields"); int len = fieldsJson.length(); for (int i = 0; i < len; i++) { JSONObject fieldJson = fieldsJson.getJSONObject(i); if (Config.LOGD) Log.d(TAG, "fieldJson=" + fieldJson); String name = fieldJson.getString(Field.Json.NAME); String serializedName = fieldJson.optString(Field.Json.SERIALIZED_NAME); String type = fieldJson.getString(Field.Json.TYPE); boolean isIndex = fieldJson.optBoolean(Field.Json.INDEX, false); boolean isNullable = fieldJson.optBoolean(Field.Json.NULLABLE, true); String defaultValue = fieldJson.optString(Field.Json.DEFAULT_VALUE); String enumName = fieldJson.optString(Field.Json.ENUM_NAME); JSONArray enumValuesJson = fieldJson.optJSONArray(Field.Json.ENUM_VALUES); List<String> enumValues = new ArrayList<String>(); if (enumValuesJson != null) { int enumLen = enumValuesJson.length(); for (int j = 0; j < enumLen; j++) { String valueName = enumValuesJson.getString(j); enumValues.add(valueName); } } Field field = new Field(name, serializedName, type, isIndex, isNullable, defaultValue, enumName, enumValues); entity.addField(field); } // Constraints (optional) JSONArray constraintsJson = entityJson.optJSONArray("constraints"); if (constraintsJson != null) { len = constraintsJson.length(); for (int i = 0; i < len; i++) { JSONObject constraintJson = constraintsJson.getJSONObject(i); if (Config.LOGD) Log.d(TAG, "constraintJson=" + constraintJson); String name = constraintJson.getString(Constraint.Json.NAME); String definition = constraintJson.getString(Constraint.Json.DEFINITION); Constraint constraint = new Constraint(name, definition); entity.addConstraint(constraint); } } // QueryParams (optional) JSONArray paramsJson = entityJson.optJSONArray("queryParams"); if (paramsJson != null) { len = paramsJson.length(); for (int i = 0; i < len; i++) { JSONObject constraintJson = paramsJson.getJSONObject(i); String name = constraintJson.getString(Constraint.Json.NAME); entity.addQueryParam(name); } } Model.get().addEntity(entity); } // Header (optional) File headerFile = new File(inputDir, "header.txt"); if (headerFile.exists()) { String header = FileUtils.readFileToString(headerFile).trim(); Model.get().setHeader(header); } if (Config.LOGD) Log.d(TAG, Model.get().toString()); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreebankCombinedReaderWriterTest.java
public void testOneWay(String aExpectedFile, String aFile, Object... aExtraParams) throws Exception { File reference = new File("src/test/resources/stanfordPennTrees/" + aExpectedFile); File input = new File("src/test/resources/stanfordPennTrees/" + aFile); File output = new File("target/test-output/" + name.getMethodName()); List<Object> extraReaderParams = new ArrayList<>(); extraReaderParams.add(PennTreebankCombinedReader.PARAM_SOURCE_LOCATION); extraReaderParams.add(input);/*w ww .j a v a2 s . c o m*/ extraReaderParams.addAll(asList(aExtraParams)); CollectionReaderDescription reader = createReaderDescription(PennTreebankCombinedReader.class, extraReaderParams.toArray()); List<Object> extraWriterParams = new ArrayList<>(); extraWriterParams.add(PennTreebankCombinedWriter.PARAM_TARGET_LOCATION); extraWriterParams.add(output); extraWriterParams.add(PennTreebankCombinedWriter.PARAM_STRIP_EXTENSION); extraWriterParams.add(true); extraWriterParams.addAll(asList(aExtraParams)); AnalysisEngineDescription writer = createEngineDescription(PennTreebankCombinedWriter.class, extraWriterParams.toArray()); runPipeline(reader, writer); String expected = FileUtils.readFileToString(reference, "UTF-8"); String actual = FileUtils .readFileToString(new File(output, FilenameUtils.getBaseName(input.toString()) + ".penn"), "UTF-8"); assertEquals(expected.trim(), actual.trim()); }
From source file:com.piketec.jenkins.plugins.tpt.Utils.java
/** * Creates a String with a path to create for the test data dir. This will be relative to the * build workspace/* ww w .j a va 2 s. c o m*/ * * @param ec * through the jenkins configuration we get the name and the configuration of the file. * Used to create an unique path. * @return a String with the folders for the test data dir. */ public static String getGeneratedTestDataDir(JenkinsConfiguration ec) { if (ec.getTestdataDir() == null || ec.getTestdataDir().trim().isEmpty()) { return "Piketec" + File.separator + FilenameUtils.getBaseName(ec.getTptFile()) + File.separator + ec.getConfiguration() + File.separator + "testdata"; } else { return ec.getTestdataDir(); } }
From source file:de.uzk.hki.da.convert.PdfConversionStrategy.java
/** * Generate target file path.//from w w w . j a v a2 s .c o m * * @param ci the ci * @return the string */ public String generateTargetFilePath(WorkArea wa, ConversionInstruction ci) { String input = wa.toFile(ci.getSource_file()).getAbsolutePath(); return wa.dataPath() + "/" + object.getNameOfLatestBRep() + "/" + StringUtilities.slashize(ci.getTarget_folder()) + FilenameUtils.getBaseName(input) + "." + ci.getConversion_routine().getTarget_suffix(); }
From source file:eu.udig.style.advanced.raster.PredefinedColorRules.java
/** * Reads and returns the {@link HashMap map} holding all predefined color rules. * /*from w ww. j ava2s . c om*/ * <p> * The map has the name of the colortable as key and * and array of Strings as value, representing the colors and values * of the colortable.<br> * The array can be of two types:<br> * <ul> * <li> * 3 values per row (r, g, b): in that case the colortable * will be interpolated over a supplied range and be kept * continuos between the values. On example is the elevation map. * </li> * <li> * 8 values per row (v1, r1, g1, b1, v2, r2, g2, b2): * in that case the values of every step is defined and the * color rules are used as they come. One example is the corine * landcover map, that has to be consistent with the given values * and colors. * </li> * </ul> * </p> * * @param doReset if true the folder of colortables is reread. * @return the map of colortables. */ public static HashMap<String, String[][]> getColorsFolder(boolean doReset) { int size = colorRules.size(); if (!doReset && size > 0) { return colorRules; } /* * read the default colortables from the plugin folder */ try { // create the rainbow colortable, which has to exist colorRules.put("rainbow", rainbow); //$NON-NLS-1$ File colorTablesFolder = null; Bundle bundle = Platform.getBundle(StylePlugin.PLUGIN_ID); if (bundle != null) { URL queriesUrl = bundle.getResource("colortables"); //$NON-NLS-1$ String colorTablesFolderPath = FileLocator.toFileURL(queriesUrl).getPath(); colorTablesFolder = new File(colorTablesFolderPath); } else { File baseFolder = new File(".."); //$NON-NLS-1$ File[] listFiles = baseFolder.listFiles(); for (File folder : listFiles) { String name = folder.getName().toLowerCase(); if (name.startsWith("eu.hydrologis.jgrass.libs") && !name.contains("external") //$NON-NLS-1$//$NON-NLS-2$ && !name.contains("scripting")) { //$NON-NLS-1$ colorTablesFolder = new File(folder, "colortables"); //$NON-NLS-1$ } } } if (colorTablesFolder != null && colorTablesFolder.exists()) { File[] files = colorTablesFolder.listFiles(); for (File file : files) { String name = file.getName(); if (name.toLowerCase().endsWith(".clr")) { //$NON-NLS-1$ BufferedReader bR = new BufferedReader(new FileReader(file)); List<String[]> lines = new ArrayList<String[]>(); String line = null; int cols = 0; while ((line = bR.readLine()) != null) { if (line.startsWith("#")) { //$NON-NLS-1$ continue; } String[] lineSplit = line.trim().split("\\s+"); //$NON-NLS-1$ cols = lineSplit.length; lines.add(lineSplit); } bR.close(); String[][] linesArray = (String[][]) lines.toArray(new String[lines.size()][cols]); String ruleName = FilenameUtils.getBaseName(file.getName()); ruleName = ruleName.replaceAll("\\_", " "); //$NON-NLS-1$ //$NON-NLS-2$ colorRules.put(ruleName, linesArray); } } } } catch (IOException e) { e.printStackTrace(); } return colorRules; }
From source file:it.geosolutions.geobatch.destination.RasterMigrationTest.java
@Test public void testCopyPartnerFiles() throws IOException { // First partner string initialization String partnerName = PARTNER_FILES[0]; // Initialization of the migration object RasterMigration rasterMig = new RasterMigration(partnerName, INPUT_DIR, OUTPUT_DIR, metadataHandler, dataStore, new ProgressListenerForwarder(null)); // Copying file rasterMig.execute(null, false);//from ww w .j a v a 2 s . c o m // Path of the new files String filePathBase = INPUT_DIR + PATHSEPARATOR + partnerName; File inputDirPartner = new File(filePathBase); File[] files = inputDirPartner.listFiles(); String fileName = null; String outputFilePath = OUTPUT_DIR + PATHSEPARATOR; for (File file : files) { // Selection of the name associated to the file without the extension fileName = FilenameUtils.getBaseName(file.getName()); // New file copied with the new name File newFile = new File(outputFilePath + fileName + PATHSEPARATOR + fileName + LOWER_SEP + partnerName.toLowerCase(Locale.ENGLISH) + TIF_EXTENSION); // Check if the file is present assertTrue(newFile.exists()); // Elimination of the new file created newFile.delete(); // Elimination of file associated new directory newFile.getParentFile().delete(); } }
From source file:com.kamike.misc.FsNameUtils.java
public static String getName(String prefix, String disk, String date, String name, String fid, String uid, String extension) {//from ww w . j a v a 2s .c om String baseName = FilenameUtils.getBaseName(name); String escapedName = escapeName(baseName); StringBuffer buffer = new StringBuffer(); buffer.append(prefix); buffer.append(disk); buffer.append('/'); buffer.append(uid); buffer.append('/'); buffer.append(date); buffer.append('/'); //?idid buffer.append(fid); buffer.append('/'); buffer.append(escapedName); if (!"".equals(extension)) { buffer.append('.'); buffer.append(extension); } return buffer.toString(); }
From source file:com.highcharts.export.controller.ExportController.java
@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }) public HttpEntity<byte[]> exporter(@RequestParam(value = "svg", required = false) String svg, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "filename", required = false) String filename, @RequestParam(value = "width", required = false) String width, @RequestParam(value = "scale", required = false) String scale, @RequestParam(value = "options", required = false) String options, @RequestParam(value = "globaloptions", required = false) String globalOptions, @RequestParam(value = "constr", required = false) String constructor, @RequestParam(value = "callback", required = false) String callback, @RequestParam(value = "callbackHC", required = false) String callbackHC, @RequestParam(value = "async", required = false, defaultValue = "false") Boolean async, @RequestParam(value = "jsonp", required = false, defaultValue = "false") Boolean jsonp, HttpServletRequest request, HttpSession session) throws ServletException, InterruptedException, SVGConverterException, NoSuchElementException, PoolException, TimeoutException, IOException, ZeroRequestParameterException { MimeType mime = getMime(type); String randomFilename = null; String jsonpCallback = ""; boolean isAndroid = request.getHeader("user-agent") != null && request.getHeader("user-agent").contains("Android"); if ("GET".equalsIgnoreCase(request.getMethod())) { // Handle redirect downloads for Android devices, these come in without request parameters String tempFile = (String) session.getAttribute("tempFile"); session.removeAttribute("tempFile"); if (tempFile != null && !tempFile.isEmpty()) { logger.debug("filename stored in session, read and stream from filesystem"); String basename = FilenameUtils.getBaseName(tempFile); String extension = FilenameUtils.getExtension(tempFile); return getFile(basename, extension); }/*from ww w . ja v a 2 s . com*/ } // check for visitors who don't know this domain is really only for the exporting service ;) if (request.getParameterMap().isEmpty()) { throw new ZeroRequestParameterException(); } /* Most JSONP implementations use the 'callback' request parameter and this overwrites * the original callback parameter for chart creation with Highcharts. If JSONP is * used we recommend using the requestparameter callbackHC as the callback for Highcharts. * store the callback method name and reset the callback parameter, * otherwise it will be used when creation charts */ if (jsonp) { async = true; jsonpCallback = callback; callback = null; if (callbackHC != null) { callback = callbackHC; } } if (isAndroid || MimeType.PDF.equals(mime) || async) { randomFilename = createRandomFileName(mime.name().toLowerCase()); } /* If randomFilename is not null, then we want to save the filename in session, in case of GET is used later on*/ if (isAndroid) { logger.debug("storing randomfile in session: " + FilenameUtils.getName(randomFilename)); session.setAttribute("tempFile", FilenameUtils.getName(randomFilename)); } String output = convert(svg, mime, width, scale, options, constructor, callback, globalOptions, randomFilename); ByteArrayOutputStream stream; HttpHeaders headers = new HttpHeaders(); if (async) { String link = TempDir.getDownloadLink(randomFilename); stream = new ByteArrayOutputStream(); if (jsonp) { StringBuilder sb = new StringBuilder(jsonpCallback); sb.append("('"); sb.append(link); sb.append("')"); stream.write(sb.toString().getBytes("utf-8")); headers.add("Content-Type", "text/javascript; charset=utf-8"); } else { stream.write(link.getBytes("utf-8")); headers.add("Content-Type", "text/html; charset=UTF-8"); } } else { headers.add("Content-Type", mime.getType() + "; charset=utf-8"); if (randomFilename != null && randomFilename.equals(output)) { stream = writeFileToStream(randomFilename); } else { boolean base64 = !mime.getExtension().equals("svg"); stream = outputToStream(output, base64); } filename = getFilename(filename); headers.add("Content-Disposition", "attachment; filename=" + filename.replace(" ", "_") + "." + mime.name().toLowerCase()); } headers.setContentLength(stream.size()); return new HttpEntity<byte[]>(stream.toByteArray(), headers); }
From source file:com.cognifide.cq.cqsm.core.scripts.ScriptFinderImpl.java
private boolean isNotIgnoredPath(String path) { return !ScriptManager.FILE_FOR_EVALUATION.equals(FilenameUtils.getBaseName(path)); }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
public static String[] getExeFileCompleteOptions(String name) { List<String> nameList = new ArrayList<String>(); List<String> sysExeNameList = getSysExeNameList(); for (String exePath : sysExeNameList) { String exeName = FilenameUtils.getBaseName(exePath); String ext = FilenameUtils.getExtension(exePath); if (exeName.equals(name) && isExecuteFile(ext)) { nameList.add(exePath);/*from ww w .ja v a 2s . co m*/ } } if (nameList.size() == 0) return null; String[] result = new String[nameList.size()]; for (int i = 0; i < nameList.size(); i++) { result[i] = nameList.get(i); } return result; }