/*
 * Copyright 2014 the original author or authors.
 *
 * 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.
 */
package leap.htpl;

import java.util.HashMap;
import java.util.Map;

public class DefaultHtplPage implements HtplPage {
	
	protected final HtplTemplate 		template;
	protected final Map<String, Object> properties = new HashMap<String, Object>(1);
	
	public DefaultHtplPage(HtplTemplate template) {
		this.template = template;
	}

	@Override
	public Object getProperty(String name) {
		return properties.get(name);
	}

	@Override
	public void setProperty(String name, Object value) {
		properties.put(name, value);
	}

	@Override
	public Map<String, Object> getProperties() {
		return properties;
	}
	
	@Override
    public void putProperties(Map<String, ? extends Object> m) {
		if(null != m){
			properties.putAll(m);
		}
	}

	@Override
	public HtplTemplate getTemplate() {
		return template;
	}
}

@@ -629,16 +629,43 @@
 .htpl;%0A%0A
+import leap.lang.Strings;%0A%0A
 import j
@@ -682,16 +682,16 @@
 ashMap;%0A
-
 import j
@@ -961,16 +961,146 @@
 mplate;%0A
+%09%09if(!Strings.isEmpty(template.getName())) %7B%0A            this.setProperty(%22name%22, extractPageName(template.getName()));%0A        %7D%0A
 %09%7D%0A%0A%09@Ov
@@ -1559,13 +1559,171 @@
 mplate;%0A
-
 %09%7D
+%0A%0A%09private String extractPageName(String path) %7B%0A        int index = path.lastIndexOf('/');%0A        return index %3C 0 ? path : path.substring(index + 1);%0A    %7D
 %0A%7D%0A

add page.name property by default