Example usage for java.lang Character Character

List of usage examples for java.lang Character Character

Introduction

In this page you can find the example usage for java.lang Character Character.

Prototype

@Deprecated(since = "9")
public Character(char value) 

Source Link

Document

Constructs a newly allocated Character object that represents the specified char value.

Usage

From source file:net.sf.json.TestJSONArray.java

public void testToList_Character() {
    List expected = new ArrayList();
    expected.add("A");
    expected.add("B");
    List chars = new ArrayList();
    chars.add(new Character('A'));
    chars.add(new Character('B'));
    JSONArray jsonArray = JSONArray.fromObject(chars);
    List actual = JSONArray.toList(jsonArray);
    Assertions.assertEquals(expected, actual);
}

From source file:Arrays.java

/**
 * Converts array of characters to Vector.
 *
 * @param pacData array of character data
 * @return equivalent collection of Character objects
 * @since 0.3.0.3/*from w w  w. ja  v a  2s. c o m*/
 */
public static Vector arrayToVector(final char[] pacData) {
    Vector oVector = new Vector(pacData.length);

    for (int i = 0; i < pacData.length; i++) {
        oVector.add(new Character(pacData[i]));
    }

    return oVector;
}

From source file:net.sf.json.TestJSONObject.java

public void testToBean_ObjectBean() {
    // FR 1611204
    ObjectBean bean = new ObjectBean();
    bean.setPbyte(Byte.valueOf("1"));
    bean.setPshort(Short.valueOf("1"));
    bean.setPint(Integer.valueOf("1"));
    bean.setPlong(Long.valueOf("1"));
    bean.setPfloat(Float.valueOf("1"));
    bean.setPdouble(Double.valueOf("1"));
    bean.setPchar(new Character('1'));
    bean.setPboolean(Boolean.TRUE);
    bean.setPstring("json");
    bean.setParray(new String[] { "a", "b" });
    bean.setPbean(new BeanA());
    List list = new ArrayList();
    list.add("1");
    list.add("2");
    bean.setPlist(list);/*from w  w  w.  j  av a 2s. c  o  m*/
    Map map = new HashMap();
    map.put("string", "json");
    bean.setPmap(map);
    bean.setPfunction(new JSONFunction("this;"));
    JSONObject json = JSONObject.fromObject(bean);
    Map classMap = new HashMap();
    classMap.put("pbean", BeanA.class);
    ObjectBean obj = (ObjectBean) JSONObject.toBean(json, ObjectBean.class, classMap);
    assertEquals(Integer.valueOf("1"), obj.getPbyte());
    assertEquals(Integer.valueOf("1"), obj.getPshort());
    assertEquals(Integer.valueOf("1"), obj.getPint());
    assertEquals(Integer.valueOf("1"), obj.getPlong());
    assertEquals(Double.valueOf("1"), obj.getPfloat());
    assertEquals(Double.valueOf("1"), obj.getPdouble());
    assertEquals("1", obj.getPchar());
    assertEquals("json", obj.getPstring());
    List l = new ArrayList();
    l.add("a");
    l.add("b");
    ArrayAssertions.assertEquals(l.toArray(), (Object[]) obj.getParray());
    l = new ArrayList();
    l.add("1");
    l.add("2");
    ArrayAssertions.assertEquals(l.toArray(), (Object[]) obj.getPlist());
    assertEquals(new BeanA(), obj.getPbean());
    assertTrue(obj.getPmap() instanceof MorphDynaBean);
}

From source file:zsk.JFCMainClient.java

/**
 * processing event of dropping a HTTP URL, YT-Video Image or plain text (URL) onto the frame
 * //from  w ww.j  a v  a  2 s  . com
 * seems not to work with M$-IE (8,9) - what a pity!
 */
