Example usage for org.apache.commons.vfs FileObject getName

List of usage examples for org.apache.commons.vfs FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getName.

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:com.panet.imeta.trans.step.errorhandling.AbstractFileErrorHandler.java

public void handleFile(FileObject file) throws KettleException {
    close();//from ww w . j  a v a2 s.  c om
    this.processingFilename = file.getName().getBaseName();
}

From source file:com.sonatype.nexus.plugin.groovyconsole.DefaultScriptStorage.java

private void updateScript(FileObject file) {
    FileName name = file.getName();
    getLogger().info("New script file found: " + name);

    String script;//from  w ww  .  j  a v a 2  s  .  c o  m
    try {
        FileContent content = file.getContent();
        script = IOUtils.toString(content.getInputStream());
        content.close();
    } catch (IOException e) {
        getLogger().warn("Unable to read script file: " + name, e);
        return;
    }

    synchronized (scripts) {
        scripts.put(getName(name), script);
    }
}

From source file:com.pongasoft.kiwidoc.builder.DirectoryContentHandler.java

/**
 * Loads the content of the given resource.
 *
 * @param resource the resource to load/*from  w  w w . ja va 2 s. c  o m*/
 * @return the content as an object since it depends on which content is being read (ex: manifest,
 *         library, packages, class) (never <code>null</code>)
 * @throws NoSuchContentException if the content does not exist
 * @throws StoreException         if there is a problem reading the content.
 */
public M loadContent(R resource) throws NoSuchContentException, StoreException {
    if (resource == null)
        throw new NoSuchContentException(resource);

    Collection<String> childResources = new ArrayList<String>();

    FileObject root = getResourceFile(resource);

    try {
        if (!root.exists())
            throw new NoSuchContentException(resource);

        if (root.getType() == FileType.FOLDER) {
            FileObject[] children = root.getChildren();
            for (FileObject child : children) {
                if (child.getType() == FileType.FOLDER) {
                    childResources.add(child.getName().getBaseName());
                }
            }
        }
    } catch (FileSystemException e) {
        throw new StoreException(e);
    }

    return _modelFactory.buildModel(resource, childResources);
}

From source file:com.panet.imeta.core.playlist.FilePlayListReplay.java

private void initializeCurrent(FileObject file, String filePart) throws KettleException {
    try {//from   ww w  . j  a  v a 2s. c om
        FileObject lineFile = AbstractFileErrorHandler.getReplayFilename(lineNumberDirectory,
                file.getName().getBaseName(), replayDate, lineNumberExtension, filePart);
        if (lineFile.exists())
            currentLineNumberFile = new FilePlayListReplayLineNumberFile(lineFile, encoding, file, filePart);
        else
            currentLineNumberFile = new FilePlayListReplayFile(file, filePart);

        FileObject errorFile = AbstractFileErrorHandler.getReplayFilename(errorDirectory,
                file.getName().getURI(), replayDate, errorExtension, AbstractFileErrorHandler.NO_PARTS);
        if (errorFile.exists())
            currentErrorFile = new FilePlayListReplayErrorFile(errorFile, file);
        else
            currentErrorFile = new FilePlayListReplayFile(file, AbstractFileErrorHandler.NO_PARTS);
    } catch (IOException e) {
        throw new KettleException(e);
    }
}

From source file:cc.aileron.dao.db.sql.G2DaoSqlMapImpl.java

@Override
public void compile(final Class<?> targetClass)
        throws IOException, ResourceNotFoundException, TemplateSyntaxEexception, ParserMethodNotFoundException {
    final String sqlDir = getDir(targetClass);
    if (StringUtils.isEmpty(sqlDir)) {
        return;/*from  w  ww  . j  a  va  2s.co  m*/
    }

    logger.trace("compile : {} @ {}", targetClass, sqlDir);

    final Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(sqlDir);

    while (urls.hasMoreElements()) {
        final URL url = urls.nextElement();
        final Resource resource = ResourceConvertUtils.convertUrl(url);
        for (final FileObject file : resource.toFileObject().getChildren()) {
            final String name = file.getName().getBaseName().split("\\.")[0];

            logger.trace("load sql-file : {}.sql", name);

            if (!file.getType().equals(FileType.FILE) || !file.getName().getExtension().equals("sql")) {
                continue;
            }

            /*
             * SQL??
             */
            final Template template = compiler.compile(resource(file.getContent()).toString());

            /*
             * findBy -> find ????
             */
            final String key = name.replaceFirst("^findBy", "find").replaceFirst("^countBy", "count")
                    .replaceFirst("^updateBy", "update").replaceFirst("^deleteBy", "delete")
                    .replaceFirst("^executeBy", "execute");

            final HashMap<String, Template> m = sqlMap.get(targetClass);
            m.put(key, template);
            m.put(name, template);
        }
    }
}

From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java

private void assertEntity(FileObject fileObject) throws Exception {
    Key key = KeyFactory.createKey("GaeFileObject", fileObject.getName().getPath());
    assertEntity(datastore.get(key));/*from  w w w  . j a  v a 2  s.c  o  m*/
}

From source file:com.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoRetriever.java

