22#include <com/sun/star/beans/PropertyAttribute.hpp>
23#include <com/sun/star/beans/PropertyExistException.hpp>
24#include <com/sun/star/lang/IllegalArgumentException.hpp>
25#include <com/sun/star/xml/sax/SAXException.hpp>
31#include <osl/diagnose.h>
36#include <boost/algorithm/string.hpp>
45 const uno::Reference< document::XDocumentProperties >& rDocProp )
46 : m_xDocProp( rDocProp )
51 , m_CustomStringPropertyState(
NONE)
53 if ( !xContext.is() || !rDocProp.is() )
54 throw uno::RuntimeException();
76 const uno::Reference< beans::XPropertyContainer > xUserProps =
78 if ( !xUserProps.is() )
79 throw uno::RuntimeException();
84 beans::PropertyAttribute::REMOVABLE, aAny );
86 catch( beans::PropertyExistException& )
90 catch( uno::Exception& )
92 OSL_FAIL(
"Can not add custom property!" );
98 oslDateTime aOslDTime = { 0, 0, 0, 0, 0, 0, 0, 0 };
99 const size_t nLen = aChars.size();
102 aOslDTime.Year =
static_cast<sal_Int16
>(
o3tl::toInt32(aChars.substr( 0, 4 )));
104 if ( nLen >= 7 && aChars[4] ==
'-' )
106 aOslDTime.Month =
static_cast<sal_uInt16
>(
o3tl::toInt32(aChars.substr( 5, 2 )));
108 if ( nLen >= 10 && aChars[7] ==
'-' )
110 aOslDTime.Day =
static_cast<sal_uInt16
>(
o3tl::toInt32(aChars.substr( 8, 2 )));
112 if ( nLen >= 16 && aChars[10] ==
'T' && aChars[13] ==
':' )
114 aOslDTime.Hours =
static_cast<sal_uInt16
>(
o3tl::toInt32(aChars.substr( 11, 2 )));
115 aOslDTime.Minutes =
static_cast<sal_uInt16
>(
o3tl::toInt32(aChars.substr( 14, 2 )));
118 if ( nLen >= 19 && aChars[16] ==
':' )
120 aOslDTime.Seconds =
static_cast<sal_uInt16
>(
o3tl::toInt32(aChars.substr( 17, 2 )));
122 if ( nLen >= 20 && aChars[19] ==
'.' )
125 size_t digitPos = 20;
126 while (nLen > digitPos && digitPos < 29)
129 if ( c < '0' || c >
'9')
131 aOslDTime.NanoSeconds *= 10;
132 aOslDTime.NanoSeconds += c -
'0';
139 nOptTime += digitPos - 20;
140 for(; digitPos<29; ++digitPos)
142 aOslDTime.NanoSeconds *= 10;
148 while(nLen > digitPos)
151 if ( c < '0' || c >
'9')
155 nOptTime += digitPos - 20;
160 sal_Int32 nModif = 0;
161 if ( nLen >= 16 + nOptTime + 6 )
163 if ( ( aChars[16 + nOptTime] ==
'+' || aChars[16 + nOptTime] ==
'-' )
164 && aChars[16 + nOptTime + 3] ==
':' )
166 nModif =
o3tl::toInt32(aChars.substr( 16 + nOptTime + 1, 2 )) * 3600;
167 nModif +=
o3tl::toInt32(aChars.substr( 16 + nOptTime + 4, 2 )) * 60;
168 if ( aChars[16 + nOptTime] ==
'-' )
177 if ( osl_getTimeValueFromDateTime( &aOslDTime, &aTmp ) )
179 aTmp.Seconds -= nModif;
180 osl_getDateTimeFromTimeValue( &aTmp, &aOslDTime );
188 return util::DateTime( aOslDTime.NanoSeconds, aOslDTime.Seconds,
189 aOslDTime.Minutes, aOslDTime.Hours,
190 aOslDTime.Day, aOslDTime.Month, aOslDTime.Year,
false);
195 if ( !aChars.empty() )
198 std::vector<std::string> aUtf8Result;
199 boost::split( aUtf8Result, aUtf8Chars, boost::is_any_of(
" ,;:\t"), boost::token_compress_on );
201 if (!aUtf8Result.empty())
203 uno::Sequence< OUString > aResult( aUtf8Result.size() );
204 OUString* pResultValues = aResult.getArray();
205 for (
auto const& elem : aUtf8Result)
207 *pResultValues = OUString( elem.c_str(),
static_cast< sal_Int32
>( elem.size() ),RTL_TEXTENCODING_UTF8 );
214 return uno::Sequence< OUString >();
219 uno::Sequence< beans::NamedValue > aSet =
m_xDocProp->getDocumentStatistics();
225 aName =
"NonWhitespaceCharacterCount";
229 aName =
"CharacterCount";
241 aName =
"ParagraphCount";
245 OSL_FAIL(
"Unexpected statistic!" );
249 if (
aName.isEmpty() )
253 for (
auto pProp = aSet.getConstArray(); nInd < aSet.getLength(); ++nInd )
257 if (nInd == aSet.getLength())
258 aSet.realloc( nInd + 1 );
298 OSL_FAIL(
"Unexpected file format!" );
308 if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) )
311 else if (
m_nState &&
m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
316 else if (
m_nState &&
m_nInBlock == 3 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
321 else if (
m_nState &&
m_nInBlock == 4 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
327 SAL_WARN(
"oox",
"OOXMLDocPropHandler::startFastElement: unknown element " << getBaseToken(nElement) <<
" m_nState=" <<
m_nState <<
" m_nInBlock=" <<
m_nInBlock);
331 throw uno::RuntimeException();
338 SAL_WARN(
"oox",
"Unknown element " << aNamespace <<
":" <<
aName);
341 throw uno::RuntimeException();
395 return uno::Reference< xml::sax::XFastContextHandler >(
static_cast< xml::sax::XFastContextHandler*
>(
this ) );
400 return uno::Reference< xml::sax::XFastContextHandler >(
static_cast< xml::sax::XFastContextHandler*
>(
this ) );
439 if ( aChars.getLength() >= 4 )
456 if ( aChars.getLength() >= 2 )
465 if ( aChars.getLength() >= 4 )
470 if ( aChars.getLength() >= 4 )
478 static_cast<sal_Int16
>(aChars.toInt32()) );
480 catch (lang::IllegalArgumentException &)
495 OSL_FAIL(
"Unexpected core property!" );
513 if (!o3tl::checked_multiply<sal_Int32>(aChars.toInt32(), 60, nDuration))
520 catch (
const lang::IllegalArgumentException&)
538 if ( aChars.toBoolean() )
545 if ( aChars.toBoolean() )
552 if ( aChars.toBoolean() )
559 if ( aChars.toBoolean() )
569 if ( aChars.toInt32() != 0 )
576 if ( aChars.toInt32() != 0 )
583 if ( aChars.toInt32() != 0 )
590 if ( aChars.toInt32() != 0 )
597 if ( aChars.toInt32() != 0 )
635 OSL_FAIL(
"Unexpected extended property!" );
691 OSL_FAIL(
"Unexpected tag in custom property!" );
696 catch( uno::RuntimeException& )
700 catch( xml::sax::SAXException& )
704 catch( uno::Exception& )
707 throw xml::sax::SAXException(
708 "Error while setting document property!",
709 uno::Reference< uno::XInterface >(),
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static OUString decodeXString(const OUString &rValue)
Returns the decoded string value.
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &rxLocator) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL startDocument() override
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
static css::uno::Sequence< OUString > GetKeywordsSet(std::u16string_view aChars)
OOXMLDocPropHandler(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::document::XDocumentProperties > &rDocProp)
virtual void SAL_CALL endFastElement(::sal_Int32 Element) override
enum oox::docprop::OOXMLDocPropHandler::@0 m_CustomStringPropertyState
virtual void SAL_CALL processingInstruction(const OUString &rTarget, const OUString &rData) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(::sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
static css::util::DateTime GetDateTimeFromW3CDTF(std::u16string_view aChars)
virtual void SAL_CALL startFastElement(::sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL endDocument() override
css::uno::Reference< css::document::XDocumentProperties > m_xDocProp
OUString m_aCustomPropertyName
void UpdateDocStatistic(std::u16string_view aChars)
virtual void SAL_CALL characters(const OUString &aChars) override
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void AddCustomProperty(const css::uno::Any &aAny)
virtual ~OOXMLDocPropHandler() override
#define CUSTPR_TOKEN(token)
#define EXTPR_TOKEN(token)
#define COREPR_TOKEN(token)
#define SAL_WARN(area, stream)
std::vector< ParagraphInfo > Paragraphs
Any SAL_CALL getCaughtException()
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
::boost::spirit::classic::rule< ScannerT > identifier