Example usage for org.apache.commons.io FilenameUtils getFullPath

List of usage examples for org.apache.commons.io FilenameUtils getFullPath

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getFullPath.

Prototype

public static String getFullPath(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path.

Usage

From source file:org.saiku.adhoc.providers.impl.standalone.StandalonePrptProvider.java

public void load() {
    datasources.clear();/* w  ww  .  j  a  v  a 2s  .  co m*/
    try {
        if (repoURL != null) {
            File[] files = new File(repoURL.getFile()).listFiles();

            for (File file : files) {
                if (!file.isHidden()) {
                    if (getFileExtension(file.getAbsolutePath()) != null
                            && getFileExtension(file.getAbsolutePath()).equalsIgnoreCase("prpt")) {
                        //                        Properties props = new Properties();
                        //                        props.load(new FileInputStream(file));
                        //                        String name = props.getProperty("name");
                        //                        String type = props.getProperty("type");
                        //                        if (name != null && type != null) {
                        //                            Type t = ReportTemplate.Type.valueOf(type.toUpperCase());
                        ReportTemplate ds = new ReportTemplateStandalone(null,
                                FilenameUtils.getFullPath(file.getPath()),
                                FilenameUtils.removeExtension(file.getName()));
                        datasources.put(FilenameUtils.removeExtension(file.getName()), ds);
                        //}
                    }
                }
            }
        } else {
            throw new Exception("repo URL is null");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:org.smart.migrate.setting.MigratePlanIO.java

/**
 * Get Plan Root in which all plans stored
 * ?//from   w  w w  .j  a v  a  2 s.  c  om
 * @return
 */
public static String getPlanRoot() {
    String rootFile = MigratePlanIO.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    System.out.println(rootFile);
    //        String path = MigratePlanSerializer.class.getResource("/").getPath();
    String root = FilenameUtils.getFullPath(rootFile) + "plans";
    File file = new File(root);
    if (!file.exists()) {
        file.mkdir();
    }
    return root;
}

From source file:org.soaplab.clients.InputUtils.java

static byte[][] list2Files(String value) throws IOException {

    ArrayList<byte[]> result = new ArrayList<byte[]>();
    File listFile = new File(value);
    String fullPath = FilenameUtils.getFullPath(listFile.getAbsolutePath());
    LineIterator it = FileUtils.lineIterator(listFile);
    try {//from   ww w .j  a va 2s. c  o m
        while (it.hasNext()) {
            String line = it.nextLine().trim();
            if (StringUtils.isEmpty(line))
                continue; // ignore blank lines
            if (line.startsWith("#"))
                continue; // ignore comments
            File aFile = new File(line);
            try {
                result.add(FileUtils.readFileToByteArray(aFile));
            } catch (IOException e) {
                // try to add path of the list file
                if (aFile.isAbsolute()) {
                    throw new IOException("Error when reading [" + line + "]: " + e.getMessage());
                } else {
                    File bFile = new File(fullPath, line);
                    result.add(FileUtils.readFileToByteArray(bFile));
                }
            }
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
    return result.toArray(new byte[][] {});
}

From source file:org.staticioc.SpringConfigParser.java

/**
 * Load a single configuration file with or without resolving Beans 
 * @param entryFile to load//from w ww  . jav  a2 s .c o m
 * @param loadedContext Set to track all loaded context to avoid infinite looping should configuration files be incorrects
 * @param resolveBean
 * @return a Map<Bean's Id, Bean>  containing all loaded Beans, resolved or not depending on resolveBean parameter value
 * @throws SAXException
 * @throws IOException
 */
private Map<String, Bean> load(String entryFile, Set<String> loadedContext, boolean resolveBean)
        throws SAXException, IOException {
    // Start by keeping track of loaded file (after normalizing its name)
    final String fullPath = FilenameUtils.getFullPath(entryFile);
    final String configurationFile = FilenameUtils.concat(fullPath, FilenameUtils.getName(entryFile));
    loadedContext.add(configurationFile);

    final Document confFileDom = db.parse(configurationFile);

    try {
        logger.debug("Starting loading of {}", configurationFile);

        // Extract namespaces and load matching namespace plugins
        final NodeList beansRoot = (NodeList) xBeanRoot.evaluate(confFileDom, XPathConstants.NODESET);

        Map<String, String> namespaces = ParserHelper.extractNamespacePrefix(beansRoot);
        logger.debug("XML namespaces prefix mapping: {}", namespaces);

        for (NamespaceParser namespaceParser : namespaceParsers) {
            if (namespaces.containsKey(namespaceParser.getNameSpaceUri())) {
                prefix = namespaces.get(namespaceParser.getNameSpaceUri());
                namespaceParser.setPrefix(prefix);
                logger.debug("Namespace {}. Adding {} node parser plugins", namespaceParser.getNameSpaceUri(),
                        namespaceParser.getNodeParserPlugins().size());

                nodeParserPlugins.addAll(namespaceParser.getNodeParserPlugins());

                for (NodeSupportPlugin plugin : namespaceParser.getNodeSupportPlugins()) {
                    final String supportedNode = plugin.getSupportedNode();
                    logger.debug("Namespace {}. Adding node support plugin for {} nodes",
                            namespaceParser.getNameSpaceUri(), supportedNode);

                    nodesSupportPlugins.put(supportedNode, plugin);
                }
            }
        }

        // Now start loading imports and beans

        final NodeList importsRef = (NodeList) xImports.evaluate(confFileDom, XPathConstants.NODESET);
        final NodeList beansRef = (NodeList) xBeans.evaluate(confFileDom, XPathConstants.NODESET);

        // Start by recursively resolve all imports
        resolveImports(importsRef, loadedContext, fullPath);

        // the parse bean definition 
        handleNodes(beansRef);

        // resolve parent definition that couldn't be resolved in the first pass.
        if (resolveBean) {
            beanContainer.resolveParentDefinition();
        }

        // Finally resolve alias references
        beanContainer.resolveReferences();
    } catch (XPathExpressionException e) {
        logger.error("Error parsing file " + configurationFile, e);
    } catch (ParserConfigurationException e) {
        logger.error("Unexpected error loading " + configurationFile, e);
    }

    if (logger.isDebugEnabled()) {
        for (String beanName : beanContainer.getBeans().keySet()) {
            logger.debug("Registered bean {}", beanName);
        }
    }

    return beanContainer.getBeans();
}

From source file:org.sventon.service.javahl.JavaHLRepositoryService.java

@Override
public DirEntry getEntryInfo(SVNConnection connection, final String path, long revision)
        throws SventonException {
    final JavaHLConnection conn = (JavaHLConnection) connection;
    final SVNClientInterface client = conn.getDelegate();
    final String encodedPath = encodeUri(path);

    final List<DirEntry> dirEntries = new ArrayList<DirEntry>();
    try {//  w w  w  .j a va  2s .c  o  m
        client.info2(conn.getRepositoryRootUrl().getFullPath(encodedPath),
                org.tigris.subversion.javahl.Revision.getInstance(revision),
                org.tigris.subversion.javahl.Revision.getInstance(revision), Depth.empty, null,
                new InfoCallback() {
                    @Override
                    public void singleInfo(Info2 info2) {
                        final String name = info2.getPath();
                        final String author = info2.getLastChangedAuthor();
                        final long lastChangedRev = info2.getLastChangedRev();
                        final Date date = info2.getLastChangedDate();
                        dirEntries.add(new DirEntry(FilenameUtils.getFullPath(path), name, author, date,
                                JavaHLConverter.convertNodeKind(info2.getKind()), lastChangedRev,
                                info2.getReposSize()));
                    }
                });
        return dirEntries.get(0);
    } catch (ClientException ce) {
        return translateException("Cannot get info for [" + encodedPath + "@" + revision + "]", ce);
    }
}

From source file:org.sventon.service.RepositoryServiceImpl.java

/**
 * {@inheritDoc}//from  w ww.  j  ava2s . c o  m
 */
public final RepositoryEntry getEntryInfo(final SVNRepository repository, final String path,
        final long revision) throws SVNException {

    final SVNDirEntry dirEntry = repository.info(path, revision);
    if (dirEntry != null) {
        return new RepositoryEntry(dirEntry, FilenameUtils.getFullPath(path));
    } else {
        logger.warn("Entry [" + path + "] does not exist in revision [" + revision + "]");
        throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND));
    }
}

From source file:org.sventon.service.svnkit.SVNKitRepositoryService.java

@Override
public final DirEntry getEntryInfo(final SVNConnection connection, final String path, final long revision)
        throws SventonException {

    final SVNDirEntry dirEntry;
    try {//ww  w  .  jav  a  2  s  .  c  o  m
        final SVNRepository repository = ((SVNKitConnection) connection).getDelegate();
        dirEntry = repository.info(path, revision);
    } catch (SVNException ex) {
        return translateException("Cannot get info for [" + path + "@" + revision + "]", ex);
    }

    if (dirEntry != null) {
        return SVNKitConverter.createDirEntry(dirEntry, FilenameUtils.getFullPath(path));
    } else {
        logger.warn("Entry [" + path + "] does not exist in revision [" + revision + "]");
        throw new DirEntryNotFoundException(path + "@" + revision);
    }
}

From source file:org.sventon.web.command.BaseCommand.java

/**
 * Get path, excluding the leaf. For complete path including target,see
 * {@link BaseCommand#getPath()}./*from  ww  w .  j av  a  2  s  . c  om*/
 * <p/>
 * The returned string will have a final "/". If the path info is empty, ""
 * (empty string) will be returned.
 *
 * @return Path excluding target (end/leaf)
 */
public String getPathPart() {
    return FilenameUtils.getFullPath(getPath());
}

From source file:pt.webdetails.cdf.dd.api.EditorApi.java

@PUT
@Path("/file/write")
@Consumes({ APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED })
@Produces(TEXT_PLAIN)/*from   w w  w.j a  v  a2  s  . c  o m*/
public String createFile(@FormParam(MethodParams.PATH) @DefaultValue("") String path,
        @FormParam(MethodParams.DATA) @DefaultValue("") String data, @Context HttpServletResponse response)
        throws IOException {

    IResourceLoader loader = getResourceLoader(path);
    IACAccess access = loader.getAccessControl();
    IRWAccess writer = loader.getWriter();

    String msg;
    if (access.hasAccess(FilenameUtils.getFullPath(path), FileAccess.WRITE)) {
        if (writer.saveFile(path, new ByteArrayInputStream(data.getBytes(CharsetHelper.getEncoding())))) {
            msg = "file '" + path + "' saved ok";
            logger.debug(msg);
        } else {
            msg = "error saving file " + path;
            logger.error(msg);
        }
    } else {
        msg = "no permissions to write file " + path;
        logger.error(msg);
    }
    return msg;
}

From source file:pt.webdetails.cdf.dd.model.inst.writer.cggrunjs.CggRunJsGenericComponentWriter.java

public void write(IUserContentAccess access, CggRunJsDashboardWriteContext context, GenericComponent comp)
        throws ThingWriteException {
    if (!this.canWrite()) {
        return;//from ww w.j a v  a2 s.  c om
    }

    String dashboardFilePath = context.getDashboard().getSourcePath();
    String dashboardFileDir = FilenameUtils.getFullPath(dashboardFilePath);
    String dashboardFileName = FilenameUtils.getName(dashboardFilePath);

    StringBuilder out = new StringBuilder();

    out.append("lib('cdf-env.js');").append(NEWLINE).append(NEWLINE);

    this.renderChart(out, context, comp, dashboardFileDir);
    out.append(NEWLINE);

    this.renderDatasource(out, context, comp);
    out.append(NEWLINE).append(NEWLINE);

    String chartName = comp.getName();
    String compVarName = "render_" + chartName;

    out.append("cgg.render(").append(compVarName).append(");").append(NEWLINE);

    String chartScript = out.toString();

    writeFile(access, chartScript, dashboardFileDir, chartName, dashboardFileName);
    // Legacy support requires to keep generating dashboard unqualified scripts as well
    writeFile(access, chartScript, dashboardFileDir, chartName, null);
}