⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiwebutility.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */

package com.sourcetap.sfa.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericEntityException;


/**
 * DOCUMENT ME!
 *
 */
public class UIWebUtility extends UIUtility {
	public static final String module = UIWebUtility.class.getName();
    public static final String HTML_NAME_PREFIX_CURRENT = "";
    public static final String HTML_NAME_PREFIX_ORIGINAL = "#orig_";
    public static final String HTML_COMPOSITE_FORM_NAME = "compositeForm";

    public UIWebUtility() {
    }

    /**
     * DOCUMENT ME!
     *
     * @param sectionName 
     * @param fieldInfo 
     * @param row 
     *
     * @return 
     */
    public static String getHtmlName(String sectionName, UIFieldInfo fieldInfo, int row) {
        return getHtmlName(sectionName,
            fieldInfo.getUiAttribute().getUiEntity().getEntityName(),
            fieldInfo.getUiAttribute().getAttributeName(), row);
    }

	public static String getHtmlName(String sectionName, String entityName, String attributeName, int row)
	{
		return getParamName(HTML_NAME_PREFIX_CURRENT, sectionName, entityName, attributeName, row);
	}
    /**
     * DOCUMENT ME!
     *
     * @param sectionName 
     * @param fieldInfo 
     * @param row 
     *
     * @return 
     */
    public static String getHtmlNameOriginal(String sectionName,
        UIFieldInfo fieldInfo, int row) {
        return getParamName(HTML_NAME_PREFIX_ORIGINAL, sectionName,
            fieldInfo.getUiAttribute().getUiEntity().getEntityName(),
            fieldInfo.getUiAttribute().getAttributeName(), row);
    }

    /**
     * DOCUMENT ME!
     *
     * @param htmlNamePrefix 
     * @param sectionName 
     * @param entityName 
     * @param attributeName 
     * @param row 
     *
     * @return 
     */
    public static String getParamName(String htmlNamePrefix,
        String sectionName, String entityName, String attributeName, int row) {
        return htmlNamePrefix + sectionName + "_" + entityName + "_" +
        attributeName + "_" + String.valueOf(row);
    }

    /** Converts a parameter variable name to a database name.
     * The naming conventions used to allow for this are as follows:
     * a database name (table or column) is in all capital letters,
     * and the words are separated by an underscore
     * (for example: NEAT_ENTITY_NAME or RANDOM_FIELD_NAME);
     * a parameter name or screens section name is a mix of
     * upper and lowercase with underscores mixed in.
     * The parameter name follows the format:
     * [original value][screensection][entity][attribute][number]
     * For example "AccountListReportQuery_Account_accountName_0"
     * [][AccountListReportQuery][Account][accountName][0]
     * will return ACCOUNT.ACCOUNT_NAME
     * @param reportName the screen section used for the report
     * @param paramName the parameter name on the form generated by the ui screen builder
     * @return The database name
     */
    public static String getDbNameFromParamName(String reportName,
        String paramName) {
        String lsReturn = "";

        String sectionName = getSectionNameFromParamName(paramName);

        if (sectionName.equals(reportName)) {

            // We have a parameter that is part of this report
            String entityName = getEntityFromParamName(paramName);

            String attributeName = getAttribFromParamName(paramName);

            String tableName = javaNameToDbName(entityName);

            String columnName = javaNameToDbName(attributeName);

            lsReturn = tableName + "." + columnName;
        }

        return lsReturn;
    }

    /** Converts a Java variable name to a database name.
     * The naming conventions used to allow for this are as follows:
     * a database name (table or column) is in all capital letters,
     * and the words are separated by an underscore
     * (for example: NEAT_ENTITY_NAME or RANDOM_FIELD_NAME);
     * a Java name (ejb or field) is in all lower case letters,
     * except the letter at the beginning of each word
     * (for example: NeatEntityName or RandomFieldName).
     * The convention of using a capital letter at the beginning of a class name in Java,
     * or a lower-case letter for the beginning of a variable name in Java is also used
     * along with the Java name convention above.
     * @param javaName The Java variable name
     * @return The database name
     */
    public static String javaNameToDbName(String javaName) {
        if (javaName == null) {
            return null;
        }

        if (javaName.length() <= 0) {
            return "";
        }

        StringBuffer dbName = new StringBuffer();
        dbName.append(Character.toUpperCase(javaName.charAt(0)));

        int namePos = 1;

        while (namePos < javaName.length()) {
            char curChar = javaName.charAt(namePos);

            if (Character.isUpperCase(curChar)) {
                dbName.append('_');
            }

            dbName.append(Character.toUpperCase(curChar));
            namePos++;
        }

        return dbName.toString();
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static String getPrefixFromParamName(String paramName) {
        if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
            // The "original" indicator is on the beginning of the parameter name. return it.
            return HTML_NAME_PREFIX_ORIGINAL;
        }

        return HTML_NAME_PREFIX_CURRENT;
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static String getSectionNameFromParamName(String paramName) {
        if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
            // The "original" indicator is on the beginning of the parameter name. Remove it.
            paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL.length());
        }

        if (paramName.indexOf("_") < 0) {
            // The underscore was not found. The param name has no entity ID in it.
            return "";
        }

        StringTokenizer tokUnderscore = new StringTokenizer(paramName, "_");

