Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

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

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:com.l2jfree.gameserver.model.clan.L2Clan.java

/**
 * @return Returns the noticeEnabled./*from  w ww  .j  a v a2s.  c o m*/
 */
public boolean isNoticeEnabled() {
    String result = "";
    Connection con = null;
    try {

        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement("SELECT enabled FROM clan_notices WHERE clanID=?");
        statement.setInt(1, getClanId());
        ResultSet rset = statement.executeQuery();

        while (rset.next()) {
            result = rset.getString("enabled");
        }

        rset.close();
        statement.close();
    } catch (Exception e) {
        _log.warn("BBS: Error while reading _noticeEnabled for clan " + getClanId(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
    if (result.isEmpty()) {
        insertNotice();
        return false;
    } else
        return result.compareToIgnoreCase("true") == 0;
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public static String getVocabularyVersionByTag(String codingSchemeName, String ltag) {
    if (codingSchemeName == null)
        return null;
    String version = null;//  w w  w. j a va  2s. c o m
    int knt = 0;
    try {
        LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
        CodingSchemeRenderingList lcsrl = lbSvc.getSupportedCodingSchemes();
        CodingSchemeRendering[] csra = lcsrl.getCodingSchemeRendering();
        for (int i = 0; i < csra.length; i++) {
            CodingSchemeRendering csr = csra[i];
            CodingSchemeSummary css = csr.getCodingSchemeSummary();
            if (css.getFormalName().compareTo(codingSchemeName) == 0
                    || css.getLocalName().compareTo(codingSchemeName) == 0) {
                version = css.getRepresentsVersion();
                knt++;

                if (ltag == null)
                    return css.getRepresentsVersion();
                RenderingDetail rd = csr.getRenderingDetail();
                CodingSchemeTagList cstl = rd.getVersionTags();
                java.lang.String[] tags = cstl.getTag();

                for (int j = 0; j < tags.length; j++) {
                    String version_tag = (String) tags[j];

                    if (version_tag.compareToIgnoreCase(ltag) == 0) {
                        return css.getRepresentsVersion();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ltag == null || (ltag.compareToIgnoreCase("PRODUCTION") == 0 & knt == 1)) {
        _logger.warn("\tUse " + version + " as default version.");
        return version;
    }
    return null;
}

From source file:org.muse.mneme.impl.SubmissionServiceImpl.java

/**
 * {@inheritDoc}/*from ww  w.j a  va  2s  .  c  o m*/
 */
public List<Question> findPartQuestions(Part part) {
    if (M_log.isDebugEnabled())
        M_log.debug("findPartQuestions: " + part.getId());

    List<String> qids = this.storage.findPartQuestions(part);
    List<Question> rv = new ArrayList<Question>();

    for (String qid : qids) {
        QuestionImpl q = (QuestionImpl) this.questionService.getQuestion(qid);
        if (q != null) {
            q.initPartContext(part);
            rv.add(q);
        }
    }

    // sort by question text
    Collections.sort(rv, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            String s0 = StringUtil.trimToZero(((QuestionImpl) arg0).getDescription());
            String s1 = StringUtil.trimToZero(((QuestionImpl) arg1).getDescription());
            int rv = s0.compareToIgnoreCase(s1);
            return rv;
        }
    });

    return rv;
}

From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java

/**
* Get the acls for a document library./*from  w  ww.  ja v  a 2 s  .c o  m*/
* @param site
* @param guid is the list/library GUID
* @return array of sids
* @throws Exception
*/
public String[] getACLs(String site, String guid, boolean activeDirectoryAuthority)
        throws ManifoldCFException, ServiceInterruption {
    long currentTime;
    try {
        if (site.compareTo("/") == 0)
            site = ""; // root case
        UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration,
                httpClient);
        com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService
                .getUserGroupSoapHandler();

        PermissionsWS aclService = new PermissionsWS(baseUrl + site, userName, password, configuration,
                httpClient);
        com.microsoft.schemas.sharepoint.soap.directory.PermissionsSoap aclCall = aclService
                .getPermissionsSoapHandler();

        com.microsoft.schemas.sharepoint.soap.directory.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall
                .getPermissionCollection(guid, "List");
        org.apache.axis.message.MessageElement[] aclList = aclResult.get_any();

        XMLDoc doc = new XMLDoc(aclList[0].toString());
        ArrayList nodeList = new ArrayList();

        doc.processPath(nodeList, "*", null);
        if (nodeList.size() != 1) {
            throw new ManifoldCFException(
                    "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are "
                            + Integer.toString(nodeList.size()) + " nodes");
        }
        Object parent = nodeList.get(0);
        if (!doc.getNodeName(parent).equals("ns1:GetPermissionCollection"))
            throw new ManifoldCFException("Bad xml - outer node is not 'ns1:GetPermissionCollection'");

        nodeList.clear();
        doc.processPath(nodeList, "*", parent);

        if (nodeList.size() != 1) {
            throw new ManifoldCFException(" No results found.");
        }
        parent = nodeList.get(0);
        nodeList.clear();
        doc.processPath(nodeList, "*", parent);
        Set<String> sids = new HashSet<String>();
        int i = 0;
        for (; i < nodeList.size(); i++) {
            Object node = nodeList.get(i);
            String mask = doc.getValue(node, "Mask");
            long maskValue = new Long(mask).longValue();
            if ((maskValue & 1L) == 1L) {
                // Permission to view
                String isUser = doc.getValue(node, "MemberIsUser");

                if (isUser.compareToIgnoreCase("True") == 0) {
                    // Use AD user or group
                    String userLogin = doc.getValue(node, "UserLogin");
                    String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority);
                    sids.add(userSid);
                } else {
                    // Role
                    List<String> roleSids;
                    String roleName = doc.getValue(node, "RoleName");
                    if (roleName.length() == 0) {
                        roleName = doc.getValue(node, "GroupName");
                        if (roleName != null && roleName.length() > 0) {
                            roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority);
                        } else {
                            Logging.connectors.warn(
                                    "SharePoint: Unrecognized permission collection entry: no role, no group: "
                                            + doc.getXML());
                            roleSids = new ArrayList<String>();
                        }
                    } else {
                        roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority);
                    }

                    for (String sid : roleSids) {
                        sids.add(sid);
                    }
                }
            }
        }

        return sids.toArray(new String[0]);
    } catch (java.net.MalformedURLException e) {
        throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e);
    } catch (javax.xml.rpc.ServiceException e) {
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got a service exception getting the acls for site " + site
                    + " guid " + guid + " - retrying", e);
        currentTime = System.currentTimeMillis();
        throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 12 * 60 * 60000L, -1, true);
    } catch (org.apache.axis.AxisFault e) {
        currentTime = System.currentTimeMillis();
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(
                    new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
            if (elem != null) {
                elem.normalize();
                String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                if (httpErrorCode.equals("404")) {
                    // Page did not exist
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("SharePoint: The page at " + baseUrl + site
                                + " did not exist; assuming list/library deleted");
                    return null;
                } else if (httpErrorCode.equals("401")) {
                    // User did not have permissions for this library to get the acls
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug(
                                "SharePoint: The crawl user did not have access to the permissions service for "
                                        + baseUrl + site + "; skipping documents within");
                    return null;
                } else if (httpErrorCode.equals("403"))
                    throw new ManifoldCFException(
                            "Http error " + httpErrorCode + " while reading from " + baseUrl + site
                                    + " - check IIS and SharePoint security settings! " + e.getMessage(),
                            e);
                else
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e);
            }
            throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e);
        } else if (e.getFaultCode()
                .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName(
                    "http://schemas.microsoft.com/sharepoint/soap/", "errorcode"));
            if (elem != null) {
                elem.normalize();
                String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim();
                if (sharepointErrorCode.equals("0x82000006")) {
                    // List did not exist
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("SharePoint: The list " + guid + " in site " + site
                                + " did not exist; assuming list/library deleted");
                    return null;
                } else {
                    if (Logging.connectors.isDebugEnabled()) {
                        org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName(
                                "http://schemas.microsoft.com/sharepoint/soap/", "errorstring"));
                        String errorString = "";
                        if (elem != null)
                            errorString = elem2.getFirstChild().getNodeValue().trim();

                        Logging.connectors.debug("SharePoint: Getting permissions for the list " + guid
                                + " in site " + site + " failed with unexpected SharePoint error code "
                                + sharepointErrorCode + ": " + errorString + " - Skipping", e);
                    }
                    return null;
                }
            }
            if (Logging.connectors.isDebugEnabled())
                Logging.connectors
                        .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site
                                + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart()
                                + ", detail = " + e.getFaultString() + " - retrying", e);

            throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying",
                    e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false);
        }

        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/",
                "Server.userException"))) {
            String exceptionName = e.getFaultString();
            if (exceptionName.equals("java.lang.InterruptedException"))
                throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
        }

        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site "
                    + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart()
                    + ", detail = " + e.getFaultString() + " - retrying", e);
        throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 3 * 60 * 60000L, -1, false);
    } catch (java.rmi.RemoteException e) {
        // We expect the axis exception to be thrown, not this generic one!
        // So, fail hard if we see it.
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site "
                    + site + " guid " + guid, e);
        throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e);
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java

