You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/04/11 04:25:01 UTC

cvs commit: xml-xalan/c/src/XMLSupport FormatterToText.cpp FormatterToText.hpp

dbertoni    01/04/10 19:25:01

  Modified:    c/src/XMLSupport FormatterToText.cpp FormatterToText.hpp
  Log:
  Changes to allow for reusing instances.
  
  Revision  Changes    Path
  1.15      +73 -31    xml-xalan/c/src/XMLSupport/FormatterToText.cpp
  
  Index: FormatterToText.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToText.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- FormatterToText.cpp	2000/12/05 23:31:11	1.14
  +++ FormatterToText.cpp	2001/04/11 02:25:00	1.15
  @@ -72,12 +72,25 @@
   
   
   
  +FormatterToText::FormatterToText() :
  +	FormatterListener(OUTPUT_METHOD_TEXT),
  +	m_writer(0),
  +	m_maxCharacter(XalanDOMChar(~0)),
  +	m_encoding(),
  +	m_haveEncoding(false),
  +	m_normalize(true),
  +	m_handleIgnorableWhitespace(true)
  +{
  +}
  +
  +
  +
   FormatterToText::FormatterToText(
   			Writer&		writer,
   			bool		normalizeLinefeed,
   			bool		handleIgnorableWhitespace) :
   	FormatterListener(OUTPUT_METHOD_TEXT),
  -	m_writer(writer),
  +	m_writer(&writer),
   	m_maxCharacter(XalanDOMChar(~0)),
   	m_encoding(),
   	m_haveEncoding(false),
  @@ -94,46 +107,32 @@
   			bool					normalizeLinefeed,
   			bool					handleIgnorableWhitespace) :
   	FormatterListener(OUTPUT_METHOD_TEXT),
  -	m_writer(writer),
  +	m_writer(&writer),
   	m_maxCharacter(0),
   	m_encoding(isEmpty(encoding) == false ? encoding : XalanDOMString(XalanTranscodingServices::s_utf8String)),
   	m_haveEncoding(true),
   	m_normalize(normalizeLinefeed),
   	m_handleIgnorableWhitespace(handleIgnorableWhitespace)
   {
  -	XalanOutputStream* const	theStream = m_writer.getStream();
  -
  -	if (theStream == 0)
  -	{
  -		// We're pretty much screwed here, since we can't transcode, so get the
  -		// maximum character for the local code page.
  -		m_maxCharacter = XalanTranscodingServices::getMaximumCharacterValue();
  -	}
  -	else
  -	{
  -		try
  -		{
  -			theStream->setOutputEncoding(m_encoding);
  -		}
  -		catch(const XalanOutputStream::UnsupportedEncodingException&)
  -		{
  -			const XalanDOMString	theUTF8String(XalanTranscodingServices::s_utf8String);
  +	update();
  +}
   
  -			// Default to UTF-8 if the requested encoding is not supported...
  -			theStream->setOutputEncoding(theUTF8String);
   
  -			m_encoding = theUTF8String;
  -		}
   
  -		m_maxCharacter = XalanTranscodingServices::getMaximumCharacterValue(theStream->getOutputEncoding());
  -	}
  +FormatterToText::~FormatterToText()
  +{
   }
   
   
   
  -FormatterToText::~FormatterToText()
  +void
  +FormatterToText::clearEncoding()
   {
  -	m_writer.flush();
  +	clear(m_encoding);
  +
  +	m_maxCharacter = XalanDOMChar(~0);
  +
  +	m_haveEncoding = false;
   }
   
   
  @@ -157,7 +156,11 @@
   void
   FormatterToText::endDocument()
   {
  -	m_writer.close();
  +	assert(m_writer != 0);
  +
  +	m_writer->flush();
  +
  +	m_writer->close();
   }
   
   
  @@ -186,9 +189,11 @@
   			const XMLCh* const	chars,
   			const unsigned int	length)
   {
  +	assert(m_writer != 0);
  +
   	if (m_normalize == false && m_haveEncoding == false)
   	{
  -		m_writer.write(chars, 0, length);
  +		m_writer->write(chars, 0, length);
   	}
   	else
   	{
  @@ -202,7 +207,7 @@
   					(i == 0 ||
   					 chars[i - 1] != XalanUnicode::charCR))
   				{
  -					m_writer.write(XalanUnicode::charCR);
  +					m_writer->write(XalanUnicode::charCR);
   				}
   			}
   #endif
  @@ -211,7 +216,7 @@
   				//$$$ ToDo: Figure out what we're going to do here...
   			}
   
  -			m_writer.write(chars[i]);
  +			m_writer->write(chars[i]);
   		}
   	}
   }
  @@ -280,4 +285,41 @@
   			const unsigned int 	length)
   {
   	characters(ch, length);
  +}
  +
  +
  +
  +void
  +FormatterToText::update()
  +{
  +	assert(m_writer != 0);
  +
  +	XalanOutputStream* const	theStream = m_writer->getStream();
  +
  +	if (theStream == 0)
  +	{
  +		// We're pretty much screwed here, since we can't transcode, so get the
  +		// maximum character for the local code page.
  +		m_maxCharacter = XalanTranscodingServices::getMaximumCharacterValue();
  +	}
  +	else
  +	{
  +		try
  +		{
  +			theStream->setOutputEncoding(m_encoding);
  +		}
  +		catch(const XalanOutputStream::UnsupportedEncodingException&)
  +		{
  +			const XalanDOMString	theUTF8String(XalanTranscodingServices::s_utf8String);
  +
  +			// Default to UTF-8 if the requested encoding is not supported...
  +			theStream->setOutputEncoding(theUTF8String);
  +
  +			m_encoding = theUTF8String;
  +
  +			m_haveEncoding = true;
  +		}
  +
  +		m_maxCharacter = XalanTranscodingServices::getMaximumCharacterValue(theStream->getOutputEncoding());
  +	}
   }
  
  
  
  1.9       +82 -6     xml-xalan/c/src/XMLSupport/FormatterToText.hpp
  
  Index: FormatterToText.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToText.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FormatterToText.hpp	2000/12/05 23:31:11	1.8
  +++ FormatterToText.hpp	2001/04/11 02:25:00	1.9
  @@ -88,6 +88,11 @@
   
   	/**
   	 * FormatterToText instance constructor.
  +	 */
  +	FormatterToText();
  +
  +	/**
  +	 * FormatterToText instance constructor.
   	 *
   	 * @param writer writer for output
   	 * @param normalizeLindefeed Normalize \n or \r\n (on certain platforms).
  @@ -116,6 +121,73 @@
   	~FormatterToText();
   
   
  +	Writer*
  +	getWriter() const
  +	{
  +		return m_writer;
  +	}
  +
  +	void
  +	setWriter(Writer*	theWriter)
  +	{
  +		m_writer = theWriter;
  +
  +		update();
  +	}
  +
  +	void
  +	clearEncoding();
  +
  +	const XalanDOMString&
  +	getEncoding() const
  +	{
  +		return m_encoding;
  +	}
  +
  +	void
  +	setEncoding(const XalanDOMString&	theEncoding)
  +	{
  +		m_encoding = theEncoding;
  +
  +		update();
  +	}
  +
  +	XalanDOMChar
  +	getMaxCharacter() const
  +	{
  +		return m_maxCharacter;
  +	}
  +
  +	void
  +	setMaxCharacter(XalanDOMChar	theMaxChar)
  +	{
  +		m_maxCharacter = theMaxChar;
  +	}
  +
  +	bool
  +	getNormalizeLinefeed() const
  +	{
  +		return m_normalize;
  +	}
  +
  +	void
  +	setNormalizeLinefeed(bool	fNormalize)
  +	{
  +		m_normalize = fNormalize;
  +	}
  +
  +	bool
  +	getHandleIgnorableWhitespace() const
  +	{
  +		return m_handleIgnorableWhitespace;
  +	}
  +
  +	void
  +	setHandleIgnorableWhitespace(bool	fHandle)
  +	{
  +		m_handleIgnorableWhitespace = fHandle;
  +	}
  +
   	// These methods are inherited from FormatterListener ...
   
   	virtual void
  @@ -158,8 +230,7 @@
   			const XMLCh* const	target,
   			const XMLCh* const	data);
   
  -
  -   virtual void
  +	virtual void
   	resetDocument();
   
   	virtual void
  @@ -181,18 +252,23 @@
   	bool
   	operator==(const FormatterToText&) const;
   
  +	// Utility function to update various member variables
  +	// when data changes.
  +	void
  +	update();
  +
   	// Data members...
  -	Writer&			m_writer;
  +	Writer*			m_writer;
   
   	XalanDOMChar	m_maxCharacter;
   
   	XalanDOMString	m_encoding;
   
  -	const bool		m_haveEncoding;
  +	bool			m_haveEncoding;
   
  -	const bool		m_normalize;
  +	bool			m_normalize;
   
  -	const bool		m_handleIgnorableWhitespace;
  +	bool			m_handleIgnorableWhitespace;
   };
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org