This is my work around:

public class FilterUtil {

    private static char startMark = 0x02;
    private static char endMark = 0x03;

    public static Filter whereclauseToFilter(String where) {
        Filter filter = null;
        try {
            StringBuilder sb = new StringBuilder();
            for (int i = 0, count = where.length(); i < count; i++) {
                char c = where.charAt(i);
                if (c < 256) {
                    sb.append(c);
                } else {
                    String enc = URLEncoder.encode(String.valueOf(c),
"UTF-8");
                    enc = enc.replaceAll("\\%", "");
                    sb.append(startMark + enc + endMark);
                }
            }
            String encode = sb.toString();
            Filter f = ECQL.toFilter(encode);
            decodeFilter(f);
            filter = f;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return filter;
    }

    @SuppressWarnings("unchecked")
    private static void decodeFilter(Filter filter)
            throws UnsupportedEncodingException {
        if (filter instanceof OrImpl) {
            OrImpl impl = (OrImpl) filter;
            for (Iterator<Filter> itr = impl.getFilterIterator();
itr.hasNext();) {
                Filter f = itr.next();
                decodeFilter(f);
            }
        } else if (filter instanceof AndImpl) {
            AndImpl impl = (AndImpl) filter;
            for (Iterator<Filter> itr = impl.getFilterIterator();
itr.hasNext();) {
                Filter f = itr.next();
                decodeFilter(f);
            }
        } else if (filter instanceof NotImpl) {
            NotImpl impl = (NotImpl) filter;
            Filter f = impl.getFilter();
            decodeFilter(f);
        } else if (filter instanceof LikeFilterImpl) {
            LikeFilterImpl impl = (LikeFilterImpl) filter;
            String encode = impl.getLiteral();
            impl.setLiteral(decodeString(encode));
        } else if (filter instanceof IsEqualsToImpl) {
            IsEqualsToImpl impl = (IsEqualsToImpl) filter;
            decodeExpression(impl.getExpression1());
            decodeExpression(impl.getExpression2());
        } else if (filter instanceof IsNotEqualToImpl) {
            IsNotEqualToImpl impl = (IsNotEqualToImpl) filter;
            decodeExpression(impl.getExpression1());
            decodeExpression(impl.getExpression2());
        }
    }

    private static void decodeExpression(Expression exp)
            throws UnsupportedEncodingException {
        if (exp instanceof LiteralExpressionImpl) {
            LiteralExpressionImpl impl = (LiteralExpressionImpl) exp;
            String encode = String.valueOf(impl.getValue());
            impl.setValue(decodeString(encode));
        }
    }

    private static String decodeString(String encode)
            throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder();
        int i = 0, count = encode.length();
        while (i < count) {
            int start = encode.indexOf(startMark, i);
            if (start >= 0) {
                sb.append(encode.substring(i, start));
            } else {
                sb.append(encode.substring(i));
                return sb.toString();
            }

            int end = encode.indexOf(endMark, i);
            if (end > 0) {
                i = end + 1;

                String enc = encode.substring(start + 1, end);
                StringBuilder sbEnc = new StringBuilder();
                for (int j = 0, l = enc.length(); j < l; j += 2) {
                    sbEnc.append("%" + enc.charAt(j) + enc.charAt(j + 1));
                }
                String dec = URLDecoder.decode(sbEnc.toString(), "UTF-8");
                sb.append(dec);
            } else {
                sb.append(encode.substring(i + 1));
                i = count;
            }
        }
        return sb.toString();
    }

}


2010/9/21 Mario Basa <[email protected]>

> Hello.
>
> Just curious if this can apply to non-latin, double-byte characters as
> well. As in:
>
>  field_name="東京"     (Tokyo)
>
> This has been a major show stopper for us over here in Japan.
>
> Mario.
>
>
> On Thu, Sep 16, 2010 at 4:13 PM, Mauricio Pazos <[email protected]>
> wrote:
> > Hello Jesse: I have improved cql/ecql to support this feature. It is
> > available in trunk.
> >
> > Example: "crazy_name" like 'abc%'
> >
> > cheers
> >
> > On Monday 09 August 2010 02:45:50 pm Mauricio Pazos wrote:
> >> On Saturday 07 August 2010 10:17:21 pm Jesse Eichar wrote:
> >> > Its hard to explain the reasoning, but I have a feature with a
> terrible
> >> > attribute name but I need to  access it using CQL (a dynamic external
> >> > graphic).  The attribute name is basically {[crazy_name]} (including
> the
> >> > {[ characters).  Is there a way that I can escape the illegal
> characters
> >> > in CQL? or perhaps I have to create a property accessor to add the
> >> > illegal character.
> >> >
> >> > Thoughts?
> >> >
> >> > Jesse
> >>
> >> Hi Jesse, I guess that your  crazy_name has local characters like
> >> characters with different types of accents or others.
> >>
> >> Unfortunately the OGC CQL specification only allows:
> >>
> >> <simple Latin letter> ::= <simple Latin upper case letter>
> >>
> >>                            | <simple Latin lower case letter>
> >>
> >> <simple Latin upper case letter> ::=
> >>        A | B | C | D | E | F | G | H | I | J | K | L | M | N | O
> >>
> >>        | P | Q | R | S | T | U | V | W | X | Y | Z
> >>
> >> <simple Latin lower case letter> ::=
> >>        a | b | c | d | e | f | g | h | i | j | k | l | m | n | o
> >>
> >>        | p | q | r | s | t | u | v | w | x | y | z
> >>
> >> I opened the following issue to solve that sort of problems
> >> http://jira.codehaus.org/browse/GEOT-3122
> >>
> >> The idea is to use the same SQL strategy, that is, using double quote
> >>
> >> "crazy_name"
> >>
> >> cheers
> >
> > --
> > Mauricio Pazos
> > www.axios.es
> >
> >
> ------------------------------------------------------------------------------
> > Start uncovering the many advantages of virtual appliances
> > and start using them to simplify application deployment and
> > accelerate your shift to cloud computing.
> > http://p.sf.net/sfu/novell-sfdev2dev
> > _______________________________________________
> > Geotools-gt2-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> >
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to