/**
* Get the acls for a document.//from  w  w w . ja  v  a  2  s. c  om
* NOTE that this function only works for SharePoint 2007+ with the MCPermissions web service installed.
* @param site is the encoded subsite path
* @param file is the encoded file url (not including protocol or server or location, but including encoded subsite, library and folder/file path)
* @return array of document SIDs
* @throws ManifoldCFException
* @throws ServiceInterruption
*/
public String[] getDocumentACLs(String site, String file, boolean activeDirectoryAuthority)
        throws ManifoldCFException, ServiceInterruption {
    long currentTime;
    try {
        if (site.compareTo("/") == 0)
            site = ""; // root case

        // Calculate the full server-relative path of the file
        String encodedRelativePath = serverLocation + file;
        if (encodedRelativePath.startsWith("/"))
            encodedRelativePath = encodedRelativePath.substring(1);

        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Getting document acls for site '" + site + "' file '" + file
                    + "': Encoded relative path is '" + encodedRelativePath + "'");
        UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration,
                httpClient);
        com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService
                .getUserGroupSoapHandler();

        MCPermissionsWS aclService = new MCPermissionsWS(baseUrl + site, userName, password, configuration,
                httpClient);
        com.microsoft.sharepoint.webpartpages.PermissionsSoap aclCall = aclService.getPermissionsSoapHandler();

        com.microsoft.sharepoint.webpartpages.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall
                .getPermissionCollection(encodedRelativePath, "Item");
        if (aclResult == null) {
            Logging.connectors.debug("SharePoint: document acls were null");
            return null;
        }

        org.apache.axis.message.MessageElement[] aclList = aclResult.get_any();

        if (Logging.connectors.isDebugEnabled()) {
            Logging.connectors.debug("SharePoint: document acls xml: '" + aclList[0].toString() + "'");
        }

        XMLDoc doc = new XMLDoc(aclList[0].toString());
        ArrayList nodeList = new ArrayList();

        doc.processPath(nodeList, "*", null);
        if (nodeList.size() != 1) {
            throw new ManifoldCFException(
                    "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are "
                            + Integer.toString(nodeList.size()) + " nodes");
        }
        Object parent = nodeList.get(0);
        if (!doc.getNodeName(parent).equals("GetPermissionCollection"))
            throw new ManifoldCFException("Bad xml - outer node is not 'GetPermissionCollection'");

        nodeList.clear();
        doc.processPath(nodeList, "*", parent);

        if (nodeList.size() != 1) {
            throw new ManifoldCFException(" No results found.");
        }
        parent = nodeList.get(0);
        nodeList.clear();
        doc.processPath(nodeList, "*", parent);
        Set<String> sids = new HashSet<String>();
        int i = 0;
        for (; i < nodeList.size(); i++) {
            Object node = nodeList.get(i);
            String mask = doc.getValue(node, "Mask");
            long maskValue = new Long(mask).longValue();
            if ((maskValue & 1L) == 1L) {
                // Permission to view
                String isUser = doc.getValue(node, "MemberIsUser");

                if (isUser.compareToIgnoreCase("True") == 0) {
                    // Use AD user or group
                    String userLogin = doc.getValue(node, "UserLogin");
                    String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority);
                    sids.add(userSid);
                } else {
                    // Role
                    List<String> roleSids;
                    String roleName = doc.getValue(node, "RoleName");
                    if (roleName.length() == 0) {
                        roleName = doc.getValue(node, "GroupName");
                        roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority);
                    } else {
                        roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority);
                    }

                    for (String sid : roleSids) {
                        sids.add(sid);
                    }
                }
            }
        }

        return sids.toArray(new String[0]);
    } catch (java.net.MalformedURLException e) {
        throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e);
    } catch (javax.xml.rpc.ServiceException e) {
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got a service exception getting the acls for site " + site
                    + " file " + file + " - retrying", e);
        currentTime = System.currentTimeMillis();
        throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 12 * 60 * 60000L, -1, true);
    } catch (org.apache.axis.AxisFault e) {
        currentTime = System.currentTimeMillis();
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(
                    new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
            if (elem != null) {
                elem.normalize();
                String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                if (httpErrorCode.equals("404")) {
                    // Page did not exist
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("SharePoint: The page at " + baseUrl + site
                                + " did not exist; assuming library deleted");
                    return null;
                } else if (httpErrorCode.equals("401")) {
                    // User did not have permissions for this library to get the acls
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug(
                                "SharePoint: The crawl user did not have access to the MCPermissions service for "
                                        + baseUrl + site + "; skipping documents within");
                    return null;
                } else if (httpErrorCode.equals("403"))
                    throw new ManifoldCFException(
                            "Http error " + httpErrorCode + " while reading from " + baseUrl + site
                                    + " - check IIS and SharePoint security settings! " + e.getMessage(),
                            e);
                else
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e);
            }
            throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e);
        } else if (e.getFaultCode()
                .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName(
                    "http://schemas.microsoft.com/sharepoint/soap/", "errorcode"));
            if (elem != null) {
                elem.normalize();
                String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim();
                if (sharepointErrorCode.equals("0x82000006")) {
                    // List did not exist
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("SharePoint: The file " + file + " in site " + site
                                + " did not exist; assuming file deleted");
                    return null;
                } else {
                    if (Logging.connectors.isDebugEnabled()) {
                        org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName(
                                "http://schemas.microsoft.com/sharepoint/soap/", "errorstring"));
                        String errorString = "";
                        if (elem != null)
                            errorString = elem2.getFirstChild().getNodeValue().trim();

                        Logging.connectors.debug("SharePoint: Getting permissions for the file " + file
                                + " in site " + site + " failed with unexpected SharePoint error code "
                                + sharepointErrorCode + ": " + errorString + " - Skipping", e);
                    }
                    return null;
                }
            }
            if (Logging.connectors.isDebugEnabled())
                Logging.connectors
                        .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site
                                + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart()
                                + ", detail = " + e.getFaultString() + " - retrying", e);

            throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying",
                    e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false);
        }

        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/",
                "Server.userException"))) {
            String exceptionName = e.getFaultString();
            if (exceptionName.equals("java.lang.InterruptedException"))
                throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
        }

        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site "
                    + site + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart()
                    + ", detail = " + e.getFaultString() + " - retrying", e);
        throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 3 * 60 * 60000L, -1, false);
    } catch (java.rmi.RemoteException e) {
        // We expect the axis exception to be thrown, not this generic one!
        // So, fail hard if we see it.
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site "
                    + site + " file " + file, e);
        throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e);
    }
}

