/* -*- 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 . */ #ifndef _PARHTML_HXX #define _PARHTML_HXX #include "svtools/svtdllapi.h" #include #include #include #include namespace com { namespace sun { namespace star { namespace document { class XDocumentProperties; } } } } class Color; class SvNumberFormatter; class SvKeyValueIterator; #define HTMLFONTSZ1_DFLT 7 #define HTMLFONTSZ2_DFLT 10 #define HTMLFONTSZ3_DFLT 12 #define HTMLFONTSZ4_DFLT 14 #define HTMLFONTSZ5_DFLT 18 #define HTMLFONTSZ6_DFLT 24 #define HTMLFONTSZ7_DFLT 36 enum HTMLTableFrame { HTML_TF_VOID, HTML_TF_ABOVE, HTML_TF_BELOW, HTML_TF_HSIDES, HTML_TF_LHS, HTML_TF_RHS, HTML_TF_VSIDES, HTML_TF_BOX }; enum HTMLTableRules { HTML_TR_NONE, HTML_TR_GROUPS, HTML_TR_ROWS, HTML_TR_COLS, HTML_TR_ALL }; enum HTMLInputType { HTML_IT_TEXT = 0x01, HTML_IT_PASSWORD = 0x02, HTML_IT_CHECKBOX = 0x03, HTML_IT_RADIO = 0x04, HTML_IT_RANGE = 0x05, HTML_IT_SCRIBBLE = 0x06, HTML_IT_FILE = 0x07, HTML_IT_HIDDEN = 0x08, HTML_IT_SUBMIT = 0x09, HTML_IT_IMAGE = 0x0a, HTML_IT_RESET = 0x0b, HTML_IT_BUTTON = 0x0c }; enum HTMLScriptLanguage { HTML_SL_STARBASIC, HTML_SL_JAVASCRIPT, HTML_SL_UNKNOWN }; struct HTMLOptionEnum { const sal_Char *pName; // Wert einer HTML-Option sal_uInt16 nValue; // und der dazugehoerige Wert eines Enums }; // Repraesentation einer HTML-Option (=Atrribut in einem Start-Tag) // Die Werte der Optionen werden immer als String gespeichert. // Die Methoden GetNumber, ... duerfen nur aufgerufen werden, wenn // die Option auch numerisch, ... ist. class SVT_DLLPUBLIC HTMLOption { String aValue; // der Wert der Option (immer als String) String aToken; // der Name der Option als String sal_uInt16 nToken; // und das entsprechende Token public: HTMLOption( sal_uInt16 nTyp, const String& rToken, const String& rValue ); // der Name der Option ... sal_uInt16 GetToken() const { return nToken; } // ... als Enum const String& GetTokenString() const { return aToken; } // ... als String // der Wert der Option ... const String& GetString() const { return aValue; } // ... als String sal_uInt32 GetNumber() const; // ... als Zahl sal_Int32 GetSNumber() const; // ... als Zahl void GetNumbers( std::vector &rNumbers, // ... als Zahlen bool bSpaceDelim=false ) const; void GetColor( Color& ) const; // ... als Farbe // ... als Enum pOptEnums ist ein HTMLOptionEnum-Array sal_uInt16 GetEnum( const HTMLOptionEnum *pOptEnums, sal_uInt16 nDflt=0 ) const; bool GetEnum( sal_uInt16 &rEnum, const HTMLOptionEnum *pOptEnums ) const; // ... und als ein par spezielle Enums HTMLInputType GetInputType() const; // HTMLTableFrame GetTableFrame() const; // HTMLTableRules GetTableRules() const; //
//SvxAdjust GetAdjust() const; // }; typedef ::boost::ptr_vector HTMLOptions; class SVT_DLLPUBLIC HTMLParser : public SvParser { private: mutable HTMLOptions maOptions; // die Optionen des Start-Tags bool bNewDoc : 1; // neues Doc lesen ? bool bIsInHeader : 1; // scanne Header-Bereich bool bIsInBody : 1; // scanne Body-Bereich bool bReadListing : 1; // Lese Listings bool bReadXMP : 1; // Lese XMP bool bReadPRE : 1; // Lese preformatted Text bool bReadTextArea : 1; // Lese TEXTAREA bool bReadScript : 1; // Lesen von oder gefunden bool bPre_IgnoreNewPara : 1; // Flags fuers lesen von PRE-Absaetzen bool bReadNextChar : 1; // true: NextChar nochmals lesen (JavaScript!) bool bReadComment : 1; // true: NextChar nochmals lesen (JavaScript!) sal_uInt32 nPre_LinePos; // Pos in der Line im PRE-Tag String aEndToken; protected: String sSaveToken; // das gelesene Tag als String int ScanText( const sal_Unicode cBreak = 0U ); int _GetNextRawToken(); // scanne das naechste Token, virtual int _GetNextToken(); virtual ~HTMLParser(); void FinishHeader( bool bBody ) { bIsInHeader = false; bIsInBody = bBody; } public: HTMLParser( SvStream& rIn, bool bReadNewDoc = true ); virtual SvParserState CallParser(); // Aufruf des Parsers bool IsNewDoc() const { return bNewDoc; } bool IsInHeader() const { return bIsInHeader; } bool IsInBody() const { return bIsInBody; } bool IsValidSyntax() const { return true; } bool IsReadListing() const { return bReadListing; } bool IsReadXMP() const { return bReadXMP; } bool IsReadPRE() const { return bReadPRE; } bool IsReadScript() const { return bReadScript; } bool IsReadStyle() const { return bReadStyle; } void SetReadNextChar() { bReadNextChar = true; } // PRE-/LISTING oder XMP-Modus starten/beenden oder Tags entsprechend // filtern inline void StartPRE( bool bRestart=false ); void FinishPRE() { bReadPRE = false; } int FilterPRE( int nToken ); inline void StartListing( bool bRestart=false ); void FinishListing() { bReadListing = false; } int FilterListing( int nToken ); inline void StartXMP( bool bRestart=false ); void FinishXMP() { bReadXMP = false; } int FilterXMP( int nToken ); void FinishTextArea() { bReadTextArea = false; } // PRE-/LSITING- und XMP-Modus beenden void FinishPREListingXMP() { bReadPRE = bReadListing = bReadXMP = false; } // Das aktuelle Token dem aktuellen Modus (PRE, XMP, ...) entsprechend // Filtern und die Flags setzen. Wird von Continue aufgerufen, bevor // NextToken gerufen wird. Wer eigene Schleifen implementiert bzw. // selbst NextToken aufruft, sollte diese Methode vorher rufen. int FilterToken( int nToken ); // Scannen eines Scripts beenden (sollte nur unmittelbar nach dem // Lesen eines