+/*
+ * Verrari - Realm
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GyeongSeok Seo <gyeongseok.seo@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.template;
import static org.tizen.common.util.ArrayUtil.pickupFirst;
import static org.tizen.common.util.IOUtil.getBytes;
import static org.tizen.common.util.IOUtil.tryClose;
-import static org.tizen.common.util.StringUtil.nvl;
import static org.tizen.common.verrari.template.TemplateConstants.ATTR_COPY;
import static org.tizen.common.verrari.template.TemplateConstants.ATTR_EXCLUDE;
import static org.tizen.common.verrari.template.TemplateConstants.ATTR_INCLUDE;
import static org.tizen.common.verrari.template.TemplateConstants.ATTR_MAPPER;
import static org.tizen.common.verrari.template.TemplateConstants.ATTR_MAPPING;
-import static org.tizen.common.verrari.template.TemplateConstants.ATTR_VERSION;
-import static org.tizen.common.verrari.template.TemplateConstants.DV_MAPPER;
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
-import java.util.jar.Attributes.Name;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.tizen.common.FactoryWithArgument;
-import org.tizen.common.core.command.ExecutionContext;
+
import org.tizen.common.file.Filter;
-import org.tizen.common.file.SimpleFileFilter;
-import org.tizen.common.file.filter.WildCardFilterFactory;
-import org.tizen.common.util.FileUtil;
-import org.tizen.common.util.IOUtil;
-import org.tizen.common.util.ReflectionUtil;
import org.tizen.common.util.StringUtil;
import org.tizen.common.verrari.IModelProvider;
import org.tizen.common.verrari.ITemplateEngine;
import org.tizen.common.verrari.Template;
import org.tizen.common.verrari.TemplateException;
import org.tizen.common.verrari.engine.TemplateEngineFactory;
-import org.tizen.common.verrari.exception.InvalidMapperException;
-import org.tizen.common.verrari.model.ModelManager;
import org.tizen.common.verrari.realm.StandardRealm;
import org.tizen.common.verrari.util.BufferFactory;
-
+/**
+ * <p>
+ * DirectoryTemplate
+ *
+ * Built-in {@link Template} to provide RI
+ *
+ * </p>
+ *
+ * @author GyeongSeok Seo{@literal <gyeongseok.seo@samsung.com>} (S-Core)
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ *
+ * @see Template
+ */
public class
DirectoryTemplate
extends CommonTemplate
{
/**
- * name mapper
- *
- * @see Mapper
+ * Directory Template's root path
*/
- protected Mapper mapper = null;
-
protected String templateRootPath = null;
- public DirectoryTemplate( String path ) throws IOException, TemplateException {
- if ( StringUtil.isEmpty( path ) && !(new File( path ).isDirectory()) ) {
+ /**
+ * Directory Template's root file, it must directory
+ */
+ protected File templateRootFile = null;
+
+ /**
+ * constructor with template contents in path, path is must directory
+ *
+ * @param path in template contents
+ *
+ * @throws TemplateException If template mapping is invalid
+ */
+ public DirectoryTemplate( String path ) throws TemplateException {
+ if ( StringUtil.isEmpty( path ) ||
+ !( this.templateRootFile = new File( path ) ).isDirectory() ) {
throw new TemplateException();
}
- this.templateRootPath = path;
+ this.templateRootPath = this.templateRootFile.getAbsolutePath();
}
+ /**
+ * constructor with template contents in file, file is must directory
+ *
+ * @param file in template contents
+ *
+ * @throws TemplateException If template mapping is invalid
+ */
+ public DirectoryTemplate( File file ) throws TemplateException {
+ if ( null == file || !file.isDirectory() ) {
+ throw new TemplateException();
+ }
+ this.templateRootFile = file;
+ this.templateRootPath = this.templateRootFile.getAbsolutePath();
+ }
+
+ /**
+ * pre-changing MANIFEST.MF file, because of MANIFEST.MF file also marking to template engine
+ *
+ * @param manifestfile
+ * @param models
+ * @throws IOException
+ * @throws TemplateException
+ */
private
void
templateManifest( File manifestfile, IModelProvider models ) throws IOException, TemplateException
}
}
+ /**
+ * directory template's message bundle loading.
+ * It working on recursive
+ *
+ * @param root
+ * @throws IOException
+ */
protected
void
recursiveBundleLoad( File root ) throws IOException {
for ( File file : lists ) {
if ( file.isDirectory() ) {
recursiveBundleLoad( file );
+ continue;
}
String name = file.getName();
FileInputStream in = null;
}
}
+ /**
+ * directory template's MANIFES.MF loading.
+ * It working on recursive
+ *
+ * @param root
+ * @param models
+ * @throws IOException
+ * @throws TemplateException
+ */
protected
void
recursiveManifestLoad( File root, IModelProvider models ) throws IOException, TemplateException {
for ( File file : lists ) {
if ( file.isDirectory() ) {
recursiveManifestLoad( file, models );
+ continue;
}
String name = file.getName();
}
}
+ /**
+ * copy file and template file classification
+ *
+ * @param root
+ * @param templates
+ * @param templateFilter
+ * @param copyFilter
+ * @throws IOException
+ */
+ protected
+ void
+ recursiveAddTemplate( File root, TemplateManager templates, Filter templateFilter, Filter copyFilter ) throws IOException {
+ File [] lists = root.listFiles();
+
+ for ( File file : lists ) {
+ if ( file.isDirectory() ) {
+ recursiveAddTemplate( file, templates, templateFilter, copyFilter );
+ continue;
+ }
+ String relativePath = file.getAbsolutePath().replace( templateRootPath+System.getProperty("file.separator"), "");
+ final String name = relativePath;
+
+ logger.trace( "Name :{}", name );
+
+ FileInputStream in = new FileInputStream( file );
+ final byte[] contents = getBytes( in );
+ templates.addTemplate( name, new InMemoryTemplate(contents, "utf-8", BufferFactory.getInstance() ) );
+
+ if ( copyFilter.accept( "/", name ) )
+ {
+ logger.debug( "{} is copy target", name );
+ this.copyNames.add( name );
+ continue;
+ }
+ else if ( !templateFilter.accept( "/", name ) )
+ {
+ logger.info( "{} filtered", name );
+ continue;
+ }
+ else
+ {
+ this.templateNames.add( name );
+ }
+ }
+ }
+
protected
void
- preload( String path, IModelProvider models ) throws IOException, TemplateException
+ preload( File rootFile, IModelProvider models ) throws IOException, TemplateException
{
// current template setting in context
context.set( this );
// bundles setting
- File rootFile = new File( path );
recursiveBundleLoad( rootFile );
// preload MANIFEST.MF
*/
protected
void
- load( String path )
+ load( File rootFile )
throws TemplateException, IOException
{
this.engine = TemplateEngineFactory.getInstance().create();
final String mappings = attrs.get( ATTR_MAPPING );
this.mapper = getMapper( attrs.get( ATTR_MAPPER ), mappings );
-
-
- final Filter filter = createFilter( StandardRealm.separate( includes ), StandardRealm.separate( excludes ) );
+ final Filter templateFilter = createFilter( StandardRealm.separate( includes ), StandardRealm.separate( excludes ) );
final Filter copyFilter = createFilter( StandardRealm.separate( copies ), null );
// Process files
-// JarEntry iter = null;
-// while ( null != ( iter = in.getNextJarEntry() ) )
-// {
-// if ( iter.isDirectory() )
-// {
-// continue;
-// }
-// final String name = iter.getName();
-// logger.trace( "Name :{}", name );
-// final byte[] contents = getBytes( in );
-//
-// templates.addTemplate( name, new InMemoryTemplate(contents, "utf-8", BufferFactory.getInstance() ) );
-// if ( copyFilter.accept( "/", name ) )
-// {
-// logger.debug( "{} is copy target", name );
-// this.copyNames.add( name );
-// continue;
-// }
-// else if ( !filter.accept( "/", name ) )
-// {
-// logger.info( "{} filtered", name );
-// continue;
-// }
-// else
-// {
-// this.templateNames.add( name );
-// }
-//
-// }
-
+ recursiveAddTemplate( rootFile, templates, templateFilter, copyFilter );
+
engine.setTemplateProvider( templates );
}
protected void pretemplate(IModelProvider models) throws IOException, TemplateException {
- preload( this.templateRootPath, models );
- load( this.templateRootPath );
+ preload( templateRootFile, models );
+ load( templateRootFile );
}
@Override
} catch (IOException e) {
throw new TemplateException( e );
}
- //storage.getTarget(key);
-
-
+
logger.info( "End template process..." );
System.out.println("End template process..." );
}
+/*
+ * Verrari - Realm
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GyeongSeok Seo <gyeongseok.seo@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.template;
import static org.junit.Assert.*;
import java.io.File;
-import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import org.tizen.common.config.Preference;
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.core.command.prompter.GenericOption;
import org.tizen.common.core.command.prompter.NopPrompter;
import org.tizen.common.file.VirtualFileHandler;
import org.tizen.common.verrari.AbstractTestCase;
import org.tizen.common.verrari.IModelProvider;
import static org.tizen.common.util.ObjectUtil.nvl;
-import static org.tizen.common.util.StringUtil.nvl;
+/**
+ * DirectoryTemplateTest.
+ *
+ * Test case for {@link DirectoryTemplate}
+ *
+ * @author GyeongSeok Seo{@literal <gyeongseok.seo@samsung.com>} (S-Core)
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ *
+ * @see DirectoryTemplate
+ *
+ */
public class DirectoryTemplateTest
extends AbstractTestCase
{
protected IModelProvider models = null;
protected String path = "./test/src/org/tizen/common/verrari/template/web-ui-fw/0.1.1";
+ /**
+ * Test {@link DirectoryTemplate#getAttribute(String)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see DirectoryTemplate#getAttribute(String)
+ */
@Test
public
void
test_getAttribute()
throws Exception
{
- String path = "./test/src/org/tizen/common/verrari/template/web-ui-fw/0.1.1";
- File file = new File( path );
- path = file.getAbsolutePath();
+ File rootFile = new File( path );
+ template.preload( rootFile, models );
- DirectoryTemplate template = new DirectoryTemplate( path );
Collection<String> keys = template.getAttributeKeys();
Iterator<String> iter = keys.iterator();
assertNotNull( attribute );
}
}
-
+
+ /**
+ * Test {@link DirectoryTemplate#preload(File, IModelProvider)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see DirectoryTemplate#preload(File, IModelProvider)
+ */
@Test
public
void
test_preload()
throws Exception
{
- template.preload(path, models);
-
+ File rootFile = new File( path );
+ template.preload( rootFile, models );
+
String expected = "0.1.1_Theme/original/*";
String actual = template.getAttribute( TemplateConstants.ATTR_COPY );
- assertEquals(expected, actual);
+ assertEquals( expected, actual );
+ }
+
+ /**
+ * Test {@link DirectoryTemplate#load(File)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see DirectoryTemplate#load(File)
+ */
+ @Test
+ public
+ void
+ test_load()
+ throws Exception
+ {
+ File rootFile = new File( path );
+ template.preload( rootFile, models );
+ template.load( rootFile );
}
/**