plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WgzImporter.java
changeset 481 e908ec135fa1
equal deleted inserted replaced
480:b6d992b9b998 481:e908ec135fa1
       
     1 /**
       
     2  * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Symbian Foundation - initial contribution.
       
    11  * Contributors:
       
    12  * Description:
       
    13  * Overview:
       
    14  * Details:
       
    15  * Platforms/Drives/Compatibility:
       
    16  * Assumptions/Requirement/Pre-requisites:
       
    17  * Failures and causes:
       
    18  */
       
    19 package org.symbian.tools.wrttools.core.project;
       
    20 
       
    21 import java.io.File;
       
    22 import java.io.FileInputStream;
       
    23 import java.io.IOException;
       
    24 import java.util.Map;
       
    25 import java.util.TreeMap;
       
    26 import java.util.zip.ZipEntry;
       
    27 import java.util.zip.ZipInputStream;
       
    28 
       
    29 import org.eclipse.core.resources.IFile;
       
    30 import org.eclipse.core.resources.IProject;
       
    31 import org.eclipse.core.runtime.CoreException;
       
    32 import org.eclipse.core.runtime.IPath;
       
    33 import org.eclipse.core.runtime.Path;
       
    34 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
       
    35 import org.symbian.tools.tmw.core.TMWCore;
       
    36 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime;
       
    37 import org.symbian.tools.tmw.ui.project.AbstractZippedApplicationImporter;
       
    38 import org.symbian.tools.wrttools.Activator;
       
    39 import org.symbian.tools.wrttools.WRTProject;
       
    40 import org.symbian.tools.wrttools.util.CoreUtil;
       
    41 
       
    42 public class WgzImporter extends AbstractZippedApplicationImporter {
       
    43 
       
    44     public IMobileWebRuntime getApplicationRuntime(File file) {
       
    45         if (file.isFile()) {
       
    46             ZipInputStream stream = null;
       
    47             try {
       
    48                 stream = new ZipInputStream(new FileInputStream(file));
       
    49                 ZipEntry entry = null;
       
    50                 while ((entry = stream.getNextEntry()) != null) {
       
    51                     if (!entry.isDirectory()) {
       
    52                         IPath path = new Path(entry.getName());
       
    53                         if (path.segmentCount() == 2 && "Info.plist".equalsIgnoreCase(path.lastSegment())) {
       
    54                             return TMWCore.getRuntimesManager().getRuntime(WRTProject.WRT11_RUNTIME,
       
    55                                     WRTProject.WRT11_VERSION);
       
    56                         }
       
    57                     }
       
    58                 }
       
    59             } catch (IOException e) {
       
    60                 Activator.log(e);
       
    61             } finally {
       
    62                 if (stream != null) {
       
    63                     try {
       
    64                         stream.close();
       
    65                     } catch (IOException e) {
       
    66                         Activator.log(e);
       
    67                     }
       
    68                 }
       
    69             }
       
    70         }
       
    71         return null;
       
    72     }
       
    73 
       
    74     public Map<String, String> getFileFilters() {
       
    75         Map<String, String> filters = new TreeMap<String, String>();
       
    76         filters.put("*.wgz", "WRT Application Archive (*.wgz)");
       
    77         filters.put("*.zip", "Zip Archive (*.zip)");
       
    78         return filters;
       
    79     }
       
    80 
       
    81     public IFile[] getFilesToOpen(IProject project) {
       
    82         try {
       
    83             return new IFile[] { CoreUtil.getIndexFile(project) };
       
    84         } catch (CoreException e) {
       
    85             Activator.log(e);
       
    86             return null;
       
    87         }
       
    88     }
       
    89 
       
    90     public IProjectFacetVersion[] getConfiguredFacets(File file) {
       
    91         return null;
       
    92     }
       
    93 
       
    94     @Override
       
    95     protected IPath getApplicationRelativePath(ZipEntry entry) {
       
    96         return new Path(entry.getName()).removeFirstSegments(1);
       
    97     }
       
    98 }