001package com.hfg.xml.msofficexml.xlsx.spreadsheetml;
002
003
004import java.util.regex.Pattern;
005
006import com.hfg.xml.XMLNode;
007import com.hfg.xml.XMLTag;
008import com.hfg.xml.msofficexml.OfficeXML;
009import com.hfg.xml.msofficexml.xlsx.Xlsx;
010
011//------------------------------------------------------------------------------
012/**
013 Represents an Office Open XML rich text run (<ssml:r>) tag.
014 This is the root tag of a table part.
015
016 @author J. Alex Taylor, hairyfatguy.com
017 */
018//------------------------------------------------------------------------------
019// com.hfg XML/HTML Coding Library
020//
021// This library is free software; you can redistribute it and/or
022// modify it under the terms of the GNU Lesser General Public
023// License as published by the Free Software Foundation; either
024// version 2.1 of the License, or (at your option) any later version.
025//
026// This library is distributed in the hope that it will be useful,
027// but WITHOUT ANY WARRANTY; without even the implied warranty of
028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
029// Lesser General Public License for more details.
030//
031// You should have received a copy of the GNU Lesser General Public
032// License along with this library; if not, write to the Free Software
033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
034//
035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
036// jataylor@hairyfatguy.com
037//------------------------------------------------------------------------------
038
039public class SsmlTextRun extends SsmlXMLTag
040{
041   private static final Pattern sMultispacePattern = Pattern.compile("\\s{2,}");
042
043   private SsmlTextRunProperties mProperties;
044
045   //###########################################################################
046   // CONSTRUCTORS
047   //###########################################################################
048
049   //---------------------------------------------------------------------------
050   public SsmlTextRun(Xlsx inXlsx)
051   {
052      super(SsmlXML.TEXT_RUN, inXlsx);
053   }
054
055   //---------------------------------------------------------------------------
056   public SsmlTextRun(Xlsx inXlsx, String inText)
057   {
058      super(SsmlXML.TEXT_RUN, inXlsx);
059      setText(inText);
060   }
061
062   //###########################################################################
063   // PUBLIC METHODS
064   //###########################################################################
065
066   //---------------------------------------------------------------------------
067   public SsmlTextRun setText(String inValue)
068   {
069      XMLNode textTag = new XMLTag(SsmlXML.TEXT).setContent(inValue);
070
071      if (sMultispacePattern.matcher(inValue).find())
072      {
073         setAttribute(OfficeXML.SPACE, "preserve");
074      }
075
076      addSubtag(textTag);
077      return this;
078   }
079
080   //---------------------------------------------------------------------------
081   public SsmlTextRunProperties getProperties()
082   {
083      if (null == mProperties)
084      {
085         // Check it it has been added via addSubtag()...
086         mProperties = getOptionalSubtagByName(SsmlXML.TEXT_RUN_PROPS);
087         if (null == mProperties)
088         {
089            mProperties = new SsmlTextRunProperties(getParentDoc());
090            addSubtag(mProperties);
091         }
092      }
093
094      return mProperties;
095   }
096
097}