List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java
protected void handleClob(String tableName, String columnName, int rowNum, ResultSet resultSet, int columnIndex, ContentHandler handler, ParseContext context) throws SQLException, IOException, SAXException { Clob clob = resultSet.getClob(columnIndex); if (resultSet.wasNull()) { return;//from w w w .ja v a2s. co m } boolean truncated = clob.length() > Integer.MAX_VALUE || clob.length() > maxClobLength; int readSize = (clob.length() < maxClobLength ? (int) clob.length() : maxClobLength); Metadata m = new Metadata(); m.set(Database.TABLE_NAME, tableName); m.set(Database.COLUMN_NAME, columnName); m.set(Database.PREFIX + "ROW_NUM", Integer.toString(rowNum)); m.set(Database.PREFIX + "IS_CLOB", "true"); m.set(Database.PREFIX + "CLOB_LENGTH", Long.toString(clob.length())); m.set(Database.PREFIX + "IS_CLOB_TRUNCATED", Boolean.toString(truncated)); m.set(Metadata.CONTENT_TYPE, "text/plain; charset=UTF-8"); m.set(Metadata.CONTENT_LENGTH, Integer.toString(readSize)); m.set(TikaMetadataKeys.RESOURCE_NAME_KEY, //just in case something screwy is going on with the column name FilenameUtils.normalize(FilenameUtils.getName(columnName + "_" + rowNum + ".txt"))); //is there a more efficient way to go from a Reader to an InputStream? String s = clob.getSubString(0, readSize); if (embeddedDocumentUtil.shouldParseEmbedded(m)) { embeddedDocumentUtil.parseEmbedded(new ByteArrayInputStream(s.getBytes(UTF_8)), handler, m, true); } }
From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java
protected void handleBlob(String tableName, String columnName, int rowNum, ResultSet resultSet, int columnIndex, ContentHandler handler, ParseContext context) throws SQLException, IOException, SAXException { Metadata m = new Metadata(); m.set(Database.TABLE_NAME, tableName); m.set(Database.COLUMN_NAME, columnName); m.set(Database.PREFIX + "ROW_NUM", Integer.toString(rowNum)); m.set(Database.PREFIX + "IS_BLOB", "true"); Blob blob = null;/*from w ww . j a va 2 s . c o m*/ TikaInputStream is = null; try { blob = getBlob(resultSet, columnIndex, m); if (blob == null) { return; } is = TikaInputStream.get(blob, m); Attributes attrs = new AttributesImpl(); ((AttributesImpl) attrs).addAttribute("", "type", "type", "CDATA", "blob"); ((AttributesImpl) attrs).addAttribute("", "column_name", "column_name", "CDATA", columnName); ((AttributesImpl) attrs).addAttribute("", "row_number", "row_number", "CDATA", Integer.toString(rowNum)); handler.startElement("", "span", "span", attrs); String extension = embeddedDocumentUtil.getExtension(is, m); m.set(TikaMetadataKeys.RESOURCE_NAME_KEY, //just in case something screwy is going on with the column name FilenameUtils.normalize(FilenameUtils.getName(columnName + "_" + rowNum + extension))); if (embeddedDocumentUtil.shouldParseEmbedded(m)) { embeddedDocumentUtil.parseEmbedded(is, handler, m, true); } } finally { if (blob != null) { try { blob.free(); } catch (SQLException | UnsupportedOperationException e) { //swallow } } IOUtils.closeQuietly(is); } handler.endElement("", "span", "span"); }
From source file:org.apache.tika.parser.ocr.TesseractOCRConfig.java
/** * Set the path to the Tesseract executable's directory, needed if it is not on system path. * <p>// w ww. jav a2s .c om * Note that if you set this value, it is highly recommended that you also * set the path to the 'tessdata' folder using {@link #setTessdataPath}. * </p> */ public void setTesseractPath(String tesseractPath) { tesseractPath = FilenameUtils.normalize(tesseractPath); if (!tesseractPath.isEmpty() && !tesseractPath.endsWith(File.separator)) tesseractPath += File.separator; this.tesseractPath = tesseractPath; }
From source file:org.apache.tika.parser.ocr.TesseractOCRConfig.java
/** * Set the path to the 'tessdata' folder, which contains language files and config files. In some cases (such * as on Windows), this folder is found in the Tesseract installation, but in other cases * (such as when Tesseract is built from source), it may be located elsewhere. *///ww w. jav a 2 s . c o m public void setTessdataPath(String tessdataPath) { tessdataPath = FilenameUtils.normalize(tessdataPath); if (!tessdataPath.isEmpty() && !tessdataPath.endsWith(File.separator)) tessdataPath += File.separator; this.tessdataPath = tessdataPath; }
From source file:org.apache.tika.parser.ocr.TesseractOCRConfig.java
/** * Set the path to the ImageMagick executable directory, needed if it is not on system path. * * @param imageMagickPath to ImageMagick executable directory. *///from www . j av a2 s .c om public void setImageMagickPath(String imageMagickPath) { imageMagickPath = FilenameUtils.normalize(imageMagickPath); if (!imageMagickPath.isEmpty() && !imageMagickPath.endsWith(File.separator)) imageMagickPath += File.separator; this.imageMagickPath = imageMagickPath; }
From source file:org.asqatasun.rules.test.AbstractRuleImplementationTestCase.java
private void initializePath() { testcasesFilePath = "file://" + System.getProperty("user.dir") + "/" + testcasesFilePath; testcasesFilePath = FilenameUtils.normalize(testcasesFilePath); }
From source file:org.batoo.jpa.parser.impl.acl.ClassloaderAnnotatedClassLocator.java
private Set<Class<?>> findClasses(ClassLoader cl, Set<Class<?>> classes, String root, String path) { final File file = new File(path); if (file.isDirectory()) { ClassloaderAnnotatedClassLocator.LOG.debug("Processing directory {0}", path); for (final String child : file.list()) { this.findClasses(cl, classes, root, path + "/" + child); }//w ww .jav a 2s .c om } else { if (FilenameUtils.isExtension(path, "class")) { final String normalizedPath = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(path)); final int rootLength = FilenameUtils.normalizeNoEndSeparator(root).length(); String className = normalizedPath.substring(rootLength + 1).replaceAll("/", "."); className = StringUtils.left(className, className.length() - 6); final Class<?> clazz = this.isPersistentClass(cl, className); if (clazz != null) { ClassloaderAnnotatedClassLocator.LOG.debug("Found persistent class {0}", className); classes.add(clazz); } } } return classes; }
From source file:org.batoo.jpa.parser.impl.acl.ClassloaderAnnotatedClassLocator.java
/** * {@inheritDoc}// www. ja va2 s. c o m * */ @Override public Set<Class<?>> locateClasses(PersistenceUnitInfo persistenceUnitInfo, URL url) { final String root = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(url.getFile())); ClassloaderAnnotatedClassLocator.LOG.info("Checking persistence root {0} for persistence classes...", root); final HashSet<Class<?>> classes = Sets.newHashSet(); try { return this.findClasses(persistenceUnitInfo.getClassLoader(), classes, root, root); } finally { ClassloaderAnnotatedClassLocator.LOG.info("Found persistent classes {0}", classes.toString()); } }
From source file:org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl.java
@Transactional("blTransactionManagerAssetStorageInfo") @Override/*from w w w . j a v a2 s . c o m*/ public void createStaticAssetStorage(InputStream fileInputStream, StaticAsset staticAsset) throws IOException { if (StorageType.DATABASE.equals(staticAsset.getStorageType())) { StaticAssetStorage storage = staticAssetStorageDao.create(); storage.setStaticAssetId(staticAsset.getId()); Blob uploadBlob = staticAssetStorageDao.createBlob(fileInputStream, staticAsset.getFileSize()); storage.setFileData(uploadBlob); staticAssetStorageDao.save(storage); } else if (StorageType.FILESYSTEM.equals(staticAsset.getStorageType())) { FileWorkArea tempWorkArea = broadleafFileService.initializeWorkArea(); // Convert the given URL from the asset to a system-specific suitable file path String destFileName = FilenameUtils.normalize(tempWorkArea.getFilePathLocation() + File.separator + FilenameUtils.separatorsToSystem(staticAsset.getFullUrl())); InputStream input = fileInputStream; byte[] buffer = new byte[fileBufferSize]; File destFile = new File(destFileName); if (!destFile.getParentFile().exists()) { if (!destFile.getParentFile().mkdirs()) { if (!destFile.getParentFile().exists()) { throw new RuntimeException("Unable to create parent directories for file: " + destFileName); } } } OutputStream output = new FileOutputStream(destFile); boolean deleteFile = false; try { int bytesRead; int totalBytesRead = 0; while ((bytesRead = input.read(buffer)) != -1) { totalBytesRead += bytesRead; if (totalBytesRead > maxUploadableFileSize) { deleteFile = true; throw new IOException("Maximum Upload File Size Exceeded"); } output.write(buffer, 0, bytesRead); } // close the output file stream prior to moving files around output.close(); broadleafFileService.addOrUpdateResource(tempWorkArea, destFile, deleteFile); } finally { IOUtils.closeQuietly(output); broadleafFileService.closeWorkArea(tempWorkArea); } } }
From source file:org.broadleafcommerce.common.file.service.BroadleafFileServiceImpl.java
protected File getLocalResource(String resourceName, boolean skipSite) { if (skipSite) { String baseDirectory = getBaseDirectory(skipSite); // convert the separators to the system this is currently run on String systemResourcePath = FilenameUtils.separatorsToSystem(resourceName); String filePath = FilenameUtils.normalize(baseDirectory + File.separator + systemResourcePath); return new File(filePath); } else {/*www . j a v a 2 s . c o m*/ String baseDirectory = getBaseDirectory(true); ExtensionResultHolder<String> holder = new ExtensionResultHolder<String>(); if (extensionManager != null) { ExtensionResultStatusType result = extensionManager.getProxy().processPathForSite(baseDirectory, resourceName, holder); if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) { return new File(holder.getResult()); } } return getLocalResource(resourceName, true); } }