Esempio n. 1
0
static void OutputNode(wxOutputStream& stream, wxXmlNode *node, int indent,
                       wxMBConv *convMem, wxMBConv *convFile)
{
    wxXmlNode *n, *prev;
    wxXmlProperty *prop;

    switch (node->GetType())
    {
        case wxXML_TEXT_NODE:
            OutputStringEnt(stream, node->GetContent(), convMem, convFile);
            break;

        case wxXML_ELEMENT_NODE:
            OutputString(stream, wxT("<"), NULL, NULL);
            OutputString(stream, node->GetName(), NULL, NULL);

            prop = node->GetProperties();
            while (prop)
            {
                OutputString(stream, wxT(" ") + prop->GetName() +  wxT("=\""),
                             NULL, NULL);
                OutputStringEnt(stream, prop->GetValue(), NULL, NULL,
                                true/*escapeQuotes*/);
                OutputString(stream, wxT("\""), NULL, NULL);
                prop = prop->GetNext();
            }

            if (node->GetChildren())
            {
                OutputString(stream, wxT(">"), NULL, NULL);
                prev = NULL;
                n = node->GetChildren();
                while (n)
                {
                    if (n && n->GetType() != wxXML_TEXT_NODE)
                        OutputIndentation(stream, indent + 1);
                    OutputNode(stream, n, indent + 1, convMem, convFile);
                    prev = n;
                    n = n->GetNext();
                }
                if (prev && prev->GetType() != wxXML_TEXT_NODE)
                    OutputIndentation(stream, indent);
                OutputString(stream, wxT("</"), NULL, NULL);
                OutputString(stream, node->GetName(), NULL, NULL);
                OutputString(stream, wxT(">"), NULL, NULL);
            }
            else
                OutputString(stream, wxT("/>"), NULL, NULL);
            break;

        case wxXML_COMMENT_NODE:
            OutputString(stream, wxT("<!--"), NULL, NULL);
            OutputString(stream, node->GetContent(), convMem, convFile);
            OutputString(stream, wxT("-->"), NULL, NULL);
            break;

        default:
            wxFAIL_MSG(wxT("unsupported node type"));
    }
}
Esempio n. 2
0
static void OutputNode(wxOutputStream& stream, wxXmlNode *node, int indent,
                       wxMBConv *convMem, wxMBConv *convFile, int indentstep)
{
    wxXmlNode *n, *prev;
    wxXmlProperty *prop;

    switch (node->GetType())
    {
        case wxXML_CDATA_SECTION_NODE:
            OutputString( stream, wxT("<![CDATA["));
            OutputString( stream, node->GetContent() );
            OutputString( stream, wxT("]]>") );
            break;

        case wxXML_TEXT_NODE:
            OutputEscapedString(stream, node->GetContent(),
                                convMem, convFile,
                                Escape_Text);
            break;

        case wxXML_ELEMENT_NODE:
            OutputString(stream, wxT("<"));
            OutputString(stream, node->GetName());

            prop = node->GetProperties();
            while (prop)
            {
                OutputString(stream, wxT(" ") + prop->GetName() +  wxT("=\""));
                OutputEscapedString(stream, prop->GetValue(),
                                    convMem, convFile,
                                    Escape_Attribute);
                OutputString(stream, wxT("\""));
                prop = prop->GetNext();
            }

            if (node->GetChildren())
            {
                OutputString(stream, wxT(">"));
                prev = NULL;
                n = node->GetChildren();
                while (n)
                {
                    if (indentstep >= 0 && n && n->GetType() != wxXML_TEXT_NODE)
                        OutputIndentation(stream, indent + indentstep);
                    OutputNode(stream, n, indent + indentstep, convMem, convFile, indentstep);
                    prev = n;
                    n = n->GetNext();
                }
                if (indentstep >= 0 && prev && prev->GetType() != wxXML_TEXT_NODE)
                    OutputIndentation(stream, indent);
                OutputString(stream, wxT("</"));
                OutputString(stream, node->GetName());
                OutputString(stream, wxT(">"));
            }
            else
                OutputString(stream, wxT("/>"));
            break;

        case wxXML_COMMENT_NODE:
            OutputString(stream, wxT("<!--"));
            OutputString(stream, node->GetContent(), convMem, convFile);
            OutputString(stream, wxT("-->"));
            break;

        default:
            wxFAIL_MSG(wxT("unsupported node type"));
    }
}
/// Recursive helper function for file saving
bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& osFile, int indent)
{
    OutputIndentation(osFile, indent*2);
    wxTextOutputStream stream(osFile);

    wxString name(item->GetName());
    wxString s;
    wxString typeStr;
    if (item->GetType() == ctTypeGroup)
        typeStr = wxT("group");
    else if (item->GetType() == ctTypeCheckGroup)
        typeStr = wxT("check-group");
    else if (item->GetType() == ctTypeRadioGroup)
        typeStr = wxT("radio-group");
    else if (item->GetType() == ctTypeString)
        typeStr = wxT("string");
    else if (item->GetType() == ctTypeBoolCheck)
        typeStr = wxT("bool-check");
    else if (item->GetType() == ctTypeBoolRadio)
        typeStr = wxT("bool-radio");
    else if (item->GetType() == ctTypeInteger)
        typeStr = wxT("integer");
    else
        typeStr = wxT("unknown");

    stream << wxT("<setting type=\"") << typeStr << wxT("\">");

    indent ++;

    OutputIndentation(osFile, indent*2);
    if (item->IsActive())
        stream << wxT("<active>1</active>");
    else
        stream << wxT("<active>0</active>");
    OutputIndentation(osFile, indent*2);
    if (item->IsEnabled())
        stream << wxT("<enabled>1</enabled>");
    else
        stream << wxT("<enabled>0</enabled>");

    // Output properties
    wxObjectList::compatibility_iterator node = item->GetProperties().GetList().GetFirst();
    while (node)
    {
        ctProperty* prop = (ctProperty*) node->GetData();
        OutputIndentation(osFile, indent*2);
        stream << wxT("<") << prop->GetName() ;

        if (prop->IsCustom())
        {
            stream << wxT(" custom=\"true\"");
            stream << wxT(" type=\"") << prop->GetVariant().GetType() << wxT("\"");
            stream << wxT(" editor-type=\"") << prop->GetEditorType() << wxT("\"");
            stream << wxT(" description=\"") << prop->GetDescription() << wxT("\"");
            if (prop->GetChoices().GetCount() > 0)
            {
                wxString choices;
                ctConfigItem::ArrayToString(prop->GetChoices(), choices);
                stream << wxT(" choices=\"") << choices << wxT("\"");
            }
        }

        stream << wxT(">");

        stream << ctEscapeHTMLCharacters(prop->GetVariant().GetString()) ;
        stream << wxT("</") << prop->GetName() << wxT(">");

        node = node->GetNext();
    }

    // Output children
    node = item->GetChildren().GetFirst();
    while (node)
    {
        ctConfigItem* child = (ctConfigItem*) node->GetData();
        DoSave(child, osFile, indent);

        node = node->GetNext();
    }

    indent --;

    OutputIndentation(osFile, indent*2);
    stream << wxT("</setting>");

    return true;
}