⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formatter.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 5 页
字号:

    if (!adds || !NotZeroArrayLenght(1, adds))
        return NULL;

    StringBuffer* ret = new StringBuffer();

    for (int i = 0; i < adds->size(); i++) {
        ret->append(getAdd(((Add*)adds->get(i))));
    }
    return ret;
}

StringBuffer* Formatter::getAdd(Add* add) {

    if (!add)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer* cmdID     = NULL;
    StringBuffer* cred      = NULL;
    StringBuffer* meta      = NULL;
    StringBuffer* items     = NULL;
    StringBuffer* noResp    = NULL;

    cmdID     = getCmdID   (add->getCmdID());
    cred      = getCred    (add->getCred());
    meta      = getMeta    (add->getMeta());
    items     = getItems   (add->getItems());
    noResp    = getValue   (NO_RESP, add->getNoResp());

    if (NotZeroStringBufferLenght(5, cmdID, cred, meta, items, noResp)) {
        s = new StringBuffer();
        s->append(cmdID);
        s->append(noResp);
        s->append(cred);
        s->append(meta);
        s->append(items);
    }

    ret = getValue(ADD, s);
    deleteAllStringBuffer(6, &s, &cred, &cmdID, &meta, &items, &noResp);

    return ret;
}

StringBuffer* Formatter::getPut(Put* put) {

    if (!put)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer*        cmdID  = NULL;
    StringBuffer*        meta   = NULL;
    StringBuffer*        items  = NULL;
    StringBuffer*        cred   = NULL;
    StringBuffer*        noResp = NULL;
    StringBuffer*        lang   = NULL;

    cmdID     = getCmdID   (put->getCmdID());
    noResp    = getValue   (NO_RESP, put->getNoResp());
    lang      = getValue   (LANG, put->getLang());
    cred      = getCred    (put->getCred());
    meta      = getMeta    (put->getMeta());
    items     = getItems   (put->getItems());

    if (NotZeroStringBufferLenght(6, cmdID, lang, meta, items, cred, noResp)) {
        s = new StringBuffer();
        s->append(cmdID);
        s->append(noResp);
        s->append(lang);
        s->append(cred);
        s->append(meta);
        s->append(items);
    }

    ret = getValue(PUT, s);
    deleteAllStringBuffer(7, &s, &cmdID, &items, &cred, &lang, &meta, &noResp);

    return ret;
}

StringBuffer* Formatter::getResults(Results* results) {

    if (!results)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer*        cmdID  = NULL;
    StringBuffer*        msgRef = NULL;
    StringBuffer*        cmdRef = NULL;
    StringBuffer*        meta   = NULL;
    StringBuffer*        items  = NULL;
    StringBuffer*        targetRefs  = NULL;
    StringBuffer*        sourceRefs  = NULL;

    cmdID     = getCmdID   (results->getCmdID());
    msgRef    = getValue   (MSG_REF, results->getMsgRef());
    cmdRef    = getValue   (CMD_REF, results->getCmdRef());
    meta      = getMeta    (results->getMeta());
    items     = getItems   (results->getItems());
    sourceRefs = getSourceRefs(results->getSourceRef());
    targetRefs = getTargetRefs(results->getTargetRef());

    if (NotZeroStringBufferLenght(7, cmdID, msgRef, cmdRef, meta, items, sourceRefs, targetRefs)) {
        s = new StringBuffer();
        s->append(cmdID);
        s->append(msgRef);
        s->append(cmdRef);
        s->append(meta);
        s->append(targetRefs);
        s->append(sourceRefs);
        s->append(items);
    }

    ret = getValue(RESULTS, s);
    deleteAllStringBuffer(8, &s, &cmdID, &items, &msgRef, &cmdRef, &meta, &sourceRefs, &targetRefs);

    return ret;
}

/*
* Returns a series of
*  <Status> ... </Status>
*  <Status> ... </Status>
*  <Status> ... </Status>
*
*/
StringBuffer* Formatter::getStatusArray(ArrayList* statusArray) {

    if (!statusArray || !NotZeroArrayLenght(1, statusArray))
        return NULL;

    StringBuffer* ret = new StringBuffer();
    StringBuffer* tmp = NULL;

    for (int i = 0; i < statusArray->size(); i++) {
        tmp = getStatus(((Status*)statusArray->get(i)));
        ret->append(tmp);
        if (tmp) { delete tmp; tmp = NULL; }
    }
    return ret;
}

StringBuffer* Formatter::getStatus(Status* status) {

    if (!status)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer*        cmdID  = NULL;
    StringBuffer*        msgRef = NULL;
    StringBuffer*        cmdRef = NULL;
    StringBuffer*        cmd    = NULL;
    StringBuffer*        cred   = NULL;
    StringBuffer*        items  = NULL;
    StringBuffer*        targetRefs  = NULL;
    StringBuffer*        sourceRefs  = NULL;
    StringBuffer*        data        = NULL;
    StringBuffer*        chal        = NULL;

    cmdID     = getCmdID   (status->getCmdID());
    msgRef    = getValue   (MSG_REF, status->getMsgRef());
    cmdRef    = getValue   (CMD_REF, status->getCmdRef());
    cmd       = getValue   (CMD     , status->getCmd());
    items     = getItems   (status->getItems());
    cred      = getCred    (status->getCred());
    sourceRefs = getSourceRefs(status->getSourceRef());
    targetRefs = getTargetRefs(status->getTargetRef());
    chal      = getChal(status->getChal());
    data      = getData   (status->getData());

    if (NotZeroStringBufferLenght(10, cmdID, msgRef, cmdRef, cmd, cred, data, items, sourceRefs, targetRefs, chal)) {
        s = new StringBuffer();
        s->append(cmdID);
        s->append(msgRef);
        s->append(cmdRef);
        s->append(cmd);
        s->append(targetRefs);
        s->append(sourceRefs);
        s->append(cred);
        s->append(chal);
        s->append(data);
        s->append(items);
    }

    ret = getValue(STATUS, s);
    deleteAllStringBuffer(11, &s, &cred, &cmdID, &data, &items, &msgRef, &cmdRef, &cmd, &sourceRefs, &targetRefs, &chal);

    return ret;
}

StringBuffer* Formatter::getChal(Chal* chal) {
    if (!chal)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer* meta     = getMeta   (chal->getMeta());

    if (NotZeroStringBufferLenght(1, meta)) {
        s = new StringBuffer();
        s->append(meta);
    }

    ret = getValue(CHAL, s);
    deleteAllStringBuffer(2, &s, &meta);

    return ret;

}

/*
* Returns a series of
*  <Alert> ... </Alert>
*  <Alert> ... </Alert>
*  <Alert> ... </Alert>
*
*  The root is <SyncBody>
*/
StringBuffer* Formatter::getAlerts(ArrayList* alerts) {

    if (!alerts || !NotZeroArrayLenght(1, alerts))
        return NULL;

    StringBuffer* ret = new StringBuffer();
    StringBuffer* tmp = NULL;

    for (int i = 0; i < alerts->size(); i++) {
        tmp = getAlert(((Alert*)alerts->get(i)));
        ret->append(tmp);
        if (tmp) { delete tmp; tmp = NULL; }
    }
    return ret;
}

StringBuffer* Formatter::getAlert(Alert* alert) {

    if (!alert)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer* cmdID     = getCmdID   (alert->getCmdID());
    StringBuffer* cred      = getCred    (alert->getCred());
    StringBuffer* data      = getValue   (DATA, (long)alert->getData());
    StringBuffer* items     = getItems   (alert->getItems());
    StringBuffer* noResp    = getValue   (NO_RESP, alert->getNoResp());

    if (NotZeroStringBufferLenght(5, cmdID, cred, data, items, noResp)) {
        s = new StringBuffer();
        s->append(cmdID);
        s->append(noResp);
        s->append(cred);
        s->append(data);
        s->append(items);
    }

    ret = getValue(ALERT, s);
    deleteAllStringBuffer(6, &s, &cred, &cmdID, &data, &items, &noResp);

    return ret;
}

/*
* Returns a series of
*  <Item> ... </Item>
*  <Item> ... </Item>
*  <Item> ... </Item>
*
*/
StringBuffer* Formatter::getItems(ArrayList* items) {

    if (!items || !NotZeroArrayLenght(1, items))
        return NULL;

    StringBuffer* ret = new StringBuffer();
    StringBuffer* tmp = NULL;

    for (int i = 0; i < items->size(); i++) {
        tmp = getItem(((Item*)items->get(i)));
        ret->append(tmp);
        if (tmp) { delete tmp; tmp = NULL; }
    }
    return ret;
}

