///////////////////////////////////////// // Write feature information as XML document. // MgByteReader* MgFeatureInformation::ToXml() { STRING xml; STRING xmlSelection = m_selection? m_selection->ToXml(false): L""; // TODO: define a schema for this XML xml.append(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureInformation>\n"); size_t len = xmlSelection.length(); if(len > 0) { xml.reserve(len + 2048); xml.append(xmlSelection); } else { xml.reserve(2048); xml.append(L"<FeatureSet />\n"); } if(m_tooltip.length() > 0) { xml.append(L"<Tooltip>"); xml.append(MgUtil::ReplaceEscapeCharInXml(m_tooltip)); xml.append(L"</Tooltip>\n"); } else xml.append(L"<Tooltip />\n"); if(m_hyperlink.length() > 0) { xml.append(L"<Hyperlink>"); xml.append(MgUtil::ReplaceEscapeCharInXml(m_hyperlink)); xml.append(L"</Hyperlink>\n"); } else xml.append(L"<Hyperlink />\n"); if(m_properties != NULL) { for(int i = 0; i < m_properties->GetCount(); i++) { Ptr<MgStringProperty> prop = (MgStringProperty*)m_properties->GetItem(i); xml.append(L"<Property name=\""); xml.append(MgUtil::ReplaceEscapeCharInXml(prop->GetName())); xml.append(L"\" value=\""); xml.append(MgUtil::ReplaceEscapeCharInXml(prop->GetValue())); xml.append(L"\" />\n"); } } xml.append(L"</FeatureInformation>\n"); string xmlDoc = MgUtil::WideCharToMultiByte(xml); STRING mimeType = L"text/xml"; return MgUtil::GetByteReader(xmlDoc, &mimeType); }
MgByteReader* MgHtmlController::CollectQueryMapFeaturesResult(MgResourceService* resourceService, INT32 requestData, MgFeatureInformation* featInfo, MgSelection* selectionSet, MgBatchPropertyCollection* attributes, MgByteReader* inlineSelection) { STRING xml; STRING tooltip; STRING hyperlink; STRING xmlSelection = selectionSet? selectionSet->ToXml(false): L""; if (NULL != featInfo) { tooltip = featInfo->GetTooltip(); hyperlink = featInfo->GetHyperlink(); } // TODO: Stil haven't defined a schema for v2.6. Should we? xml.append(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureInformation>\n"); size_t len = xmlSelection.length(); if(len > 0) { xml.reserve(len + 2048); xml.append(xmlSelection); } else { xml.reserve(2048); xml.append(L"<FeatureSet />\n"); } if (((requestData & REQUEST_TOOLTIP) == REQUEST_TOOLTIP) && !tooltip.empty()) { xml.append(L"<Tooltip>"); xml.append(MgUtil::ReplaceEscapeCharInXml(tooltip)); xml.append(L"</Tooltip>\n"); } else xml.append(L"<Tooltip />\n"); if (((requestData & REQUEST_HYPERLINK) == REQUEST_HYPERLINK) && !hyperlink.empty()) { xml.append(L"<Hyperlink>"); xml.append(MgUtil::ReplaceEscapeCharInXml(hyperlink)); xml.append(L"</Hyperlink>\n"); } else xml.append(L"<Hyperlink />\n"); if (((requestData & REQUEST_INLINE_SELECTION) == REQUEST_INLINE_SELECTION) && NULL != inlineSelection) { xml.append(L"<InlineSelectionImage>\n"); xml.append(L"<MimeType>"); xml.append(inlineSelection->GetMimeType()); xml.append(L"</MimeType>\n"); xml.append(L"<Content>"); MgByteSink sink(inlineSelection); Ptr<MgByte> bytes = sink.ToBuffer(); Ptr<MgMemoryStreamHelper> streamHelper = new MgMemoryStreamHelper((INT8*) bytes->Bytes(), bytes->GetLength(), false); std::string b64 = streamHelper->ToBase64(); STRING wb64 = MgUtil::MultiByteToWideChar(b64); xml.append(wb64); xml.append(L"</Content>\n"); xml.append(L"</InlineSelectionImage>\n"); } else xml.append(L"<InlineSelectionImage />\n"); if (((requestData & REQUEST_ATTRIBUTES) == REQUEST_ATTRIBUTES) && NULL != attributes) { xml.append(L"<SelectedFeatures>\n"); WriteSelectedFeatureAttributes(resourceService, selectionSet, attributes, xml); xml.append(L"</SelectedFeatures>\n"); } else xml.append(L"<SelectedFeatures />\n"); xml.append(L"</FeatureInformation>\n"); string xmlDoc = MgUtil::WideCharToMultiByte(xml); STRING mimeType = L"text/xml"; return MgUtil::GetByteReader(xmlDoc, &mimeType); }