<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/jsoup-1.6.3.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
org.tizen.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: lib/jsoup-1.6.3.jar,
+ .
<p>See <a href="about_files/LICENSE-2.0.htm">Apache License, Version 2.0</a>.</p>
+<h3>Third Party Content</h3>
+
+<p>The Content includes items that have been sourced from third parties as set out below. If you did not
+receive this Content directly from the Eclipse Foundation, the following is provided for informational
+purposes only, and you should look to the Redistributor's license for terms and conditions of use.</p>
+
+<h4>jsoup</h4>
+<p>
+jsoup is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods
+</p>
+
+<p>
+A copy of the license is included in <a href="about_files/jsoup-LICENSE.txt">about_files/jsoup-LICENSE.txt</a>. The home page is located at:
+<ul>
+<a href="http://jsoup.org/">http://jsoup.org/</a>
+</ul>
+</p>
+
</body>
</html>
\ No newline at end of file
--- /dev/null
+The MIT License\r
+\r
+Copyright (c) 2009, 2010, 2011, 2012 Jonathan Hedley <jonathan@hedley.net>\r
+\r
+Permission is hereby granted, free of charge, to any person obtaining a copy\r
+of this software and associated documentation files (the "Software"), to deal\r
+in the Software without restriction, including without limitation the rights\r
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+copies of the Software, and to permit persons to whom the Software is\r
+furnished to do so, subject to the following conditions:\r
+\r
+The above copyright notice and this permission notice shall be included in\r
+all copies or substantial portions of the Software.\r
+\r
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+THE SOFTWARE.
\ No newline at end of file
template/,\
about.html,\
about_files/,\
- OSGI-INF/
+ OSGI-INF/,\
+ lib/jsoup-1.6.3.jar
import java.io.BufferedWriter;
import java.util.Locale;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.tizen.common.util.FreeMarkerUtil;
import org.tizen.common.verrari.engine.AbstractTemplateEngine;
import org.tizen.common.verrari.model.MapModel;
import org.tizen.common.verrari.target.TargetUnit;
import org.tizen.common.verrari.template.FileTemplate;
-import org.xml.sax.SAXException;
import freemarker.template.Configuration;
import freemarker.template.Template;
-// TODO::
+/**
+ * FreemarkerTemplateEngine.
+ *
+ * @author ChangHyun Lee{@literal <changhyun1.lee@samsung.com>} (S-Core)
+ */
public class FreemarkerTemplateEngine extends AbstractTemplateEngine {
protected Configuration cfg;
super.generate(unit);
MapModel model = (MapModel) getModel(unit.getModelKey());
if (null == model) {
- // TODO::
+ throw new Exception("Model is Empty.");
}
FileTemplate template = (FileTemplate) getTemplate(unit.getTemplateKey());
if (null == template) {
- // TODO::
+ throw new Exception("Template is Empty.");
}
Template freemarkerTemplate = cfg.getTemplate(template.getContainer().getPath());
cfg.setEncoding(Locale.getDefault(), unit.getEncoding());
- // TODO::
+ freemarkerTemplate.process(model.getContainer(), new BufferedWriter(unit.getWriter()));
+ //freemarkertemp.process(model.getModel(), new OutputStreamWriter(System.out));
+
+ // TODO:: XML Parser
// Map<String, Object> root = new HashMap<String, Object>();
// NodeModel model2 = NodeModel.parse(new File("template/html/test.xml"));
// root.put("doc", model2);
- freemarkerTemplate.process(model.getContainer(), new BufferedWriter(unit.getWriter()));
- //freemarkertemp.process(model.getModel(), new OutputStreamWriter(System.out));
}
- @Override
+ @SuppressWarnings("static-access")
+ @Override
public String getEngineVersion() {
return cfg.getVersionNumber();
}
--- /dev/null
+/*
+ * Verrari - TemplateEngine
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * BonYong Lee <bonyong.lee@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.common.verrari.engine.jsoup;
+
+import java.util.Map;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Attribute;
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.tizen.common.verrari.engine.AbstractTemplateEngine;
+import org.tizen.common.verrari.model.MapModel;
+import org.tizen.common.verrari.target.TargetUnit;
+import org.tizen.common.verrari.template.FileTemplate;
+
+/**
+ * JsoupTemplateEngine.
+ * HTML Parser.
+ *
+ * @author ChangHyun Lee{@literal <changhyun1.lee@samsung.com>} (S-Core)
+ */
+public class JsoupTemplateEngine extends AbstractTemplateEngine {
+
+ public JsoupTemplateEngine() {
+ }
+
+ @Override
+ public void generate(TargetUnit unit) throws Exception {
+ super.generate(unit);
+
+ MapModel model = (MapModel) getModel(unit.getModelKey());
+ if (null == model) {
+ throw new Exception("Model is Empty.");
+ }
+
+ FileTemplate template = (FileTemplate) getTemplate(unit.getTemplateKey());
+ if (null == template) {
+ throw new Exception("Template is Empty.");
+ }
+
+ Document doc = Jsoup.parse(template.getContainer(), template.getEncoding());
+
+ @SuppressWarnings("unchecked")
+ Map<Object, Object> root = (Map<Object, Object>) model.getContainer();
+ for (Map.Entry<Object, Object> entry : root.entrySet()) {
+ Elements elements = doc.select((String) entry.getKey());
+ if (!elements.isEmpty()) {
+ Element element = elements.get(0);
+ Object attr = entry.getValue() ;
+ if (attr instanceof Attribute) {
+ element.attr(((Attribute) attr).getKey(), ((Attribute) attr).getValue());
+ } else if (attr instanceof Attributes){
+ Attributes attributes = (Attributes) attr;
+ for (Attribute attribute : attributes) {
+ element.attr(attribute.getKey(), attribute.getValue());;
+ }
+ } else {
+ element.attr((String)entry.getKey(), (String)attr);
+ }
+ }
+ }
+ unit.getWriter().write(doc.html());
+ unit.getWriter().flush();
+ }
+
+ @Override
+ public String getEngineVersion() {
+ // FIXME::
+ // Platform.getBundle("org.jsoup").getHeaders().get("Bundle-Version");
+ return "1.6.3";
+ }
+
+}
--- /dev/null
+package org.tizen.common.verrari.engine.jsoup;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.util.HashMap;
+
+import org.jsoup.nodes.Attribute;
+import org.jsoup.nodes.Attributes;
+import org.junit.Test;
+import org.tizen.common.verrari.model.MapModel;
+import org.tizen.common.verrari.target.TargetUnit;
+import org.tizen.common.verrari.template.FileTemplate;
+import org.tizen.common.verrari.template.ITemplate;
+
+public class JsoupTemplateEngineTest {
+
+ /**
+ * Test {@link JsoupTemplateEngine#generate(TargetUnit unit)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see JsoupTemplateEngine#generate(TargetUnit unit)
+ */
+ @Test
+ public void test_generate() throws Exception {
+ JsoupTemplateEngine engine = new JsoupTemplateEngine();
+ ITemplate template = new FileTemplate(new File("./test/src/org/tizen/common/verrari/engine/jsoup/TizenSingle.html"));
+ engine.getTemplateProvider().addTemplate("jsoupTemplate", template);
+
+ // selector - http://jsoup.org/apidocs/org/jsoup/select/Selector.html
+ MapModel mapModel = new MapModel(new HashMap<Object, Object>());
+ Attribute jquery = new Attribute("src", "/usr/share/tizen-web-ui-fw/latest/js/jquery.js");
+ mapModel.put("script[src$=tizen-web-ui-fw/latest/js/jquery.js]", jquery);
+
+ Attribute tizenwebuifwlibs = new Attribute("src", "/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js");
+ mapModel.put("script[src$=tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js]", tizenwebuifwlibs);
+
+ Attributes tizenwebuifw = new Attributes();
+ tizenwebuifw.put("src", "/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js");
+ tizenwebuifw.put("data-framework-theme", "tizen-white");
+ tizenwebuifw.put("data-framework-viewport-scale", "true");
+ mapModel.put("script[src$=tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js]", tizenwebuifw);
+
+ engine.getModelProvider().addModel("jsoupModel", mapModel);
+
+ File genTizenSingleFile = new File("./test/src/org/tizen/common/verrari/engine/jsoup/genTizenSingle.html");
+ TargetUnit unit = new TargetUnit("jsoupTemplate", "jsoupModel", new OutputStreamWriter(new FileOutputStream(genTizenSingleFile.getPath())), "UTF-8");
+ //TargetUnit unit = new TargetUnit("jsonTemplate", "jsonModel", new OutputStreamWriter(System.out), "UTF-8");
+ engine.generate(unit);
+
+ }
+
+}
--- /dev/null
+<!--
+ Copyright 2012 changhyun1.lee@samsung.com All rights reserved.
+-------------------------------------------------------------------------------------------------><!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, target-densityDpi=device-dpi" />
+ <meta name="description" content="Tizen template generated by Tizen Web IDE" />
+ <title>Tizen Web UI FW - Single</title>
+ <script src="./tizen-web-ui-fw/latest/js/jquery.js"></script>
+ <script src="./tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js"></script>
+ <script src="./tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js" data-framework-theme="tizen-gray" data-framework-viewport-scale="false"></script>
+ <!--NOTE:
+ Additional scripts and css files are to be placed here.
+ You can use jQuery namespace($) and all functionalities in jQuery
+ in your script. For example:
+
+ <script src="main.js"></script>
+ <link rel="stylesheet" href="my.css">
+
+ When you want to manipulate elements in your code, you have to
+ use domReady for your code to work properly, like this;
+
+ domReady(function(){ ... });
+ -->
+ <script type="text/javascript" src="./js/main.js"></script>
+ <link rel="stylesheet" type="text/css" href="./css/style.css" />
+ </head>
+ <body>
+ <div data-role="page">
+ <div data-role="header" data-position="fixed">
+ <h1>Single-Page Application </h1>
+ </div>
+ <!-- /header -->
+ <div data-role="content">
+ <p>This is a single page boilerplate template that you can copy to build your first Tizen Web UI Framework page.</p>
+ </div>
+ <!-- /content -->
+ <div data-role="footer" data-position="fixed">
+ <h4>Footer content</h4>
+ </div>
+ <!-- /footer -->
+ </div>
+ <!-- /page -->
+ </body>
+</html>
\ No newline at end of file
--- /dev/null
+<!--
+ Copyright 2012 changhyun1.lee@samsung.com All rights reserved.
+-------------------------------------------------------------------------------------------------><!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, target-densityDpi=device-dpi" />
+ <meta name="description" content="Tizen template generated by Tizen Web IDE" />
+ <title>Tizen Web UI FW - Single</title>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js" data-framework-theme="tizen-white" data-framework-viewport-scale="true"></script>
+ <!--NOTE:
+ Additional scripts and css files are to be placed here.
+ You can use jQuery namespace($) and all functionalities in jQuery
+ in your script. For example:
+
+ <script src="main.js"></script>
+ <link rel="stylesheet" href="my.css">
+
+ When you want to manipulate elements in your code, you have to
+ use domReady for your code to work properly, like this;
+
+ domReady(function(){ ... });
+ -->
+ <script type="text/javascript" src="./js/main.js"></script>
+ <link rel="stylesheet" type="text/css" href="./css/style.css" />
+ </head>
+ <body>
+ <div data-role="page">
+ <div data-role="header" data-position="fixed">
+ <h1>Single-Page Application </h1>
+ </div>
+ <!-- /header -->
+ <div data-role="content">
+ <p>This is a single page boilerplate template that you can copy to build your first Tizen Web UI Framework page.</p>
+ </div>
+ <!-- /content -->
+ <div data-role="footer" data-position="fixed">
+ <h4>Footer content</h4>
+ </div>
+ <!-- /footer -->
+ </div>
+ <!-- /page -->
+ </body>
+</html>
\ No newline at end of file