public void drop(DropTargetDropEvent dtde) {
    Transferable tr = dtde.getTransferable();
    DataFlavor[] flavors = tr.getTransferDataFlavors();
    DataFlavor fl = null;
    String str = "";

    debugoutput("DataFlavors found: ".concat(Integer.toString(flavors.length)));
    for (int i = 0; i < flavors.length; i++) {
        fl = flavors[i];
        if (fl.isFlavorTextType() /* || fl.isMimeTypeEqual("text/html") || fl.isMimeTypeEqual("application/x-java-url") || fl.isMimeTypeEqual("text/uri-list")*/) {
            try {
                dtde.acceptDrop(dtde.getDropAction());
            } catch (Throwable t) {
            }
            try {
                if (tr.getTransferData(fl) instanceof InputStreamReader) {
                    debugoutput("Text-InputStream");
                    BufferedReader textreader = new BufferedReader((Reader) tr.getTransferData(fl));
                    String sline = "";
                    try {
                        while (sline != null) {
                            sline = textreader.readLine();
                            if (sline != null)
                                str += sline;
                        }
                    } catch (Exception e) {
                    } finally {
                        textreader.close();
                    }
                    str = str.replaceAll("<[^>]*>", ""); // remove HTML tags, especially a hrefs - ignore HTML characters like &szlig; (which are no tags)
                } else if (tr.getTransferData(fl) instanceof InputStream) {
                    debugoutput("Byte-InputStream");
                    InputStream input = new BufferedInputStream((InputStream) tr.getTransferData(fl));
                    int idata = input.read();
                    String sresult = "";
                    while (idata != -1) {
                        if (idata != 0)
                            sresult += new Character((char) idata).toString();
                        idata = input.read();
                    } // while
                    debugoutput("sresult: ".concat(sresult));
                } else {
                    str = tr.getTransferData(fl).toString();
                }
            } catch (IOException ioe) {
            } catch (UnsupportedFlavorException ufe) {
            }

            debugoutput("drop event text: ".concat(str).concat(" (").concat(fl.getMimeType()).concat(") "));
            // insert text into textfield - almost the same as user drops text/url into this field
            // except special characaters -> from http://de.wikipedia.org/wiki/GNU-Projekt (GNU is not Unix)(&bdquo;GNU is not Unix&ldquo;)
            // two drops from same source .. one time in textfield and elsewhere - maybe we change that later?!
            if (str.matches(szYTREGEX.concat("(.*)"))) {
                synchronized (JFCMainClient.frame.textinputfield) {
                    JFCMainClient.frame.textinputfield
                            .setText(str.concat(JFCMainClient.frame.textinputfield.getText()));
                }
                debugoutput("breaking for-loop with str: ".concat(str));
                break;
            }
        } else {
            String sv = "drop event unknown type: ".concat(fl.getHumanPresentableName());
            //output(sv);
            debugoutput(sv);
        }
    } // for

    dtde.dropComplete(true);
}

From source file:CustomControlExample.java

void setValue() {
    /* The parameter type must be the same as the get method's return type */
    String methodRoot = nameCombo.getText();
    Class returnType = getReturnType(methodRoot);
    String methodName = setMethodName(methodRoot);
    String value = setText.getText();
    Control[] controls = getExampleWidgets();
    for (int i = 0; i < controls.length; i++) {
        try {//from   w w w.ja v a2  s  .  c o m
            java.lang.reflect.Method method = controls[i].getClass().getMethod(methodName,
                    new Class[] { returnType });
            String typeName = returnType.getName();
            Object[] parameter = null;
            if (typeName.equals("int")) {
                parameter = new Object[] { new Integer(value) };
            } else if (typeName.equals("long")) {
                parameter = new Object[] { new Long(value) };
            } else if (typeName.equals("char")) {
                parameter = new Object[] {
                        value.length() == 1 ? new Character(value.charAt(0)) : new Character('\0') };
            } else if (typeName.equals("boolean")) {
                parameter = new Object[] { new Boolean(value) };
            } else if (typeName.equals("java.lang.String")) {
                parameter = new Object[] { value };
            } else if (typeName.equals("org.eclipse.swt.graphics.Point")) {
                String xy[] = value.split(",");
                parameter = new Object[] {
                        new Point(new Integer(xy[0]).intValue(), new Integer(xy[1]).intValue()) };
            } else if (typeName.equals("[Ljava.lang.String;")) {
                parameter = new Object[] { value.split(",") };
            } else {
                parameter = parameterForType(typeName, value, controls[i]);
            }
            method.invoke(controls[i], parameter);
        } catch (Exception e) {
            getText.setText(e.toString());
        }
    }
}

From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java

/**
 * Produce an XML message for an instance of the Character.
 * <br>/*from w  ww . ja v a  2  s.c  o  m*/
 * @param object the instance for which the message is to be produced.
 * @param parent the XML element that is to be the parent of the produced XML message.
 * @return the root element of the XML segment that was produced.
 * @exception JDOMException if there is an error producing the message.
 */
