Import-Package:
org.tizen.nativecommon.build,
org.tizen.nativecommon.build.exception,
+ org.tizen.web.apptemplate.model,
org.tizen.web.builder,
org.tizen.web.builder.exception,
- org.tizen.web.common
+ org.tizen.web.common,
+ org.tizen.web.config.schema.model,
+ org.tizen.web.model,
+ org.tizen.web.project.configuration,
+ org.tizen.web.project.wizard.model,
+ org.tizen.web.project.wizard.operation,
+ org.tizen.web.project.wizard.ui.commandbar
\r
public static final String TIZEN_CLI_GLOBAL_KEY = "TIZEN.CLI.GLOBAL";//Preference key\r
public static final String TIZEN_CLI_LOCAL_KEY = "TIZEN.CLI.LOCAL";//Preference key\r
+ \r
+ public static final String CLI_HOME = System.getenv("CLI_HOME");\r
\r
}\r
-/*\r
- * IDE\r
- *\r
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Shingi Kang <shingil.kang@samsung.com>\r
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>\r
- * Kangho Kim <kh5325.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- */\r
-package org.tizen.ncli.ide.shell;\r
-\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.net.MalformedURLException;\r
-import java.net.URL;\r
-\r
-import org.kohsuke.args4j.Option;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.tizen.ncli.ide.util.PolicyRegistryFactory;\r
-import org.tizen.common.Factory;\r
-import org.tizen.common.config.Preference;\r
-import org.tizen.common.core.command.ExecutionContext;\r
-import org.tizen.common.core.command.Prompter;\r
-import org.tizen.common.core.command.policy.PolicyRegistry;\r
-import org.tizen.common.file.FileHandler;\r
-import org.tizen.common.file.StandardFileHandler;\r
-import org.tizen.common.verrari.Realm;\r
-import org.tizen.common.verrari.RealmFactory;\r
-import org.tizen.common.verrari.TemplateContext;\r
-import org.tizen.common.verrari.TemplateException;\r
-import org.tizen.ncli.ide.config.ConfigConstant;\r
-import org.tizen.ncli.ide.subcommands.BuildWebCLICommand;\r
-import org.tizen.ncli.ide.subcommands.CreateProject;\r
-import org.tizen.ncli.ide.subcommands.CreateProjectCommand;\r
-import org.tizen.ncli.ide.util.ConsolePrompter;\r
-import org.tizen.ncli.ide.util.Launcher;\r
-import org.tizen.ncli.ide.util.TemplateModelProvider;\r
-\r
-/**\r
- * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
- */\r
-public class CreateProjectCLI extends AbstractCLI\r
-{\r
- private Logger logger = LoggerFactory.getLogger(CreateProjectCLI.class);\r
-\r
- @Option(name = "-t", aliases = { "--type" })\r
- private TizenAppType appType;\r
-\r
- @Option(name = "-n", aliases = "--name", required = true)\r
- private String projectName;\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see org.tizen.ncli.ide.shell.AbstractCLI#execute()\r
- */\r
- @Override\r
- public void execute()\r
- {\r
- logger.info("Project Name:{}", projectName);\r
-\r
- CreateProjectCommand command = new CreateProjectCommand();\r
- command.setAppType(appType);\r
- command.setProjectName(projectName);\r
- CreateProject createProject = command.runCommand();\r
- \r
- FileHandler fileHandler = new StandardFileHandler();\r
- Factory<PolicyRegistry> factory = new org.tizen.ncli.ide.util.PolicyRegistryFactory();\r
- PolicyRegistry pr = factory.create();\r
- Prompter prompter = new ConsolePrompter( System.out, new InputStreamReader( System.in ));\r
- \r
- ExecutionContext context = new ExecutionContext(\r
- pr,\r
- prompter,\r
- fileHandler\r
- );\r
- \r
- // set model provider\r
- TemplateContext.getInstance().setModelProvider(new TemplateModelProvider(context));\r
-\r
- // get realm url\r
- URL url = null;\r
- try\r
- {\r
- url = new URL( ConfigConstant.WEB_REALM_URL );\r
- } catch (MalformedURLException e1)\r
- {\r
- // TODO Auto-generated catch block\r
- logger.error( "Error: ", e1 );\r
- }\r
- \r
- // create realm\r
- Realm realm = null;\r
- try\r
- {\r
- realm = RealmFactory.getInstance().create( url );\r
- }\r
- catch ( final Throwable e )\r
- {\r
- logger.error( "Error: ", e );\r
- return ;\r
- }\r
- \r
- // put realm constant\r
- context.setValue( ConfigConstant.REALM, realm );\r
-\r
- try\r
- {\r
- createProject.process(context, appType, projectName);\r
- } catch (IOException e)\r
- {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (TemplateException e)\r
- {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
-\r
- /*\r
- switch (appType) {\r
- case NATIVE:\r
- logger.trace("Native app is being created");\r
- break;\r
- case WEB:\r
- logger.trace("Web app is being created");\r
- break;\r
- default:\r
- break;\r
- }\r
- */\r
- }\r
-\r
-}\r
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingi Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.ide.shell;
+
+import org.kohsuke.args4j.Option;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+//import org.tizen.ncli.ide.subcommands.CreateNativeProjectCommand;
+import org.tizen.ncli.ide.subcommands.CreateWebProjectCommand;
+
+/**
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ */
+public class CreateProjectCLI extends AbstractCLI
+{
+ private Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Option(name = "-t", aliases = { "--type" })
+ private TizenAppType appType;
+
+ @Option(name = "-n", aliases = "--name", required = true)
+ private String projectName;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.tizen.ncli.ide.shell.AbstractCLI#execute()
+ */
+ @Override
+ public void execute()
+ {
+ logger.info("Project Name:{}", projectName);
+
+ switch (appType) {
+ case NATIVE:
+// CreateNativeProjectCommand nativeCommand = new CreateNativeProjectCommand();
+// nativeCommand.setAppType(appType);
+// nativeCommand.setProjectName(projectName);
+// nativeCommand.runCommand();
+ break;
+ case WEB:
+ CreateWebProjectCommand webCommand = new CreateWebProjectCommand();
+ webCommand.setAppType(appType);
+ webCommand.setProjectName(projectName);
+ webCommand.runCommand();
+ break;
+ default:
+ break;
+ }
+ }
+}
+++ /dev/null
-/*
- * IDE
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil Kang <shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- * Kangho Kim <kh5325.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- */
-package org.tizen.ncli.ide.subcommands;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-import org.tizen.common.core.command.AbstractCommand;
-import org.tizen.common.core.command.ExecutionContext;
-import org.tizen.common.core.command.Executor;
-import org.tizen.common.verrari.Realm;
-import org.tizen.common.verrari.Storage;
-import org.tizen.common.verrari.Template;
-import org.tizen.common.verrari.TemplateContext;
-import org.tizen.common.verrari.TemplateException;
-import org.tizen.common.verrari.realm.CommonRealm;
-import org.tizen.common.verrari.storage.FileStorage;
-import org.tizen.common.verrari.template.TemplateConstants;
-import org.tizen.ncli.ide.config.ConfigConstant;
-import org.tizen.ncli.ide.shell.TizenAppType;
-import org.tizen.ncli.ide.util.TemplateModelProvider;
-
-/**
- * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
- *
- *
- */
-public class CreateProject
-{
- private TizenAppType appType;
- private String projectName;
-
- CreateProject(TizenAppType appType, String projectName)
- {
- this.appType = appType;
- this.projectName = projectName;
- }
-
- public void process(
- final ExecutionContext context,
- TizenAppType appType,
- String projectName
- ) throws IOException, TemplateException
- {
-
- final Realm realm = (Realm) context.getValue( ConfigConstant.REALM );
-
- final FileStorage storage = new FileStorage( context.getFileHandler() );
-
- final TemplateModelProvider models = new TemplateModelProvider( context );
-
- TemplateContext.getInstance().setModelProvider( models );
-
- try
- {
- template( realm, appType, projectName, models, storage );
- }
- finally
- {
- TemplateContext.clear();
- }
-
- }
-
- protected void
- template(
- final Realm realm,
- TizenAppType appType,
- String projectName,
- final TemplateModelProvider models,
- final Storage storage
- ) throws IOException, TemplateException
- {
- final HashMap<String, Template> ret = new HashMap<String, Template>();
-
- String[] projectNames = new String[]{projectName};
- template( realm, appType, projectNames, models, storage, ret );
-
- }
-
- protected
- void
- template(
- final Realm realm,
- TizenAppType appType,
- String[] projectNames,
- final TemplateModelProvider models,
- final Storage storage,
- final HashMap<String, Template> cache
- )
- throws IOException, TemplateException
- {
- for ( final String projectName : projectNames )
- {
- ExecutionContext.getCurrentContext().setValue( "id", projectName );
-
- // get template if cached
- Template template = cache.get( projectName );
- if ( null == template )
- {
- //get template if not cached
- template = realm.getTemplate( projectName );
- }
-
- cache.put( projectName, template );
- template.template( models, storage );
- final String[] dependencies = CommonRealm.separate( template.getAttribute( TemplateConstants.ATTR_DEPENDENCY ) );
- if ( null == dependencies )
- {
- continue;
- }
-
- template( realm, appType, dependencies, models, storage, cache );
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * IDE
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil Kang <shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- * Kangho Kim <kh5325.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- */
-package org.tizen.ncli.ide.subcommands;
-
-import org.kohsuke.args4j.Option;
-import org.tizen.ncli.ide.shell.TizenAppType;
-
-/**
- * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
- *
- *
- */
-public class CreateProjectCommand extends AbstractSubCommand<CreateProject>
-{
- private TizenAppType appType;
- private String projectName;
-
- public void setAppType(TizenAppType appType)
- {
- this.appType = appType;
- }
-
- public void setProjectName(String projectName)
- {
- this.projectName = projectName;
- }
-
- @Override
- protected CreateProject call()
- {
- // TODO Auto-generated method stub
- return new CreateProject(appType, projectName);
- }
-}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.ide.subcommands;
+
+import static org.tizen.web.common.WebConstant.WIDGET_CONFIGURATION_FILE;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.tizen.common.AppIdGenerator;
+import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.ncli.ide.shell.TizenAppType;
+
+/**
+ * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
+ *
+ *
+ */
+public class CreateProjectCommandData
+{
+ private static final String PLATFORM_PATH = InstallPathConfig.getPlatformPath(null, null);
+ private static final String WEB_PROJECT_PATH = "samples" + File.separator + "web" + File.separator + "Template" + File.separator + "Tizen";
+ private static final String TIZEN_WEB_APP_TEMPLATE_FILE = "tizen-app-template.xml";
+ private static final String TIZEN_PROJECT_FOLDER = "project";
+ private static final String TIZEN_PROJECT_CONFIG_PATH = "config" + File.separator + "config.xml";
+
+ public static final Map<String, String> webProjects = new HashMap<String, String>();
+
+ private TizenAppType appType;
+ private String projectName;
+ private String targetAbsoultePath = System.getProperty("user.dir") + File.separator + "te";
+
+ private String APPID = AppIdGenerator.getInstance().create();
+
+ static
+ {
+ webProjects.put("tizen-basic", "Basic" + File.separator + "Tizen_Blank");
+ webProjects.put("tizenwebuifw-masterdetail", "Tizen Web UI Framework + File.separator + Tizen_Web_UI_FW_MasterDetail ");
+ webProjects.put("tizenwebuifw-multipage", "Tizen Web UI Framework + File.separator + Tizen_Web_UI_FW_MultiPage");
+ webProjects.put("tizenwebuifw-navigation", "Tizen Web UI Framework + File.separator + Tizen_Web_UI_FW_NavigationView");
+ webProjects.put("tizenwebuifw-singlepage", "Tizen Web UI Framework" + File.separator + "Tizen_Web_UI_FW_SinglePage");
+ webProjects.put("jqm-masterdetail", "jQuery Mobile" + File.separator + "MasterDetail");
+ webProjects.put("jqm-multipage", "jQuery Mobile" + File.separator + "MultiPage");
+ webProjects.put("jqm-navigatio", "jQuery Mobile" + File.separator + "NavigationView");
+ webProjects.put("jqm-singlepage", "jQuery Mobile" + File.separator + "SinglePage");
+ }
+
+ public String getTargetAbsoultePath()
+ {
+ return targetAbsoultePath;
+ }
+
+ public void setTargetAbsoultePath(File targetAbsoultePath)
+ {
+ this.targetAbsoultePath = targetAbsoultePath.getAbsolutePath();
+ }
+
+ public void setAppType(TizenAppType appType)
+ {
+ this.appType = appType;
+ }
+
+ public TizenAppType getAppType()
+ {
+ return appType;
+ }
+
+ public void setProjectName(String projectName)
+ {
+ this.projectName = projectName;
+ }
+
+ public String getProjectName()
+ {
+ return projectName;
+ }
+
+ public String getAppID()
+ {
+ return APPID;
+ }
+
+ public void setAppID(String aPPID)
+ {
+ APPID = aPPID;
+ }
+
+ // get web template root path
+ public String getTizenWebTemplateRootPath(String id)
+ {
+ String TemplatePath = PLATFORM_PATH + File.separator + WEB_PROJECT_PATH + File.separator + webProjects.get(id);
+
+ return TemplatePath;
+ }
+
+ // get web project root path
+ public String getTizenWebProjectRootPath(String id)
+ {
+ String TemplatePath = getTizenWebTemplateRootPath(id);
+
+ return TemplatePath + File.separator + TIZEN_PROJECT_FOLDER;
+ }
+
+ // get web project template configuration path
+ public String getTizenWebTemplateConfigFile(String id)
+ {
+ String TemplatePath = getTizenWebTemplateRootPath(id);
+
+ return TemplatePath + File.separator + TIZEN_WEB_APP_TEMPLATE_FILE;
+ }
+
+ // get web project configuration path
+ public String getTizenWebProjectConfigFile(String id)
+ {
+ String TemplatePath = getTizenWebTemplateRootPath(id);
+
+ return TemplatePath + File.separator + WIDGET_CONFIGURATION_FILE;
+ }
+
+ // get web project configuration destination path
+ public String getDestTizenWebProjectConfigFile(String id)
+ {
+ return targetAbsoultePath + File.separator + WIDGET_CONFIGURATION_FILE;
+ }
+
+ // get web project configuration file
+ public String getTizenWebConfigTemplatePath()
+ {
+ return PLATFORM_PATH + File.separator + WEB_PROJECT_PATH + File.separator + TIZEN_PROJECT_CONFIG_PATH;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.ide.subcommands;
+
+import static org.tizen.web.common.WebConstant.ATTR_WIDGET_URI;
+import static org.tizen.web.common.WebConstant.WIDGET_BASE_IDENTIFIER;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.kohsuke.args4j.Option;
+import org.tizen.common.Factory;
+import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.core.application.ProfileInfo;
+import org.tizen.common.core.application.TizenProjectDescription;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.StandardFileHandler;
+import org.tizen.common.util.EFSUtil;
+import org.tizen.common.util.FileUtil;
+import org.tizen.common.util.FreeMarkerUtil;
+import org.tizen.common.util.IOUtil;
+import org.tizen.common.util.ObjectUtil;
+import org.tizen.common.util.PluginUtil;
+import org.tizen.common.util.ProjectUtil;
+import org.tizen.ncli.ide.config.ConfigConstant;
+import org.tizen.ncli.ide.shell.TizenAppType;
+import org.tizen.web.apptemplate.model.LibraryElement;
+import org.tizen.web.apptemplate.model.OptionElement;
+import org.tizen.web.apptemplate.model.OptionGroup;
+import org.tizen.web.apptemplate.model.Options;
+import org.tizen.web.apptemplate.model.SupportLibraries;
+import org.tizen.web.apptemplate.model.SupportLibrary;
+import org.tizen.web.apptemplate.model.TizenTemplateKindsOfLibraries;
+import org.tizen.web.common.WebConstant;
+import org.tizen.web.config.schema.model.ObjectFactory;
+import org.tizen.web.config.schema.model.Widget;
+import org.tizen.web.model.TizenAppTemplate;
+import org.tizen.web.model.TizenModelFactory;
+import org.tizen.web.project.configuration.ConfigurationException;
+import org.tizen.web.project.configuration.ConfiguratorFactory;
+import org.tizen.web.project.configuration.ITizenConfigurator;
+import org.tizen.web.project.configuration.TizenConfiguratorImpl;
+import org.tizen.web.project.wizard.model.TizenTemplateLibrariesPool;
+import org.tizen.web.project.wizard.model.TizenTemplateLibraryGroup;
+import org.tizen.web.project.wizard.operation.LibraryCopyOperation;
+import org.tizen.web.project.wizard.operation.OptionProcessOperation;
+import org.tizen.web.project.wizard.operation.TemplateCopyOperation;
+import org.tizen.web.project.wizard.operation.LibraryCopyOperation.TizenWebUIFWType;
+import org.tizen.web.project.wizard.ui.commandbar.WebProjectCreator;
+
+import freemarker.template.Configuration;
+
+/**
+ * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
+ *
+ */
+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 TizenTemplateLibrariesPool libraryPool;
+
+ /* 1. copy web project template
+ * 2. copy the dependent library
+ * 3. copy configuration
+ * 4. generate HTML and XML file from template
+ */
+ @Override
+ protected CreateProjectCommandData call()
+ {
+ //1. copy web project template
+ copyWebProjectTemplate();
+
+ //2. copy the dependent library
+ copyLibrary();
+
+ //3. generate configuration
+ copyConfiguration();
+
+ //4. generate file from template
+ processOption();
+
+ return data;
+ }
+
+ public void setAppType(TizenAppType appType)
+ {
+ this.data.setAppType(appType);
+ }
+
+ public void setProjectName(String projectName)
+ {
+ this.data.setProjectName(projectName);
+ }
+
+ private void copyWebProjectTemplate(){
+ String projectName = data.getProjectName();
+ String projectPath = data.getTizenWebProjectRootPath(projectName);
+ String destDir = data.getTargetAbsoultePath();
+
+ // filter file (.project)
+ File[] resourceFilter = { new File( ".project" ) };
+
+ // copy template resources
+ try
+ {
+ FileUtil.copyRecursively( projectPath, destDir, true, resourceFilter );
+ } catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage());
+ }
+ }
+
+ private void copyLibrary(){
+
+ String projectName = data.getProjectName();
+ String configFile = data.getTizenWebTemplateConfigFile(projectName);
+
+ try
+ {
+ // unmarshal app template.
+ tizenAppTemplate = TizenModelFactory.unmarshalAppTemplate(configFile);
+ } catch (FileNotFoundException e2)
+ {
+ // 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();
+
+ // get library pool
+ libraryPool = new TizenTemplateLibrariesPool(profileInfo);
+
+ // get template library groups
+ if (libraryPool != null) { // In case of sample, pool is null
+ List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(sl);
+
+ // copy libraries
+ for (TizenTemplateLibraryGroup group : groupList) {
+ /*
+ if ( isSampleGroup( template ) ) {
+ group.setSelectedMinifiedWithDependsUpdate( true );
+ }
+ */
+ if ( group.getSelectedElement().getKindsOfLibrary() == TizenTemplateKindsOfLibraries.TIZENWEBUIFW ) {
+ copyTizenWebUIFWLibrary( group );
+ }
+ else {
+ copyNormalLibrary( group);
+ }
+ }
+ }
+ }
+
+ private void copyTizenWebUIFWLibrary(TizenTemplateLibraryGroup group)
+ {
+ String libraryPath = group.getSelectedLibraryPath();
+ 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
+ }
+
+ // create target directory
+ TizenWebUIFWType type = null;
+ String elementKey = group.getSelectedElementKey();
+ try {
+ type = TizenWebUIFWType.valueOf( elementKey );
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+
+ URI destinationURI = null;
+ switch ( type ) {
+ case TizenWebUIFramework_Theme:
+ case TizenWebUIFramework_Theme_Images:
+ String themePaths[] = libraryPath.split( "Theme/" );
+ // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath() + themePaths[1]);
+ break;
+ default:
+ // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath());
+ break;
+ }
+
+ // decide target directory
+ 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) );
+ }
+ } else {
+ File parentFile = new File(destinationURI).getParentFile();
+ if ( !FileUtil.isExist( parentFile.getPath() ) ) {
+ FileUtil.createDirectory( parentFile );
+ }
+ }
+ // copyLibrary(source.toURI(), destinationURI);
+ }
+
+ private void copyNormalLibrary(TizenTemplateLibraryGroup group)
+ {
+ String libraryPath = group.getSelectedLibraryPath();
+ 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;
+ }
+
+ // decide target directory
+ TizenTemplateKindsOfLibraries kindOfLibrary = group.getSelectedElement().getKindsOfLibrary();
+
+ String destDir;
+
+ switch (kindOfLibrary) {
+ case JAVASCRIPT :
+ destDir = data.getTargetAbsoultePath() + "js";
+ break;
+ case CSS :
+ destDir = data.getTargetAbsoultePath() + "css";
+ break;
+ case OTHERS : // copy to root folder basically
+ default :
+ destDir = data.getTargetAbsoultePath();
+ break;
+ }
+
+ try
+ {
+ FileUtil.copyRecursively(libraryPath, destDir, true);
+ } catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage());
+ }
+
+ }
+
+ private void processOption(){
+
+ // set default FreeMarker configuration
+ cfg = FreeMarkerUtil.getDefaultConfiguration();
+
+ if(tizenAppTemplate == null)
+ return;
+
+ // get options
+ Options options = tizenAppTemplate.getOptions();
+ if(options == null)
+ return;
+
+ // get path of template
+ String projectDestDir = data.getTargetAbsoultePath();
+ File projectDir = new File(projectDestDir);
+
+ // get path which template is loaded on
+ try
+ {
+ cfg.setDirectoryForTemplateLoading(projectDir);
+ } catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage());
+ }
+
+ // building support library model
+ SupportLibraries supportLibraries = options.getSupportLibraries();
+ if (supportLibraries != null) {
+ buildModelForSupportLibraries(supportLibraries);
+ }
+
+ // building option model
+ 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) {
+ File[] fileList = projectRootFile.listFiles();
+ for (File file : fileList) {
+ if(file.isDirectory())
+ generateFilefromProjectRoot(file);
+
+ 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) {
+ return true;
+ }
+ }
+
+ 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
+
+ // get template library groups
+ List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(supportLibraries);
+
+ for (TizenTemplateLibraryGroup group : groupList) {
+ // get key
+ String key = group.getKey();
+
+ // get value
+ LibraryElement selectedElement = group.getSelectedElement();
+ String value = group.isSelectedMinified() ?
+ selectedElement.getMinifiedValue() : selectedElement.getOriginalValue();
+
+ // put key and value
+ if (value != null) {
+ root.put(key, value);
+ }
+ }
+ }
+ }
+
+ 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 value = optionElement.getValue();
+
+ switch(optionGroup.getOptionType()) {
+ case MANDATORY :
+ root.put(addedKey, value);
+ break;
+ case MULTI_SELECTION :
+ root.put(addedKey, isDefault ? value : "");
+ break;
+ case SINGLE_SELECTION :
+ if (isDefault) {
+ root.put(key, value);
+ }
+ break;
+ default :
+ }
+ }
+
+ // process inner group
+ for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup()) {
+ String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key ex) group1_group2
+ buildModelForOptionGroup(innerOptionGroup, addedKey);
+ }
+ }
+
+ private void buildModelForConfigFile(){
+ root.put("APP_ID", data.getAppID());
+ root.put("WIDGET_ID", data.getProjectName());
+ }
+
+ 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 {
+ // generate file from template file
+ FreeMarkerUtil.generateDocument(root, cfg, templateFile.getName(), originalFilePath);
+ } catch (IOException e)
+ {
+ log.error("not found file", e.getMessage());
+ } catch (freemarker.template.TemplateException e)
+ {
+ log.error("Fail to generate HTML files.", e.getMessage());
+ } 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 generateConfiguration(){
+
+ //getConfiguration();
+ //initializeConfiguration();
+ }
+
+ /**
+ * find widget configuration file in a project
+ *
+ * @return the configuration file. null if no such file exists.
+ */
+ 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())
+ return configurationFile;
+ else
+ return null;
+ }
+
+ /**
+ * get widget configuration file in a project
+ *
+ * @return the configuration file. default configuration file if no such file exists.
+ */
+ 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();
+
+ // copy a default configuration to the project
+// EFSUtil.copy( sourceURI, destinationURI, EFS.OVERWRITE, createSubMonitor( monitor, tick ) );
+
+// configurationFile = findConfiguration();
+ }
+ return configurationFile;
+ }
+
+ /**
+ * initialize Widget configuration with app ID generation.
+ *
+ * @param monitor {@link IProgressMonitor}. if this is null, {@link NullProgressMonitor} is used.
+ * @throws ConfigurationException
+ * @throws IOException
+ */
+ private void initializeConfiguration(){
+
+ String projectName = data.getProjectName();
+ //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 );
+
+ // Setting appid of configuration for new project
+ configurator.setApplication( projectName, null, 0 );
+
+ // save
+ try
+ {
+ configurator.doSave();
+ } catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage());
+ } catch (ConfigurationException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage());
+ }
+ }
+
+ private ITizenConfigurator unmarshalWidgetConfiguration(File configurationFile){
+
+ ITizenConfigurator config = null;
+ InputStream input = null;
+
+ try {
+ JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+
+ input = new FileInputStream(configurationFile);
+
+ 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 );
+ }
+
+ } catch (JAXBException e) {
+ log.error(e.getMessage());
+ } catch (FileNotFoundException e)
+ {
+ log.error(e.getMessage());
+ } finally {
+ IOUtil.tryClose( input );
+ }
+ return config;
+
+ }
+
+ /**
+ * 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}
+ */
+// private String getWidgetURI() {
+// String widgetURI = getPreferenceStore().getString( ATTR_WIDGET_URI );
+// return widgetURI.isEmpty() ? WIDGET_BASE_IDENTIFIER : widgetURI;
+// }
+}
\ No newline at end of file
+++ /dev/null
-/*
- * CLI - Command Line Interface
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil Kang <shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.ncli.ide.util;
-
-import static org.tizen.common.core.command.PrompterConstants.SUPPORT_CONSOLE;
-import static org.tizen.common.util.CollectionUtil.isEmpty;
-import static org.tizen.common.util.StringUtil.isEmpty;
-import static org.tizen.common.util.StringUtil.trim;
-
-import java.io.BufferedReader;
-import java.io.Console;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Map;
-
-import org.tizen.common.core.command.Prompter;
-import org.tizen.common.core.command.UserField;
-import org.tizen.common.core.command.prompter.AbstractPrompter;
-import org.tizen.common.core.command.prompter.ChoiceOption;
-import org.tizen.common.core.command.prompter.GenericOption;
-import org.tizen.common.core.command.prompter.Option;
-import org.tizen.common.util.Assert;
-
-/**
- * <p>
- * ConsolePrompter.
- *
- * {@link Prompter} for command line interface
- *
- * Print out using {@link PrintStream} and Read input from console( including standard input )
- * </p>
- *
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
- */
-public class
-ConsolePrompter
-extends AbstractPrompter
-implements Prompter
-{
- /**
- * {@link PrintStream} for output
- */
- protected final PrintStream out;
-
- /**
- * {@link BufferedReader} for input
- */
- protected final BufferedReader reader;
-
- /**
- * Constructor with {@link PrintStream} and {@link Reader}
- *
- * @param out {@link PrintStream} for output
- * @param reader {@link Reader} for input
- */
- public
- ConsolePrompter(
- final PrintStream out,
- final Reader reader
- )
- {
- Assert.notNull( out );
- this.out = out;
- this.reader = new BufferedReader( reader );
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#interact(java.lang.String, int, org.tizen.common.core.command.prompter.Option[])
- */
- @Override
- public
- Option
- interact(
- final String question,
- final Option... options
- )
- {
- final HashSet<Option> reducedOptions = new LinkedHashSet<Option>();
- Option defaultOption = null;
- final ArrayList<String> optionNames = new ArrayList<String>();
- for ( final Option option : options )
- {
- if ( reducedOptions.contains( option ) )
- {
- throw new IllegalArgumentException( "Question can't have duplicated choice(s) :" + option );
- }
- optionNames.add( option.getName() );
- reducedOptions.add( option );
- if ( option.isDefault() )
- {
- if ( null != defaultOption )
- {
- throw new IllegalArgumentException(
- "Question must have only one default choice"
- );
- }
-
- defaultOption = option;
- }
- }
-
- String choice = null;
- try
- {
- while ( true )
- {
- printQuestion( question, options );
-
- choice = reader.readLine();
- if ( isEmpty( choice ) )
- {
- return defaultOption;
- }
- for ( final Option option : options )
- {
- if ( option.isMatch( choice ) )
- {
- return option;
- }
- }
- }
- } catch ( final IOException e )
- {
- throw new IllegalStateException( e );
- }
- }
-
- /**
- * Print out question and options for choice
- *
- * @param question message to print
- * @param options options to suggest
- */
- protected
- void
- printQuestion(
- final String question,
- final Option... options
- )
- {
- out.print( getFullQuestion(question, options) );
- }
-
- private char[] getFullQuestion(String question, Option[] options) {
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(question + "\n");
-
- int len = options.length - 1;
- for(int i = 0; i< len; i++) {
- if(options[i] instanceof ChoiceOption) {
- ChoiceOption choiceOption = (ChoiceOption) options[i];
- buffer.append(String.format("%s: (%s), ", choiceOption.getName(), choiceOption.getShortName()));
- }
- }
-
- if(options[len] instanceof ChoiceOption) {
- ChoiceOption choiceOption = (ChoiceOption) options[len];
- buffer.append(String.format("%s: (%s) ", choiceOption.getName(), choiceOption.getShortName()));
- }
-
- buffer.append("?");
-
- return buffer.toString().toCharArray();
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#notify(java.lang.String, java.lang.Object[])
- */
- @Override
- public
- void
- notify(
- final String message
- )
- {
- out.println( message );
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#cancel()
- */
- @Override
- public void cancel()
- {
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#password(java.lang.String)
- */
- @Override
- public
- Object password(
- final String message
- )
- {
- out.print( trim( message ) );
- out.print( " " );
- Console console = System.console();
- return console.readPassword();
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#error(java.lang.String, java.lang.Object[])
- */
- @Override
- public
- void
- error(
- final String message
- )
- {
- out.println( message );
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.core.command.Prompter#batch(java.util.Collection)
- */
- @Override
- public
- void
- batch(
- final Collection<UserField> userFields,
- final Map<String, Object> options
- )
- {
- batch( 0, userFields );
- }
-
- /**
- * <p>
- * Process <code>fields</code> for <code>depth</code> level
- *
- * process result are stored in <code>answer</code>
- * </p>
- * @param depth process depth
- * @param fields user input specifications
- * @param answer user answer
- */
- protected
- void
- batch(
- final int depth,
- final Collection<UserField> fields
- )
- {
- for ( final UserField child : fields )
- {
- batch( depth, child );
- }
- }
-
- /**
- * <p>
- * Process <code>field</code> for <code>depth</code> level
- *
- * process result are stored in <code>answer</code>
- * </p>
- * @param depth process depth
- * @param field user input specification
- * @param answer user answer
- */
- protected
- void
- batch(
- final int depth,
- final UserField field
- )
- {
- final String msg = field.getMessage();
-
- final Collection<Object> supports = field.getSupports();
- if ( null != supports && !supports.contains( SUPPORT_CONSOLE ) )
- {
- logger.warn( "{} is not supported in {}", field, this );
- return ;
- }
-
- final Class<?> type = field.getType();
-
- boolean bChild = true;
-
- if ( field.canModify() )
- {
- if ( String.class.equals( type ) )
- {
- final GenericOption option = new GenericOption();
- interact( indent( depth, msg ), option );
- if ( field.getValue() == null || !isEmpty( option.getAnswer() ) )
- {
- field.setValue( option.getAnswer() );
- }
- }
- else if ( char[].class.equals( type ) || Character[].class.equals( type ) )
- {
- field.setValue( password( indent( depth, msg ) ) );
- }
- else if ( boolean.class.equals( type ) || Boolean.class.equals( type ) )
- {
- final boolean initValue = (null == field.getValue())?true:((Boolean) field.getValue());
- final ChoiceOption yes = new ChoiceOption( "Yes", initValue );
- final ChoiceOption no = new ChoiceOption( "No", !initValue );
- final Object opt = interact( indent( depth, msg ), yes, no );
- bChild = yes.equals( opt );
- field.setValue( bChild );
- }
- }
-
- final Collection<UserField> children = field.getChildren();
- if ( bChild && !isEmpty( children ) )
- {
- notify( indent( depth, msg ) );
- batch( depth + 1, children );
- }
- }
-
- /**
- * Make indented message
- *
- * @param depth message depth
- * @param msg message
- *
- * @return created message
- */
- protected
- String
- indent(
- final int depth,
- final String msg
- )
- {
- final StringBuilder buffer = new StringBuilder();
-
- for ( int i = 0 ; i<depth ; ++i )
- {
- buffer.append( " " );
- }
- buffer.append( msg );
- return buffer.toString();
- }
-
-}
+++ /dev/null
-/*
- * Web IDE - Command Line Interface
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil kang<shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.ncli.ide.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Properties;
-
-//import org.apache.commons.cli.CommandLine;
-//import org.apache.commons.cli.CommandLineParser;
-//import org.apache.commons.cli.GnuParser;
-//import org.apache.commons.cli.OptionBuilder;
-//import org.apache.commons.cli.Options;
-//import org.apache.commons.cli.ParseException;
-//import org.apache.commons.cli.PosixParser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.tizen.common.config.Preference;
-import org.tizen.common.config.provider.EnvironmentProvider;
-import org.tizen.common.config.provider.SystemPropertiesProvider;
-import org.tizen.common.core.command.ExecutionContext;
-import org.tizen.common.core.command.Executor;
-import org.tizen.common.core.command.Prompter;
-import org.tizen.common.core.command.policy.PolicyRegistry;
-import org.tizen.common.file.FileHandler;
-import org.tizen.common.file.FileHandler.Attribute;
-import org.tizen.common.file.StandardFileHandler;
-import org.tizen.common.util.CollectionUtil;
-import org.tizen.common.util.IOUtil;
-import org.tizen.common.util.MapUtil;
-import org.tizen.common.util.OSChecker;
-import org.tizen.common.util.PropertyUtil;
-import org.tizen.common.util.StringUtil;
-
-/**
- * <p>
- * AbstractLauncher.
- *
- * abstract class for simple command.
- *
- * provide {@link ExecutionContext} for command line
- * </p>
- *
- * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-Core)
- */
-public class
-Launcher
-{
-//
-// /**
-// * <p>
-// * Option for help text
-// * </p>
-// */
-// protected static final String OPT_HELP = "help";
-//
-// /**
-// * <p>
-// * Description for help option
-// *
-// * This is printed out in usage
-// * </p>
-// *
-// * @see #OPT_HELP
-// */
-// protected static final String DESC_HELP = "Print out this page";
-//
-// /**
-// * <p>
-// * Option for log level
-// *
-// * This option is shared in shell
-// * </p>
-// */
-// protected static final String OPT_LOG = "log";
-//
-// /**
-// * <p>
-// * Description for log level option
-// *
-// * This is printed out in usage
-// * </p>
-// *
-// * @see #OPT_LOG
-// */
-// protected static final String DESC_LOG = "Specify log category (error | warn | info | debug | trace)";
-//
-// /**
-// * <p>
-// * Option for no output
-// * </p>
-// */
-// protected static final String OPT_QUIET = "quiet";
-//
-// /**
-// * <p>
-// * Description for no output option
-// *
-// * This is printed out in usage
-// * </p>
-// *
-// * @see #OPT_QUIET
-// */
-// protected static final String DESC_QUIET = "Execute silently";
-//
-// /**
-// * <p>
-// * Property key for command line parameter parser
-// * </p>
-// */
-// protected static final String PROP_PARSER = "tizen.cli.parser";
-//
-//
-// /**
-// * <p>
-// * suffix for help properties
-// * </p>
-// */
-// protected static final String SUFFIX_CONFIG = ".properties";
-//
-// /**
-// * <p>
-// * logger for this object
-// * </p>
-// */
-// protected final Logger logger = LoggerFactory.getLogger( getClass() );
-//
-// /**
-// * <p>
-// * object for usage help
-// * </p>
-// */
-// protected Help help;
-
-// /**
-// * <p>
-// * optional flag to be specified by user
-// *
-// * flag is formatted in POSIX style in default
-// * </p>
-// */
-// protected CommandLine cmd;
-
- /**
- * {@link Executor} for Command Line Interface
- */
- public Executor executor;
-
- /**
- * A command user inputs
- */
-// protected String inputCmd = "";
-//
-// /**
-// * Convert <code>path</code> to canonical path
-// *
-// * @param path relative or abstract path
-// *
-// * @return canonical path
-// *
-// * @throws IOException If file system deny request
-// */
-// protected
-// String
-// convertPath(
-// final String path
-// )
-// throws IOException
-// {
-// String target = path;
-// if ((!OSChecker.isWindows())
-// && target.startsWith("~"+File.separator)) {
-// target = path.replaceFirst("~", System.getProperty("user.home"));
-// }
-// final FileHandler fileHandler = getFileHandler();
-// return (String) fileHandler.get( target, Attribute.PATH );
-// }
-
- /**
- * return execution command for usage
- *
- * @return execution command
- */
-// protected String getSyntax()
-// {
-// return getHelp().getSyntax();
-// }
-//
-// /**
-// * {@link Options} for usage
-// *
-// * @return defined {@link Options}
-// */
-// @SuppressWarnings("static-access")
-// protected
-// Options
-// getOptions()
-// {
-// final Options options = new Options();
-//
-// options.addOption( OptionBuilder.withLongOpt( OPT_HELP ).withDescription( DESC_HELP ).create( OPT_HELP.substring( 0, 1 ) ) );
-// options.addOption( OptionBuilder.hasArg().withLongOpt( OPT_LOG ).withDescription( DESC_LOG ).create( OPT_LOG.substring( 0, 1 ) ) );
-// options.addOption( OptionBuilder.withLongOpt( OPT_QUIET ).withDescription( DESC_QUIET ).create( OPT_QUIET.substring( 0, 1 ) ) );
-//
-// return options;
-// }
-//
-// /**
-// * {@link Options} for usage. A command does not use short option name and argument.
-// *
-// * @return defined {@line Options}
-// */
-// protected
-// Options
-// getCommands()
-// {
-// final Options options = new Options();
-// return options;
-// }
-//
-//
-// /**
-// * <p>
-// * Create and return {@link Help} instance
-// * </p>
-// *
-// * @return {@link Help}
-// */
-// protected
-// Help
-// createHelp() {
-// return new Help( getOptions() );
-// }
-//
-// /**
-// * <p>
-// * Return {@link Help} in this cli instance
-// * </p>
-// * @return {@link Help}
-// */
-// synchronized protected
-// Help
-// getHelp()
-// {
-// if ( null == help )
-// {
-// this.help = createHelp();
-// final ClassLoader cl = getClass().getClassLoader();
-// final String resourceName = getClass().getName().replace( '.', '/' ) + SUFFIX_CONFIG;
-//
-// logger.trace( "Resource name :{}", resourceName );
-// try
-// {
-// final Enumeration<URL> iter = cl.getResources( resourceName );
-// while ( iter.hasMoreElements() )
-// {
-// final URL url = iter.nextElement();
-// logger.trace( "URL :{}", url );
-// final Properties properties = PropertyUtil.loadProperties( url.openStream() );
-// logger.debug( "Properties :{}", properties );
-//
-// for ( final Object key : properties.keySet() )
-// {
-// final String value = properties.getProperty( (String) key );
-// byte[] contents = IOUtil.getBytes( cl.getResourceAsStream( value ), true );
-// this.help.addHelpDetail( (String) key, new String( contents, Charset.forName( "utf8" ) ) );
-// }
-// }
-// }
-// catch ( final IOException e )
-// {
-// logger.warn( "Can't load help", e );
-// }
-// }
-//
-// return this.help;
-// }
-//
-// /**
-// * Print out sample usage
-// *
-// * @return sample usage string
-// */
-// protected
-// String
-// printHelpDetail( String option )
-// {
-// final String detailStr = getHelp().getHelpDetail( option );
-// getPrompter().error( detailStr );
-// return detailStr;
-// }
-//
-// /**
-// * Print out usage
-// *
-// * @return usage string
-// */
-// protected
-// String
-// printHelp()
-// {
-// final String helpStr = getHelp().getHelp();
-// getPrompter().error( helpStr );
-// return helpStr;
-// }
-//
-// /**
-// * Print out invalid usage
-// *
-// * @return invalid usage string
-// */
-// protected
-// String
-// printError( String msg )
-// {
-// String errorStr = "E: Invalid usage";
-// if ( !StringUtil.isEmpty( msg ) ) {
-// errorStr = MessageFormat.format( "E: Invalid usage [{0}]", msg );
-// }
-// getPrompter().error( errorStr );
-// return errorStr;
-// }
-//
-// /**
-// * Entry method for execution
-// *
-// * @param args command line argument
-// *
-// * @throws Exception If unhandled exception occured
-// */
-// public void
-// run(
-// final String... args
-// )
-// throws Exception
-// {
-// Preference.register( "OS", new EnvironmentProvider() );
-// Preference.register( "JVM", new SystemPropertiesProvider() );
-// executor = new CommandLineExecutor(
-// new ConsolePrompter( System.out, new InputStreamReader( System.in ) )
-// );
-// if ( logger.isTraceEnabled() )
-// {
-// logger.trace( "OS Environment :\n{}", MapUtil.toString( System.getenv() ) );
-// logger.trace( "System properties :\n{}", MapUtil.toString( System.getProperties() ) );
-// logger.trace( "Args :{}", CollectionUtil.concatenate( Arrays.asList( args ), "," ) );
-// }
-//
-// try
-// {
-// Options cmds = this.getCommands();
-//
-// if(args.length == 0 && isPrintHelp()) {
-// printHelp();
-// return;
-// }
-// if(cmds.getOptions().size() > 0 && args.length > 0 && cmds.hasOption(args[0])) {
-// this.inputCmd = args[0];
-// String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
-// this.cmd = parse( newArgs);
-// }
-// else {
-// this.cmd = parse( args );
-// }
-//
-// if ( cmd.hasOption( OPT_QUIET ) )
-// {
-// executor = new CommandLineExecutor(
-// new ConsolePrompter( new PrintStream( new OutputStream() {
-// public void write(int b) throws IOException {
-// }
-// } ), new InputStreamReader( System.in ) )
-// );
-//
-// }
-//
-// if ( cmd.hasOption( OPT_HELP ) )
-// {
-// printHelp();
-//
-// logger.debug( "Help argument :{}", cmd.getArgList() );
-//
-// for ( String keyword : cmd.getArgs() )
-// {
-// printHelpDetail( keyword );
-// }
-// return ;
-// }
-//
-// execute( cmd );
-// }
-// catch ( final ParseException e )
-// {
-//
-// logger.error( "Parsing Error: ", e );
-// logger.trace( "Invalid usage." );
-//
-// // args include "-h, --help" then working 'help'
-// boolean bPrintHelp = false;
-// for ( String arg : args ) {
-// if ( ( "-" + OPT_HELP.substring( 0, 1 ) ).equals( arg ) || ( "--" + OPT_HELP ).equals( arg ) ) {
-// printHelp();
-// bPrintHelp = true;
-// break;
-// }
-// }
-//
-// if ( !bPrintHelp ) {
-// printError( e.getMessage() );
-// }
-//
-// if ( null != cmd ) {
-// logger.debug( "Help argument :{}", cmd.getArgList() );
-//
-// for ( String keyword : cmd.getArgs() )
-// {
-// printHelpDetail( keyword );
-// }
-//
-// }
-// }
-// catch ( final Throwable e )
-// {
-// handleException( e );
-// }
-// }
-//
-// /**
-// * Gets a command that user inputs.
-// *
-// * @return a command user inputs
-// */
-// protected String getInputCmd() {
-// return this.inputCmd;
-// }
-//
-// /**
-// * Handle uncaught exception
-// *
-// * @param e uncaught exception
-// */
-// protected
-// void
-// handleException(
-// final Throwable e
-// )
-// {
-// getPrompter().error( e.getMessage() );
-// logger.error( "Command stop because of exception", e );
-//
-// Throwable iter = e;
-// while ( null != iter )
-// {
-// final String localMessage = iter.getLocalizedMessage();
-// if ( null != localMessage )
-// {
-// logger.error( localMessage );
-// exit( 1 );
-// }
-//
-// final String message = iter.getMessage();
-// if ( null != message )
-// {
-// logger.error( message );
-// exit( 1 );
-// }
-// iter = iter.getCause();
-// }
-// }
-//
-// /**
-// * Parse arguments <code>args</code> with {@link CommandLineParser}
-// *
-// * @param args arguments to parse
-// *
-// * @return {@link CommandLine} to be parsed
-// *
-// * @throws InstantiationException If custom parser is invalid
-// * @throws IllegalAccessException If custom parser is invalid
-// * @throws ParseException If arguements is invalid
-// */
-// protected
-// CommandLine
-// parse(
-// final String... args
-// )
-// throws InstantiationException, IllegalAccessException, ParseException
-// {
-// final CommandLineParser parser = getParser();
-//
-// final Options options = getOptions();
-//
-// final CommandLine cmdLine = parser.parse( options, args );
-//
-// return cmdLine;
-// }
-//
-// /**
-// * Return default parser {@link Class}
-// *
-// * @return {@link Class} for default parser
-// */
-// protected
-// static
-// Class<?>
-// getDefaultParserClass()
-// {
-// return PosixParser.class;
-// }
-//
-// /**
-// * Return parser along user selection.
-// *
-// * The selection is specified JVM system properties
-// *
-// * Support two built-in parser
-// * <ul>
-// * <li>POSIX style - tar -zxvf foo.tar.gz</li>
-// * <li>GNU style - du --human-readable --max-depth=1</li>
-// * </ul>
-// *
-// * if you want use custom parser, specify class name
-// *
-// * @return {@link CommandLineParser} to parse
-// *
-// * @throws InstantiationException If custom parser can't be instantiated
-// * @throws IllegalAccessException If custom parser's constructor is NOT accessible
-// *
-// * @see #PROP_PARSER
-// * @see CommandLineParser
-// */
-// protected
-// CommandLineParser
-// getParser()
-// throws InstantiationException, IllegalAccessException {
-// final String parserName = System.getProperty( PROP_PARSER );
-// logger.trace( "Parser name :{}", parserName );
-// Class<?> parserClazz = getDefaultParserClass();
-// try {
-// if ( null != parserName )
-// {
-// parserClazz = Class.forName( parserName );
-// }
-// }
-// catch ( final ClassNotFoundException e )
-// {
-// if ( "posix".equalsIgnoreCase( parserName ) )
-// { // tar -zxvf foo.tar.gz
-// parserClazz = PosixParser.class;
-// }
-// else if ( "gnu".equalsIgnoreCase( parserName ) )
-// {
-// parserClazz = GnuParser.class;
-// }
-// else
-// {
-// logger.warn( "Invalid argument parser :" + parserName );
-// }
-// }
-//
-// logger.trace( "Parser class :{}", parserClazz );
-//
-// return (CommandLineParser) parserClazz.newInstance();
-// }
-//
-// /**
-// * Return managed command line arguments
-// *
-// * @return managed arguments
-// *
-// * @see CommandLine
-// */
-// protected
-// CommandLine
-// getCommandLine()
-// {
-// return this.cmd;
-// }
-
- /**
- * Return defined executor for command
- *
- * @return {@link ExecutionContext} to use
- */
- public
- Executor
- getExecutor()
- {
- if ( null == executor )
- {
- this.executor = new Executor();
- }
-
- return executor;
- }
-
- /**
- * Return {@link ExecutionContext} in cli
- *
- * @return {@link ExecutionContext}
- */
- public
- ExecutionContext
- getExecutionContext()
- {
- return getExecutor().getContext();
- }
-
- /**
- * Return {@link PolicyRegistry} in cli
- *
- * @return {@link PolicyRegistry}
- */
- public
- PolicyRegistry
- getPolicy()
- {
- return getExecutionContext().getPolicyRegistry();
- }
-
- /**
- * Return {@link FileHandler} in cli
- *
- * @return {@link FileHandler}
- *
- * @see #getExecutionContext()
- * @see StandardFileHandler
- */
- public
- FileHandler
- getFileHandler()
- {
- return getExecutionContext().getFileHandler();
- }
-
- /**
- * Return {@link Prompter} in cli
- *
- * @return {@link Prompter}
- *
- * @see #getExecutionContext()
- */
- public
- Prompter
- getPrompter()
- {
- return getExecutionContext().getPrompter();
- }
-
-// /**
-// * Returns whether print help or not if argument is empty.
-// *
-// * @return returns </code>true</code> if it prints help. Else, <code>false</code>.
-// */
-// protected
-// boolean
-// isPrintHelp() {
-// return false;
-// }
-//
-// /**
-// * Gets the uses description of the CLI.
-// *
-// * @return returns usage description string.
-// */
-// protected String getUsageDescription() {
-// return StringUtil.EMPTY_STRING;
-// }
-
- /**
- * Terminates the currently running command line interface.<p>
- * The argument serves as a status code<br>
- * by convention, a nonzero status code indicates abnormal termination.<br>
- * This method calls the System.exit method.
- *
- * @param status exit status.
- */
- public
- void
- exit(int status)
- {
- System.exit( status );
- }
-
- /**
- * Execute command
- *
- * Implement execution of command
- *
- * @param cmdLine arguments
- *
- * @throws Exception If Unhandled exception occured
- */
-// abstract protected void execute( CommandLine cmdLine ) throws Exception;
-
-
-}
+++ /dev/null
-/*
- * Web IDE - Command Line Interface
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil Kang <shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.ncli.ide.util;
-
-import static org.tizen.common.core.command.Policy.EXIST_OUT_FILE;
-import static org.tizen.common.core.command.Policy.NONEXIST_IN_FILE;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.tizen.common.Factory;
-import org.tizen.common.core.command.Policy;
-import org.tizen.common.core.command.policy.AbstractPolicy;
-import org.tizen.common.core.command.policy.FilePolicy;
-import org.tizen.common.core.command.policy.MessagePolicy;
-import org.tizen.common.core.command.policy.OptionPolicy;
-import org.tizen.common.core.command.policy.PolicyRegistry;
-import org.tizen.common.core.command.prompter.FileHandlingOption;
-
-/**
- * <p>
- * PolicyRegistryFactory.
- *
- * {@link Factory} to provide {@link PolicyRegistry}
- *
- * </p>
- *
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
- */
-public class
-PolicyRegistryFactory
-implements Factory<PolicyRegistry>
-{
- /**
- * Logger for this instance
- */
- protected final Logger logger =
- LoggerFactory.getLogger( PolicyRegistryFactory.class );
-
- /**
- * <p>
- * CLIPolicy.
- *
- * {@link Policy} when command line interface
- * </p>
- *
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
- *
- * @see PolicyRegistry, {@link Policy}
- */
- class CLIPolicy
- extends AbstractPolicy
- {
- /**
- * <p>
- * Constructor with <code>name</code>
- * </p>
- *
- * @param name policy name
- */
- public CLIPolicy( final String name )
- {
- super( name );
- }
-
- /* (non-Javadoc)
- * @see org.tizen.common.Adaptable#adapt(java.lang.Class)
- */
- @Override
- @SuppressWarnings("unchecked")
- public <T>
- T
- adapt(
- final Class<T> clazz
- )
- {
- if ( clazz.isAssignableFrom( FilePolicy.class ) )
- {
- return (T) FilePolicy.STOP_PROCESS;
- }
- else if ( clazz.isAssignableFrom( MessagePolicy.class) )
- {
- return (T) MessagePolicy.PROMPTER;
- }
- return null;
- }
-
- }
- /* (non-Javadoc)
- * @see org.tizen.common.Factory#create()
- */
- @Override
- public
- PolicyRegistry
- create()
- {
- final PolicyRegistry registry = new PolicyRegistry();
-
- registry.register( new CLIPolicy( EXIST_OUT_FILE ) );
- registry.register( new CLIPolicy( NONEXIST_IN_FILE ) );
-
- CLIPolicy existFileWhenCopy = new CLIPolicy(Policy.EXIST_FILE_WHEN_COPY) {
-
- @SuppressWarnings("unchecked")
- @Override
- public <T> T adapt(Class<T> clazz) {
- return (T)(new OptionPolicy(FileHandlingOption.OVERWRITE, FileHandlingOption.IGNORE, FileHandlingOption.OVERWRITE_ALL, FileHandlingOption.IGNORE_ALL, FileHandlingOption.CANCEL));
- }
- };
-
- registry.register(existFileWhenCopy);
- return registry;
- }
-
-}
+++ /dev/null
-/*
- * Command line interface
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Shingil Kang <shingil.kang@samsung.com>
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.ncli.ide.util;
-
-import static org.tizen.common.util.ObjectUtil.nvl;
-import static org.tizen.common.util.StringUtil.nvl;
-
-import java.util.Collection;
-
-import org.tizen.common.config.Preference;
-import org.tizen.common.core.command.ExecutionContext;
-import org.tizen.common.core.command.Prompter;
-import org.tizen.common.core.command.prompter.GenericOption;
-import org.tizen.common.verrari.IModelProvider;
-import org.tizen.common.verrari.template.CommonTemplate;
-
-public class
-TemplateModelProvider
-implements IModelProvider
-{
- protected static final Object NULL = new Object();
-
- protected final ExecutionContext context;
-
-
- public
- TemplateModelProvider(
- final ExecutionContext context
- )
- {
- this.context = context;
- }
-
- @Override
- public boolean isEmpty()
- {
- return false;
- }
-
- @Override
- public Collection<String> keys()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public
- Object
- getModel(
- final String key
- )
- {
- Object obj = context.getValue( key );
- if ( NULL.equals( obj ) )
- {
- return null;
- } else if ( null != obj )
- {
- return obj;
- }
-
- obj = Preference.getValue( key, null );
- if ( null != obj )
- {
- return obj;
- }
-
- obj = inputFromUser( key );
-
- this.context.setValue( key, nvl( obj, NULL ) );
-
- return obj;
- }
-
- protected Object inputFromUser( final String key )
- {
- final Prompter prompter = this.context.getPrompter();
- final GenericOption opt = new GenericOption();
-
- CommonTemplate current = CommonTemplate.getCurrentTemplate();
- String message = "Input " + key + " ?";
- if ( null != current )
- {
- message = nvl( current.getMessage( key ), message );
- }
- prompter.interact( message, opt );
-
- return opt.getAnswer();
- }
-
-}