/* -*- 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 .
*/
// this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format class OFOPXMLHelper_Impl
: public cppu::WeakImplHelper< css::xml::sax::XDocumentHandler >
{
sal_uInt16 const m_nFormat; // which format to parse
css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > m_aResultSeq;
std::vector< OUString > m_aElementsSeq; // stack of elements being parsed
// Find the extension and use it to get the type. const sal_Int32 nDotOffset = rFilename.lastIndexOf('.'); const OUString aExt = (nDotOffset >= 0 ? rFilename.copy(nDotOffset + 1) : rFilename); // Skip the dot.
uno::Sequence< uno::Sequence< beans::StringPair > > const & OFOPXMLHelper_Impl::GetParsingResult() const
{ if ( !m_aElementsSeq.empty() ) throw uno::RuntimeException(); // the parsing has still not finished!
if ( nNewLength != 1 ) throw css::xml::sax::SAXException(); // TODO: this element must be the first level element
m_aElementsSeq.push_back( aName );
return; // nothing to do
} elseif ( aName == g_aRelElement )
{
sal_Int32 nNewLength = m_aElementsSeq.size() + 1; if ( nNewLength != 2 ) throw css::xml::sax::SAXException(); // TODO: this element must be the second level element
m_aElementsSeq.push_back( aName );
sal_Int32 nNewEntryNum = m_aResultSeq.getLength() + 1;
m_aResultSeq.realloc( nNewEntryNum ); auto pResultSeq = m_aResultSeq.getArray();
sal_Int32 nAttrNum = 0;
pResultSeq[nNewEntryNum-1].realloc( 4 ); // the maximal expected number of arguments is 4 auto pAttrs = pResultSeq[nNewEntryNum-1].getArray();
OUString aIDValue = xAttribs->getValueByName( g_aIDAttr ); if ( aIDValue.isEmpty() ) throw css::xml::sax::SAXException(); // TODO: the ID value must present
pResultSeq[nNewEntryNum-1].realloc( nAttrNum );
} else throw css::xml::sax::SAXException(); // TODO: no other elements expected!
} elseif ( m_nFormat == CONTENTTYPE_FORMAT )
{ if ( aName == g_aTypesElement )
{
sal_Int32 nNewLength = m_aElementsSeq.size() + 1;
if ( nNewLength != 1 ) throw css::xml::sax::SAXException(); // TODO: this element must be the first level element
m_aElementsSeq.push_back( aName );
if ( !m_aResultSeq.hasElements() )
m_aResultSeq.realloc( 2 );
return; // nothing to do
} elseif ( aName == g_aDefaultElement )
{
sal_Int32 nNewLength = m_aElementsSeq.size() + 1; if ( nNewLength != 2 ) throw css::xml::sax::SAXException(); // TODO: this element must be the second level element
m_aElementsSeq.push_back( aName );
if ( !m_aResultSeq.hasElements() )
m_aResultSeq.realloc( 2 );
if ( m_aResultSeq.getLength() != 2 ) throw uno::RuntimeException("m_aResultSeq already has elements and is not reallocated to 2.");
auto pResultSeq = m_aResultSeq.getArray();
const OUString aExtensionValue = xAttribs->getValueByName( g_aExtensionAttr ); if ( aExtensionValue.isEmpty() ) throw css::xml::sax::SAXException(); // TODO: the Extension value must present
const OUString aContentTypeValue = xAttribs->getValueByName( g_aContentTypeAttr ); if ( aContentTypeValue.isEmpty() ) throw css::xml::sax::SAXException(); // TODO: the ContentType value must present
pSeq[nNewResultLen-1].First = aExtensionValue;
pSeq[nNewResultLen-1].Second = aContentTypeValue;
} elseif ( aName == g_aOverrideElement )
{
sal_Int32 nNewLength = m_aElementsSeq.size() + 1; if ( nNewLength != 2 ) throw css::xml::sax::SAXException(); // TODO: this element must be the second level element
m_aElementsSeq.push_back( aName );
if ( !m_aResultSeq.hasElements() )
m_aResultSeq.realloc( 2 );
if ( m_aResultSeq.getLength() != 2 ) throw uno::RuntimeException("m_aResultSeq already has elements and is not reallocated to 2.");
auto pResultSeq = m_aResultSeq.getArray();
OUString aPartNameValue = xAttribs->getValueByName( g_aPartNameAttr ); if ( aPartNameValue.isEmpty() ) throw css::xml::sax::SAXException(); // TODO: the PartName value must present
OUString aContentTypeValue = xAttribs->getValueByName( g_aContentTypeAttr ); if ( aContentTypeValue.isEmpty() ) throw css::xml::sax::SAXException(); // TODO: the ContentType value must present
pSeq[nNewResultLen-1].First = aPartNameValue;
pSeq[nNewResultLen-1].Second = aContentTypeValue;
} else throw css::xml::sax::SAXException(); // TODO: no other elements expected!
} else throw css::xml::sax::SAXException(); // TODO: no other elements expected!
}
void SAL_CALL OFOPXMLHelper_Impl::endElement( const OUString& aName )
{ if ( m_nFormat == RELATIONINFO_FORMAT || m_nFormat == CONTENTTYPE_FORMAT )
{
sal_Int32 nLength = m_aElementsSeq.size(); if ( nLength <= 0 ) throw css::xml::sax::SAXException(); // TODO: no other end elements expected!
if ( m_aElementsSeq[nLength-1] != aName ) throw css::xml::sax::SAXException(); // TODO: unexpected element ended
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.