Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

In this page you can find the example usage for java.util SortedMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnTenantRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//  ww w. j  a v a2 s . c o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Tenant Attributes
        String attrClusterId = null;
        String attrTenantName = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("Tenant");

        CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantName")) {
                if (attrTenantName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrTenantName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantName");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        String natTenantName = attrTenantName;

        int natRevision = Integer.parseInt(attrRevision);
        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAstTenantObj obj = schemaObj.getTenantTableObj().newInstance();
        CFAstTenantBuff dataBuff = obj.getTenantBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredTenantName(natTenantName);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        SortedMap<CFAstTenantPKey, ICFAstTenantObj> sortedMap = (SortedMap<CFAstTenantPKey, ICFAstTenantObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstTenantObj realized = (ICFAstTenantObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:com.clearcenter.mobile_demo.mdStatusActivity.java

public List<JSONObject> sortedSamplesList(String data) {
    SortedMap<String, JSONObject> map = new TreeMap<String, JSONObject>();

    try {// w ww  .  j a v  a2  s.  co  m
        int version = 0;
        JSONObject json_data = new JSONObject(data);
        if (json_data.has("version"))
            version = json_data.getInt("version");
        if (version < 1 && json_data.has("time")) {
            String key = json_data.getString("time");
            map.put(key, json_data);
        } else if (version >= 1 && json_data.has("samples") && !json_data.isNull("samples")) {
            json_data = json_data.getJSONObject("samples");
            Iterator i = json_data.keys();
            while (i.hasNext()) {
                String key = i.next().toString();
                JSONObject sample = json_data.getJSONObject(key);
                sample.put("time", key);
                map.put(key, sample);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSONException", e);
    }

    return new LinkedList<JSONObject>(map.values());
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnTagRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//  ww  w .j  av  a2 s .c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Tag Attributes
        String attrTenantId = null;
        String attrName = null;
        String attrDescr = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("Tag");

        CFAccXMsgRspnHandler xmsgRspnHandler = (CFAccXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAccSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Descr")) {
                if (attrDescr != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDescr = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natId = Long.parseLong(attrId);

        String natName = attrName;

        String natDescr = attrDescr;

        int natRevision = Integer.parseInt(attrRevision);
        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAccTagObj obj = schemaObj.getTagTableObj().newInstance();
        CFAccTagBuff dataBuff = obj.getTagBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredName(natName);
        dataBuff.setOptionalDescr(natDescr);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        SortedMap<CFAccTagPKey, ICFAccTagObj> sortedMap = (SortedMap<CFAccTagPKey, ICFAccTagObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAccTagObj realized = (ICFAccTagObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnAsteriskConfRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from   ww w.  j a  v a2  s.  c  o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ConfigurationFile Attributes
        String attrClusterId = null;
        String attrHostNodeId = null;
        String attrFileFullName = null;
        // AsteriskConf Attributes
        String attrFileContents = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("AsteriskConf");

        CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("HostNodeId")) {
                if (attrHostNodeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrHostNodeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileFullName")) {
                if (attrFileFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileContents")) {
                if (attrFileContents != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileContents = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if ((attrHostNodeId == null) || (attrHostNodeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "HostNodeId");
        }
        if (attrFileFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileFullName");
        }
        if (attrFileContents == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileContents");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        long natHostNodeId = Long.parseLong(attrHostNodeId);

        String natFileFullName = attrFileFullName;

        int natRevision = Integer.parseInt(attrRevision);
        String natFileContents = attrFileContents;

        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAstAsteriskConfObj obj = schemaObj.getAsteriskConfTableObj().newInstance();
        CFAstAsteriskConfBuff dataBuff = obj.getAsteriskConfBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredHostNodeId(natHostNodeId);
        dataBuff.setRequiredFileFullName(natFileFullName);
        dataBuff.setRequiredRevision(natRevision);
        dataBuff.setRequiredFileContents(natFileContents);
        obj.copyBuffToPKey();
        SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj> sortedMap = (SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstAsteriskConfObj realized = (ICFAstAsteriskConfObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmXMsgRspnHandler.CFCrmXMsgRspnProjectBaseRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from w w  w  . j  a v a  2 s  .  c om
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // DomainBase Attributes
        String attrTenantId = null;
        String attrDescription = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // ProjectBase Attributes
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ProjectBase");

        CFCrmXMsgRspnHandler xmsgRspnHandler = (CFCrmXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFCrmSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Description")) {
                if (attrDescription != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDescription = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natId = Long.parseLong(attrId);

        String natDescription = attrDescription;

        int natRevision = Integer.parseInt(attrRevision);
        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFCrmProjectBaseObj obj = schemaObj.getProjectBaseTableObj().newInstance();
        CFCrmProjectBaseBuff dataBuff = obj.getProjectBaseBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredId(natId);
        dataBuff.setOptionalDescription(natDescription);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        SortedMap<CFCrmDomainBasePKey, ICFCrmDomainBaseObj> sortedMap = (SortedMap<CFCrmDomainBasePKey, ICFCrmDomainBaseObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFCrmProjectBaseObj realized = (ICFCrmProjectBaseObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:trendulo.web.query.QueryService.java

public Map<String, SortedMap<String, Long>> getCounts(String[] words, String startDateString,
        String endDateString) {/*  www. jav  a2 s.  com*/

    Map<String, SortedMap<String, Long>> wordDateCounters = new HashMap<String, SortedMap<String, Long>>();
    // initialize the wordDateCounters so that we have at least an empty SortedMap for each word
    for (String word : words) {
        wordDateCounters.put(word, new TreeMap<String, Long>());
    }

    // set the granularity based on the length of the string passed in
    String dateGranularity = (startDateString.length() == 8) ? "DAY" : "HOUR";

    tweetsBatchScanner.clearColumns();
    List<Range> ranges = new ArrayList<Range>();
    for (String word : words) {
        Key startKey = new Key(new Text(word), new Text(dateGranularity), new Text(startDateString));
        // We want the endKey to include the endDateString, so we will build the Key just following it but then
        // set the Range to be exclusive. Simply using the endDateString and making the Range inclusive doesn't
        // work because of the default Value of the Key's timestamp (Long.MAX_VALUE)
        // See "Bug in Range behavior?" message on Accumulo user mailing list on Mar 22, 2012
        Key endKey = new Key(new Text(word), new Text(dateGranularity), new Text(endDateString))
                .followingKey(PartialKey.ROW_COLFAM_COLQUAL);
        log.debug("Start Key: " + startKey.toStringNoTime());
        log.debug("End Key: " + endKey.toStringNoTime());
        Range range = new Range(startKey, true, endKey, false);
        ranges.add(range);
    }

    tweetsBatchScanner.setRanges(ranges);

    // Get the results. As we are using the BatchScanner, these aren't in order
    for (Entry<Key, Value> entry : tweetsBatchScanner) {

        // Get the word as that will be the key to the Map
        String word = entry.getKey().getRow().toString();
        Long count = 0l;

        // Check is we have a SortedMap for the word yet. The sorted map is a list of date->count
        SortedMap<String, Long> dateCounters = wordDateCounters.get(word);
        if (dateCounters == null) {
            dateCounters = new TreeMap<String, Long>();
            wordDateCounters.put(word, dateCounters);
        }
        // Get the date value which is the CQ
        String dateValue = entry.getKey().getColumnQualifier().toString();

        // Now get the counter value
        count = LongCombiner.VAR_LEN_ENCODER.decode(entry.getValue().get());

        // add the date and count to the dateCounters SortedMap
        dateCounters.put(dateValue, count);
    }

    return wordDateCounters;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnExtConfigConfRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from   w  w w  .j a  v  a 2  s  .c om
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ConfigurationFile Attributes
        String attrClusterId = null;
        String attrHostNodeId = null;
        String attrFileFullName = null;
        // ExtConfigConf Attributes
        String attrFileContents = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ExtConfigConf");

        CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("HostNodeId")) {
                if (attrHostNodeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrHostNodeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileFullName")) {
                if (attrFileFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileContents")) {
                if (attrFileContents != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileContents = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if ((attrHostNodeId == null) || (attrHostNodeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "HostNodeId");
        }
        if (attrFileFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileFullName");
        }
        if (attrFileContents == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileContents");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        long natHostNodeId = Long.parseLong(attrHostNodeId);

        String natFileFullName = attrFileFullName;

        int natRevision = Integer.parseInt(attrRevision);
        String natFileContents = attrFileContents;

        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAstExtConfigConfObj obj = schemaObj.getExtConfigConfTableObj().newInstance();
        CFAstExtConfigConfBuff dataBuff = obj.getExtConfigConfBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredHostNodeId(natHostNodeId);
        dataBuff.setRequiredFileFullName(natFileFullName);
        dataBuff.setRequiredRevision(natRevision);
        dataBuff.setRequiredFileContents(natFileContents);
        obj.copyBuffToPKey();
        SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj> sortedMap = (SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstExtConfigConfObj realized = (ICFAstExtConfigConfObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnVoicemailConfRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from  w w w.jav a  2 s. com*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ConfigurationFile Attributes
        String attrClusterId = null;
        String attrHostNodeId = null;
        String attrFileFullName = null;
        // VoicemailConf Attributes
        String attrFileContents = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("VoicemailConf");

        CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("HostNodeId")) {
                if (attrHostNodeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrHostNodeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileFullName")) {
                if (attrFileFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileContents")) {
                if (attrFileContents != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileContents = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if ((attrHostNodeId == null) || (attrHostNodeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "HostNodeId");
        }
        if (attrFileFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileFullName");
        }
        if (attrFileContents == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileContents");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        long natHostNodeId = Long.parseLong(attrHostNodeId);

        String natFileFullName = attrFileFullName;

        int natRevision = Integer.parseInt(attrRevision);
        String natFileContents = attrFileContents;

        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAstVoicemailConfObj obj = schemaObj.getVoicemailConfTableObj().newInstance();
        CFAstVoicemailConfBuff dataBuff = obj.getVoicemailConfBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredHostNodeId(natHostNodeId);
        dataBuff.setRequiredFileFullName(natFileFullName);
        dataBuff.setRequiredRevision(natRevision);
        dataBuff.setRequiredFileContents(natFileContents);
        obj.copyBuffToPKey();
        SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj> sortedMap = (SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstVoicemailConfObj realized = (ICFAstVoicemailConfObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:org.jasig.schedassist.web.VisibleScheduleTag.java

@Override
public int doStartTagInternal() {
    final ServletContext servletContext = pageContext.getServletContext();

    final Date scheduleStart = visibleSchedule.getScheduleStart();
    if (null == scheduleStart) {
        // the visibleSchedule is empty, short circuit
        try {//from  ww w  .  j a v a  2s  . c o  m
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } catch (IOException e) {
            LOG.error("IOException occurred in doStartTag", e);
        }
        // SKIP_BODY means don't print any content from body of tag
        return SKIP_BODY;
    }

    LOG.debug("scheduleStart: " + scheduleStart);
    SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>();
    Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
    Date scheduleEnd = visibleSchedule.getScheduleEnd();
    while (index.before(scheduleEnd)) {
        dailySchedules.put(index, new ArrayList<AvailableBlock>());
        index = DateUtils.addDays(index, 1);
    }
    final Date lastMapKey = dailySchedules.lastKey();
    LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days");

    try {
        SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap();
        int numberOfEventsToDisplay = 0;
        for (AvailableBlock block : scheduleBlockMap.keySet()) {
            Date eventStartDate = block.getStartTime();
            LOG.debug("event start date: " + eventStartDate);
            Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE);
            if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart)
                    && dailySchedules.containsKey(mapKey)) {
                dailySchedules.get(mapKey).add(block);
                numberOfEventsToDisplay++;
            }
        }
        LOG.debug("number of events to display: " + numberOfEventsToDisplay);
        if (numberOfEventsToDisplay == 0) {
            // no available times in this range!
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } else {
            int weekNumber = 1;
            Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
            Date currentWeekFinish = DateUtils.addDays(currentWeekStart,
                    CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart));
            currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

            boolean renderAnotherWeek = true;

            while (renderAnotherWeek) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("will render another week using currentWeekStart " + currentWeekStart
                            + " and currentWeekFinish " + currentWeekFinish);
                }
                SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart,
                        currentWeekFinish);
                renderWeek(servletContext, pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap);

                currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1);
                currentWeekFinish = DateUtils.addDays(currentWeekStart, 7);
                currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish "
                            + currentWeekFinish);
                }

                if (currentWeekStart.after(lastMapKey)) {
                    renderAnotherWeek = false;
                    LOG.debug("will not render another week");
                }
            }
        }

    } catch (IOException e) {
        LOG.error("IOException occurred in doStartTag", e);
    }
    // SKIP_BODY means don't print any content from body of tag
    return SKIP_BODY;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnExtensionsConfRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from w  ww  . j  a  v a 2s.c o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ConfigurationFile Attributes
        String attrClusterId = null;
        String attrHostNodeId = null;
        String attrFileFullName = null;
        // ExtensionsConf Attributes
        String attrFileContents = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ExtensionsConf");

        CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("HostNodeId")) {
                if (attrHostNodeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrHostNodeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileFullName")) {
                if (attrFileFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FileContents")) {
                if (attrFileContents != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFileContents = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if ((attrHostNodeId == null) || (attrHostNodeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "HostNodeId");
        }
        if (attrFileFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileFullName");
        }
        if (attrFileContents == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FileContents");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        long natHostNodeId = Long.parseLong(attrHostNodeId);

        String natFileFullName = attrFileFullName;

        int natRevision = Integer.parseInt(attrRevision);
        String natFileContents = attrFileContents;

        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAstExtensionsConfObj obj = schemaObj.getExtensionsConfTableObj().newInstance();
        CFAstExtensionsConfBuff dataBuff = obj.getExtensionsConfBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredHostNodeId(natHostNodeId);
        dataBuff.setRequiredFileFullName(natFileFullName);
        dataBuff.setRequiredRevision(natRevision);
        dataBuff.setRequiredFileContents(natFileContents);
        obj.copyBuffToPKey();
        SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj> sortedMap = (SortedMap<CFAstConfigurationFilePKey, ICFAstConfigurationFileObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstExtensionsConfObj realized = (ICFAstExtensionsConfObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}