Package java.text

Examples of java.text.Collator


     *            the source string to compare with this string
     */
    public int collate(String source) {
        if (source == null)
            data_RaiseNilOperandExcpt();
        Collator myCollator = Collator.getInstance();
        return myCollator.compare(source, theString.toString());
    }
View Full Code Here


     *            the source string to compare with this string
     */
    public int collate(String source) {
        if (source == null)
            data_RaiseNilOperandExcpt();
        Collator myCollator = Collator.getInstance();
        return myCollator.compare(source, theString.toString());
    }
View Full Code Here

     */

    public static StringCollator makeCollation(Configuration config, String uri, Properties props)
            throws XPathException {

        Collator collator = null;
        StringCollator stringCollator = null;

        // If a specific collation class is requested, this overrides everything else

        String classAtt = props.getProperty("class");
        if (classAtt != null) {
            Object comparator = config.getInstance(classAtt, null);
            if (comparator instanceof Collator) {
                collator = (Collator)comparator;
            } else if (comparator instanceof StringCollator) {
                stringCollator = (StringCollator)comparator;
            } else if (comparator instanceof Comparator) {
                stringCollator = new NamedCollation(uri, (Comparator)comparator);
            } else {
                throw new XPathException("Requested collation class " + classAtt + " is not a Comparator");
            }
        }

        // If rules are specified, create a RuleBasedCollator

        if (collator == null && stringCollator == null) {
            String rulesAtt = props.getProperty("rules");
            if (rulesAtt != null) {
                try {
                    collator = new RuleBasedCollator(rulesAtt);
                } catch (ParseException e) {
                    throw new XPathException("Invalid collation rules: " + e.getMessage());
                }
            }

            // Start with the lang attribute

            if (collator == null) {
                String langAtt = props.getProperty("lang");
                if (langAtt!=null) {
                    collator = Collator.getInstance(getLocale(langAtt));
                } else {
                    collator = Collator.getInstance()// use default locale
                }
            }
        }

        if (collator != null) {
            // See if there is a strength attribute
            String strengthAtt = props.getProperty("strength");
            if (strengthAtt!=null) {
                if (strengthAtt.equals("primary")) {
                    collator.setStrength(Collator.PRIMARY);
                } else if (strengthAtt.equals("secondary")) {
                    collator.setStrength(Collator.SECONDARY);
                } else if (strengthAtt.equals("tertiary")) {
                    collator.setStrength(Collator.TERTIARY);
                } else if (strengthAtt.equals("identical")) {
                    collator.setStrength(Collator.IDENTICAL);
                } else {
                    throw new XPathException("strength must be primary, secondary, tertiary, or identical");
                }
            }

            // Look for the properties ignore-case, ignore-modifiers, ignore-width

            String ignore = props.getProperty("ignore-width");
            if (ignore != null) {
                if (ignore.equals("yes") && strengthAtt == null) {
                    collator.setStrength(Collator.TERTIARY);
                } else if (ignore.equals("no")) {
                    // no-op
                } else {
                    throw new XPathException("ignore-width must be yes or no");
                }
            }

            ignore = props.getProperty("ignore-case");
            if (ignore != null && strengthAtt == null) {
                if (ignore.equals("yes")) {
                    collator.setStrength(Collator.SECONDARY);
                } else if (ignore.equals("no")) {
                    // no-op
                } else {
                    throw new XPathException("ignore-case must be yes or no");
                }
            }

            ignore = props.getProperty("ignore-modifiers");
            if (ignore != null) {
                if (ignore.equals("yes") && strengthAtt == null) {
                    collator.setStrength(Collator.PRIMARY);
                } else if (ignore.equals("no")) {
                    // no-op
                } else {
                    throw new XPathException("ignore-modifiers must be yes or no");
                }
            }

            // The ignore-symbols property is ignored

            // See if there is a decomposition attribute
            String decompositionAtt = props.getProperty("decomposition");
            if (decompositionAtt!=null) {
                if (decompositionAtt.equals("none")) {
                    collator.setDecomposition(Collator.NO_DECOMPOSITION);
                } else if (decompositionAtt.equals("standard")) {
                    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
                } else if (decompositionAtt.equals("full")) {
                    collator.setDecomposition(Collator.FULL_DECOMPOSITION);
                } else {
                    throw new XPathException("decomposition must be non, standard, or full");
                }
            }
        }

        if (stringCollator == null) {
            stringCollator = new NamedCollation(uri, collator);
        }

        // See if there is a case-order property
        String caseOrder = props.getProperty("case-order");
        if (caseOrder != null && !"#default".equals(caseOrder)) {
            // force base collator to ignore case differences
            if (collator != null) {
                collator.setStrength(Collator.SECONDARY);
            }
            if (caseOrder.equals("lower-first")) {
                stringCollator = new LowercaseFirstCollator(stringCollator);
            } else if (caseOrder.equals("upper-first")) {
                stringCollator = new UppercaseFirstCollator(stringCollator);
View Full Code Here

  }


  Comparator comparatorStringLocale(final String fieldName,
      Locale locale) {
    final Collator collator = Collator.getInstance(locale);
    return new ShardComparator(fieldName) {
      public final int compare(final Object o1, final Object o2) {
        ShardDoc sd1 = (ShardDoc) o1;
        ShardDoc sd2 = (ShardDoc) o2;
        Comparable v1 = (Comparable)sortVal(sd1);
        Comparable v2 = (Comparable)sortVal(sd2);
        if (v1==v2)
          return 0;
        if (v1==null)
          return 1;
        if(v2==null)
          return -1;
        return -collator.compare(v1,v2);
      }
    };
  }
View Full Code Here

                                    XPathContext context,
                                    boolean isFirst) throws XPathException {

        Pattern match = keydef.getMatch();
        Expression use = keydef.getUse();
        Collator collator = keydef.getCollation();
        NodeInfo sourceRoot = doc;
        NodeInfo curr = sourceRoot;
        XPathContextMajor xc = context.newContext();
        xc.setOrigin(keydef);
View Full Code Here

            putIndex(doc, fingerprint, itemType, index, context);
        }

        KeyDefinition definition = (KeyDefinition)getKeyDefinitions(fingerprint).get(0);
               // the itemType and collation will be the same for all keys with the same name
        Collator collation = definition.getCollation();

        Object val;
        if (itemType==Type.STRING || itemType==Type.UNTYPED_ATOMIC) {
            if (collation==null) {
                val = value.getStringValue();
            } else {
                val = collation.getCollationKey(value.getStringValue());
            }
        } else {
            val = value;
        }
View Full Code Here

     }

    public Expression compile(Executable exec) throws TransformerConfigurationException {

        Collator collator = null;
        if (collationName != null) {
            Comparator comp = getPrincipalStylesheet().findCollation(collationName);
            if (comp==null) {
                 compileError("The collation name " + Err.wrap(collationName) + " is not recognized", "XT1210");
            }
View Full Code Here

        Comparator comp;
        if (collation != null) {
           comp = collation;
        } else {
            Collator base;
            if (languageX.equals("")) {
                // get Java collator for the default locale
                base = Collator.getInstance();
            } else {
                Locale locale = Configuration.getLocale(languageX);
View Full Code Here

            String langAtt,
            String strengthAtt,
            String decompositionAtt )
    {

        Collator collator = null;
        // Start with the lang attribute

        if (langAtt!=null) {
            collator = Collator.getInstance(getLocale(langAtt));
        } else {
            collator = Collator.getInstance()// use default locale
        }

        if (strengthAtt!=null && collator instanceof Collator) {
            if (strengthAtt.equals("primary")) {
                collator.setStrength(Collator.PRIMARY);
            } else if (strengthAtt.equals("secondary")) {
                collator.setStrength(Collator.SECONDARY);
            } else if (strengthAtt.equals("tertiary")) {
                collator.setStrength(Collator.TERTIARY);
            } else if (strengthAtt.equals("identical")) {
                collator.setStrength(Collator.IDENTICAL);
            } else {
                //throw new XPathException.Dynamic("Collation strength must be primary, secondary, tertiary, or identical");
            }
        }

        if (decompositionAtt!=null && collator instanceof Collator) {
            if (decompositionAtt.equals("none")) {
                collator.setDecomposition(Collator.NO_DECOMPOSITION);
            } else if (decompositionAtt.equals("standard")) {
                collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
            } else if (decompositionAtt.equals("full")) {
                collator.setDecomposition(Collator.FULL_DECOMPOSITION);
            } else {
                //throw new XPathException.Dynamic("Collation decomposition must be none, standard, or full");
            }
        }
        return collator;
View Full Code Here

                          collections.add(currentFolder);
                        }
                    }
                    Collections.sort(collections, new Comparator() {
                        public int compare(Object arg0, Object arg1) {
                            Collator comp = Collator.getInstance(Locale.US);
                            comp.setStrength(Collator.PRIMARY);
                            return comp.compare(((Collection) arg0).getName().toLowerCase(), ((Collection) arg1).getName().toLowerCase() );
                        }
                    });
                    this.collection.setCollections(collections);
                    this.isCollectionsInit = true;
                    return this.collection.getCollections();
                   
                } else if (method.getName().equals("getFolders") && !this.isFoldersInit) {
                    List folders = new ArrayList();
                    FolderDao folderDao = FolderDao.createInstance();
                    Node node = session.getNodeByUUID(this.collection.getId());
                    if (!node.hasNode(NodesTypes.PREFIX + CollectionDao.FOLDERS_NODE_NAME)) {
                        this.isFoldersInit = true;
                      return folders;
                    }
                    for (NodeIterator ni = node.getNode(NodesTypes.PREFIX + CollectionDao.FOLDERS_NODE_NAME).getNodes(); ni.hasNext(); ) {
                        Node folderNode = ni.nextNode();
                        Folder folder = folderDao.retrieve(folderNode.getUUID());
                        folders.add(folder);
                    }
                    Collections.sort(folders, new Comparator() {
                        public int compare(Object arg0, Object arg1) {
                            Collator comp = Collator.getInstance(Locale.US);
                            comp.setStrength(Collator.PRIMARY);
                            return comp.compare(((Folder) arg0).getName().toLowerCase(), ((Folder) arg1).getName().toLowerCase() );
                        }
                    });
                    this.collection.setFolders(folders);
                    this.isFoldersInit = true;
                    return this.collection.getFolders();
View Full Code Here

TOP

Related Classes of java.text.Collator

Copyright © 2018 www.massapicom. 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.