From source file:gov.nih.nci.evs.browser.utils.SourceTreeUtils.java

public ResolvedConceptReferencesIterator findConceptWithSourceCodeMatching(String scheme, String version,
        String sourceAbbr, String code, int maxToReturn, boolean searchInactive) {
    if (sourceAbbr == null || code == null)
        return null;
    CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
    versionOrTag.setVersion(version);/*w  w  w .  j  a v  a2s.  c  om*/

    if (lbSvc == null) {
        _logger.warn("lbSvc = null");
        return null;
    }

    LocalNameList contextList = null;
    NameAndValueList qualifierList = null;

    Vector<String> v = null;

    //if (code != null && code.compareTo("") != 0) {
    if (code.compareTo("") != 0) {
        qualifierList = new NameAndValueList();
        NameAndValue nv = new NameAndValue();
        nv.setName("source-code");
        nv.setContent(code);
        qualifierList.addNameAndValue(nv);
    }

    LocalNameList propertyLnL = null;
    // sourceLnL
    Vector<String> w2 = new Vector<String>();
    w2.add(sourceAbbr);
    LocalNameList sourceLnL = vector2LocalNameList(w2);
    if (sourceAbbr.compareTo("*") == 0 || sourceAbbr.compareToIgnoreCase("ALL") == 0) {
        sourceLnL = null;
    }

    ResolvedConceptReferencesIterator matchIterator = null;
    SortOptionList sortCriteria = null;// Constructors.createSortOptionList(new
                                       // String[]{"matchToQuery", "code"});
    try {
        CodedNodeSet cns = lbSvc.getNodeSet(scheme, null, null);
        if (cns == null) {
            _logger.warn("lbSvc.getCodingSchemeConceptsd returns null");
            return null;
        }
        CodedNodeSet.PropertyType[] types = new CodedNodeSet.PropertyType[] {
                CodedNodeSet.PropertyType.PRESENTATION };
        cns = cns.restrictToProperties(propertyLnL, types, sourceLnL, contextList, qualifierList);

        if (cns != null) {
            boolean activeOnly = !searchInactive;
            cns = restrictToActiveStatus(cns, activeOnly);

            try {
                matchIterator = cns.resolve(sortCriteria, null, null);// ConvenienceMethods.createLocalNameList(getPropertyForCodingScheme(cs)),null);
            } catch (Exception ex) {

            }
            return matchIterator;
        }

    } catch (Exception e) {
        // getLogger().error("ERROR: Exception in findConceptWithSourceCodeMatching.");
        return null;
    }
    return null;
}

