List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:org.fusesource.mvnplugins.linkchecker.LinkcheckReport.java
private void generateDetailsSection(Locale locale, LinkcheckModel linkcheckModel) { getSink().section1();/*from w w w . ja v a 2s . co m*/ getSink().sectionTitle1(); getSink().text(i18n.getString("sitegen-linkcheck-report", locale, "report.sitegen.linkcheck.detail")); getSink().sectionTitle1_(); getSink().paragraph(); getSink().rawText( i18n.getString("sitegen-linkcheck-report", locale, "report.sitegen.linkcheck.detail.overview")); getSink().paragraph_(); getSink().table(); // Header generateTableHeader(locale, true); // Content List linkcheckFiles = linkcheckModel.getFiles(); for (Iterator it = linkcheckFiles.iterator(); it.hasNext();) { LinkcheckFile linkcheckFile = (LinkcheckFile) it.next(); getSink().tableRow(); getSink().tableCell(); if (linkcheckFile.getUnsuccessful() == 0) { iconValid(locale); } else { iconError(locale); } getSink().tableCell_(); // tableCell( createLinkPatternedText( linkcheckFile.getRelativePath(), "./" // + linkcheckFile.getRelativePath() ) ); getSink().tableCell(); getSink().link(linkcheckFile.getRelativePath()); getSink().text(linkcheckFile.getRelativePath()); getSink().link_(); getSink().tableCell_(); getSink().tableCell(); getSink().text(String.valueOf(linkcheckFile.getNumberOfLinks())); getSink().tableCell_(); getSink().tableCell(); getSink().text(String.valueOf(linkcheckFile.getNumberOfLinks(LinkcheckFileResult.VALID_LEVEL))); getSink().tableCell_(); getSink().tableCell(); getSink().text(String.valueOf(linkcheckFile.getNumberOfLinks(LinkcheckFileResult.WARNING_LEVEL))); getSink().tableCell_(); getSink().tableCell(); getSink().text(String.valueOf(linkcheckFile.getNumberOfLinks(LinkcheckFileResult.ERROR_LEVEL))); getSink().tableCell_(); getSink().tableRow_(); // Detail error if (linkcheckFile.getUnsuccessful() != 0) { getSink().tableRow(); getSink().tableCell(); getSink().text(""); getSink().tableCell_(); // TODO it is due to DOXIA-78 getSink().rawText("<td colspan=\"5\">"); getSink().table(); for (Iterator it2 = linkcheckFile.getResults().iterator(); it2.hasNext();) { LinkcheckFileResult linkcheckFileResult = (LinkcheckFileResult) it2.next(); if (linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.VALID_LEVEL) { continue; } getSink().tableRow(); getSink().tableCell(); if (linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.WARNING_LEVEL) { iconWarning(locale); } else if (linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.ERROR_LEVEL) { iconError(locale); } getSink().tableCell_(); getSink().tableCell(); getSink().italic(); if (linkcheckFileResult.getTarget().startsWith("#")) { getSink().link(linkcheckFile.getRelativePath() + linkcheckFileResult.getTarget()); } else if (linkcheckFileResult.getTarget().startsWith(".")) { // We need to calculate a correct absolute path here, because target is a relative path String absolutePath = FilenameUtils.getFullPath(linkcheckFile.getRelativePath()) + linkcheckFileResult.getTarget(); String normalizedPath = FilenameUtils.normalize(absolutePath); if (normalizedPath == null) { normalizedPath = absolutePath; } getSink().link(normalizedPath); } else { getSink().link(linkcheckFileResult.getTarget()); } // Show the link as it was written to make it easy for // the author to find it in the source document getSink().text(linkcheckFileResult.getTarget()); getSink().link_(); getSink().text(": "); getSink().text(linkcheckFileResult.getErrorMessage()); getSink().italic_(); getSink().tableCell_(); getSink().tableRow_(); } getSink().table_(); getSink().tableCell_(); getSink().tableRow_(); } } getSink().table_(); getSink().section1_(); }
From source file:org.geosdi.geoplatform.services.utility.PublishUtility.java
public static File getFileNameToLowerCase(File file) { File fileToReturn = new File( FilenameUtils.getFullPath(file.getAbsolutePath()) + file.getName().toLowerCase()); try {/*ww w. j a va 2 s . c o m*/ FileUtils.moveFile(file, fileToReturn); } catch (IOException ex) { logger.error("Error renaming file: " + ex); } return fileToReturn; }
From source file:org.geotools.coverage.io.util.Utilities.java
/** * Creates a human readable message that describe the provided {@link File} object in terms of its properties. * /*from ww w. j a v a 2 s. c om*/ * <p> * Useful for creating meaningful log messages. * * @param file the {@link File} object to create a descriptive message for * @return a {@link String} containing a descriptive message about the provided {@link File}. * */ public static String getFileInfo(final File file) { final StringBuilder builder = new StringBuilder(); builder.append("Checking file:").append(FilenameUtils.getFullPath(file.getAbsolutePath())).append("\n"); builder.append("isHidden:").append(file.isHidden()).append("\n"); builder.append("exists:").append(file.exists()).append("\n"); builder.append("isFile").append(file.isFile()).append("\n"); builder.append("canRead:").append(file.canRead()).append("\n"); builder.append("canWrite").append(file.canWrite()).append("\n"); builder.append("canExecute:").append(file.canExecute()).append("\n"); builder.append("isAbsolute:").append(file.isAbsolute()).append("\n"); builder.append("lastModified:").append(file.lastModified()).append("\n"); builder.append("length:").append(file.length()); final String message = builder.toString(); return message; }
From source file:org.geotools.gce.imagecollection.ImageCollectionReader.java
/** * Creates a new instance of ImageCollectionReader * /* w ww . j a va 2 s .c o m*/ * @param input * the input folder * @param uHints * user-supplied hints TODO currently are unused * @throws DataSourceException */ public ImageCollectionReader(Object input, Hints uHints) throws DataSourceException { super(input, uHints); // // Set the source being careful in case it is an URL pointing to a file // File file = null; try { this.sourceURL = Utils.checkSource(source); source = DataUtilities.urlToFile(sourceURL); if (source instanceof File) { file = (File) source; rootPath = FilenameUtils.getFullPath( FilenameUtils.normalizeNoEndSeparator(file.getAbsolutePath()) + Utils.SEPARATOR); loadConfig(); } } catch (IOException e) { throw new DataSourceException(e); } rasterManager = new RasterManager(this); getHRInfo(); }
From source file:org.geotools.gce.imagecollection.Utils.java
/** * Checks that a {@link File} is a real file, exists and is readable. * /*from www .ja va 2 s.c om*/ * @param file * the {@link File} instance to check. Must not be null. * * @return <code>true</code> in case the file is a real file, exists and is * readable; <code>false </code> otherwise. */ static boolean checkFileReadable(final File file) { if (LOGGER.isLoggable(Level.FINE)) { final StringBuilder builder = new StringBuilder(); builder.append("Checking file:").append(FilenameUtils.getFullPath(file.getAbsolutePath())).append("\n"); builder.append("canRead:").append(file.canRead()).append("\n"); builder.append("isHidden:").append(file.isHidden()).append("\n"); builder.append("isFile").append(file.isFile()).append("\n"); builder.append("canWrite").append(file.canWrite()).append("\n"); LOGGER.fine(builder.toString()); } if (!file.exists() || !file.canRead() || !file.isFile()) return false; return true; }
From source file:org.geotools.gce.imagemosaic.catalog.GTDataStoreGranuleCatalog.java
public GTDataStoreGranuleCatalog(final Properties params, final boolean create, final DataStoreFactorySpi spi, final Hints hints) { super(hints); Utilities.ensureNonNull("params", params); Utilities.ensureNonNull("spi", spi); try {/*ww w .jav a2 s .c o m*/ this.pathType = (PathType) params.get(Utils.Prop.PATH_TYPE); this.locationAttribute = (String) params.get(Utils.Prop.LOCATION_ATTRIBUTE); final String temp = (String) params.get(Utils.Prop.SUGGESTED_SPI); this.suggestedRasterSPI = temp != null ? (ImageReaderSpi) Class.forName(temp).newInstance() : null; this.parentLocation = (String) params.get(Utils.Prop.PARENT_LOCATION); if (params.containsKey(Utils.Prop.HETEROGENEOUS)) { this.heterogeneous = (Boolean) params.get(Utils.Prop.HETEROGENEOUS); } // creating a store, this might imply creating it for an existing underlying store or // creating a brand new one Map<String, Serializable> dastastoreParams = Utils.filterDataStoreParams(params, spi); // H2 workadound if (Utils.isH2Store(spi)) { Utils.fixH2DatabaseLocation(dastastoreParams, parentLocation); Utils.fixH2MVCCParam(dastastoreParams); } if (!create) { tileIndexStore = spi.createDataStore(dastastoreParams); } else { // this works only with the shapefile datastore, not with the others // therefore I try to catch the error to try and use themethdo without *New* try { tileIndexStore = spi.createNewDataStore(dastastoreParams); } catch (UnsupportedOperationException e) { tileIndexStore = spi.createDataStore(dastastoreParams); } } if (Utils.isOracleStore(spi)) { tileIndexStore = new OracleDatastoreWrapper(tileIndexStore, FilenameUtils.getFullPath(parentLocation)); } // is this a new store? If so we do not set any properties if (create) { return; } String typeName = null; boolean scanForTypeNames = false; if (params.containsKey(Utils.Prop.TYPENAME)) { typeName = (String) params.get(Utils.Prop.TYPENAME); } if (params.containsKey(Utils.SCAN_FOR_TYPENAMES)) { scanForTypeNames = Boolean.valueOf(params.get(Utils.SCAN_FOR_TYPENAMES).toString()); } // if this is not a new store let's extract basic properties from it if (scanForTypeNames) { String[] typeNames = tileIndexStore.getTypeNames(); if (typeNames != null) { for (String tn : typeNames) { this.typeNames.add(tn); } } } else if (typeName != null) { addTypeName(typeName, false); } if (this.typeNames.size() > 0) { extractBasicProperties(typeNames.iterator().next()); } else { extractBasicProperties(typeName); } } catch (Throwable e) { try { if (tileIndexStore != null) tileIndexStore.dispose(); } catch (Throwable e1) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e1.getLocalizedMessage(), e1); } finally { tileIndexStore = null; } throw new IllegalArgumentException(e); } }
From source file:org.geotools.gce.imagepyramid.Utils.java
/** * Prepares a message with the status of the provided file. * @param sourceFile The {@link File} to provided the status message for * @return a status message for the provided {@link File} or a {@link NullPointerException} in case the {@link File}is <code>null</code>. *//*from ww w .j av a2 s. c om*/ private static String fileStatus(File sourceFile) { if (sourceFile == null) { throw new NullPointerException("Provided null input to fileStatus method"); } final StringBuilder builder = new StringBuilder(); builder.append("Checking file:").append(FilenameUtils.getFullPath(sourceFile.getAbsolutePath())) .append("\n"); builder.append("exists").append(sourceFile.exists()).append("\n"); builder.append("isFile").append(sourceFile.isFile()).append("\n"); builder.append("canRead:").append(sourceFile.canRead()).append("\n"); builder.append("canWrite").append(sourceFile.canWrite()).append("\n"); builder.append("canExecute").append(sourceFile.canExecute()).append("\n"); builder.append("isHidden:").append(sourceFile.isHidden()).append("\n"); builder.append("lastModified").append(sourceFile.lastModified()).append("\n"); return builder.toString(); }
From source file:org.gluu.oxtrust.action.ViewLogFileAction.java
private Map<Integer, String> prepareLogFiles() { Map<Integer, String> logFiles = new HashMap<Integer, String>(); int fileIndex = 0; for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) { String logTemplatePattern = logTemplate.getValue2(); if (StringHelper.isEmpty(logTemplatePattern)) { continue; }/*from w ww . j a v a 2 s .c o m*/ String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern); String logTemplateFile = FilenameUtils.getName(logTemplatePattern); File logTemplateBaseDir = new File(logTemplatePath); FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile)); File[] files = logTemplateBaseDir.listFiles(fileFilter); if (files == null) { continue; } for (int i = 0; i < files.length; i++) { logFiles.put(fileIndex++, files[i].getPath()); } } return logFiles; }
From source file:org.jasig.resource.aggr.ResourcesAggregatorImpl.java
/** * Aggregate the specified Deque of elements into a single element. The provided MessageDigest is used for * building the file name based on the hash of the file contents. The callback is used for type specific * operations.//from ww w.ja v a2s . c o m */ protected <T extends BasicInclude> T aggregateList(final MessageDigest digest, final Deque<T> elements, final List<File> skinDirectories, final File outputRoot, final File alternateOutput, final String extension, final AggregatorCallback<T> callback) throws IOException { if (null == elements || elements.size() == 0) { return null; } // reference to the head of the list final T headElement = elements.getFirst(); if (elements.size() == 1 && this.resourcesDao.isAbsolute(headElement)) { return headElement; } final File tempFile = File.createTempFile("working.", extension); final File aggregateOutputFile; try { //Make sure we're working with a clean MessageDigest digest.reset(); TrimmingWriter trimmingWriter = null; try { final BufferedOutputStream bufferedFileStream = new BufferedOutputStream( new FileOutputStream(tempFile)); final MessageDigestOutputStream digestStream = new MessageDigestOutputStream(bufferedFileStream, digest); final OutputStreamWriter aggregateWriter = new OutputStreamWriter(digestStream, this.encoding); trimmingWriter = new TrimmingWriter(aggregateWriter); for (final T element : elements) { final File resourceFile = this.findFile(skinDirectories, element.getValue()); FileInputStream fis = null; try { fis = new FileInputStream(resourceFile); final BOMInputStream bomIs = new BOMInputStream(new BufferedInputStream(fis)); if (bomIs.hasBOM()) { logger.debug("Stripping UTF-8 BOM from: " + resourceFile); } final Reader resourceIn = new InputStreamReader(bomIs, this.encoding); if (element.isCompressed()) { IOUtils.copy(resourceIn, trimmingWriter); } else { callback.compress(resourceIn, trimmingWriter); } } catch (IOException e) { throw new IOException( "Failed to read '" + resourceFile + "' for skin: " + skinDirectories.get(0), e); } finally { IOUtils.closeQuietly(fis); } trimmingWriter.write(SystemUtils.LINE_SEPARATOR); } } finally { IOUtils.closeQuietly(trimmingWriter); } if (trimmingWriter.getCharCount() == 0) { return null; } // temp file is created, get checksum final String checksum = Base64.encodeBase64URLSafeString(digest.digest()); digest.reset(); // create a new file name final String newFileName = checksum + extension; // Build the new file name and path if (alternateOutput == null) { final String elementRelativePath = FilenameUtils.getFullPath(headElement.getValue()); final File directoryInOutputRoot = new File(outputRoot, elementRelativePath); // create the same directory structure in the output root directoryInOutputRoot.mkdirs(); aggregateOutputFile = new File(directoryInOutputRoot, newFileName).getCanonicalFile(); } else { aggregateOutputFile = new File(alternateOutput, newFileName).getCanonicalFile(); } //Move the aggregate file into the correct location FileUtils.deleteQuietly(aggregateOutputFile); FileUtils.moveFile(tempFile, aggregateOutputFile); } finally { //Make sure the temp file gets deleted FileUtils.deleteQuietly(tempFile); } final String newResultValue = RelativePath.getRelativePath(outputRoot, aggregateOutputFile); this.logAggregation(elements, newResultValue); return callback.getAggregateElement(newResultValue, elements); }
From source file:org.jasig.resource.aggr.ResourcesAggregatorImpl.java
/** * Similar to the {@link #equals(Object)} method, this will return * true if this object and the argument are "aggregatable". * /* w ww . ja va 2s. co m*/ * 2 {@link Css} objects are aggregatable if and only if: * <ol> * <li>Neither object returns true for {@link #isAbsolute()}</li> * <li>The values of their "conditional" properties are equivalent</li> * <li>The values of their "media" properties are equivalent</li> * <li>The "paths" of their values are equivalent</li> * </ol> * * The last rule mentioned above uses {@link FilenameUtils#getFullPath(String)} * to compare each object's value. In short, the final file name in the value's path * need not be equal, but the rest of the path in the value must be equal. * * @param second * @return */ protected boolean willAggregateWith(Css first, Css second) { Validate.notNull(first, "Css argument cannot be null"); Validate.notNull(second, "Css argument cannot be null"); // never can aggregate absolute Css values if (this.resourcesDao.isAbsolute(first) || this.resourcesDao.isAbsolute(second)) { return false; } final String firstFullPath = FilenameUtils.getFullPath(first.getValue()); final String secondFullPath = FilenameUtils.getFullPath(second.getValue()); return new EqualsBuilder().append(first.getConditional(), second.getConditional()) .append(first.getMedia(), second.getMedia()).append(firstFullPath, secondFullPath).isEquals(); }