import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Scanner;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.kohsuke.args4j.Option;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.tizen.common.Factory;
import org.tizen.common.core.application.InstallPathConfig;
import org.tizen.common.core.application.ProfileInfo;
public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCommandData>
{
private CreateProjectCommandData data = new CreateProjectCommandData();
-
+
// Freemarker variables
private Map<String, Object> root = new HashMap<String, Object>();
private Configuration cfg;
-
+
private static String temporaryFileAdditionalName = ".template"; //$NON-NLS-1$
private static String optionGroupSeparator = "_"; //$NON-NLS-1$
-
+
TizenAppTemplate tizenAppTemplate;
-
+
+ private ProjectGenUtil pg = new ProjectGenUtil();
+
private TizenTemplateLibrariesPool libraryPool;
-
- /* 1. copy web project template
- * 2. copy the dependent library
- * 3. copy configuration
- * 4. generate HTML and XML file from template
+
+ /*
+ * create web project from template.
+ *
+ * 1. get template list
+ * 2. copy web project template
+ * 3. copy the dependent library
+ * 4. copy configuration
+ * 5. generate HTML and XML file from template
*/
@Override
protected CreateProjectCommandData call()
{
- //1. copy web project template
+ // 1. get template list
+ data.getTemplateList();
+
+ // 2. copy web project template
copyWebProjectTemplate();
-
- //2. copy the dependent library
+
+ // 3. copy the dependent library
copyLibrary();
-
- //3. generate configuration
+
+ // 4. generate configuration
copyConfiguration();
-
- //4. generate file from template
+
+ // 5. generate file from template
processOption();
-
+
return data;
}
{
this.data.setProjectName(projectName);
}
-
- private void copyWebProjectTemplate(){
+
+ public void setOutputName(String projectName)
+ {
+ this.data.setOutputName(projectName);
+ }
+
+ private void copyWebProjectTemplate()
+ {
String projectName = data.getProjectName();
String projectPath = data.getTizenWebProjectRootPath(projectName);
- String destDir = data.getTargetAbsoultePath();
-
+ String destDir = data.getOutputName();
+
// filter file (.project)
- File[] resourceFilter = { new File( ".project" ) };
-
+ File[] resourceFilter = { new File(".project") };
+
// copy template resources
try
{
- FileUtil.copyRecursively( projectPath, destDir, true, resourceFilter );
+ FileUtil.copyRecursively(projectPath, destDir, true, resourceFilter);
} catch (IOException e)
{
// TODO Auto-generated catch block
log.error(e.getMessage());
}
}
-
- private void copyLibrary(){
-
+
+ private void copyLibrary()
+ {
+
String projectName = data.getProjectName();
- String configFile = data.getTizenWebTemplateConfigFile(projectName);
-
+ String configFile = data.getTizenWebTemplateConfigFile(projectName);
+
try
{
// unmarshal app template.
// TODO Auto-generated catch block
log.error(e2.getMessage());
}
-
+
// get options
Options options = tizenAppTemplate.getOptions();
// get support libraries
SupportLibraries sl = options.getSupportLibraries();
-
+
// get profile info
ProfileInfo profileInfo = InstallPathConfig.getLatestProfileInfo();
+
+ // extract jar file contained built-in library
+ String rootPath = pg.extractBuiltinJarFiles();
// get library pool
- libraryPool = new TizenTemplateLibrariesPool(profileInfo);
-
+ libraryPool = new TizenTemplateLibrariesPool(profileInfo, rootPath);
+
// get template library groups
- if (libraryPool != null) { // In case of sample, pool is null
+ if (libraryPool != null)
+ { // In case of sample, pool is null
List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(sl);
-
+
// copy libraries
- for (TizenTemplateLibraryGroup group : groupList) {
+ for (TizenTemplateLibraryGroup group : groupList)
+ {
/*
- if ( isSampleGroup( template ) ) {
- group.setSelectedMinifiedWithDependsUpdate( true );
- }
- */
- if ( group.getSelectedElement().getKindsOfLibrary() == TizenTemplateKindsOfLibraries.TIZENWEBUIFW ) {
- copyTizenWebUIFWLibrary( group );
+ * if ( isSampleGroup( template ) ) {
+ * group.setSelectedMinifiedWithDependsUpdate( true ); }
+ */
+ if (group.getSelectedElement().getKindsOfLibrary() == TizenTemplateKindsOfLibraries.TIZENWEBUIFW)
+ {
+ copyTizenWebUIFWLibrary(group);
}
- else {
- copyNormalLibrary( group);
+ else
+ {
+ copyNormalLibrary(group);
}
}
}
}
-
+
private void copyTizenWebUIFWLibrary(TizenTemplateLibraryGroup group)
{
String libraryPath = group.getSelectedLibraryPath();
- if (libraryPath == null) {
- return ;
+ if (libraryPath == null)
+ {
+ return;
}
// cannot find library directory (source)
File source = new File(libraryPath);
- if ( !source.exists() ) {
- String errorMsg = "Cannot find template library resource : " + libraryPath; // TODO : externalize
+ if (!source.exists())
+ {
+ String errorMsg = "Cannot find template library resource : " + libraryPath; // TODO
+ // :
+ // externalize
}
// create target directory
TizenWebUIFWType type = null;
String elementKey = group.getSelectedElementKey();
- try {
- type = TizenWebUIFWType.valueOf( elementKey );
- } catch (IllegalArgumentException e) {
+ try
+ {
+ type = TizenWebUIFWType.valueOf(elementKey);
+ } catch (IllegalArgumentException e)
+ {
return;
}
URI destinationURI = null;
- switch ( type ) {
+ switch (type) {
case TizenWebUIFramework_Theme:
case TizenWebUIFramework_Theme_Images:
- String themePaths[] = libraryPath.split( "Theme/" );
- // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath() + themePaths[1]);
+ String themePaths[] = libraryPath.split("Theme/");
+ // destinationURI = URI.create(project.getLocationURI() +
+ // type.getDestinationPath() + themePaths[1]);
break;
default:
- // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath());
+ // destinationURI = URI.create(project.getLocationURI() +
+ // type.getDestinationPath());
break;
}
// decide target directory
- if ( type != TizenWebUIFWType.TizenWebUIFramework_Theme ) {
- destinationURI = URI.create( destinationURI + group.getSelectedElementValue() );
+ if (type != TizenWebUIFWType.TizenWebUIFramework_Theme)
+ {
+ destinationURI = URI.create(destinationURI + group.getSelectedElementValue());
}
// copy must pre-create directory
- if ( source.isDirectory() ) {
- if ( !FileUtil.isExist( destinationURI.getPath() ) ) {
- FileUtil.createDirectory( new File(destinationURI) );
+ if (source.isDirectory())
+ {
+ if (!FileUtil.isExist(destinationURI.getPath()))
+ {
+ FileUtil.createDirectory(new File(destinationURI));
}
- } else {
+ }
+ else
+ {
File parentFile = new File(destinationURI).getParentFile();
- if ( !FileUtil.isExist( parentFile.getPath() ) ) {
- FileUtil.createDirectory( parentFile );
+ if (!FileUtil.isExist(parentFile.getPath()))
+ {
+ FileUtil.createDirectory(parentFile);
}
}
// copyLibrary(source.toURI(), destinationURI);
}
-
- private void copyNormalLibrary(TizenTemplateLibraryGroup group)
+
+ private void copyNormalLibrary(TizenTemplateLibraryGroup group)
{
String libraryPath = group.getSelectedLibraryPath();
- if (libraryPath == null) {
+ if (libraryPath == null)
+ {
return;
}
// cannot find library directory (source)
File source = new File(libraryPath);
- if (!source.exists() || !source.isDirectory()) {
- String errorMsg = "Cannot find template library resource directory : " + libraryPath;
+ if (!source.exists() || !source.isDirectory())
+ {
+ String errorMsg = "Cannot find template library resource directory : " + libraryPath;
}
-
+
// decide target directory
TizenTemplateKindsOfLibraries kindOfLibrary = group.getSelectedElement().getKindsOfLibrary();
-
+
String destDir;
-
+
switch (kindOfLibrary) {
- case JAVASCRIPT :
- destDir = data.getTargetAbsoultePath() + "js";
+ case JAVASCRIPT:
+ destDir = data.getOutputName() + "js";
break;
- case CSS :
- destDir = data.getTargetAbsoultePath() + "css";
+ case CSS:
+ destDir = data.getOutputName() + "css";
break;
- case OTHERS : // copy to root folder basically
- default :
- destDir = data.getTargetAbsoultePath();
+ case OTHERS: // copy to root folder basically
+ default:
+ destDir = data.getOutputName();
break;
}
-
+
try
{
FileUtil.copyRecursively(libraryPath, destDir, true);
}
}
-
- private void processOption(){
-
+
+ private void processOption()
+ {
+
// set default FreeMarker configuration
cfg = FreeMarkerUtil.getDefaultConfiguration();
- if(tizenAppTemplate == null)
+ if (tizenAppTemplate == null)
return;
-
+
// get options
Options options = tizenAppTemplate.getOptions();
- if(options == null)
+ if (options == null)
return;
-
- // get path of template
- String projectDestDir = data.getTargetAbsoultePath();
+
+ // get path of template
+ String projectDestDir = data.getOutputName();
File projectDir = new File(projectDestDir);
-
+
// get path which template is loaded on
try
{
// TODO Auto-generated catch block
log.error(e.getMessage());
}
-
+
// building support library model
SupportLibraries supportLibraries = options.getSupportLibraries();
- if (supportLibraries != null) {
+ if (supportLibraries != null)
+ {
buildModelForSupportLibraries(supportLibraries);
}
-
+
// building option model
- for (OptionGroup optionGroup : options.getOptionGroup()) {
- buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key ex) group1
+ for (OptionGroup optionGroup : options.getOptionGroup())
+ {
+ buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key
+ // ex)
+ // group1
}
-
+
// building config model
buildModelForConfigFile();
-
+
// generate files in project
generateFilefromProjectRoot(projectDir);
}
- private void generateFilefromProjectRoot(File projectRootFile){
- if (projectRootFile.isDirectory()) {
- if (projectRootFile.listFiles().length != 0) {
+ private void generateFilefromProjectRoot(File projectRootFile)
+ {
+ if (projectRootFile.isDirectory())
+ {
+ if (projectRootFile.listFiles().length != 0)
+ {
File[] fileList = projectRootFile.listFiles();
- for (File file : fileList) {
- if(file.isDirectory())
+ for (File file : fileList)
+ {
+ if (file.isDirectory())
generateFilefromProjectRoot(file);
-
- else if(isAvailableTemplate(file.getName())){
+
+ else if (isAvailableTemplate(file.getName()))
+ {
generateFileFromTemplate(file);
}
}
}
}
}
-
- private boolean isAvailableTemplate(String fileName) {
- String[] availableExtension = {".html"};
- String[] availableList = {"app.xml", "config.xml"};
-
- for (String res : availableExtension) {
- if (fileName.indexOf(res) != -1) {
+
+ private boolean isAvailableTemplate(String fileName)
+ {
+ String[] availableExtension = { ".html" };
+ String[] availableList = { "app.xml", "config.xml" };
+
+ for (String res : availableExtension)
+ {
+ if (fileName.indexOf(res) != -1)
+ {
return true;
}
}
-
- for (String res : availableList) {
- if (fileName.indexOf(res) != -1) {
+
+ for (String res : availableList)
+ {
+ if (fileName.indexOf(res) != -1)
+ {
return true;
}
}
-
+
return false;
}
-
- private void buildModelForSupportLibraries(SupportLibraries supportLibraries) {
- if (libraryPool != null) { // In case of sample, pool is null
-
+
+ private void buildModelForSupportLibraries(SupportLibraries supportLibraries)
+ {
+ if (libraryPool != null)
+ { // In case of sample, pool is null
+
// get template library groups
List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(supportLibraries);
-
- for (TizenTemplateLibraryGroup group : groupList) {
+
+ for (TizenTemplateLibraryGroup group : groupList)
+ {
// get key
String key = group.getKey();
-
+
// get value
LibraryElement selectedElement = group.getSelectedElement();
- String value = group.isSelectedMinified() ?
- selectedElement.getMinifiedValue() : selectedElement.getOriginalValue();
-
+ String value = group.isSelectedMinified() ? selectedElement.getMinifiedValue() : selectedElement.getOriginalValue();
+
// put key and value
- if (value != null) {
+ if (value != null)
+ {
root.put(key, value);
}
}
}
}
-
- private void buildModelForOptionGroup(OptionGroup optionGroup, String key) {
- for (OptionElement optionElement : optionGroup.getOptionElement()) {
+
+ private void buildModelForOptionGroup(OptionGroup optionGroup, String key)
+ {
+ for (OptionElement optionElement : optionGroup.getOptionElement())
+ {
boolean isDefault = (optionElement.isDefaultElement() != null) ? optionElement.isDefaultElement() : false;
- String addedKey = key + optionGroupSeparator + optionElement.getKey(); // key ex) group1_element
+ String addedKey = key + optionGroupSeparator + optionElement.getKey(); // key
+ // ex)
+ // group1_element
String value = optionElement.getValue();
-
- switch(optionGroup.getOptionType()) {
- case MANDATORY :
+
+ switch (optionGroup.getOptionType()) {
+ case MANDATORY:
root.put(addedKey, value);
break;
- case MULTI_SELECTION :
+ case MULTI_SELECTION:
root.put(addedKey, isDefault ? value : "");
break;
- case SINGLE_SELECTION :
- if (isDefault) {
+ case SINGLE_SELECTION:
+ if (isDefault)
+ {
root.put(key, value);
}
break;
- default :
+ default:
}
}
-
+
// process inner group
- for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup()) {
- String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key ex) group1_group2
+ for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup())
+ {
+ String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key
+ // ex)
+ // group1_group2
buildModelForOptionGroup(innerOptionGroup, addedKey);
}
}
-
- private void buildModelForConfigFile(){
+
+ private void buildModelForConfigFile()
+ {
root.put("APP_ID", data.getAppID());
root.put("WIDGET_ID", data.getProjectName());
}
-
- private void generateFileFromTemplate(File srcFile){
-
+
+ private void generateFileFromTemplate(File srcFile)
+ {
+
// rename source file to template file
String originalFilePath = srcFile.getAbsolutePath();
String templateFilePath = originalFilePath + temporaryFileAdditionalName;
File templateFile = new File(templateFilePath);
srcFile.renameTo(templateFile);
-
- try {
+
+ try
+ {
// generate file from template file
FreeMarkerUtil.generateDocument(root, cfg, templateFile.getName(), originalFilePath);
} catch (IOException e)
} catch (freemarker.template.TemplateException e)
{
log.error("Fail to generate HTML files.", e.getMessage());
- } finally {
+ } finally
+ {
templateFile.delete();
}
}
-
- private void copyConfiguration(){
- String srcConfigurationFilePath = data.getTizenWebConfigTemplatePath();
- String destConfigurationFilePath = data.getDestTizenWebProjectConfigFile(data.getProjectName());
-
- try
- {
- FileUtil.copyTo(srcConfigurationFilePath, destConfigurationFilePath);
- } catch (IOException e)
- {
- // TODO Auto-generated catch block
- log.error(e.getMessage());
- }
+
+ private void copyConfiguration()
+ {
+ pg.copyConfigFile(data.getDestTizenWebProjectConfigFile(data.getProjectName()));
}
-
- private void generateConfiguration(){
-
- //getConfiguration();
- //initializeConfiguration();
+
+ private void generateConfiguration()
+ {
+
+ // getConfiguration();
+ // initializeConfiguration();
}
-
+
/**
* find widget configuration file in a project
*
* @return the configuration file. null if no such file exists.
*/
- private File findConfiguration() {
+ private File findConfiguration()
+ {
// get configuration file
String configurationFilePath = data.getTizenWebProjectConfigFile(data.getProjectName());
File configurationFile = new File(configurationFilePath);
-
+
// check if configuration file exists
- if(configurationFile.isFile())
+ if (configurationFile.isFile())
return configurationFile;
else
return null;
}
-
+
/**
* get widget configuration file in a project
*
- * @return the configuration file. default configuration file if no such file exists.
+ * @return the configuration file. default configuration file if no such
+ * file exists.
*/
- private File getConfiguration() throws URISyntaxException, IOException {
-
+ private File getConfiguration() throws URISyntaxException, IOException
+ {
+
File configurationFile = findConfiguration();
-
+
// get default configuration file
- if ( configurationFile == null) {
- // get URI
-// URI sourceURI = getRealEntry( DEFAULT_CONFIG_DIR_IN_PLUGIN );
-// URI destinationURI = project.getLocationURI();
+ if (configurationFile == null)
+ {
+ // get URI
+ // URI sourceURI = getRealEntry( DEFAULT_CONFIG_DIR_IN_PLUGIN );
+ // URI destinationURI = project.getLocationURI();
- // copy a default configuration to the project
-// EFSUtil.copy( sourceURI, destinationURI, EFS.OVERWRITE, createSubMonitor( monitor, tick ) );
+ // copy a default configuration to the project
+ // EFSUtil.copy( sourceURI, destinationURI, EFS.OVERWRITE,
+ // createSubMonitor( monitor, tick ) );
-// configurationFile = findConfiguration();
+ // configurationFile = findConfiguration();
}
return configurationFile;
}
-
+
/**
* initialize Widget configuration with app ID generation.
*
- * @param monitor {@link IProgressMonitor}. if this is null, {@link NullProgressMonitor} is used.
+ * @param monitor
+ * {@link IProgressMonitor}. if this is null,
+ * {@link NullProgressMonitor} is used.
* @throws ConfigurationException
* @throws IOException
*/
- private void initializeConfiguration(){
-
+ private void initializeConfiguration()
+ {
+
String projectName = data.getProjectName();
- //String widgetId = getWidgetURI() + projectName;
-
+ // String widgetId = getWidgetURI() + projectName;
+
// get widget id
String widgetId = WIDGET_BASE_IDENTIFIER + projectName;
-
+
File configurationFile = new File(data.getDestTizenWebProjectConfigFile(projectName));
-
+
// get configuration manager
ITizenConfigurator configurator = unmarshalWidgetConfiguration(configurationFile);
-
+
// set default configuration
- configurator.setId( widgetId );
- configurator.setName( projectName, null );
-
+ configurator.setId(widgetId);
+ configurator.setName(projectName, null);
+
// Setting appid of configuration for new project
- configurator.setApplication( projectName, null, 0 );
-
+ configurator.setApplication(projectName, null, 0);
+
// save
try
{
log.error(e.getMessage());
}
}
-
- private ITizenConfigurator unmarshalWidgetConfiguration(File configurationFile){
-
+
+ private ITizenConfigurator unmarshalWidgetConfiguration(File configurationFile)
+ {
+
ITizenConfigurator config = null;
InputStream input = null;
-
- try {
+
+ try
+ {
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-
+
input = new FileInputStream(configurationFile);
-
- Object configModel = unmarshaller.unmarshal( input );
-//
+
+ Object configModel = unmarshaller.unmarshal(input);
+ //
// platform specific model class
-// TizenProjectDescription tizenDesc = ProjectUtil.getTizenProjectDescription(project);
-// if ( tizenDesc != null ) {
-// String platformName = tizenDesc.getPlatformName();
-// IConfigurationElement[] ces = PluginUtil.getExtensionConfigurationElements( WebConstant.EXTENTION_POINT_CONFIGURATION );
-// for ( IConfigurationElement ce : ces ) {
-// if ( platformName.equalsIgnoreCase( ce.getAttribute( "platform" ) ) ) {
-// if ( ce.getAttribute( "class") != null ) {
-// config = (ITizenConfigurator) ce.createExecutableExtension( "class" );
-// config.init( project, (Widget) configModel );
-// }
-// break;
-// }
-// }
-// }
- // if don't supported platform or class is not setting, then default model is TizenConfiguratorImpl
- if ( config == null ) {
-// config = new TizenConfiguratorImpl();
-// config.init( project, (Widget) configModel );
+ // TizenProjectDescription tizenDesc =
+ // ProjectUtil.getTizenProjectDescription(project);
+ // if ( tizenDesc != null ) {
+ // String platformName = tizenDesc.getPlatformName();
+ // IConfigurationElement[] ces =
+ // PluginUtil.getExtensionConfigurationElements(
+ // WebConstant.EXTENTION_POINT_CONFIGURATION );
+ // for ( IConfigurationElement ce : ces ) {
+ // if ( platformName.equalsIgnoreCase( ce.getAttribute( "platform" )
+ // ) ) {
+ // if ( ce.getAttribute( "class") != null ) {
+ // config = (ITizenConfigurator) ce.createExecutableExtension(
+ // "class" );
+ // config.init( project, (Widget) configModel );
+ // }
+ // break;
+ // }
+ // }
+ // }
+ // if don't supported platform or class is not setting, then default
+ // model is TizenConfiguratorImpl
+ if (config == null)
+ {
+ // config = new TizenConfiguratorImpl();
+ // config.init( project, (Widget) configModel );
}
- } catch (JAXBException e) {
+ } catch (JAXBException e)
+ {
log.error(e.getMessage());
} catch (FileNotFoundException e)
{
log.error(e.getMessage());
- } finally {
- IOUtil.tryClose( input );
+ } finally
+ {
+ IOUtil.tryClose(input);
}
return config;
-
+
}
-
+
/**
- * Widget URI getter for the ID of configuration
+ * Widget URI getter for the ID of configuration
*
- * @return Widget URI String in the preferences. If cannot get this, return default URI String.
- * {@value org.tizen.web.common.WebConstant#WIDGET_BASE_IDENTIFIER}
+ * @return Widget URI String in the preferences. If cannot get this, return
+ * default URI String.
+ * {@value org.tizen.web.common.WebConstant#WIDGET_BASE_IDENTIFIER}
*/
-// private String getWidgetURI() {
-// String widgetURI = getPreferenceStore().getString( ATTR_WIDGET_URI );
-// return widgetURI.isEmpty() ? WIDGET_BASE_IDENTIFIER : widgetURI;
-// }
-}
\ No newline at end of file
+ // private String getWidgetURI() {
+ // String widgetURI = getPreferenceStore().getString( ATTR_WIDGET_URI );
+ // return widgetURI.isEmpty() ? WIDGET_BASE_IDENTIFIER : widgetURI;
+ // }
+}
+
+class ProjectGenUtil
+{
+ protected final Logger logger = LoggerFactory.getLogger( getClass() );
+
+ private final String CONFIG_FILE = "/config/Tizen/config.xml";
+ private final String CONFIG_EXTRA_TIZEN_INFO = " <tizen:application id=\"${APP_ID}.${WIDGET_ID}\" package=\"${APP_ID}\" required_version=\"2.2\"/>";
+ private final String CONFIG_EXTRA_NAME_INFO = " <name>${WIDGET_ID}</name>";
+
+ public void copyConfigFile(String destConfigPath)
+ {
+ InputStream ips = null;
+ FileOutputStream fos = null;
+
+ try
+ {
+ ips = getClass().getResource(CONFIG_FILE).openStream();
+ fos = new FileOutputStream(destConfigPath);
+ FileUtil.redirectStream(ips, fos);
+ } catch (IOException e)
+ {
+ // logger.error(e.getMessage());
+
+ } finally
+ {
+ IOUtil.tryClose(ips, fos);
+ }
+
+ addExtraInfo2Config(destConfigPath);
+ }
+
+ public void addExtraInfo2Config(String destConfigPath)
+ {
+ OutputStreamWriter out = null;
+ Scanner scanner = null;
+
+ String newLine = System.getProperty("line.separator");
+
+ try
+ {
+ scanner = new Scanner(new FileInputStream(destConfigPath));
+ out = new OutputStreamWriter(new FileOutputStream(destConfigPath + ".output"));
+
+ String line;
+ while (scanner.hasNextLine())
+ {
+ line = scanner.nextLine();
+
+ out.write(line);
+ out.write(newLine);
+
+ if (line.startsWith("<widget"))
+ {
+ out.write(CONFIG_EXTRA_TIZEN_INFO);
+ out.write(newLine);
+ out.write(CONFIG_EXTRA_NAME_INFO);
+ out.write(newLine);
+ }
+ }
+
+ File destConfigFile = new File(destConfigPath);
+ File outputConfigFile = new File(destConfigPath + ".output");
+
+ destConfigFile.delete();
+ outputConfigFile.renameTo(destConfigFile);
+
+ } catch (IOException e)
+ {
+ logger.error(e.getMessage());
+ } finally
+ {
+ IOUtil.tryClose(scanner, out);
+ }
+
+ }
+
+ public String extractBuiltinJarFiles()
+ {
+ URL url = getClass().getClassLoader().getResource(WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER);
+ String urlPath = url.getPath();
+ String paths[] = urlPath.split("[:!]");
+ String jarPath = paths[1];
+ String destDirPath = jarPath + "_dir";
+ String templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
+
+ File destDirFile = new File(destDirPath);
+ if (destDirFile.isDirectory())
+ {
+ return templateLibPath;
+ }
+ else
+ {
+ destDirFile.mkdir();
+ }
+
+ try
+ {
+ JarFile jar = new JarFile(jarPath);
+ Enumeration enum2 = jar.entries();
+ while (enum2.hasMoreElements())
+ {
+ JarEntry file = (JarEntry) enum2.nextElement();
+ File f = new File(destDirPath + File.separator + file.getName());
+ if (file.isDirectory())
+ { // if its a directory, create it
+ f.mkdir();
+ continue;
+ }
+ InputStream is = jar.getInputStream(file); // get the input
+ // stream
+ FileOutputStream fos = new FileOutputStream(f);
+ while (is.available() > 0)
+ { // write contents of 'is' to 'fos'
+ fos.write(is.read());
+ }
+ fos.close();
+ is.close();
+ }
+ } catch (FileNotFoundException e)
+ {
+ logger.error(e.getMessage());
+ } catch (IOException e)
+ {
+ logger.error(e.getMessage());
+ }
+ return templateLibPath;
+ }
+}