Package org.jboss.virtual.plugins.context

Examples of org.jboss.virtual.plugins.context.DelegatingHandler


            {
               boolean useCopyMode = forceCopy;
               if (useCopyMode == false)
                  useCopyMode = getAggregatedOptions().getBooleanOption(VFSUtils.USE_COPY_QUERY);

               DelegatingHandler delegator;

               if (useCopyMode)
               {
                  File dest = null;
                  String entryName = ent.getName();
                  String path = null;

                  VFSContext context = getPeerContext();
                  if (context != null)
                  {
                     path = getPath(context, entryName);
                     TempInfo ti = context.getTempInfo(path);
                     if (ti != null && ti.isValid())
                     {
                        dest = ti.getTempFile();
                     }
                  }

                  boolean createNewTempInfo = (dest == null || dest.exists() == false);

                  if (createNewTempInfo)
                  {
                     // extract it to temp dir
                     String tempName = getTempFileName(entryName);
                     TempStore store = (context != null) ? context.getTempStore() : null;
                     if (store != null)
                     {
                        File tempDir = store.createTempFolder(zipSource.getName(), ent.getName());
                        if (tempDir != null)
                           dest = new File(tempDir, tempName);
                     }
                     if (dest == null)
                        dest = new File(getTempDir() + "/" + tempName);
                     dest.deleteOnExit();

                     if (trace)
                     {
                        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
                        log.trace("Dest: " + dest + ", Stack-trace:\n" + Arrays.toString(stackTraceElements));
                     }

                     // ensure parent exists
                     dest.getParentFile().mkdirs();

                     InputStream is = zipSource.openStream(new DefaultZipEntryInfo(ent));
                     OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
                     VFSUtils.copyStreamAndClose(is, os);
                  }

                  // mount another instance of ZipEntryContext
                  delegator = mountZipFile(parent, name, dest);

                  if (context != null && path != null && createNewTempInfo)
                     context.addTempInfo(new ZipEntryTempInfo(path, dest, delegator, this));
               }
               else
               {
                  // mount another instance of ZipEntryContext
                  delegator = mountZipStream(parent, name, zipSource.openStream(new DefaultZipEntryInfo(ent)));
               }

               entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
               addChild(parent, delegator);
            }
            else
            {
               ZipEntryHandler wrapper = new ZipEntryHandler(this, parent, name, ent.isDirectory() == false);
View Full Code Here


    * @throws IOException for any error
    * @throws URISyntaxException for any URI syntax error
    */
   protected DelegatingHandler mountZipFile(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
   {
      DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
      URL fileUrl = file.toURI().toURL();
      URL delegatorUrl = fileUrl;

      if (parent != null)
         delegatorUrl = getChildURL(parent, name);

      delegatorUrl = setOptionsToURL(delegatorUrl);
      ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, fileUrl, true);

      VirtualFileHandler handler = ctx.getRoot();
      delegator.setDelegate(handler);

      return delegator;
   }
View Full Code Here

    * @throws IOException for any error
    * @throws URISyntaxException for any URI syntax error
    */
   protected DelegatingHandler mountZipStream(VirtualFileHandler parent, String name, InputStream zipStream) throws IOException, URISyntaxException
   {
      DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
      long lastModified = (parent != null) ? parent.getLastModified() : System.currentTimeMillis();
      ZipStreamWrapper wrapper = new ZipStreamWrapper(zipStream, name, lastModified);

      URL delegatorUrl = null;

      if (parent != null)
         delegatorUrl = getChildURL(parent, name);

      delegatorUrl = setOptionsToURL(delegatorUrl);
      ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, wrapper, false);

      VirtualFileHandler handler = ctx.getRoot();
      delegator.setDelegate(handler);

      return delegator;
   }
View Full Code Here

   {
      ensureEntries();
      ZipEntryContextInfo parentEntry = entries.get(parent.getLocalPathName());
      if (parentEntry != null)
      {
         DelegatingHandler newOne;

         if (replacement instanceof DelegatingHandler)
         {
            newOne = (DelegatingHandler) replacement;
         }
View Full Code Here

      VFSContextFactory factory = VFSContextFactoryLocator.getFactory(linkURI);
      VFSContext context = factory.getVFS(linkURI);
      VirtualFileHandler rootHandler = context.getRoot();
      // Wrap the handler in a delegate so we can change the parent and name
      // TODO: if the factory caches contexts the root handler may not point to the link
      return new DelegatingHandler(this.getVFSContext(), parent, name, rootHandler);
   }
View Full Code Here

    * @throws IOException for any error
    * @throws URISyntaxException for any URI syntax error
    */
   protected DelegatingHandler mountZipFS(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
   {
      DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
      URL fileUrl = file.toURI().toURL();
      URL delegatorUrl = fileUrl;

      if (parent != null)
         delegatorUrl = getChildURL(parent, name);

      delegatorUrl = setOptionsToURL(delegatorUrl);
      ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, fileUrl);

      VirtualFileHandler handler = ctx.getRoot();
      delegator.setDelegate(handler);

      return delegator;
   }
View Full Code Here

      VFSContextFactory factory = VFSContextFactoryLocator.getFactory(linkURI);
      VFSContext context = factory.getVFS(linkURI);
      VirtualFileHandler rootHandler = context.getRoot();
      // Wrap the handler in a delegate so we can change the parent and name
      // TODO: if the factory caches contexts the root handler may not point to the link
      return new DelegatingHandler(this.getVFSContext(), parent, name, rootHandler);
   }
View Full Code Here

    * @throws IOException for any error
    * @throws URISyntaxException for any URI syntax error
    */
   protected DelegatingHandler mountZipFS(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
   {
      DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
      URL fileUrl = file.toURL();
      URL delegatorUrl = fileUrl;

      if (parent != null)
         delegatorUrl = getChildURL(parent, name);

      ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, fileUrl);

      VirtualFileHandler handler = ctx.getRoot();
      delegator.setDelegate(handler);

      return delegator;
   }
View Full Code Here

               {
                  String flag = getOptions().get(VFSUtils.USE_COPY_QUERY);
                  useCopyMode = Boolean.valueOf(flag);
               }

               DelegatingHandler delegator;

               if (useCopyMode)
               {
                  // extract it to temp dir
                  File dest = new File(getTempDir() + "/" + getTempFileName(ent.getName()));
                  dest.deleteOnExit();

                  // ensure parent exists
                  dest.getParentFile().mkdirs();

                  InputStream is = zipSource.openStream(ent);
                  OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
                  copyStreamAndClose(is, os);

                  // mount another instance of ZipEntryContext
                  delegator = mountZipFile(parent, name, dest);
               }
               else
               {
                  // mount another instance of ZipEntryContext
                  delegator = mountZipStream(parent, name, zipSource.openStream(ent));
               }

               entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
               addChild(parent, delegator);
            }
            else
            {
               ZipEntryHandler wrapper = new ZipEntryHandler(this, parent, name, ent.isDirectory() == false);
View Full Code Here

    * @throws IOException for any error
    * @throws URISyntaxException for any URI syntax error
    */
   protected DelegatingHandler mountZipFile(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
   {
      DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
      URL fileUrl = file.toURL();
      URL delegatorUrl = fileUrl;

      if (parent != null)
         delegatorUrl = getChildURL(parent, name);

      ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, fileUrl, true);
      VirtualFileHandler handler = ctx.getRoot();
      delegator.setDelegate(handler);

      return delegator;
   }
View Full Code Here

TOP

Related Classes of org.jboss.virtual.plugins.context.DelegatingHandler

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.