@Override
public MovieInfo getMovieInfo(String filePath) {
    MediaInfo mediaInfo = new MediaInfo();
    String fileToParse = filePath;
    // test if we have iso
    if (filePath.toLowerCase().endsWith("iso")) {
        // open iso and parse the ifo files
        Map<Integer, String> ifoFiles = new TreeMap<>();
        try {/* w  ww  .j  av a2 s .co m*/
            FileSystemManager fsManager = VFS.getManager();
            FileObject fo = fsManager.resolveFile("iso:" + filePath + "!/");
            // create an ifo file selector
            FileSelector ifoFs = new FileFilterSelector(new FileFilter() {

                @Override
                public boolean accept(FileSelectInfo fsi) {
                    return fsi.getFile().getName().getBaseName().toLowerCase().endsWith("ifo");
                }
            });
            FileObject[] files = fo.getChild("VIDEO_TS").findFiles(ifoFs);
            for (FileObject file : files) {
                File tmpFile = new File(
                        System.getProperty("java.io.tmpdir") + File.separator + file.getName().getBaseName());
                System.out.println(file.getName().getBaseName());
                IOUtils.copy(file.getContent().getInputStream(), new FileOutputStream(tmpFile));
                mediaInfo.Open(tmpFile.getAbsolutePath());
                String format = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Format_Profile",
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
                System.out.println("Format profile: " + format);
                // if format is "Program" -> it's a video file
                if (format.equalsIgnoreCase("program")) {
                    String duration = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Duration",
                            MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
                    System.out.println("Duration: " + duration);
                    ifoFiles.put(Integer.valueOf(duration), tmpFile.getName());
                }
                mediaInfo.Close();
            }
            if (!ifoFiles.isEmpty()) {
                if (ifoFiles.size() == 1) {
                    fileToParse = ifoFiles.values().iterator().next();
                } else {
                    // get the last entry -> the bigger one
                    Set<Integer> keys = ifoFiles.keySet();
                    Iterator<Integer> iterator = keys.iterator();
                    for (int i = 0; i < keys.size(); i++) {
                        String fileName = ifoFiles.get(iterator.next());
                        if (i == keys.size() - 1) {
                            fileToParse = fileName;
                        } else {
                            new File(fileName).delete();
                        }
                    }
                }
            }
        } catch (IOException | NumberFormatException ex) {

        }
    }
    // here fileToParse is correct
    mediaInfo.Open(fileToParse);
    System.out.println(mediaInfo.Inform());

    return new MovieInfoImpl(mediaInfo, filePath);
}

From source file:com.thinkberg.moxo.dav.PropFindHandler.java

private Document getMultiStatusRespons(FileObject object, List<String> requestedProperties, URL baseUrl,
        int depth, boolean ignoreValues) throws FileSystemException {
    Document propDoc = DocumentHelper.createDocument();
    propDoc.setXMLEncoding("UTF-8");

    Element multiStatus = propDoc.addElement(TAG_MULTISTATUS, "DAV:");
    FileObject[] children = object.findFiles(new DepthFileSelector(depth));
    for (FileObject child : children) {
        Element responseEl = multiStatus.addElement(TAG_RESPONSE);
        try {//w  ww.ja  v a 2  s. c  om
            URL url = new URL(baseUrl, URLEncoder.encode(child.getName().getPath(), "UTF-8"));
            log("!! " + url);
            responseEl.addElement(TAG_HREF).addText(url.toExternalForm());
        } catch (Exception e) {
            e.printStackTrace();
        }
        DavResource resource = DavResourceFactory.getInstance().getDavResource(child);
        resource.setIgnoreValues(ignoreValues);
        resource.serializeToXml(responseEl, requestedProperties);
    }
    return propDoc;
}

From source file:com.thinkberg.webdav.PropFindHandler.java

/**
 * Create a multistatus response by requesting all properties and writing a response for each
 * the found and the non-found properties
 *
 * @param object  the context object the propfind request applies to
 * @param propEl  the &lt;prop&gt; element containing the actual properties
 * @param baseUrl the base url of this server
 * @param depth   a depth argument for how deep the find will go
 * @return an XML document that is the response
 * @throws FileSystemException if there was an error executing the propfind request
 *//*from   w  w w .  j  a  v  a  2 s  .com*/
private Document getMultiStatusResponse(FileObject object, Element propEl, URL baseUrl, int depth)
        throws FileSystemException {
    Document propDoc = DocumentHelper.createDocument();
    propDoc.setXMLEncoding("UTF-8");

    Element multiStatus = propDoc.addElement(TAG_MULTISTATUS, NAMESPACE_DAV);
    FileObject[] children = object.findFiles(new DepthFileSelector(depth));
    for (FileObject child : children) {
        Element responseEl = multiStatus.addElement(TAG_RESPONSE);
        try {
            URL url = new URL(baseUrl, URLEncoder.encode(child.getName().getPath(), "UTF-8"));
            responseEl.addElement(TAG_HREF).addText(url.toExternalForm());
        } catch (Exception e) {
            LOG.error("can't set href in response", e);
        }
        DavResource resource = DavResourceFactory.getInstance().getDavResource(child);
        resource.getPropertyValues(responseEl, propEl);
    }
    return propDoc;
}

From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java

private FileObject testRootObject() throws Exception {
    FileObject rootObject = GaeVFS.resolveFile("/");
    assertTrue(rootObject.exists());/*from   www . ja va2 s.  com*/
    assertEquals(rootObject.getName().getScheme(), "gae");
    assertFolder(rootObject);
    assertNull(rootObject.getParent());
    assertChildren(rootObject, rootChildren);

    // TODO: test rootObject.getName() and FileName methods

    assertEntity(rootObject);
    return rootObject;
}