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

📄 parser.cpp

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

Copy* Parser::getCopy(const char*xml) {
    Copy* ret = NULL;

    CmdID*      cmdID   = NULL;
    BOOL        noResp  = NULL;
    Cred*       cred    = NULL;
    Meta*       meta    = NULL;
    ArrayList*  items   = NULL;

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
    cmdID   = getCmdID     (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContentLevel (xml, META,    NULL);
    meta    = getMeta      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, CRED   , NULL);
    cred    = getCred      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
    noResp  = getNoResp    (t);
    if (t) {delete [] t; t = NULL;}
    items = getItems(xml, COPY);

    if ((cmdID) ||
        (cred)  ||
        NotZeroArrayLenght(1, items)
        )  {

        ret = new Copy(cmdID, noResp, cred, meta, items);
    }

    deleteCmdID(&cmdID);
    deleteMeta(&meta);
    deleteCred(&cred);
    deleteArrayList(&items);

    return ret;
}


Add* Parser::getAdd(const char*xml) {
    Add* ret = NULL;

    CmdID*      cmdID   = NULL;
    BOOL        noResp  = NULL;
    Cred*       cred    = NULL;
    Meta*       meta    = NULL;
    ArrayList*  items   = NULL;

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
    cmdID   = getCmdID     (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContentLevel (xml, META,    NULL);
    meta    = getMeta      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, CRED   , NULL);
    cred    = getCred      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
    noResp  = getNoResp    (t);
    if (t) {delete [] t; t = NULL;}
    items = getItems(xml, ADD);

    if ((cmdID) ||
        (cred)  ||
        NotZeroArrayLenght(1, items)
        )  {

        ret = new Add(cmdID, noResp, cred, meta, items);
    }

    deleteCmdID(&cmdID);
    deleteMeta(&meta);
    deleteCred(&cred);
    deleteArrayList(&items);

    return ret;
}

Delete* Parser::getDelete(const char*xml) {
    Delete* ret = NULL;

    CmdID*      cmdID   = NULL;
    BOOL        noResp  = NULL;
    BOOL        archive = NULL;
    BOOL        sftDel  = NULL;
    Cred*       cred    = NULL;
    Meta*       meta    = NULL;
    ArrayList*  items   = NULL;

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
    cmdID   = getCmdID     (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContentLevel (xml, META,    NULL);
    meta    = getMeta      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, CRED   , NULL);
    cred    = getCred      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
    noResp  = getNoResp    (t);
    if (t) {delete [] t; t = NULL;}
    items = getItems(xml, DEL);

    if ((cmdID) ||
        (cred)  ||
        NotZeroArrayLenght(1, items)
        )  {

        ret = new Delete(cmdID, noResp, archive, sftDel, cred, meta, items);
    }

    deleteCmdID(&cmdID);
    deleteMeta(&meta);
    deleteCred(&cred);
    deleteArrayList(&items);

    return ret;
}

