📄 nodetemplateimpl.java
字号:
/*
* ====================================================================
* The JSP Tree Software License, Version 1.1
*
* (this license is derived and fully compatible with the Apache Software
* License - see http://www.apache.org/LICENSE.txt)
*
* Copyright (c) 2002-2005 jsptree.sourceforge.net . All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* jsptree.sourceforge.net (http://jsptree.sourceforge.net/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "JSP Tree" must not be used to endorse or promote
* products derived from this software without prior written permission.
* For written permission, please contact modano@users.sourceforge.net .
*
* 5. Products derived from this software may not be called "JSP Tree",
* nor may "JSP Tree" appear in their name, without prior written
* permission of jsptree.sourceforge.net.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
package net.sf.jsptree.template;
import java.util.Iterator;
import java.util.Map;
/**
* @author Vladislav Kamensky
*/
public class NodeTemplateImpl implements NodeTemplate {
public static final String NODE = "node.tmpl";
public static final String SELECTED_NODE = "selected_node.tmpl";
public static final String OPENED_NODE = "opened_node.tmpl";
public static final String OPENED_NODE_LAST_CHILD = "opened_node_last.tmpl";
public static final String OPENED_SELECTED_NODE = "opened_selected_node.tmpl";
public static final String OPENED_SELECTED_NODE_LAST_CHILD = "opened_selected_node_last.tmpl";
public static final String CLOSED_NODE = "closed_node.tmpl";
public static final String CLOSED_NODE_LAST_CHILD = "closed_node_last.tmpl";
public static final String CLOSED_SELECTED_NODE = "closed_selected_node.tmpl";
public static final String CLOSED_SELECTED_NODE_LAST_CHILD = "closed_selected_node_last.tmpl";
public static final String LEAF = "leaf.tmpl";
public static final String LEAF_LAST_CHILD = "leaf_last.tmpl";
public static final String LEAF_SELECTED = "leaf_selected.tmpl";
public static final String LEAF_SELECTED_LAST_CHILD = "leaf_selected_last.tmpl";
public static final String LEFT_SHIFT = "left_shift.tmpl";
public static final String RIGHT_SHIFT = "right_shift.tmpl";
public static final String[] DEFAULT_TEMPLATES = {NODE,
SELECTED_NODE,
LEAF,
LEAF_SELECTED,
LEFT_SHIFT,
RIGHT_SHIFT};
public static final String[] MENU_TEMPLATES = {OPENED_NODE,
OPENED_SELECTED_NODE,
CLOSED_NODE,
CLOSED_SELECTED_NODE,
LEAF,
LEAF_SELECTED,
LEFT_SHIFT};
public static final String[] FOLDER_TEMPLATES = {OPENED_NODE,
OPENED_NODE_LAST_CHILD,
OPENED_SELECTED_NODE,
OPENED_SELECTED_NODE_LAST_CHILD,
CLOSED_NODE,
CLOSED_NODE_LAST_CHILD,
CLOSED_SELECTED_NODE,
CLOSED_SELECTED_NODE_LAST_CHILD,
LEAF,
LEAF_LAST_CHILD,
LEAF_SELECTED,
LEAF_SELECTED_LAST_CHILD,
LEFT_SHIFT,
RIGHT_SHIFT};
private String m_body;
NodeTemplateImpl(String p_body) {
m_body = p_body;
}
public String getHTML() {
return m_body;
}
public String getHTML(String p_tag, String p_value) {
return searchAndReplace(m_body, p_tag, p_value);
}
public String getHTML(Map p_tags) {
String a_body = m_body;
for (Iterator a_it = p_tags.keySet().iterator(); a_it.hasNext();) {
String a_key = (String) a_it.next();
String a_value = (String) p_tags.get(a_key);
a_body = searchAndReplace(a_body, a_key, a_value);
}
return a_body;
}
public static String searchAndReplace(String p_str, String p_search, String p_replace) {
if (p_str == null || p_search == null || p_replace == null) return p_str;
String a_left = null;
String a_right = null;
int result = 0;
while ((result = p_str.indexOf(p_search, result - 1)) != -1) {
a_left = p_str.substring(0, result);
a_right = p_str.substring(result + p_search.length());
result += p_replace.length() + 1;
p_str = a_left + p_replace + a_right;
if (result > p_str.length()) {
break;
}
}
return p_str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -