Package com.eteks.sweethome3d.tools

Examples of com.eteks.sweethome3d.tools.URLContent


      String entryNameOrDirectory = String.valueOf(i);
      if (content instanceof ResourceURLContent) {
        writeResourceZipEntries(zipOut, entryNameOrDirectory, (ResourceURLContent)content);
      } else if (content instanceof URLContent
                 && ((URLContent)content).isJAREntry()) {
        URLContent urlContent = (URLContent)content;
        // If content comes from a home stream
        if (urlContent instanceof HomeURLContent) {
          writeHomeZipEntries(zipOut, entryNameOrDirectory, (HomeURLContent)urlContent);           
        } else {
          writeZipEntries(zipOut, entryNameOrDirectory, urlContent);
View Full Code Here


        int lastSlashIndex = entryName.lastIndexOf('/');
        String entryDirectory = entryName.substring(0, lastSlashIndex + 1);
        // Write in home stream each zipped stream entry that is stored in the same directory 
        for (String zipEntryName : getZipUrlEntries(zipUrl)) {
          if (zipEntryName.startsWith(entryDirectory)) {
            Content siblingContent = new URLContent(new URL("jar:" + zipUrl + "!/"
                + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
            writeZipEntry(zipOut, entryNameOrDirectory + zipEntryName.substring(lastSlashIndex), siblingContent);
          }
        }
      } else {
        // This should be the case only when resource isn't in a JAR file during development
        File contentFile = new File(urlContent.getURL().getFile());
        File parentFile = new File(contentFile.getParent());
        File [] siblingFiles = parentFile.listFiles();
        // Write in home stream each file that is stored in the same directory 
        for (File siblingFile : siblingFiles) {
          if (!siblingFile.isDirectory()) {
            writeZipEntry(zipOut, entryNameOrDirectory + "/" + siblingFile.getName(),
                new URLContent(siblingFile.toURI().toURL()));
          }
        }
      }
    } else {
      writeZipEntry(zipOut, entryNameOrDirectory, urlContent);
View Full Code Here

      URL zipUrl = urlContent.getJAREntryURL();
      String entryDirectory = entryName.substring(0, slashIndex + 1);
      // Write in home stream each zipped stream entry that is stored in the same directory 
      for (String zipEntryName : getZipUrlEntries(zipUrl)) {
        if (zipEntryName.startsWith(entryDirectory)) {
          Content siblingContent = new URLContent(new URL("jar:" + zipUrl + "!/"
              + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
          writeZipEntry(zipOut, entryNameOrDirectory + zipEntryName.substring(slashIndex), siblingContent);
        }
      }
    } else {
View Full Code Here

      // Open zipped stream that contains urlContent
      zipIn = new ZipInputStream(urlContent.getJAREntryURL().openStream());
      // Write each zipped stream entry in home stream
      for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
        String zipEntryName = entry.getName();
        Content siblingContent = new URLContent(new URL("jar:" + urlContent.getJAREntryURL() + "!/"
            + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
        writeZipEntry(zipOut, directory + "/" + zipEntryName, siblingContent);
      }
    } finally {
      if (zipIn != null) {
View Full Code Here

        // Add obj to Content objects list
        contents.add((Content)obj);

        String subEntryName = "";
        if (obj instanceof URLContent) {
          URLContent urlContent = (URLContent)obj;
          // If content comes from a zipped content 
          if (urlContent.isJAREntry()) {
            String entryName = urlContent.getJAREntryName();
            if (urlContent instanceof HomeURLContent) {
              int slashIndex = entryName.indexOf('/');
              // If content comes from a directory of a home file
              if (slashIndex > 0) {
                // Retrieve entry name in zipped stream without the directory
                subEntryName = entryName.substring(slashIndex);
              }
            } else if (urlContent instanceof ResourceURLContent) {
              ResourceURLContent resourceUrlContent = (ResourceURLContent)urlContent;
              if (resourceUrlContent.isMultiPartResource()) {
                // If content is a resource coming from a JAR file, retrieve its file name
                subEntryName = entryName.substring(entryName.lastIndexOf('/'));
              }
            } else {
              // Retrieve entry name in zipped stream
              subEntryName = "/" + entryName;
            }           
          } else if (urlContent instanceof ResourceURLContent) {
            ResourceURLContent resourceUrlContent = (ResourceURLContent)urlContent;
            // If content is a resource coming from a directory (this should be the case
            // only when resource isn't in a JAR file during development), retrieve its file name
            if (resourceUrlContent.isMultiPartResource()) {
              subEntryName = "/" + new File(resourceUrlContent.getURL().getFile()).getName();
            }
          }
        }

        // Return a temporary URL that points to content object
        return new URLContent(new URL("jar:file:temp!/" + (contents.size() - 1) + subEntryName));
      } else {
        return obj;
      }
    }
View Full Code Here

            }
           
            // If content couldn't be loaded, try to load model as a zipped file
            ZipInputStream zipIn = null;
            try {
              URLContent urlContent = (URLContent)modelContent;
              // Open zipped stream
              zipIn = new ZipInputStream(urlContent.openStream());
              // Parse entries to see if one is readable
              for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
                try {
                  String entryName = entry.getName();
                  // Ignore directory entries and entries starting by a dot
                  if (!entryName.endsWith("/")) {
                    int slashIndex = entryName.lastIndexOf('/');
                    String entryFileName = entryName.substring(++slashIndex);
                    if (!entryFileName.startsWith(".")) {
                      URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
                          + URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
                      modelContent = new TemporaryURLContent(entryUrl);
                      model = readModel(modelContent);
                      modelSize = ModelManager.getInstance().getSize(model);
                      break;
View Full Code Here

  public Content getIcon() {
    try {
      return this.iconPreviewComponent.getIcon(400);
    } catch (IOException ex) {
      try {
        return new URLContent(new URL("file:/dummySweetHome3DContent"));
      } catch (MalformedURLException ex1) {
        return null;
      }
    }
  }
View Full Code Here

   * Returns a {@link URLContent URL content} object that references
   * the given file path.
   */
  public Content getContent(String contentName) throws RecorderException {
    try {
      return new URLContent(new File(contentName).toURI().toURL());
    } catch (IOException ex) {
      throw new RecorderException("Couldn't access to content " + contentName);
    }
  }
View Full Code Here

        // Ignore write requests
      }
    };

    Home home = new Home();
    Content imageContent = new URLContent(UserPreferencesPanelTest.class.getResource("resources/test.png"));
    home.setBackgroundImage(new BackgroundImage(imageContent, 1, 0, 1, 0, 1, 0, 0));

    SwingViewFactory viewFactory = new SwingViewFactory();
    FileContentManager contentManager = new FileContentManager(preferences);
    UndoableEditSupport undoableEditSupport = new UndoableEditSupport();
View Full Code Here

    testIconLoading(getClass().getResource("resources/test.png"), true, iconLoadingStartBarrier);
    // Test icon loading on a content that doesn't an image
    testIconLoading(getClass().getResource("IconManagerTest.class"), false, iconLoadingStartBarrier);

    Class iconProxyClass = Class.forName(iconManager.getClass().getName() + "$IconProxy");
    URLContent waitIconContent =
        (URLContent)TestUtilities.getField(iconManager, "waitIconContent");
    URLContent errorIconContent =
        (URLContent)TestUtilities.getField(iconManager, "errorIconContent");

    // Check waitIcon is loaded directly without proxy
    Icon waitIcon = iconManager.getIcon(waitIconContent, HEIGHT, null);
    assertNotSame("Wait icon loaded with IconProxy", waitIcon.getClass(), iconProxyClass);
View Full Code Here

TOP

Related Classes of com.eteks.sweethome3d.tools.URLContent

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.