        return tokUnderscore.nextToken();
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static String getEntityFromParamName(String paramName) {
        if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
            // The "original" indicator is on the beginning of the parameter name. Remove it.
            paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL.length());
        }

        if (paramName.indexOf("_") < 0) {
            // The underscore was not found. The param name has no entity ID in it.
            return "";
        }

        StringTokenizer tokUnderscore = new StringTokenizer(paramName, "_");
        String sectionName = tokUnderscore.nextToken();

        return tokUnderscore.nextToken();
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static String getAttribFromParamName(String paramName) {
        if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
            // The "original" indicator is on the beginning of the parameter name. Remove it.
            paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL.length());
        }

        if (paramName.indexOf("_") < 0) {
            // The underscore was not found. The param name is the attribute ID.
            return paramName;
        }

        StringTokenizer tokUnderscore = new StringTokenizer(paramName, "_");
        String sectionName = tokUnderscore.nextToken();
        String entityName = tokUnderscore.nextToken();

        return tokUnderscore.nextToken();
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static String getRowFromParamName(String paramName) {
        StringTokenizer tokUnderscore = new StringTokenizer(paramName, "_");
        String sectionName = tokUnderscore.nextToken();
        String entityName = tokUnderscore.nextToken();
        String attributeName = tokUnderscore.nextToken();

        return tokUnderscore.nextToken();
    }

    /**
     * DOCUMENT ME!
     *
     * @param keyMap 
     * @param entityDetailsVector 
     *
     * @return 
     */
    public static String getUrlArgs(HashMap keyMap, Vector entityDetailsVector) {
        // Get the key values for the header so we can make the arrow button pull up the right header row.
        String displayHtml = "";
        Iterator keyMapIterator = keyMap.keySet().iterator();
        int keyCount = 0;

        while (keyMapIterator.hasNext()) {
            String key = (String) keyMapIterator.next();
            String valueSource = (String) keyMap.get(key);

            try {
                String value = decodeAttributeValue(valueSource,
                        entityDetailsVector, "");
                keyCount++;
                displayHtml += ("&" + key + "=" + value);
            } catch (Exception e) {
                Debug.logVerbose(
                    "[UIWebUtility.getUrlArgs] An error occurred while trying to read the value for attribute " +
                    valueSource + ": " + e.getLocalizedMessage(), module);
            }
        }

        keyMapIterator = null;

        return displayHtml;
    }

    /**
     * DOCUMENT ME!
     *
     * @param keyMap 
     * @param entityDetailsVector 
     * @param spaces 
     *
     * @return 
     */
    public static String getHiddenArgs(HashMap keyMap,
        Vector entityDetailsVector, String spaces) {
        // Get the key values for the header so we can make the arrow button pull up the right header row.
        String displayHtml = "";
        Iterator keyMapIterator = keyMap.keySet().iterator();
        int keyCount = 0;

        while (keyMapIterator.hasNext()) {
            String key = (String) keyMapIterator.next();
            String valueSource = (String) keyMap.get(key);

            try {
                String value = decodeAttributeValue(valueSource,
                        entityDetailsVector, "");
                keyCount++;
                displayHtml += (spaces + "<INPUT TYPE=\"hidden\" NAME=\"" +
                key + "\" VALUE=\"" + value + "\">\n");
            } catch (Exception e) {
                Debug.logError(
                    "[UIWebUtility.getHiddenArgs] An error occurred while trying to read the value for attribute " +
                    valueSource + ": " + e.getLocalizedMessage(), module);
            }
        }

        keyMapIterator = null;

        return displayHtml;
    }

    /**
     * DOCUMENT ME!
     *
     * @param keyMap 
     * @param spaces 
     *
     * @return 
     */
    public static String getHiddenArgs(HashMap keyMap, String spaces) {
        // Get the key values for the header so we can make the arrow button pull up the right header row.
        String displayHtml = "";
        Iterator keyMapIterator = keyMap.keySet().iterator();
        int keyCount = 0;

        while (keyMapIterator.hasNext()) {
            String key = (String) keyMapIterator.next();
            String value = (String) keyMap.get(key);
            keyCount++;
            displayHtml += (spaces + "<INPUT TYPE=\"hidden\" NAME=\"" + key +
            "\" VALUE=\"" + value + "\">\n");
        }

        keyMapIterator = null;

        return displayHtml;
    }

    /**
     * DOCUMENT ME!
     *
     * @param paramName 
     *
     * @return 
     */
    public static boolean checkReservedParameterName(String paramName) {
        if (!paramName.equals("action") && !paramName.equals("rowCount") &&
                !paramName.equals("queryId") && !paramName.equals("queryName") &&
                !paramName.equals("startRow") &&
                !paramName.equals("rowsPerPage") &&
                (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) < 0)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiDisplayObject 
     * @param htmlName 
     * @param dataValue 
     * @param displayValue 
     * @param entityDetailsVector 
     *
     * @return 
     */
    public static String displayFieldReadOnly(UIDisplayObject uiDisplayObject,
        String htmlName, String dataValue, String displayValue,
        Vector entityDetailsVector) {
        return displayFieldReadOnly(uiDisplayObject, htmlName, dataValue,
            displayValue,
            UIWebUtility.translateAttribAnchorHrefDef(
                uiDisplayObject.getAttribAnchorHrefDef(), entityDetailsVector,
                UIWebUtility.getAttribFromParamName(htmlName)),
            UIWebUtility.translateAttribAnchorTarget(
                uiDisplayObject.getAttribAnchorTarget()));
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiDisplayObject 
     * @param htmlName 
     * @param dataValue 
     * @param displayValue 
     * @param anchorHref 
     * @param anchorTarget 
     *
     * @return 
     */
    public static String displayFieldReadOnly(UIDisplayObject uiDisplayObject,
        String htmlName, String dataValue, String displayValue,
        String anchorHref, String anchorTarget) {
        StringBuffer displayHtml = new StringBuffer();
        displayHtml.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + htmlName +
            "\" VALUE='" + dataValue + "'>\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -