-
Notifications
You must be signed in to change notification settings - Fork 10
feature[TW29198]: Add name and outline number check to publishing xml… #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| import org.w3c.dom.Document; | ||
| import org.w3c.dom.Element; | ||
| import org.w3c.dom.Node; | ||
| import org.w3c.dom.NodeList; | ||
| import org.xml.sax.SAXException; | ||
|
|
||
| /** | ||
|
|
@@ -846,6 +847,96 @@ private void startOperation() { | |
| this.lastError.remove(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a <w:p> block contains "Artifact Id" followed by a numeric value. | ||
| * | ||
| * @param paragraphElement the <w:p> element to check. | ||
| * @return true if the <w:p> contains "Artifact Id" followed by a numeric value; false otherwise. | ||
| */ | ||
| public static boolean isArtifactIdMetadataAttribute(Element paragraphElement) { | ||
| // Get all <w:t> elements within this <w:p> | ||
| NodeList textNodes = paragraphElement.getElementsByTagName("w:t"); | ||
|
|
||
| boolean foundArtifactIdLabel = false; | ||
|
|
||
| for (int i = 0; i < textNodes.getLength(); i++) { | ||
| Node textNode = textNodes.item(i); | ||
|
|
||
| if (textNode.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element textElement = (Element) textNode; | ||
|
|
||
| // Check if this <w:t> contains "Artifact Id" | ||
| if ("Artifact Id".equals(textElement.getTextContent())) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be startsWith or contains? |
||
| foundArtifactIdLabel = true; | ||
| } | ||
|
|
||
| // Check if this <w:t> contains a numeric artifact ID (e.g., "200406") | ||
| if (foundArtifactIdLabel && textElement.getTextContent().matches("\\d+")) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Return false if no matching structure is found | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a <w:p> block contains any of the specified artifact names. | ||
| * | ||
| * @param paragraphElement the <w:p> element to check. | ||
| * @param artifactNames an array of artifact names to check for. | ||
| * @return true if the <w:p> contains any of the artifact names; false otherwise. | ||
| */ | ||
| public static boolean containsAnyName(Element paragraphElement, String[] artifactNames) { | ||
| // Get all <w:t> elements within this <w:p> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment as above |
||
| NodeList textNodes = paragraphElement.getElementsByTagName("w:t"); | ||
|
|
||
| for (int i = 0; i < textNodes.getLength(); i++) { | ||
| Node textNode = textNodes.item(i); | ||
|
|
||
| if (textNode.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element textElement = (Element) textNode; | ||
|
|
||
| // Check if the text matches any of the artifact names | ||
| String textContent = textElement.getTextContent(); | ||
| for (String artifactName : artifactNames) { | ||
| if (artifactName.equals(textContent)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a <w:p> block contains an outline number (e.g., <wx:t wx:val="4.1.3.1.1">). | ||
| * | ||
| * @param paragraphElement the <w:p> element to check. | ||
| * @return true if the <w:p> contains an outline number; false otherwise. | ||
| */ | ||
| public static boolean hasOutlineNumber(Element paragraphElement) { | ||
| // Get all <wx:t> elements within this <w:p> | ||
| NodeList outlineNodes = paragraphElement.getElementsByTagName("wx:t"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment as above |
||
|
|
||
| for (int i = 0; i < outlineNodes.getLength(); i++) { | ||
| Node outlineNode = outlineNodes.item(i); | ||
|
|
||
| if (outlineNode.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element outlineElement = (Element) outlineNode; | ||
|
|
||
| // Check if the wx:val attribute is present | ||
| if (outlineElement.hasAttribute("wx:val")) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /* EOF */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, is there not a stream/iterator way of doing this like for(TextNode node: paragraphElement.getElementsByTagName("w:t")){...}?
Additionally, if you can do this with streams, you can use .anyMatch()