コード例 #1
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlStartTag);

            XmlNode nodeStart = xmlDoc.DocumentElement;

            if (nodeStart != null)
            {
                if (nodeStart.HasChildNodes)
                {
                    foreach (XmlNode childNode in nodeStart.ChildNodes)
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, childNode.InnerText));
                        }
                        else if (childNode.Name == "ws")
                        {
                            if (childNode.Attributes.Count == 1)
                            {
                                XmlNode nodeCnt = childNode.Attributes.GetNamedItem("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.InnerText)));
                                }
                            }
                        }
                        else if (childNode.Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (childNode.Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }
コード例 #2
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XDocument xmlDoc = XDocument.Parse(xmlStartTag);

            XElement nodeStart = xmlDoc.Root;

            if (nodeStart != null)
            {
                if (nodeStart.HasElements)
                {
                    foreach (XNode childNode in nodeStart.Nodes())
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, ((XText)childNode).Value));
                        }
                        else if (((XElement)childNode).Name == "ws")
                        {
                            if (((XElement)childNode).Attributes().Count() == 1)
                            {
                                XAttribute nodeCnt = ((XElement)childNode).Attribute("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.Value)));
                                }
                            }
                        }
                        else if (((XElement)childNode).Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (((XElement)childNode).Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }
コード例 #3
0
		/// <summary>
		/// Builds the text collection.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="text">The text.</param>
		/// <returns></returns>
		public static ITextCollection BuildTextCollection(IDocument document, string text)
		{
			string xmlStartTag				= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
			ITextCollection txtCollection	= new ITextCollection();
			text							= WhiteSpaceHelper.GetWhiteSpaceXml(text);
			text							= text.Replace("\t", "<t/>");
			text							= text.Replace("\n", "<n/>");
			xmlStartTag						+= "<txt>"+text+"</txt>";

			XmlDocument xmlDoc				= new XmlDocument();
			xmlDoc.LoadXml(xmlStartTag);

			XmlNode nodeStart				= xmlDoc.DocumentElement;
			if (nodeStart != null)
				if (nodeStart.HasChildNodes)
				{
					foreach(XmlNode childNode in nodeStart.ChildNodes)
					{
						if (childNode.NodeType == XmlNodeType.Text)
							txtCollection.Add(new SimpleText(document, childNode.InnerText));
						else if (childNode.Name == "ws")
						{
							if (childNode.Attributes.Count == 1)
							{
								XmlNode nodeCnt = childNode.Attributes.GetNamedItem("id");
								if (nodeCnt != null)
									txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.InnerText)));
							}
						}
						else if (childNode.Name == "t")
						{
							txtCollection.Add(new TabStop(document));
						}
						else if (childNode.Name == "n")
						{
							txtCollection.Add(new LineBreak(document));
						}
					}
				}
				else
				{
					txtCollection.Add(new SimpleText(document, text));
				}
			return txtCollection;
		}
コード例 #4
0
		/// <summary>
		/// Creates the header.
		/// </summary>
		/// <param name="headernode">The headernode.</param>
		/// <returns></returns>
		public Header CreateHeader(XmlNode headernode)
		{
			try
			{
				if (this._debugMode)
					this.LogNode(headernode, "Log header node before");

				//Create a new Header
				Header header				= new Header(headernode, this._document);
				//Create a ITextCollection
				ITextCollection textColl	= new ITextCollection();
				//Recieve the HeaderStyle
				IStyle headerStyle			= this._document.Styles.GetStyleByName(header.StyleName);

				if (headerStyle != null)
					header.Style			= headerStyle;

				//Create the IText content
				foreach(XmlNode nodeChild in header.Node.ChildNodes)
				{
					TextContentProcessor tcp	= new TextContentProcessor();
					IText iText					= tcp.CreateTextObject(this._document, nodeChild);
					
					if (iText != null)
						textColl.Add(iText);
					else
					{
						this.OnWarning(new AODLWarning("Couldn't create IText object from header child node!.", nodeChild));
					}
				}

				//Remove all
				header.Node.InnerXml		= "";

				foreach(IText iText in textColl)
				{
					if (this._debugMode)
						this.LogNode(iText.Node, "Log IText node read from header");
					header.TextContent.Add(iText);
				}

				return header;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a Header.", ex);
			}
		}
コード例 #5
0
		/// <summary>
		/// Creates the formated text.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		public FormatedText CreateFormatedText(IDocument document, XmlNode node)
		{
			//Create a new FormatedText object
			FormatedText formatedText		= new FormatedText(document, node);
			ITextCollection iTextColl		= new ITextCollection();
			formatedText.Document			= document;
			formatedText.Node				= node;
			//Recieve a TextStyle
			
			IStyle textStyle				= document.Styles.GetStyleByName(formatedText.StyleName);

			if (textStyle != null)
				formatedText.Style			= textStyle;
			//else
			//{
			//	IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
			//}
			
			//Ceck for more IText object
			foreach(XmlNode iTextNode in node.ChildNodes)
			{
				IText iText						= this.CreateTextObject(document, iTextNode.CloneNode(true));
				if (iText != null)
				{
					iTextColl.Add(iText);
				}
				else
					iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
			}

			formatedText.Node.InnerText			= "";

			foreach(IText iText in iTextColl)
				formatedText.TextContent.Add(iText);

			return formatedText;
		}
コード例 #6
0
		/// <summary>
		/// Creates the X link.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		public XLink CreateXLink(IDocument document, XmlNode node)
		{
			try
			{
				XLink xlink				= new XLink(document);
				xlink.Node				= node.CloneNode(true);
				ITextCollection iTxtCol	= new ITextCollection();

				foreach(XmlNode nodeText in xlink.Node.ChildNodes)
				{
					IText iText			= this.CreateTextObject(xlink.Document, nodeText);
					if (iText != null)
						iTxtCol.Add(iText);
				}

				xlink.Node.InnerXml		= "";

				foreach(IText iText in iTxtCol)
					xlink.TextContent.Add(iText);

				return xlink;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a XLink.", ex);
			}
		}
コード例 #7
0
        /// <summary>
        /// Creates the header.
        /// </summary>
        /// <param name="headernode">The headernode.</param>
        /// <returns></returns>
        public Header CreateHeader(XmlNode headernode)
        {
            try
            {
                #region Old code Todo: delete
                //				XmlNode node			= headernode.SelectSingleNode("//@text:style-name", this._document.NamespaceManager);
                //				if(node != null)
                //				{
                //					if(!node.InnerText.StartsWith("Heading"))
                //					{
                //						//Check if a the referenced paragraphstyle reference a heading as parentstyle
                //						XmlNode stylenode	= this._document.XmlDoc.SelectSingleNode("//style:style[@style:name='"+node.InnerText+"']", this._document.NamespaceManager);
                //						if(stylenode != null)
                //						{
                //							XmlNode parentstyle	= stylenode.SelectSingleNode("@style:parent-style-name",
                //								this._document.NamespaceManager);
                //							if(parentstyle != null)
                //								if(parentstyle.InnerText.StartsWith("Heading"))
                //									headernode.SelectSingleNode("@text:style-name",
                //										this._document.NamespaceManager).InnerText = parentstyle.InnerText;
                //						}
                //					}
                //				}
                #endregion
                if(this._debugMode)
                    this.LogNode(headernode, "Log header node before");

                //Create a new Header
                Header header				= new Header(headernode, this._document);
                //Create a ITextCollection
                ITextCollection textColl	= new ITextCollection();
                //Recieve the HeaderStyle
                IStyle headerStyle			= this._document.Styles.GetStyleByName(header.StyleName);

                if(headerStyle != null)
                    header.Style			= headerStyle;

                //Create the IText content
                foreach(XmlNode nodeChild in header.Node.ChildNodes)
                {
                    TextContentProcessor tcp	= new TextContentProcessor();
                    IText iText					= tcp.CreateTextObject(this._document, nodeChild);

                    if(iText != null)
                        textColl.Add(iText);
                    else
                    {
                        if(this.OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("Couldn't create IText object from header child node!.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= nodeChild;
                            this.OnWarning(warning);
                        }
                    }
                }

                //Remove all
                header.Node.InnerXml		= "";

                foreach(IText iText in textColl)
                {
                    if(this._debugMode)
                        this.LogNode(iText.Node, "Log IText node read from header");
                    header.TextContent.Add(iText);
                }

                return header;
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to create a Header.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.Node				= headernode;
                exception.OriginalException	= ex;

                throw exception;
            }

            return null;
        }
コード例 #8
0
        /// <summary>
        /// Creates the X link.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public XLink CreateXLink(IDocument document, XmlNode node)
        {
            try
            {
                XLink xlink				= new XLink(document);
                xlink.Node				= node.CloneNode(true);
                ITextCollection iTxtCol	= new ITextCollection();

                foreach(XmlNode nodeText in xlink.Node.ChildNodes)
                {
                    IText iText			= this.CreateTextObject(xlink.Document, nodeText);
                    if(iText != null)
                        iTxtCol.Add(iText);
                }

                xlink.Node.InnerXml		= "";

                foreach(IText iText in iTxtCol)
                    xlink.TextContent.Add(iText);

                return xlink;
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to create a XLink.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.Node				= node;
                exception.OriginalException	= ex;

                throw exception;
            }
        }
コード例 #9
0
        /// <summary>
        /// Creates the formated text.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public FormatedText CreateFormatedText(IDocument document, XmlNode node)
        {
            try
            {
                //Create a new FormatedText object
                FormatedText formatedText		= new FormatedText(document, node);
                ITextCollection iTextColl		= new ITextCollection();
                formatedText.Document			= document;
                formatedText.Node				= node;
                //Recieve a TextStyle

                IStyle textStyle				= document.Styles.GetStyleByName(formatedText.StyleName);

                if(textStyle != null)
                    formatedText.Style			= textStyle;
                else
                {
                    IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
                    if(iStyle == null)
                    {
                        if(OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("A TextStyle for the FormatedText object wasn't found.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= node;
                            OnWarning(warning);
                        }
                    }
                }

                //Ceck for more IText object
                foreach(XmlNode iTextNode in node.ChildNodes)
                {
                    IText iText						= this.CreateTextObject(document, iTextNode.CloneNode(true));
                    if(iText != null)
                    {
                        iTextColl.Add(iText);
                    }
                    else
                        iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
                }

                formatedText.Node.InnerText			= "";

                foreach(IText iText in iTextColl)
                    formatedText.TextContent.Add(iText);

                return formatedText;
            }
            catch(Exception ex)
            {
                throw;
            }
        }