示例#1
0
const StringBuffer &CEspApplicationPort::getNavBarContent(IEspContext &context, StringBuffer &content, StringBuffer &contentType, bool rawxml)
{
    if (xslp)
    {
        Owned<IPropertyTree> navtree=createPTree("EspNavigationData");
        {
            ReadLockBlock rblock(rwLock);
            int count = getBindingCount();
            for (int idx = 0; idx<count; idx++)
                bindings[idx]->queryBinding()->getNavigationData(context, *navtree.get());
        }

        StringBuffer xml;
        buildNavTreeXML(navtree.get(), xml);
        if (rawxml)
        {
            content.swapWith(xml);
            contentType.clear().append(HTTP_TYPE_APPLICATION_XML_UTF8);
        }
        else
        {
            const char* viewType = navtree->queryProp("@viewType");

            Owned<IXslTransform> xform = xslp->createXslTransform();

            StringBuffer xslsource;
            if (viewType && *viewType)
            {
                xslsource.append(getCFD()).appendf("./xslt/%s.xsl", stricmp(viewType, "tree") != 0 ? viewType: "navigation");
            }
            else
            {
                xslsource.append(getCFD()).append("./xslt/nav.xsl");

            }
            xform->loadXslFromFile(xslsource.str());


            xform->setXmlSource(xml.str(), xml.length()+1);
            xform->transform(content);
            contentType.clear().append("text/html; charset=UTF-8");
        }
    }
    return content;
}
示例#2
0
void CEspApplicationPort::buildNavTreeXML(IPropertyTree* navtree, StringBuffer& xmlBuf, bool insideFolder)
{
    if (!navtree)
        return;

    //Find out the menu items which do not request a specific position
    //Also find out the maximum position being requested
    unsigned positionMax = 0;
    StringArray itemsGroup1;
    Owned<IPropertyTreeIterator> items = navtree->getElements("*");
    ForEach(*items)
    {
        IPropertyTree &item = items->query();
        unsigned position = (unsigned) item.getPropInt("@relPosition", 0);
        if (position > positionMax)
        {
            positionMax = position;
        }
        else if (position < 1)
        {//if the item does not request a position, add it to the 'itemsGroup1'.
            StringBuffer itemXML;
            if (!insideFolder)
                buildNavTreeXML(&item, itemXML, true);
            else
                toXML(&item, itemXML);

            itemsGroup1.append(itemXML);
        }
    }

    xmlBuf.appendf("<%s", navtree->queryName());
    Owned<IAttributeIterator> attrs = navtree->getAttributes();
    ForEach(*attrs)
    {
        const char *attrname = attrs->queryName()+1;
        const char *attrvaluee = attrs->queryValue();
        if (attrname && *attrname && attrvaluee && *attrvaluee)
            xmlBuf.appendf(" %s=\"%s\"", attrname, attrvaluee);
    }
    xmlBuf.append(">\n");

    unsigned positionInGroup1 = 0;
    unsigned itemCountInGroup1 = itemsGroup1.length();

    //append the menu items based on the position requested
    unsigned position = 1;
    while (position <= positionMax)
    {
        bool foundOne = false;

        //process the item(s) which asks for this position
        StringBuffer xPath;
        xPath.appendf("*[@relPosition=%d]", position);
        Owned<IPropertyTreeIterator> items1 = navtree->getElements(xPath.str());
        ForEach(*items1)
        {
            IPropertyTree &item = items1->query();

            StringBuffer itemXML;
            if (!insideFolder)
                buildNavTreeXML(&item, itemXML, true);
            else
                toXML(&item, itemXML);
            xmlBuf.append(itemXML.str());

            foundOne = true;
        }

        //If no one asks for this position, pick one from the itemsGroup1
        if (!foundOne && (positionInGroup1 < itemCountInGroup1))
        {
            StringBuffer itemXML = itemsGroup1.item(positionInGroup1);
            xmlBuf.append(itemXML.str());
            positionInGroup1++;
        }

        position++;
    }

    //Check any item left inside the itemsGroup1 and append it into the xml
    while (positionInGroup1 < itemCountInGroup1)
    {
        StringBuffer itemXML = itemsGroup1.item(positionInGroup1);
        xmlBuf.append(itemXML.str());
        positionInGroup1++;
    }

    xmlBuf.appendf("</%s>\n", navtree->queryName());
}