StringBuffer* Formatter::getItem(Item* item) {

    if (!item)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer*      target   = NULL;
    StringBuffer*      source   = NULL;
    StringBuffer*      meta     = NULL;
    StringBuffer*      data     = NULL;
    StringBuffer*      moreData = NULL;
    StringBuffer*      targetParent = NULL;
    StringBuffer*      sourceParent = NULL;



    target    = getTarget   (item->getTarget());
    source    = getSource   (item->getSource());
    meta      = getMeta     (item->getMeta());
    data      = getData     (item->getData());
    moreData  = getValue    (MORE_DATA, item->getMoreData());
    targetParent  = getValue    (TARGET_PARENT, item->getTargetParent());
    sourceParent  = getValue    (SOURCE_PARENT, item->getSourceParent());


    if (NotZeroStringBufferLenght(7, target, source, targetParent, sourceParent, meta, data, moreData)) {
        s = new StringBuffer();
        s->append(target);
        s->append(source);
        s->append(targetParent);
        s->append(sourceParent);
        s->append(meta);
        s->append(data);
        s->append(moreData);
    }

    ret = getValue(ITEM, s);
    deleteAllStringBuffer(8, &s, &target, &source, &targetParent, &sourceParent, &meta, &data, &moreData);

    return ret;
}

StringBuffer* Formatter::getData(Data* data) {

    if (!data)
        return NULL;

    StringBuffer* ret       = NULL;
    StringBuffer* s         = NULL;
    const char* simpleData  = NULL;

    if ((simpleData = data->getData()) != NULL) {
        s = new StringBuffer();
        s->append(simpleData);
        ret = getValue(DATA, s);
    }
    deleteAllStringBuffer(1, &s);
    return ret;
}

StringBuffer* Formatter::getData(ComplexData* data) {

    if (!data)
        return NULL;

    StringBuffer s;

    StringBuffer* anchor = getAnchor(data->getAnchor());
    StringBuffer* devInf = getDevInf(data->getDevInf());

    if ((anchor != NULL && anchor->length() > 0) ||
        (devInf != NULL && devInf->length() > 0)) {
        s.append(anchor);
        s.append(devInf);
    } else {
        if (data->getData() == NULL || strlen(data->getData()) == 0) {
            //nothing to do. For mailfilter
        }
        // it avoid error for the closing tag of CDATA
        else if (data->getData() && strstr(data->getData(), "]]>") == NULL ) {

            s.append("<![CDATA[");
            s.append(data->getData());
            s.append("]]>");

        } else {
            StringBuffer tmp(data->getData());
            tmp.replaceAll("&", "&amp;");
            tmp.replaceAll("<", "&lt;");
            s.append(tmp);
        }
    }

    deleteAllStringBuffer(2, &anchor, &devInf);

    //
    // Now let's process the list of Property (if any)
    //
    int nProps = 0;
    ArrayList* properties = data->getProperties();
    if (properties) {
        nProps = properties->size();
    }

    StringBuffer* t1 = NULL;
    for (int i=0; i<nProps; ++i) {
        t1 = getProperty((Property*)properties->get(i));
        s.append(t1);
        delete t1; t1 = NULL;
    }

    return getValue(DATA, &s);
}

StringBuffer* Formatter::getDevInf(DevInf* devInf) {

    if (!devInf)
        return NULL;

    StringBuffer* ret = NULL;
    StringBuffer* s   = NULL;

    StringBuffer* verDTD    = NULL;
    StringBuffer* man       = NULL;
    StringBuffer* mod       = NULL;
    StringBuffer* oem       = NULL;
    StringBuffer* fwV       = NULL;
    StringBuffer* swV       = NULL;
    StringBuffer* hwV       = NULL;
    StringBuffer* devID     = NULL;
    StringBuffer* devTyp    = NULL;

    StringBuffer* dataStores= NULL;     //DataStore[]
    StringBuffer* ctCaps    = NULL;     // CTCap[]
    StringBuffer* exts      = NULL;         // Ext[]

    StringBuffer* utc                    = NULL;
    StringBuffer* supportLargeObjs       = NULL;
    StringBuffer* supportNumberOfChanges = NULL;

    StringBuffer* syncCap   = NULL;

    // verDTD must always be sent!
    verDTD  = getVerDTD         (devInf->getVerDTD());

    // These elements should not be inserted if value is empty.
    man     = getValueNotEmpty  (MAN, devInf->getMan());
    mod     = getValueNotEmpty  (MOD, devInf->getMod());
    oem     = getValueNotEmpty  (OEM, devInf->getOEM());
    fwV     = getValueNotEmpty  (FWV, devInf->getFwV());
    swV     = getValueNotEmpty  (SWV, devInf->getSwV());
    hwV     = getValueNotEmpty  (HWV, devInf->getHwV());
    devID   = getValueNotEmpty  (DEV_ID, devInf->getDevID());
    devTyp  = getValueNotEmpty  (DEV_TYP, devInf->getDevTyp());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -