Package org.apache.commons.vfs

Examples of org.apache.commons.vfs.FileObject


            String fullPath = fo.getURL().toString();
            int pos = fullPath.indexOf("?");
            if (pos != -1) {
                fullPath = fullPath.substring(0, pos);
            }
            FileObject lockObject = fsManager.resolveFile(fullPath + ".lock");
            if (lockObject.exists()) {
                log.debug("There seems to be an external lock, aborting the processing of the file "
                        + fo.getName() + ". This could possibly be due to some other party already "
                        + "processing this file or the file is still being uploaded");
            } else {

                // write a lock file before starting of the processing, to ensure that the
                // item is not processed by any other parties
                lockObject.createFile();
                OutputStream stream = lockObject.getContent().getOutputStream();
                try {
                    stream.write(lockValue);
                    stream.flush();
                    stream.close();
                } catch (IOException e) {
                    lockObject.delete();
                    log.error("Couldn't create the lock file before processing the file "
                            + fullPath, e);
                    return false;
                } finally {
                    lockObject.close();
                }

                // check whether the lock is in place and is it me who holds the lock. This is
                // required because it is possible to write the lock file simultaneously by
                // two processing parties. It checks whether the lock file content is the same
                // as the written random lock value.
                // NOTE: this may not be optimal but is sub optimal
                FileObject verifyingLockObject = fsManager.resolveFile(
                        fullPath + ".lock");
                if (verifyingLockObject.exists() && verifyLock(lockValue, verifyingLockObject)) {
                    return true;
                }
            }
        } catch (FileSystemException fse) {
            log.error("Cannot get the lock for the file : " + maskURLPassword(fo.getName().getURI())
View Full Code Here


     * @param fsManager which is used to resolve the processed file
     * @param fo representing the processed file
     */
    public static void releaseLock(FileSystemManager fsManager, FileObject fo) {
        try {
            FileObject lockObject = fsManager.resolveFile(fo.getURL().toString() + ".lock");
            if (lockObject.exists()) {
                lockObject.delete();
            }
        } catch (FileSystemException e) {
            log.error("Couldn't release the lock for the file : "
                    + fo.getName() + " after processing");
        }
View Full Code Here

    _work = VFS.getManager().resolveFile(workDir.getAbsolutePath());
    _workDir = workDir;
  }
 
  public File getResourceAsFile(String path) throws IOException {
    FileObject unpackedResource = _work.resolveFile(path);
    if (!unpackedResource.exists()) {
      FileObject sourceFile = _source.resolveFile(path);
      sourceFile.copyFrom(unpackedResource, new FileSelector() {

        public boolean includeFile(FileSelectInfo arg0) throws Exception {
          return true;
        }
View Full Code Here

    }
    return new File(_workDir, path);
  }
 
  public void copy(String sourcePath, File targetDir) throws IOException {
    FileObject target = VFS.getManager().resolveFile(targetDir.getAbsolutePath());
    FileObject source = _source.resolveFile(sourcePath);
    if (source.exists()) {
      target.copyFrom(source, new FileSelector() {

        public boolean includeFile(FileSelectInfo arg0) throws Exception {
          return true;
        }
View Full Code Here

    if (_properties == null) {
      TemporaryFile tempFile = null;
      try {       
        tempFile = new TemporaryFile("template_" + _name, getContent(), WGADesignerPlugin.getDefault().getStateLocation().toFile());
        FileSystemManager fsManager = VFS.getManager();
        FileObject propFile = fsManager.resolveFile("zip:" + tempFile.getFile().toURI() + "!" + PROPERTIES_FILENAME);
        if (propFile.exists()) {
          _properties = new Properties();
          InputStream propIn = null;
          try {
            propIn = propFile.getContent().getInputStream();
            _properties.load(propIn);
          } finally {
            if (propIn != null) {
              try {
                propIn.close();
View Full Code Here

  public void createOrUpdateDefaultDeployment(File defaultWGAWar, IProgressMonitor monitor) throws FileSystemException, IOException, ZipException {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    FileSystemManager fsManager = VFS.getManager();
    FileObject propFile = fsManager.resolveFile( "zip:" + defaultWGAWar.toURI() + "!/WEB-INF/wgabuild.properties");
    //_defaultDeploymentName = DEFAULT_DEPLOYMENT_PREFIX + WGADeployment.determineWGAVersion(propFile.getURL().openStream(), "_", true, false);
       
    // init default wga installation
    // check if we already have a deployment with same major, minor version
    WGADeployment existingDefaultDeployment = getDeployment(DEFAULT_DEPLOYMENT_NAME);
    if (existingDefaultDeployment != null) {
      InputStream propIn = null;
      try {
        propIn = propFile.getURL().openStream();
        Version newDefaultDeploymentVersion = WGADeployment.determineWGAVersion(propIn);
        Version existingDefaultDeploymentVersion = existingDefaultDeployment.getWGAVersion();
        if (!newDefaultDeploymentVersion.equals(existingDefaultDeploymentVersion)) {
          // we have to update the default deployment
          createDeployment(DEFAULT_DEPLOYMENT_NAME, defaultWGAWar, monitor, true);
View Full Code Here

  public static boolean isWGAVersionSupported(File wgaWar) {
    InputStream propIn = null;
    try {
      FileSystemManager fsManager = VFS.getManager();
      FileObject propFile = fsManager.resolveFile( "zip:" + wgaWar.toURI() + "!/WEB-INF/wgabuild.properties");
      propIn = propFile.getURL().openStream();
      Version version = WGADeployment.determineWGAVersion(propIn);
      if (version != null) {
        if (version.isAtLeast(Activator.SUPPORTED_WGA_VERSION_MIN.getMajor(),  Activator.SUPPORTED_WGA_VERSION_MIN.getMinor())) {
          if (version.getMajorVersion() < Activator.SUPPORTED_WGA_VERSION_MAX.getMajor()) {
            return true;
View Full Code Here

                new Object[]{
                    name, rootName, name.getRootURI()});
        }

        // imario@apache.org ==> use getFileFromCache
        FileObject file;
        if (useCache)
        {
            file = getFileFromCache(name);
        }
        else
View Full Code Here

     */
    private void fireEvent(final AbstractFileChangeEvent event)
    {
        synchronized (listenerMap)
        {
            final FileObject file = event.getFile();
            final ArrayList listeners = (ArrayList) listenerMap.get(file.getName());
            if (listeners != null)
            {
                final int count = listeners.size();
                for (int i = 0; i < count; i++)
                {
View Full Code Here

     * Creates an output stream to write the file content to.
     */
    protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
    {
        int fileCount;
        FileObject webdavTmp;
        synchronized (tmpFileCountSync)
            {
                tmpFileCount++;
                fileCount = tmpFileCount;
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs.FileObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.