Package org.xulfaces.utils

Source Code of org.xulfaces.utils.XulUtils

/*
*   xulfaces : bring XUL power to Java
*  
*  Copyright (C) 2005  Olivier SCHMITT
*  This library is free software; you can redistribute it and/or
*  modify it under the terms of the GNU Lesser General Public
*  License as published by the Free Software Foundation; either
*  version 2.1 of the License, or (at your option) any later version.
*
*  This library is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*  Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public
*  License along with this library; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package org.xulfaces.utils;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import org.xulfaces.bridge.Bridge;

/**
*
* @author kito31
* @version $Id: XulUtils.java,v 1.12 2007/07/17 20:27:26 kito31 Exp $
*/
public abstract class XulUtils {
 
  static private String[] ISO_8859_1_ENTITIES = new String[]{
        "nbsp",
        "iexcl",
        "cent",
        "pound",
        "curren",
        "yen",
        "brvbar",
        "sect",
        "uml",
        "copy",
        "ordf",
        "laquo",
        "not",
        "shy",
        "reg",
        "macr",
        "deg",
        "plusmn",
        "sup2",
        "sup3",
        "acute",
        "micro",
        "para",
        "middot",
        "cedil",
        "sup1",
        "ordm",
        "raquo",
        "frac14",
        "frac12",
        "frac34",
        "iquest",
        "Agrave",
        "Aacute",
        "Acirc",
        "Atilde",
        "Auml",
        "Aring",
        "AElig",
        "Ccedil",
        "Egrave",
        "Eacute",
        "Ecirc",
        "Euml",
        "Igrave",
        "Iacute",
        "Icirc",
        "Iuml",
        "ETH",
        "Ntilde",
        "Ograve",
        "Oacute",
        "Ocirc",
        "Otilde",
        "Ouml",
        "times",
        "Oslash",
        "Ugrave",
        "Uacute",
        "Ucirc",
        "Uuml",
        "Yacute",
        "THORN",
        "szlig",
        "agrave",
        "aacute",
        "acirc",
        "atilde",
        "auml",
        "aring",
        "aelig",
        "ccedil",
        "egrave",
        "eacute",
        "ecirc",
        "euml",
        "igrave",
        "iacute",
        "icirc",
        "iuml",
        "eth",
        "ntilde",
        "ograve",
        "oacute",
        "ocirc",
        "otilde",
        "ouml",
        "divide",
        "oslash",
        "ugrave",
        "uacute",
        "ucirc",
        "uuml",
        "yacute",
        "thorn",
        "yuml"
    };

 
  private static String LEFT_DOUBLE_QUOTATION_MARK ="“"//“
  private static String RIGHT_DOUBLE_QUOTATION_MARK = "”"//”
  private static String LEFT_SINGLE_QUOTATION_MARK ="‘"; //  ‘
  private static String RIGHT_SINGLE_QUOTATION_MARK ="’"//’ (including English possessives and contractions)
 
  public static boolean isEmptyElement(String name) {
    if(name.equals("script")){
      return true;
    }   
    else if(name.equals("command")){
      return true;
    }
    else if(name.equals("button")){
      return true;
    }
    else if(name.equals("toolbarbutton")){
      return true;
    }
    else if(name.equals("textbox")){
      return true;
    }
    else if(name.equals("checkbox")){
      return true;
    }
    else if(name.equals("textbox")){
      return true;
    }
    else if(name.equals("treecol")){
      return true;
    }
    else if(name.equals("treecell")){
      return true;
    }
    else if(name.equals("menuitem")){
      return true;
    }
    else if(name.equals("listheader")){
      return true;
    }
    else if(name.equals("listcol")){
      return true;
    }
    else if(name.equals("listcell")){
      return true;
    }
    else if(name.equals("radio")){
      return true;
    }
    else if(name.equals("label")){
      return true;
    }
    else if(name.equals("xfc:updateZone")){
      return true;
    }
    else if(name.equals("xfc:removeZone")){
      return true;
    }
    else if(name.equals("xfc:redirect")){
      return true;
    }   
    return false;
  }

  public static Bridge getBridge(){
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{bridge}");
    Bridge bridge = (Bridge) valueBinding.getValue(facesContext);
    return bridge;
  }
 
  public static String encodeString(String string){
    String encodedString = string;
    encodedString = encodedString.replace("<","&lt;");
    encodedString = encodedString.replace(">","&gt;");
    return encodedString;
   
  }
 
 
 
  /**
     * Return character as a decimal escape.  Hex escapes are smaller than
     * the decimal version, but Netscape didn't support hex escapes until
     * 4.7.4.
     */
    public static String toDecimalEscape(char ch) {
      StringBuffer result = new StringBuffer();
        if (ch == '\u20ac') {
          result.append("&euro;");
            return result.toString();
        }
        result.append("&#");
        // Formerly used String.valueOf().  This version tests out
        // about 40% faster in a microbenchmark (and on systems where GC is
        // going gonzo, it should be even better)
        int i = (int) ch;
        if (i > 10000) {
            result.append('0' + (i / 10000));
            i = i % 10000;
            result.append('0' + (i / 1000));
            i = i % 1000;
            result.append('0' + (i / 100));
            i = i % 100;
            result.append('0' + (i / 10));
            i = i % 10;
            result.append('0' + i);
        } else if (i > 1000) {
            result.append('0' + (i / 1000));
            i = i % 1000;
            result.append('0' + (i / 100));
            i = i % 100;
            result.append('0' + (i / 10));
            i = i % 10;
            result.append('0' + i);
        } else {
            result.append('0' + (i / 100));
            i = i % 100;
            result.append('0' + (i / 10));
            i = i % 10;
            result.append('0' + i);
        }
        result.append(';');
        return result.toString();
    }
}
TOP

Related Classes of org.xulfaces.utils.XulUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.