/// <summary> /// Gets the code for a field, starting at the given field start node. /// If the field is not well formed, then an exception is thrown. /// </summary> public static string ParseInlineField(this FieldStart start, out FieldSeparator separator, out string result, out FieldEnd end) { if (start.NextSibling == null) throw new Exception("Found field start with no next sibling."); Node lastNode; var code = ParseInlineCode(start, out lastNode); if (lastNode == null || lastNode == start) throw new Exception(string.Format("Didn't find field code in \"{0}\".", GetText(start, code, separator: start.NextSibling as FieldSeparator))); separator = lastNode.NextSibling as FieldSeparator; if (separator == null) throw new Exception(string.Format("Did not find node of type 'FieldSeparator' after \"{0}\".", GetText(start, code))); result = ParseInlineResult(start, code, separator, out lastNode); end = separator.GetFollowingSiblings().OfType<FieldEnd>().FirstOrDefault(); if (end == null) throw new Exception(string.Format("Did not find node of type 'FieldEnd' after \"{0}\".", GetText(start, code, separator, result))); return code; }
public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (!string.IsNullOrEmpty(this.currentDocumentProperty)) { this.structureBuilder .AppendFormat( "<{0} {1} />", this.currentFieldTagName + "End", FormatAttributes(new NamedValue("Name", HttpUtility.HtmlEncode(this.currentDocumentProperty)))) .AppendLine(); this.currentDocumentProperty = null; } else if (!string.IsNullOrEmpty(this.currentDocumentVariable)) { this.structureBuilder .AppendFormat( "<{0} {1} />", this.currentFieldTagName + "End", FormatAttributes(new NamedValue("Name", HttpUtility.HtmlEncode(this.currentDocumentVariable)))) .AppendLine(); this.currentDocumentVariable = null; } else { this.structureBuilder.AppendLine("<FieldEnd />"); } return(VisitorAction.Continue); }
/// <summary> /// Gets the code for a field, starting at the given field start node. /// If the field is not well formed, then an exception is thrown. /// </summary> public static string ParseInlineField(this FieldStart start, out FieldEnd end) { FieldSeparator separator; string result; return start.ParseInlineField(out separator, out result, out end); }
/// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { // Make sure we enable the output when reached a field end because some fields // do not have field separator and do not have field result. mIsSkipText = false; return(VisitorAction.Continue); }
/// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { mDocTraversalDepth--; IndentAndAppendLine("[Field end]"); mVisitorIsInsideField = false; return(VisitorAction.Continue); }
/// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (this.isHidden(fieldEnd)) { fieldEnd.Remove(); } return(VisitorAction.Continue); }
/// <summary> /// Create a hierarchical group of nodes from the start of the field. /// </summary> /// <param name="fieldStart">The node which represents the start of a field.</param> public WordField(FieldStart fieldStart) { // Create the object. this.endDictionary = new Dictionary <Node, WordField>(); this.startDictionary = new Dictionary <Node, WordField>(); this.fieldStart = fieldStart; // This will find the end of the field and acts as a kind of delimiter. Since the DOM structure makes heavy use of linked lists, it can also act // to join the end of a field to the start and back again when navigating through the document. Boolean parsing = true; Node node = this.fieldStart.NextSibling; while (parsing) { // This is the field that is going to be parsed out of the stream. WordField wordField = default(WordField); // Each node is parsed to determine what kind of an object has been discovered here. switch (node.NodeType) { case NodeType.FieldStart: // This will recurse into any of the embedded fields creating a hierarchical order of fields that can be evaluated from the inside out. wordField = CreateField(node as FieldStart); // Any field found in the field field result area is ignored. All other fields are added to a collection that can be indexed sequentially // using an enumerator or directly using the dictionary. this.startDictionary.Add(wordField.FieldStart, wordField); this.endDictionary.Add(wordField.FieldEnd, wordField); // This moves the parser to the position after the field no matter how many levels of embedded fields were included. node = wordField.FieldEnd; break; case NodeType.FieldSeparator: // This indicates where the literal portion of a field starts. this.fieldSeperator = node as FieldSeparator; break; case NodeType.FieldEnd: // The end of the field is part of this obect and used when navigating forward or backward through the nodes of a paragraph. this.fieldEnd = node as FieldEnd; // When the final field is found the parsing of this field is completed. parsing = false; break; } // The parsing continues until the last field node is discovered. node = node.NextSibling; } }
private static string GetText(FieldStart start, string code, FieldSeparator separator = null, string result = null, FieldEnd end = null, bool useRawFieldChars = false) { return string.Format("{0}{1}{2}{3}{4}", start != null ? useRawFieldChars ? FieldStart : "{" : "", code ?? "", separator != null ? useRawFieldChars ? FieldSeparator : "|" : "", result ?? "", end != null ? useRawFieldChars ? FieldEnd : "}" : ""); }
public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (fieldEnd.FieldType.Equals(mTargetFieldType)) fieldEnd.Remove(); else CheckDepthAndRemoveNode(fieldEnd); // This removes the field end if it's inside a field that is being converted. return VisitorAction.Continue; }
private static void RemoveTableOfContents(Aspose.Words.Document doc, int index) { // Store the FieldStart nodes of TOC fields in the document for quick access. ArrayList fieldStarts = new ArrayList(); // This is a list to store the nodes found inside the specified TOC. They will be removed // at the end of this method. ArrayList nodeList = new ArrayList(); foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true)) { if (start.FieldType == FieldType.FieldTOC) { // Add all FieldStarts which are of type FieldTOC. fieldStarts.Add(start); } } // Ensure the TOC specified by the passed index exists. if (index > fieldStarts.Count - 1) { throw new ArgumentOutOfRangeException("TOC index is out of range"); } bool isRemoving = true; // Get the FieldStart of the specified TOC. Node currentNode = (Node)fieldStarts[index]; while (isRemoving) { // It is safer to store these nodes and delete them all at once later. nodeList.Add(currentNode); currentNode = currentNode.NextPreOrder(doc); // Once we encounter a FieldEnd node of type FieldTOC then we know we are at the end // of the current TOC and we can stop here. if (currentNode.NodeType == NodeType.FieldEnd) { FieldEnd fieldEnd = (FieldEnd)currentNode; if (fieldEnd.FieldType == FieldType.FieldTOC) { isRemoving = false; } } } // Remove all nodes found in the specified TOC. foreach (Node node in nodeList) { node.Remove(); } }
/// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (isHidden(fieldEnd)) fieldEnd.Remove(); return VisitorAction.Continue; }
/// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { // Make sure we enable the output when reached a field end because some fields // do not have field separator and do not have field result. mIsSkipText = false; return VisitorAction.Continue; }
public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (!string.IsNullOrEmpty(this.currentDocumentProperty)) { this.structureBuilder.AppendLine(string.Concat("<", this.currentFieldTagName, "End Name=\"", this.currentDocumentProperty, "\"/>")); this.currentDocumentProperty = null; } else if (!string.IsNullOrEmpty(this.currentDocumentVariable)) { this.structureBuilder.AppendLine(string.Concat("<", this.currentFieldTagName, "End Name=\"", this.currentDocumentVariable, "\"/>")); this.currentDocumentVariable = null; } else { this.structureBuilder.AppendLine("</Field>"); } return VisitorAction.Continue; }
/// <summary> /// Determines if the given field start is the quote reference field and returns its field end if so. /// </summary> public static bool IsQuoteField(FieldStart start, out FieldEnd end) { if (start.FieldType != FieldType.FieldSet) { end = null; return false; } return start.ParseInlineField(out end).Trim() == "SET q \"\\\"\""; }
public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { if (!string.IsNullOrEmpty(this.currentDocumentProperty)) { this.structureBuilder .AppendFormat( "<{0} {1} />", this.currentFieldTagName + "End", FormatAttributes(new NamedValue("Name", HttpUtility.HtmlEncode(this.currentDocumentProperty)))) .AppendLine(); this.currentDocumentProperty = null; } else if (!string.IsNullOrEmpty(this.currentDocumentVariable)) { this.structureBuilder .AppendFormat( "<{0} {1} />", this.currentFieldTagName + "End", FormatAttributes(new NamedValue("Name", HttpUtility.HtmlEncode(this.currentDocumentVariable)))) .AppendLine(); this.currentDocumentVariable = null; } else { this.structureBuilder.AppendLine("<FieldEnd />"); } return VisitorAction.Continue; }