/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/// Implements getCommandValues(".uno:Fields"). /// /// Parameters: /// /// - typeName: field type condition to not return all fields /// - namePrefix: field name prefix to not return all fields void GetFields(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell, const std::map<OUString, OUString>& rArguments)
{
OUString aTypeName;
{ auto it = rArguments.find(u"typeName"_ustr); if (it != rArguments.end())
{
aTypeName = it->second;
}
} // See SwFieldTypeFromString(). if (aTypeName != "SetRef")
{ return;
}
OUString aNamePrefix;
{ auto it = rArguments.find(u"namePrefix"_ustr); if (it != rArguments.end())
{
aNamePrefix = it->second;
}
}
SwDoc* pDoc = pDocShell->GetDoc(); auto aBookmarks = rJsonWriter.startArray("setRefs");
std::vector<const SwFormatRefMark*> aRefMarks; for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
{
aRefMarks.push_back(pDoc->GetRefMark(i));
} // Sort the refmarks based on their start position.
std::sort(aRefMarks.begin(), aRefMarks.end(),
[](const SwFormatRefMark* pMark1, const SwFormatRefMark* pMark2) -> bool { const SwTextRefMark* pTextRefMark1 = pMark1->GetTextRefMark(); const SwTextRefMark* pTextRefMark2 = pMark2->GetTextRefMark();
SwPosition aPos1(pTextRefMark1->GetTextNode(), pTextRefMark1->GetStart());
SwPosition aPos2(pTextRefMark2->GetTextNode(), pTextRefMark2->GetStart()); return aPos1 < aPos2;
});
for (constauto& pRefMark : aRefMarks)
{ if (!pRefMark->GetRefName().toString().startsWith(aNamePrefix))
{ continue;
}
auto aProperty = rJsonWriter.startStruct();
rJsonWriter.put("name", pRefMark->GetRefName().toString());
}
}
/// Implements getCommandValues(".uno:Layout"). void GetLayout(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell)
{
rJsonWriter.put("commandName", ".uno:Layout"); auto aCommandValues = rJsonWriter.startNode("commandValues"); auto aPages = rJsonWriter.startArray("pages");
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
SwRootFrame* pLayout = pWrtShell->GetLayout(); for (SwFrame* pFrame = pLayout->GetLower(); pFrame; pFrame = pFrame->GetNext())
{ auto pPage = pFrame->DynCastPageFrame(); auto aPage = rJsonWriter.startStruct();
rJsonWriter.put("isInvalidContent", pPage->IsInvalidContent());
}
}
/// Implements getCommandValues(".uno:Field"). /// /// Parameters: /// /// - typeName: field type condition to not return all fields /// - namePrefix: field name prefix to not return all fields void GetField(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell, const std::map<OUString, OUString>& rArguments)
{
OUString aTypeName;
{ auto it = rArguments.find(u"typeName"_ustr); if (it != rArguments.end())
{
aTypeName = it->second;
}
} // See SwFieldTypeFromString(). if (aTypeName != "SetRef")
{ return;
}
OUString aNamePrefix;
{ auto it = rArguments.find(u"namePrefix"_ustr); if (it != rArguments.end())
{
aNamePrefix = it->second;
}
}
/// Implements getCommandValues(".uno:ExtractDocumentStructures"). /// /// Parameters: /// /// - filter: To filter what document structure types to extract /// now, only contentcontrol is supported. void GetDocStructure(tools::JsonWriter& rJsonWriter, SwDocShell* /*pDocShell*/, const std::map<OUString, OUString>& rArguments, const uno::Reference<container::XIndexAccess>& xContentControls)
{ auto it = rArguments.find(u"filter"_ustr); if (it != rArguments.end())
{ // If filter is present but we are filtering not to contentcontrols if (!it->second.equals(u"contentcontrol"_ustr)) return;
}
int iCCcount = xContentControls->getCount();
for (int i = 0; i < iCCcount; ++i)
{
OString aNodeName("ContentControls.ByIndex."_ostr + OString::number(i)); auto ContentControlNode = rJsonWriter.startNode(aNodeName);
switch (aType)
{ case SwContentControlType::RICH_TEXT:
{
rJsonWriter.put("type", "rich-text");
} break; case SwContentControlType::CHECKBOX:
{
rJsonWriter.put("type", "checkbox"); bool bchecked = false;
xContentControlProps->getPropertyValue(UNO_NAME_CHECKED) >>= bchecked;
rJsonWriter.put(UNO_NAME_CHECKED, OUString::boolean(bchecked));
} break; case SwContentControlType::DROP_DOWN_LIST:
{
rJsonWriter.put("type", "drop-down-list"); // we could list its elements if we want
} break; case SwContentControlType::PICTURE:
{
rJsonWriter.put("type", "picture");
} break; case SwContentControlType::DATE:
{
rJsonWriter.put("type", "date");
OUString aDateFormat;
xContentControlProps->getPropertyValue(UNO_NAME_DATE_FORMAT) >>= aDateFormat;
rJsonWriter.put(UNO_NAME_DATE_FORMAT, aDateFormat);
OUString aDateLanguage;
xContentControlProps->getPropertyValue(UNO_NAME_DATE_LANGUAGE) >>= aDateLanguage;
rJsonWriter.put(UNO_NAME_DATE_LANGUAGE, aDateLanguage);
OUString aCurrentDate;
xContentControlProps->getPropertyValue(UNO_NAME_CURRENT_DATE) >>= aCurrentDate;
rJsonWriter.put(UNO_NAME_CURRENT_DATE, aCurrentDate);
} break; case SwContentControlType::PLAIN_TEXT:
{
rJsonWriter.put("type", "plain-text");
} break; case SwContentControlType::COMBO_BOX:
{
rJsonWriter.put("type", "combo-box"); // we could list its elements if we want
} break; default: //it should never happen
rJsonWriter.put("type", "no type?");
}
}
}
void GetDocStructureCharts(tools::JsonWriter& rJsonWriter, SwDocShell* /*pDocShell*/, const std::map<OUString, OUString>& rArguments, const uno::Reference<container::XIndexAccess>& xEmbeddeds)
{ auto it = rArguments.find(u"filter"_ustr); if (it != rArguments.end())
{ // If filter is present but we are filtering not to charts if (!it->second.equals(u"charts"_ustr)) return;
}
sal_Int32 nEOcount = xEmbeddeds->getCount();
for (int i = 0; i < nEOcount; ++i)
{
uno::Reference<beans::XPropertySet> xShapeProps(xEmbeddeds->getByIndex(i), uno::UNO_QUERY); if (!xShapeProps.is()) continue;
uno::Reference<frame::XModel> xDocModel;
xShapeProps->getPropertyValue(u"Model"_ustr) >>= xDocModel; if (!xDocModel.is()) continue;
uno::Reference<chart2::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY); if (!xChartDoc.is()) continue;
uno::Reference<chart2::data::XDataProvider> xDataProvider(xChartDoc->getDataProvider()); if (!xDataProvider.is()) continue;
uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc->getDataProvider(),
uno::UNO_QUERY); if (!xDataArray.is()) continue;
uno::Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram(); if (!xDiagram.is()) continue;
//we have the chart Data now, we can start to extract it
OString aNodeName("Charts.ByEmbedIndex."_ostr + OString::number(i)); auto aChartNode = rJsonWriter.startNode(aNodeName);
//get the object name
uno::Reference<container::XNamed> xNamedShape(xEmbeddeds->getByIndex(i), uno::UNO_QUERY); if (xNamedShape.is())
{
OUString aName;
aName = xNamedShape->getName();
rJsonWriter.put("name", aName);
}
//get the chart title, if there is one
uno::Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW); if (xTitled.is())
{
uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject(); if (xTitle.is())
{
OUString aTitle; const uno::Sequence<uno::Reference<chart2::XFormattedString>> aFSSeq
= xTitle->getText(); for (autoconst& fs : aFSSeq)
aTitle += fs->getString();
rJsonWriter.put("title", aTitle);
}
}
//get the chart subtitle, if there is one
uno::Reference<chart2::XTitled> xSubTitled(xDiagram, uno::UNO_QUERY_THROW); if (xSubTitled.is())
{
uno::Reference<chart2::XTitle> xSubTitle = xSubTitled->getTitleObject(); if (xSubTitle.is())
{
OUString aSubTitle; const uno::Sequence<uno::Reference<chart2::XFormattedString>> aFSSeq
= xSubTitle->getText(); for (autoconst& fs : aFSSeq)
aSubTitle += fs->getString();
rJsonWriter.put("subtitle", aSubTitle);
}
}
{
uno::Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions(); auto aRowDescNode = rJsonWriter.startArray("RowDescriptions"); for (int j = 0; j < aRowDesc.getLength(); j++)
{
rJsonWriter.putSimpleValue(aRowDesc[j]);
}
}
{
uno::Sequence<OUString> aColDesc = xDataArray->getColumnDescriptions(); auto aColDescNode = rJsonWriter.startArray("ColumnDescriptions"); for (int j = 0; j < aColDesc.getLength(); j++)
{
rJsonWriter.putSimpleValue(aColDesc[j]);
}
}
{
uno::Sequence<uno::Sequence<double>> aData = xDataArray->getData(); auto aDataValuesNode = rJsonWriter.startArray("DataValues"); for (int j = 0; j < aData.getLength(); j++)
{ auto aRowNode = rJsonWriter.startAnonArray(); for (int k = 0; k < aData[j].getLength(); k++)
{
rJsonWriter.putSimpleValue(OUString::number(aData[j][k]));
}
}
}
}
}
void GetDocStructureDocProps(tools::JsonWriter& rJsonWriter, const SwDocShell* pDocShell, const std::map<OUString, OUString>& rArguments)
{ auto it = rArguments.find(u"filter"_ustr); if (it != rArguments.end())
{ // If filter is present but we are filtering not to document properties if (!it->second.equals(u"docprops"_ustr)) return;
}
uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropsSupplier(
pDocShell->GetModel(), uno::UNO_QUERY); if (!xDocumentPropsSupplier.is()) return;
//uno::Reference<document::XDocumentProperties> xDocProps();
uno::Reference<document::XDocumentProperties2> xDocProps(
xDocumentPropsSupplier->getDocumentProperties(), uno::UNO_QUERY); if (!xDocProps.is()) return;
auto aDocPropsNode = rJsonWriter.startNode("DocumentProperties");
// StringBuffer for converting DateTimes to String
OUStringBuffer aDateBuf(32);
//Properties from XDocumentProperties
OUString aAuthor = xDocProps->getAuthor();
rJsonWriter.put("Author", aAuthor);
//Properties from XDocumentProperties2
uno::Sequence<OUString> aContributor = xDocProps->getContributor();
{ auto aContributorNode = rJsonWriter.startArray("Contributor"); for (int i = 0; i < aContributor.getLength(); i++)
{
rJsonWriter.putSimpleValue(aContributor[i]);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.