private Element produceMsg(Character object, Element parent) throws JDOMException {

    // ----------------------
    // Create the Character element ...
    // ----------------------
    Element charElement = new Element(TagNames.Elements.CHAR);

    String v = object.toString();
    if (v != null && v.length() != 0) {

        String toReplace = new String(new Character((char) 0x0).toString());
        v.replaceAll(toReplace, " ");
        charElement.setText(v.trim());

    }
    if (parent != null) {
        charElement = parent.addContent(charElement);
    }

    return charElement;
}

From source file:com.netspective.commons.xdm.XmlDataModelSchema.java

/**
 * Create a proper implementation of AttributeSetter for the given
 * attribute type.//from   w  ww  . ja  v  a2 s  .c  o  m
 */
private AttributeSetter createAttributeSetter(final Method m, final String attrName, final Class arg) {
    if (java.lang.String[].class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Object[] { TextUtils.getInstance().split(value, ",", true) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.String.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new String[] { value });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Character.class.equals(arg) || java.lang.Character.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Character[] { new Character(value.charAt(0)) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Byte.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Byte[] { new Byte(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Short.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Short[] { new Short(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Integer.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Integer[] { new Integer(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Long.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Long[] { new Long(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Float.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Float[] { new Float(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Double.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Double[] { new Double(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    }
    // boolean gets an extra treatment, because we have a nice method
    else if (java.lang.Boolean.class.equals(arg) || java.lang.Boolean.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Boolean[] { new Boolean(TextUtils.getInstance().toBoolean(value)) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    }
    // Class doesn't have a String constructor but a decent factory method
    else if (java.lang.Class.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    m.invoke(parent, new Class[] { Class.forName(value) });
                } catch (ClassNotFoundException ce) {
                    if (pc != null) {
                        DataModelException dme = new DataModelException(pc, ce);
                        pc.addError(dme);
                        if (pc.isThrowErrorException())
                            throw dme;
                    } else
                        log.error(ce);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.io.File.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                // resolve relative paths through DataModel
                m.invoke(parent, new File[] { pc != null ? pc.resolveFile(value) : new File(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (RedirectValueSource.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                TextUtils textUtils = TextUtils.getInstance();
                ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value);
                if (vs == null) {
                    // better to throw an error here since if there are objects which are based on null/non-null
                    // value of the value source, it is easier to debug
                    pc.addError("Unable to find ValueSource '" + value + "' to wrap in RedirectValueSource at "
                            + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                            + ". Valid value sources are: "
                            + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                }
                try {
                    RedirectValueSource redirectValueSource = (RedirectValueSource) arg.newInstance();
                    redirectValueSource.setValueSource(vs);
                    m.invoke(parent, new RedirectValueSource[] { redirectValueSource });
                } catch (InstantiationException e) {
                    pc.addError("Unable to create RedirectValueSource for '" + value + "' at "
                            + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                            + ". Valid value sources are: "
                            + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (ValueSource.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                TextUtils textUtils = TextUtils.getInstance();
                ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value);
                if (vs == null) {
                    // better to throw an error here since if there are objects which are based on null/non-null
                    // value of the value source, it is easier to debug
                    if (pc != null)
                        pc.addError("Unable to create ValueSource for '" + value + "' at "
                                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                                + ". Valid value sources are: " + textUtils
                                        .join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                    else
                        log.error("Unable to create ValueSource for '" + value + ". Valid value sources are: "
                                + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(),
                                        ", "));
                }
                m.invoke(parent, new ValueSource[] { vs });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Command.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    m.invoke(parent, new Command[] { Commands.getInstance().getCommand(value) });
                } catch (CommandNotFoundException e) {
                    if (pc != null) {
                        pc.addError("Unable to create Command for '" + value + "' at "
                                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                                + ".");
                        if (pc.isThrowErrorException())
                            throw new DataModelException(pc, e);
                    } else
                        log.error("Unable to create Command for '" + value + "'", e);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (XdmEnumeratedAttribute.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    XdmEnumeratedAttribute ea = (XdmEnumeratedAttribute) arg.newInstance();
                    ea.setValue(pc, parent, attrName, value);
                    m.invoke(parent, new XdmEnumeratedAttribute[] { ea });
                } catch (InstantiationException ie) {
                    pc.addError(ie);
                    if (pc.isThrowErrorException())
                        throw new DataModelException(pc, ie);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (XdmBitmaskedFlagsAttribute.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    XdmBitmaskedFlagsAttribute bfa;
                    NestedCreator creator = (NestedCreator) nestedCreators.get(attrName);
                    if (creator != null)
                        bfa = (XdmBitmaskedFlagsAttribute) creator.create(parent);
                    else
                        bfa = (XdmBitmaskedFlagsAttribute) arg.newInstance();
                    bfa.setValue(pc, parent, attrName, value);
                    m.invoke(parent, new XdmBitmaskedFlagsAttribute[] { bfa });
                } catch (InstantiationException ie) {
                    pc.addError(ie);
                    if (pc.isThrowErrorException())
                        throw new DataModelException(pc, ie);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Locale.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                String[] items = TextUtils.getInstance().split(value, ",", true);
                switch (items.length) {
                case 1:
                    m.invoke(parent, new Locale[] { new Locale(items[0], "") });
                    break;

                case 2:
                    m.invoke(parent, new Locale[] { new Locale(items[1], items[2]) });
                    break;

                case 3:
                    m.invoke(parent, new Locale[] { new Locale(items[1], items[2], items[3]) });
                    break;

                case 4:
                    if (pc != null)
                        throw new DataModelException(pc, "Too many items in Locale constructor.");
                    else
                        log.error("Too many items in Locale constructor: " + value);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (ResourceBundle.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                String[] items = TextUtils.getInstance().split(value, ",", true);
                switch (items.length) {
                case 1:
                    m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0]) });
                    break;

                case 2:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], Locale.US.getCountry())) });
                    break;

                case 3:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], items[2])) });
                    break;

                case 4:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], items[2], items[3])) });

                default:
                    if (pc != null)
                        throw new DataModelException(pc, "Too many items in ResourceBundle constructor.");
                    else
                        log.error("Too many items in Locale constructor: " + value);

                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Properties.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                // when specifying properties the following are valid
                // <xxx properties="abc.properties">  <!-- load this property file, throw exception if not found -->
                // <xxx properties="abc.properties:optional">  <!-- load this property file, no exception if not found -->
                // <xxx properties="/a/b/abc.properties,/x/y/def.properties"> <!-- load the first property file found, throw exception if none found -->
                // <xxx properties="/a/b/abc.properties,/x/y/def.properties:optional"> <!-- load the first property file found, no exception if none found -->

                final TextUtils textUtils = TextUtils.getInstance();
                final String[] options = textUtils.split(value, ":", true);
                final String[] fileNames = textUtils.split(value, ",", true);
                final Properties properties;
                switch (options.length) {
                case 1:
                    properties = PropertiesLoader.loadProperties(fileNames, true, false);
                    m.invoke(parent, new Properties[] { properties });
                    break;

                case 2:
                    properties = PropertiesLoader.loadProperties(fileNames,
                            options[1].equals("optional") ? false : true, false);
                    if (properties != null)
                        m.invoke(parent, new Properties[] { properties });
                    break;

                default:
                    if (pc != null)
                        throw new DataModelException(pc,
                                "Don't know how to get properties from PropertiesLoader: " + value);
                    else
                        log.error("Don't know how to get properties from PropertiesLoader:" + value);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else {
        // worst case. look for a public String constructor and use it
        try {
            final Constructor c = arg.getConstructor(new Class[] { java.lang.String.class });
            return new AttributeSetter() {
                public void set(XdmParseContext pc, Object parent, String value)
                        throws InvocationTargetException, IllegalAccessException, DataModelException {
                    try {
                        Object attribute = c.newInstance(new String[] { value });
                        m.invoke(parent, new Object[] { attribute });
                    } catch (InstantiationException ie) {
                        if (pc != null) {
                            pc.addError(ie);
                            if (pc.isThrowErrorException())
                                throw new DataModelException(pc, ie);
                        } else
                            log.error(ie);
                    }
                }

                public boolean isInherited() {
                    return !m.getDeclaringClass().equals(bean);
                }

                public Class getDeclaringClass() {
                    return m.getDeclaringClass();
                }
            };
        } catch (NoSuchMethodException nme) {
        }
    }

    return null;
}

From source file:com.topsec.tsm.sim.report.util.ReportUiUtil.java

/**
 * sanitize HTML?TAG? "&" --> "&amp" "<" --> "&lt" ">" --> "&gt" "\""
 * --> "&quot" "\r\n" --> "<br>" &amp; &#39;
 * //w w w  .  j a  v  a2s . co  m
 * @param str
 *            strin?
 * @return String ??
 * @version 20040810
 */

public static String sanitize(String s) {
    if (s == null)
        return null;
    StringBuffer stringbuffer = new StringBuffer();
    StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
    for (char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next()) {
        String s1 = (String) sanitizeTable.get(new Character(c));
        if (s1 != null)
            stringbuffer.append(s1);
        else
            stringbuffer.append(c);
    }

    return stringbuffer.toString();
}

From source file:org.globus.gsi.gssapi.GlobusGSSContextImpl.java

/**
 * Accept a delegated credential.//from w  w w  .  ja va2s.  co m
 *
 * This function drives the accepting side of the credential
 * delegation process. It is expected to be called in tandem with the
 * {@link #initDelegation(GSSCredential, Oid, int, byte[], int, int)
 * initDelegation} function.
 * <BR>
 * The behavior of this function can be modified by
 * {@link GSSConstants#GSS_MODE GSSConstants.GSS_MODE} context
 * option. The
 * {@link GSSConstants#GSS_MODE GSSConstants.GSS_MODE}
 * option if set to
 * {@link GSIConstants#MODE_SSL GSIConstants.MODE_SSL}
 * results in tokens that are not wrapped.
 *
 * @param lifetime
 *        The requested period of validity (seconds) of the delegated
 *        credential.
 * @return A token that should be passed to <code>initDelegation</code> if
 *        <code>isDelegationFinished</code> returns false. May be null.
 * @exception GSSException containing the following major error codes:
 *            <code>GSSException.FAILURE</code>
 */
public byte[] acceptDelegation(int lifetime, byte[] buf, int off, int len) throws GSSException {

    logger.debug("Enter acceptDelegation: " + delegationState);

    if (this.gssMode != GSIConstants.MODE_SSL && buf != null && len > 0) {
        buf = unwrap(buf, off, len);
        off = 0;
        len = buf.length;
    }

    byte[] token = null;

    switch (delegationState) {

    case DELEGATION_START:

        this.delegationFinished = false;

        if (len != 1 && buf[off] != GSIConstants.DELEGATION_CHAR) {
            throw new GlobusGSSException(GSSException.FAILURE, GlobusGSSException.DELEGATION_ERROR,
                    "delegError00", new Object[] { new Character((char) buf[off]) });
        }

        try {
            /*DEL
                            Vector certChain = this.conn.getCertificateChain();
            */
            Certificate[] certChain;
            try {
                certChain = this.sslEngine.getSession().getPeerCertificates();
            } catch (SSLPeerUnverifiedException e) {
                certChain = null;
            }
            if (certChain == null || certChain.length == 0) {
                throw new GlobusGSSException(GSSException.FAILURE, GlobusGSSException.DELEGATION_ERROR,
                        "noClientCert");
            }

            X509Certificate tmpCert =
                    /*DEL
                    PureTLSUtil.convertCert((X509Cert)certChain.lastElement());
                    */
                    (X509Certificate) certChain[0];

            token = generateCertRequest(tmpCert);
        } catch (GeneralSecurityException e) {
            throw new GlobusGSSException(GSSException.FAILURE, e);
        }

        this.delegationState = DELEGATION_COMPLETE_CRED;
        break;

    case DELEGATION_COMPLETE_CRED:

        ByteArrayInputStream in = null;
        X509Certificate[] chain = null;
        LinkedList certList = new LinkedList();
        X509Certificate cert = null;
        try {
            in = new ByteArrayInputStream(buf, off, len);
            while (in.available() > 0) {
                cert = CertificateLoadUtil.loadCertificate(in);
                certList.add(cert);
            }

            chain = new X509Certificate[certList.size()];
            chain = (X509Certificate[]) certList.toArray(chain);

            verifyDelegatedCert(chain[0]);

        } catch (GeneralSecurityException e) {
            throw new GlobusGSSException(GSSException.FAILURE, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                    logger.warn("Unable to close streamreader.");
                }
            }
        }

        X509Credential proxy = new X509Credential(this.keyPair.getPrivate(), chain);

        this.delegatedCred = new GlobusGSSCredentialImpl(proxy, GSSCredential.INITIATE_AND_ACCEPT);

        this.delegationState = DELEGATION_START;
        this.delegationFinished = true;
        break;

    default:
        throw new GSSException(GSSException.FAILURE);
    }

    logger.debug("Exit acceptDelegation");

    if (this.gssMode != GSIConstants.MODE_SSL && token != null) {
        // XXX: Why wrap() only when not in MODE_SSL?
        return wrap(token, 0, token.length);
    } else {
        return token;
    }
}

From source file:com.hexidec.ekit.EkitCore.java

public void keyTyped(KeyEvent ke) {

    // log.debug("> keyTyped(" + ke.getKeyChar() + ")");

    Element elem;//from w ww.j a  v  a2 s  .com
    int pos = this.getCaretPosition();
    int repos = -1;
    if (ke.getKeyChar() == KeyEvent.VK_BACK_SPACE) {
        try {
            if (pos > 0) {
                // if (jtpMain.getSelectedText() != null) {
                // htmlUtilities.delete();
                // refreshOnUpdate();
                // return;
                // } else {
                int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset();
                if (sOffset == jtpMain.getSelectionStart()) {
                    boolean content = true;
                    if (htmlUtilities.checkParentsTag(HTML.Tag.LI)) {
                        elem = htmlUtilities.getListItemParent();
                        content = false;
                        int so = elem.getStartOffset();
                        int eo = elem.getEndOffset();
                        if (so + 1 < eo) {
                            char[] temp = jtpMain.getText(so, eo - so).toCharArray();
                            for (char c : temp) {
                                if (!(new Character(c)).isWhitespace(c)) {
                                    content = true;
                                }
                            }
                        }
                        if (!content) {
                            htmlUtilities.removeTag(elem, true);
                            this.setCaretPosition(sOffset - 1);
                            refreshOnUpdate();
                            return;
                        } else {
                            jtpMain.replaceSelection("");
                            refreshOnUpdate();
                            return;
                        }
                    } else if (htmlUtilities.checkParentsTag(HTML.Tag.TABLE)) {
                        jtpMain.setCaretPosition(jtpMain.getCaretPosition() - 1);
                        ke.consume();
                        refreshOnUpdate();
                        return;
                    }
                }
                jtpMain.replaceSelection("");
                refreshOnUpdate();
                return;
                // }
            }
        } catch (BadLocationException ble) {
            logException("BadLocationException in keyTyped method", ble);
            new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                    Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
        } // catch (IOException ioe) {
          // logException("IOException in keyTyped method", ioe);
          // new SimpleInfoDialog(this.getWindow(),
          // Translatrix.getTranslationString("Error"), true,
          // Translatrix.getTranslationString("ErrorIOException"),
          // SimpleInfoDialog.ERROR);
          // }
          // finally {
          // log.debug("< keyTyped");
          // }
    } else if (ke.getKeyChar() == KeyEvent.VK_ENTER && !inlineEdit) {
        try {
            if (htmlUtilities.checkParentsTag(HTML.Tag.UL) == true
                    | htmlUtilities.checkParentsTag(HTML.Tag.OL) == true) {
                elem = htmlUtilities.getListItemParent();
                int so = elem.getStartOffset();
                int eo = elem.getEndOffset();
                char[] temp = this.getTextPane().getText(so, eo - so).toCharArray();
                boolean content = false;
                for (char c : temp) {
                    if (!(new Character(c)).isWhitespace(c)) {
                        content = true;
                    }
                }
                if (content) {
                    int end = -1;
                    int j = temp.length;
                    do {
                        j--;
                        if (new Character(temp[j]).isLetterOrDigit(temp[j])) {
                            end = j;
                        }
                    } while (end == -1 && j >= 0);
                    j = end;
                    do {
                        j++;
                        if (!new Character(temp[j]).isSpaceChar(temp[j])) {
                            repos = j - end - 1;
                        }
                    } while (repos == -1 && j < temp.length);
                    if (repos == -1) {
                        repos = 0;
                    }
                }
                if (!content) {
                    removeEmptyListElement(elem);
                } else {
                    if (this.getCaretPosition() + 1 == elem.getEndOffset()) {
                        insertListStyle(elem);
                        this.setCaretPosition(pos - repos);
                    } else {
                        int caret = this.getCaretPosition();
                        String tempString = this.getTextPane().getText(caret, eo - caret);
                        if (tempString != null && tempString.length() > 0) {
                            this.getTextPane().select(caret, eo - 1);
                            this.getTextPane().replaceSelection("");
                            htmlUtilities.insertListElement(tempString);
                            Element newLi = htmlUtilities.getListItemParent();
                            this.setCaretPosition(newLi.getEndOffset() - 1);
                        }
                    }
                }
            } else if (enterIsBreak) {
                insertBreak();
                ke.consume();
            }
        } catch (BadLocationException ble) {
            logException("BadLocationException in keyTyped method", ble);
            new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                    Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
        } catch (IOException ioe) {
            logException("IOException in keyTyped method", ioe);
            new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                    Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
        }
        // finally {
        // log.debug("< keyTyped");
        // }
    }
}