Replace* Parser::getReplace(const char*xml) {
    Replace* ret = NULL;

    CmdID*      cmdID   = NULL;
    BOOL        noResp  = NULL;
    Cred*       cred    = NULL;
    Meta*       meta    = NULL;
    ArrayList*  items   = NULL;

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
    cmdID   = getCmdID     (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContentLevel (xml, META,    NULL);
    meta    = getMeta      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, CRED   , NULL);
    cred    = getCred      (t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
    noResp  = getNoResp    (t);
    if (t) {delete [] t; t = NULL;}
    items = getItems(xml, REPLACE);

    if ((cmdID) ||
        (cred)  ||
        NotZeroArrayLenght(1, items)
        )  {

        ret = new Replace(cmdID, noResp, cred, meta, items);
    }

    deleteCmdID(&cmdID);
    deleteMeta(&meta);
    deleteCred(&cred);
    deleteArrayList(&items);

    return ret;
}

MapItem* Parser::getMapItem(const char*xml) {
    MapItem* ret = NULL;

    Target*    target = NULL;
    Source*    source = NULL;

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent(xml, TARGET,NULL);
    target   = getTarget(t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent(xml, SOURCE,NULL);
    source   = getSource(t);

    if ((target)||
        (source)) {

        ret = new MapItem(target, source);
    }

    deleteTarget(&target);
    deleteSource(&source);

    return ret;
}

/*
* Returns an ArrayList of mapItem command
*/
ArrayList* Parser::getMapItems(const char*xml) {

    MapItem* mapItem = NULL;
    unsigned int pos = 0, previous = 0;
    ArrayList* list = new ArrayList();

    char* t = NULL;
    t = XMLProcessor::copyElementContent(&xml[pos], MAP_ITEM, &pos);
    while ((mapItem = getMapItem(t)) != NULL) {
        if (mapItem) {
            list->add(*mapItem); // in the ArrayList NULL element cannot be inserted
            deleteMapItem(&mapItem);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL; }
        t = XMLProcessor::copyElementContent(&xml[pos], MAP_ITEM, &pos);
    }
    if (t) {delete [] t; t = NULL;}
    return list;
}

Map* Parser::getMap(const char*xml) {
    Map* ret = NULL;

    CmdID*     cmdID  = NULL;
    Cred*      cred   = NULL;
    Meta*      meta   = NULL;

    Target*    target = NULL;
    Source*    source = NULL;
    ArrayList* mapItems; //MapItem[]

    unsigned int pos = 0;
    char* t = NULL;
    t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
    cmdID   = getCmdID(t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContentLevel (xml, META,    NULL);
    meta    = getMeta(t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent (xml, CRED   , NULL);
    cred    = getCred(t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent(xml, TARGET,NULL);
    target   = getTarget(t);
    if (t) {delete [] t; t = NULL;}
    t = XMLProcessor::copyElementContent(xml, SOURCE,  NULL);
    source   = getSource(t);
    if (t) {delete [] t; t = NULL;}
    mapItems = getMapItems(xml);

    if ((cmdID) ||
        (meta)  ||
        (cred)  ||
        (target)||
        (source)||
        NotZeroArrayLenght(1, mapItems)
        )  {

        ret = new Map(cmdID, target, source, cred, meta, mapItems);
    }

    deleteCmdID(&cmdID);
    deleteMeta(&meta);
    deleteCred(&cred);
    deleteTarget(&target);
    deleteSource(&source);
    deleteArrayList(&mapItems);

    return ret;
}


/*
* Returns an ArrayList of copy command
*/
ArrayList* Parser::getCopies(const char*xml, const char*except) {

    Copy* copy = NULL;
    unsigned int pos = 0, previous = 0;
    ArrayList* list = NULL;

   /*
    * except is set to SYNC if we are looking for Copy commands external from <sync> tag
    */
    char* t = NULL;
    t = XMLProcessor::copyElementContentExcept(&xml[pos], COPY, except, &pos);
    while ((copy = getCopy(t)) != NULL) {
        if (copy) {
            if (!list)
                list = new ArrayList();
            list->add(*copy); // in the ArrayList NULL element cannot be inserted
            deleteCopy(&copy);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL; }
        t = XMLProcessor::copyElementContentExcept(&xml[pos], COPY, except, &pos);
    }
    if (t) {delete [] t; t = NULL;}
    return list;
}

/*
* Returns an ArrayList of add command
*/
ArrayList* Parser::getAdds(const char*xml, const char*except) {

    Add* add         = NULL;
    unsigned int pos = 0, previous = 0;
    ArrayList* list  = NULL;
    char* t         = NULL;
   /*
    * except is set to SYNC if we are looking for Add commands external from <sync> tag
    */
    t = XMLProcessor::copyElementContentExcept(&xml[pos], ADD, except, &pos);
    while ((add = getAdd(t)) != NULL) {
        if (add) {
            if (!list)
                list = new ArrayList();
            list->add(*add); // in the ArrayList NULL element cannot be inserted
            deleteAdd(&add);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL; }
        t = XMLProcessor::copyElementContentExcept(&xml[pos], ADD, except, &pos);
    }
    if (t) { delete [] t; t = NULL; }
    return list;
}

/*
* Returns an ArrayList of Replace commands
*/
ArrayList* Parser::getReplaces(const char*xml, const char*except) {

    Replace* replace = NULL;
    unsigned int pos = 0, previous = 0;
    ArrayList* list = NULL;
    char* t        = NULL;

    t = XMLProcessor::copyElementContentExcept(&xml[pos], REPLACE, except, &pos);
    while ((replace = getReplace(t)) != NULL) {
        if (replace) {
            if (!list)
                list = new ArrayList();
            list->add(*replace); // in the ArrayList NULL element cannot be inserted
            deleteReplace(&replace);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL; }
        t = XMLProcessor::copyElementContentExcept(&xml[pos], REPLACE, except, &pos);
    }
    if (t) { delete [] t; t = NULL; }
    return list;
}

/*
* Returns an ArrayList of Dels command
*/
ArrayList* Parser::getDels(const char*xml, const char*except) {

    Delete* del        = NULL;
    unsigned int pos   = 0, previous = 0;
    ArrayList* list    = NULL;
    char* t           = NULL;

    t = XMLProcessor::copyElementContentExcept(&xml[pos], DEL, except, &pos);
    while ((del = getDelete(t)) != NULL) {
        if (del) {
            if (!list)
                list = new ArrayList();
            list->add(*del); // in the ArrayList NULL element cannot be inserted
            deleteDelete(&del);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL;}
        t = XMLProcessor::copyElementContentExcept(&xml[pos], DEL, except, &pos);
    }
    if (t) { delete [] t; t = NULL; }
    return list;
}

/*
Commands of SyncBody tag
    Alert
    Add
    Atomic
    Copy
    Delete
    Exec
    Get
    Map
    Put
    Replace
    Results
    Search
    Sequence
    Status
    Sync
*/
ArrayList* Parser::getCommands(const char*xml) {
    ArrayList* ret    = new ArrayList();

    ArrayList* list     = NULL;
    Alert* alert        = NULL;
    Map*   map          = NULL;
    Get*   get          = NULL;
    Put*   put          = NULL;
    Status* status      = NULL;
    Results* result     = NULL;
    Exec* exec          = NULL;
    Search* search      = NULL;

    Sequence* sequence  = NULL;
    Atomic* atomic      = NULL;
    Sync* sync          = NULL;
    unsigned int pos = 0, previous = 0;
    char* t            = NULL;


    // Status
    t = XMLProcessor::copyElementContent(&xml[pos], STATUS, &pos);
    while ((status = getStatus(t)) != NULL) {
        if (status) {
            if (!list)
                list = new ArrayList();
            list->add(*status); // in the ArrayList NULL element cannot be inserted
            deleteStatus(&status);
        }
        pos += previous;
        previous = pos;
        if (t) { delete [] t; t = NULL; }
        t = XMLProcessor::copyElementContent(&xml[pos], STATUS, &pos);
    }
    if (t) { delete [] t; t = NULL; }

    if (list && list->size() > 0) {
        for (int i = 0; i < list->size(); i++) {
            ret->add(*list->get(i));

⌨️ 快捷键说明

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