From source file:mondrian.olap.Util.java

/**
 * Compares two names.//from  w  w  w.ja  v a2  s.co  m
 * Takes into account the {@link MondrianProperties#CaseSensitive case
 * sensitive option}.
 * Names must not be null.
 */
public static int compareName(String s, String t) {
    boolean caseSensitive = MondrianProperties.instance().CaseSensitive.get();
    return caseSensitive ? s.compareTo(t) : s.compareToIgnoreCase(t);
}

From source file:org.muse.mneme.impl.SubmissionServiceImpl.java

/**
 * {@inheritDoc}/*from www . j  a v a 2 s  .  c om*/
 */
public List<Submission> getUserContextSubmissions(String context, String userId,
        GetUserContextSubmissionsSort sortParam) {
    if (context == null)
        throw new IllegalArgumentException();
    if (userId == null)
        userId = sessionManager.getCurrentSessionUserId();
    if (sortParam == null)
        sortParam = GetUserContextSubmissionsSort.title_a;
    final GetUserContextSubmissionsSort sort = sortParam;
    Date asOf = new Date();

    if (M_log.isDebugEnabled())
        M_log.debug("getUserContextSubmissions: context: " + context + " userId: " + userId + ": " + sort);

    // if we are in a test drive situation, use unpublished as well
    Boolean publishedOnly = Boolean.TRUE;
    if (securityService.checkSecurity(userId, MnemeService.MANAGE_PERMISSION, context)
            && (!securityService.checkSecurity(userId, MnemeService.SUBMIT_PERMISSION, context))) {
        publishedOnly = Boolean.FALSE;
    }

    // read all the submissions for this user in the context
    List<SubmissionImpl> all = this.storage.getUserContextSubmissions(context, userId, publishedOnly);

    // filter out invalid assessments
    for (Iterator i = all.iterator(); i.hasNext();) {
        Submission s = (Submission) i.next();
        if (!s.getAssessment().getIsValid()) {
            i.remove();
        }
    }

    // get all the assessments for this context
    List<Assessment> assessments = this.assessmentService.getContextAssessments(context,
            AssessmentService.AssessmentsSort.title_a, publishedOnly);

    // if any valid assessment is not represented in the submissions we found, add an empty submission for it
    for (Assessment a : assessments) {
        if (!a.getIsValid())
            continue;

        boolean found = false;
        for (Submission s : all) {
            if (s.getAssessment().equals(a)) {
                found = true;
                break;
            }
        }

        if (!found) {
            SubmissionImpl s = this.getPhantomSubmission(userId, a);
            all.add(s);
        }
    }

    // sort
    // status sorts first by due date descending, then status final sorting is done in the service
    Collections.sort(all, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            int rv = 0;
            switch (sort) {
            case title_a: {
                String s0 = StringUtil.trimToZero(((Submission) arg0).getAssessment().getTitle());
                String s1 = StringUtil.trimToZero(((Submission) arg1).getAssessment().getTitle());
                rv = s0.compareToIgnoreCase(s1);
                break;
            }
            case title_d: {
                String s0 = StringUtil.trimToZero(((Submission) arg0).getAssessment().getTitle());
                String s1 = StringUtil.trimToZero(((Submission) arg1).getAssessment().getTitle());
                rv = -1 * s0.compareToIgnoreCase(s1);
                break;
            }
            case type_a: {
                rv = ((Submission) arg0).getAssessment().getType().getSortValue()
                        .compareTo(((Submission) arg1).getAssessment().getType().getSortValue());
                break;
            }
            case type_d: {
                rv = -1 * ((Submission) arg0).getAssessment().getType().getSortValue()
                        .compareTo(((Submission) arg1).getAssessment().getType().getSortValue());
                break;
            }
            case dueDate_a: {
                // no due date sorts high
                if (((Submission) arg0).getAssessment().getDates().getDueDate() == null) {
                    if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                        rv = 0;
                        break;
                    }
                    rv = 1;
                    break;
                }
                if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                    rv = -1;
                    break;
                }
                rv = ((Submission) arg0).getAssessment().getDates().getDueDate()
                        .compareTo(((Submission) arg1).getAssessment().getDates().getDueDate());
                break;
            }
            case dueDate_d:
            case status_a:
            case status_d: {
                // no due date sorts high
                if (((Submission) arg0).getAssessment().getDates().getDueDate() == null) {
                    if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                        rv = 0;
                        break;
                    }
                    rv = -1;
                    break;
                }
                if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                    rv = 1;
                    break;
                }
                rv = -1 * ((Submission) arg0).getAssessment().getDates().getDueDate()
                        .compareTo(((Submission) arg1).getAssessment().getDates().getDueDate());
                break;
            }
            }

            return rv;
        }
    });

    // see if any needs to be completed based on time limit or dates
    checkAutoComplete(all, asOf);

    // pick one for each assessment - the one in progress, or the official complete one
    List<Submission> official = officializeByAssessment(all);

    // // if sorting by due date, fix it so null due dates are LARGE not SMALL
    // if (sort == GetUserContextSubmissionsSort.dueDate_a || sort == GetUserContextSubmissionsSort.dueDate_d
    // || sort == GetUserContextSubmissionsSort.status_a || sort == GetUserContextSubmissionsSort.status_d)
    // {
    // // pull out the null date entries
    // List<Submission> nulls = new ArrayList<Submission>();
    // for (Iterator i = official.iterator(); i.hasNext();)
    // {
    // Submission s = (Submission) i.next();
    // if (s.getAssessment().getDates().getDueDate() == null)
    // {
    // nulls.add(s);
    // i.remove();
    // }
    // }
    //
    // // for ascending, treat the null dates as LARGE so put them at the end
    // if ((sort == GetUserContextSubmissionsSort.dueDate_a) || (sort == GetUserContextSubmissionsSort.status_d))
    // {
    // official.addAll(nulls);
    // }
    //
    // // for descending, (all status is first sorted date descending) treat the null dates as LARGE so put them at the beginning
    // else
    // {
    // nulls.addAll(official);
    // official.clear();
    // official.addAll(nulls);
    // }
    // }

    // if sorting by status, do that sort
    if (sort == GetUserContextSubmissionsSort.status_a || sort == GetUserContextSubmissionsSort.status_d) {
        official = sortByAssessmentSubmissionStatus((sort == GetUserContextSubmissionsSort.status_d), official);
    }

    return official;
}

From source file:mondrian.olap.Util.java

/**
 * Compares two names.  if case sensitive flag is false,
 * apply finer grain difference with case sensitive
 * Takes into account the {@link MondrianProperties#CaseSensitive case
 * sensitive option}./*from w  w w.  j  a  va 2  s.  c om*/
 * Names must not be null.
 */
public static int caseSensitiveCompareName(String s, String t) {
    boolean caseSensitive = MondrianProperties.instance().CaseSensitive.get();
    if (caseSensitive) {
        return s.compareTo(t);
    } else {
        int v = s.compareToIgnoreCase(t);
        // if ignore case returns 0 compare in a case sensitive manner
        // this was introduced to solve an issue with Member.equals()
        // and Member.compareTo() not agreeing with each other
        return v == 0 ? s.compareTo(t) : v;
    }
}

From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java

private RouteNode createRouteNode(RouteNode previousRouteNode, String nodeName, Node routePathNode,
        Node routeNodesNode, DocumentType documentType, RoutePathContext context)
        throws XPathExpressionException, XmlException, GroupNotFoundException {
    if (nodeName == null)
        return null;

    Node currentNode;/*from  www.  ja  va2 s .c  o  m*/
    context.nodeXPath += "//" + "*[@name = '" + nodeName + "']";
    context.nodeQName += nodeName + ":";

    try {
        currentNode = (Node) getXPath().evaluate(context.nodeXPath + "//" + "*[@name = '" + nodeName + "']",
                routePathNode, XPathConstants.NODE);
        if (currentNode == null) {
            findNodeOnXPath(nodeName, context, routePathNode);
            currentNode = (Node) getXPath().evaluate(context.nodeXPath + "//" + "*[@name = '" + nodeName + "']",
                    routePathNode, XPathConstants.NODE);
        }
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining routePath for routeNode", xpee);
        throw xpee;
    }

    if (currentNode == null) {
        String message = "Next node '" + nodeName + "' for node '" + previousRouteNode.getRouteNodeName()
                + "' not found!";
        LOG.error(message);
        throw new XmlException(message);
    }

    context.nodeXPath += "//" + "*[@name = '" + nodeName + "']";
    context.nodeQName += nodeName + ":";
    LOG.debug("nodeQNme:" + context.nodeQName);
    boolean nodeIsABranch;

    try {
        nodeIsABranch = ((Boolean) getXPath().evaluate("self::node()[local-name() = 'branch']", currentNode,
                XPathConstants.BOOLEAN)).booleanValue();
    } catch (XPathExpressionException xpee) {
        LOG.error("Error testing whether node is a branch", xpee);
        throw xpee;
    }

    if (nodeIsABranch) {
        throw new XmlException("Next node cannot be a branch node");
    }

    String localName;

    try {
        localName = (String) getXPath().evaluate("local-name(.)", currentNode, XPathConstants.STRING);
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining node local-name", xpee);
        throw xpee;
    }

    RouteNode currentRouteNode = null;

    if (nodesMap.containsKey(context.nodeQName)) {
        currentRouteNode = (RouteNode) nodesMap.get(context.nodeQName);
    } else {
        String nodeExpression = ".//*[@name='" + nodeName + "']";
        currentRouteNode = makeRouteNodePrototype(localName, nodeName, nodeExpression, routeNodesNode,
                documentType, context);
    }

    if ("split".equalsIgnoreCase(localName)) {
        getSplitNextNodes(currentNode, routePathNode, currentRouteNode, routeNodesNode, documentType,
                cloneContext(context));
    }

    if (previousRouteNode != null) {
        previousRouteNode.getNextNodes().add(currentRouteNode);
        nodesMap.put(context.previousNodeQName, previousRouteNode);
        currentRouteNode.getPreviousNodes().add(previousRouteNode);
    }

    String nextNodeName = null;
    boolean hasNextNodeAttrib;

    try {
        hasNextNodeAttrib = ((Boolean) getXPath().evaluate(NEXT_NODE_EXP, currentNode, XPathConstants.BOOLEAN))
                .booleanValue();
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining node nextNode attrib", xpee);
        throw xpee;
    }

    if (hasNextNodeAttrib) {
        // if the node has a nextNode but is not a split node, the nextNode is used for its node
        if (!"split".equalsIgnoreCase(localName)) {
            try {
                nextNodeName = (String) getXPath().evaluate(NEXT_NODE_EXP, currentNode, XPathConstants.STRING);
            } catch (XPathExpressionException xpee) {
                LOG.error("Error obtaining node nextNode attrib", xpee);
                throw xpee;
            }

            context.previousNodeQName = context.nodeQName;
            createRouteNode(currentRouteNode, nextNodeName, routePathNode, routeNodesNode, documentType,
                    cloneContext(context));
        } else {
            // if the node has a nextNode but is a split node, the nextNode must be used for that split node's join node
            nodesMap.put(context.nodeQName, currentRouteNode);
        }

    } else {
        // if the node has no nextNode of its own and is not a join which gets its nextNode from its parent split node
        if (!"join".equalsIgnoreCase(localName)) {
            nodesMap.put(context.nodeQName, currentRouteNode);

        } else { // if join has a parent nextNode (on its split node) and join has not already walked this path
            boolean parentHasNextNodeAttrib;
            try {
                parentHasNextNodeAttrib = ((Boolean) getXPath().evaluate(PARENT_NEXT_NODE_EXP, currentNode,
                        XPathConstants.BOOLEAN)).booleanValue();
            } catch (XPathExpressionException xpee) {
                LOG.error("Error obtaining parent node nextNode attrib", xpee);
                throw xpee;
            }

            if (parentHasNextNodeAttrib && !nodesMap.containsKey(context.nodeQName)) {
                try {
                    nextNodeName = (String) getXPath().evaluate(PARENT_NEXT_NODE_EXP, currentNode,
                            XPathConstants.STRING);
                } catch (XPathExpressionException xpee) {
                    LOG.error("Error obtaining parent node nextNode attrib", xpee);
                    throw xpee;
                }

                context.previousNodeQName = context.nodeQName;
                createRouteNode(currentRouteNode, nextNodeName, routePathNode, routeNodesNode, documentType,
                        cloneContext(context));
            } else {
                // if join's parent split node does not have a nextNode
                nodesMap.put(context.nodeQName, currentRouteNode);
            }
        }
    }

    // handle nextAppDocStatus route node attribute
    String nextDocStatusName = null;
    boolean hasNextDocStatus;

    try {
        hasNextDocStatus = ((Boolean) getXPath().evaluate(NEXT_DOC_STATUS_EXP, currentNode,
                XPathConstants.BOOLEAN)).booleanValue();
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining node nextAppDocStatus attrib", xpee);
        throw xpee;
    }

    if (hasNextDocStatus) {
        try {
            nextDocStatusName = (String) getXPath().evaluate(NEXT_DOC_STATUS_EXP, currentNode,
                    XPathConstants.STRING);
        } catch (XPathExpressionException xpee) {
            LOG.error("Error obtaining node nextNode attrib", xpee);
            throw xpee;
        }

        //validate against allowable values if defined
        if (documentType.getValidApplicationStatuses() != null
                && documentType.getValidApplicationStatuses().size() > 0) {
            Iterator iter = documentType.getValidApplicationStatuses().iterator();
            boolean statusValidated = false;

            while (iter.hasNext()) {
                ApplicationDocumentStatus myAppDocStat = (ApplicationDocumentStatus) iter.next();
                if (nextDocStatusName.compareToIgnoreCase(myAppDocStat.getStatusName()) == 0) {
                    statusValidated = true;
                    break;
                }
            }

            if (!statusValidated) {
                XmlException xpee = new XmlException(
                        "AppDocStatus value " + nextDocStatusName + " not allowable.");
                LOG.error("Error validating nextAppDocStatus name: " + nextDocStatusName
                        + " against acceptable values.", xpee);
                throw xpee;
            }
        }

        currentRouteNode.setNextDocStatus(nextDocStatusName);
    }

    return currentRouteNode;
}