Package com.eteks.sweethome3d.tools

Examples of com.eteks.sweethome3d.tools.URLContent


      }
     
      // 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 a obj file 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 + 1);
              if (!entryFileName.startsWith(".")) {
                int dotIndex = entryFileName.lastIndexOf(".");
                if (dotIndex != -1) {
                  modelName = entryFileName.substring(0, dotIndex);
                } else {
                  modelName = entryFileName;
                }
                URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
                    + URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
                modelContent = new TemporaryURLContent(entryUrl);
                model = ModelManager.getInstance().loadModel(modelContent);
                if (!entryFileName.toLowerCase().endsWith(".obj")
                    && (this.preferences.isModelContentAlwaysConvertedToOBJFormat()
View Full Code Here


    } else if (content instanceof URLContent) {
      if (keepURLContentUnchanged) {
        // Won't save content
        return null;
      } else {
        URLContent urlContent = (URLContent)content;
        if (urlContent.isJAREntry()) {
          String file = urlContent.getJAREntryURL().getFile();
          file = file.substring(file.lastIndexOf('/') + 1);
          int zipIndex = file.lastIndexOf(".zip");
          if (zipIndex == -1) {
            return null;
          } else {
            file = file.substring(0, zipIndex);
            entryName = file + "/" + urlContent.getJAREntryName();
          }
        } else {
          String file = urlContent.getURL().getFile();
          entryName = file.substring(file.lastIndexOf('/') + 1);
        }
        existingEntryNames.add(entryName);
        return entryName;
      }
View Full Code Here

   
    Map<String, List<ZipEntry>> zipUrlsEntries = new HashMap<String, List<ZipEntry>>();
    for (Map.Entry<Content, String> contentEntry : contentEntries.entrySet()) {
      Content content = contentEntry.getKey();
      if (content instanceof URLContent) {
        URLContent urlContent = (URLContent)content;
        String entryName = contentEntry.getValue();
        if (entryName.indexOf('/') != -1) {
          writeZipEntries(zipOut, offlineFurnitureLibrary, furnitureResourcesLocalDirectory,
              urlContent, entryName, zipUrlsEntries);
        } else if (offlineFurnitureLibrary || furnitureResourcesLocalDirectory == null) {
View Full Code Here

    if (entries == null) {
      zipUrlsEntries.put(zipUrl.toString(), entries = getZipEntries(zipUrl));
    }
    for (ZipEntry entry : entries) {
      String zipEntryName = entry.getName();
      URLContent siblingContent = new URLContent(new URL("jar:" + zipUrl + "!/" +
          URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
      if (contentDirectory.length() == 0) {
        boolean saveEntry = true;
        for (String ignoredExtension : IGNORED_EXTENSIONS) {
          if (zipEntryName.toLowerCase().endsWith(ignoredExtension)) {
View Full Code Here

      if (modifiableUrl
          && (urlUpdate == null
              || urlUpdate.openConnection().getLastModified() < urlModificationDate)) {
        // Copy updated resource URL content to a temporary file to ensure textures used in home can safely
        // reference any file of the catalog file even if its content is changed afterwards
        TemporaryURLContent contentCopy = TemporaryURLContent.copyToTemporaryURLContent(new URLContent(pluginTexturesCatalogUrl));
        URL temporaryTexturesCatalogUrl = contentCopy.getURL();
        pluginTexturesCatalogUrlUpdates.put(pluginTexturesCatalogFile, temporaryTexturesCatalogUrl);
        pluginTexturesCatalogUrl = temporaryTexturesCatalogUrl;
      } else if (urlUpdate != null) {
        pluginTexturesCatalogUrl = urlUpdate;
View Full Code Here

      if (resourceUrlBase != null) {
        url = new URL(resourceUrlBase, contentFile);
      } else {
        url = new URL(contentFile);
      }
      return new URLContent(url);
    } catch (MalformedURLException ex) {
      if (texturesUrl == null) {
        // Otherwise find if it's a resource
        return new ResourceURLContent(DefaultTexturesCatalog.class, contentFile);
      } else {
        try {
          return new URLContent(new URL("jar:" + texturesUrl + "!" + contentFile));
        } catch (MalformedURLException ex2) {
          throw new IllegalArgumentException("Invalid URL", ex2);
        }
      }
    }
View Full Code Here

* @author Emmanuel Puybaret
*/
public class ModelManagerTest extends TestCase {
  public void testDAELoader() throws IOException {
    BranchGroup model = ModelManager.getInstance().loadModel(
        new URLContent(ModelManagerTest.class.getResource("resources/test.dae")));
    assertTrue("Model shouldn't be empty", getShapesCount(model) > 0);
  }
View Full Code Here

    assertTrue("Model shouldn't be empty", getShapesCount(model) > 0);
  }

  public void testOBJLoader() throws IOException {
    BranchGroup model = ModelManager.getInstance().loadModel(
        new URLContent(ModelManagerTest.class.getResource("resources/test.obj")));
    assertTrue("Model shouldn't be empty", getShapesCount(model) > 0);
  }
View Full Code Here

    // Create a dummy content manager
    final ContentManager contentManager = new ContentManager() {
      public Content getContent(String contentName) throws RecorderException {
        try {
          // Let's consider contentName is a URL
          return new URLContent(new URL(contentName));
        } catch (IOException ex) {
          fail();
          return null;
        }
      }
View Full Code Here

    final URL testedImageName = BackgroundImageWizardTest.class.getResource("resources/test.png");
    final ContentManager contentManager = new ContentManager() {
      public Content getContent(String contentName) throws RecorderException {
        try {
          // Let's consider contentName is a URL
          return new URLContent(new URL(contentName));
        } catch (IOException ex) {
          fail();
          return null;
        }
      }
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.