From 030e476c1e89ccfacab678eb2ecaffac7f837cd4 Mon Sep 17 00:00:00 2001 From: David Whitlock Date: Fri, 28 Nov 2025 05:18:58 -0800 Subject: [PATCH 1/2] Include XML parsing example in the Phone Bill archetype. --- .../META-INF/maven/archetype-metadata.xml | 1 + .../src/main/java/PhoneBillXmlHelper.java | 19 +++++++ .../src/main/java/TextDumper.java | 2 - .../pdx/cs410J/__artifactId__/package.html | 6 ++ .../src/test/java/PhoneBillXmlHelperTest.java | 55 +++++++++++++++++++ .../pdx/cs410J/__artifactId__/package.html | 6 ++ .../invalid-__artifactId__.xml | 23 ++++++++ .../valid-__artifactId__.xml | 36 ++++++++++++ 8 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/javadoc/edu/pdx/cs410J/__artifactId__/package.html create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/java/PhoneBillXmlHelperTest.java create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/javadoc/edu/pdx/cs410J/__artifactId__/package.html create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/invalid-__artifactId__.xml create mode 100644 projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/valid-__artifactId__.xml diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index 2d6e6e6f3..1721a943e 100644 --- a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -45,6 +45,7 @@ src/test/resources **/*.txt + **/*.xml diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java new file mode 100644 index 000000000..e1d005314 --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java @@ -0,0 +1,19 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import edu.pdx.cs.joy.ProjectXmlHelper; + +public class PhoneBillXmlHelper extends ProjectXmlHelper { + + /** + * The Public ID for the Family Tree DTD + */ + protected static final String PUBLIC_ID = + "-//Joy of Coding at PSU//DTD Phone Bill//EN"; + + protected PhoneBillXmlHelper() { + super(PUBLIC_ID, "phonebill.dtd"); + } +} diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/TextDumper.java b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/TextDumper.java index 4c2293a9e..2df0a2f93 100644 --- a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/TextDumper.java +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/TextDumper.java @@ -3,10 +3,8 @@ #set( $symbol_escape = '\' ) package ${package}; -import edu.pdx.cs.joy.AppointmentBookDumper; import edu.pdx.cs.joy.PhoneBillDumper; -import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/javadoc/edu/pdx/cs410J/__artifactId__/package.html b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/javadoc/edu/pdx/cs410J/__artifactId__/package.html new file mode 100644 index 000000000..6d4adf245 --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/javadoc/edu/pdx/cs410J/__artifactId__/package.html @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + +

Contains the application classes for the Phone Bill project.

+ \ No newline at end of file diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/java/PhoneBillXmlHelperTest.java b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/java/PhoneBillXmlHelperTest.java new file mode 100644 index 000000000..43cefe97f --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/java/PhoneBillXmlHelperTest.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +class PhoneBillXmlHelperTest { + + @Test + void canParseValidXmlFile() throws ParserConfigurationException, IOException, SAXException { + PhoneBillXmlHelper helper = new PhoneBillXmlHelper(); + + + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + factory.setValidating(true); + + DocumentBuilder builder = + factory.newDocumentBuilder(); + builder.setErrorHandler(helper); + builder.setEntityResolver(helper); + + builder.parse(this.getClass().getResourceAsStream("valid-${artifactId}.xml")); + } + + @Test + void cantParseInvalidXmlFile() throws ParserConfigurationException { + PhoneBillXmlHelper helper = new PhoneBillXmlHelper(); + + + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + factory.setValidating(true); + + DocumentBuilder builder = + factory.newDocumentBuilder(); + builder.setErrorHandler(helper); + builder.setEntityResolver(helper); + + assertThrows(SAXParseException.class, () -> + builder.parse(this.getClass().getResourceAsStream("invalid-${artifactId}.xml")) + ); + } + +} diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/javadoc/edu/pdx/cs410J/__artifactId__/package.html b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/javadoc/edu/pdx/cs410J/__artifactId__/package.html new file mode 100644 index 000000000..a579da692 --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/javadoc/edu/pdx/cs410J/__artifactId__/package.html @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + +

Contains the test classes for the Phone Bill project.

+ \ No newline at end of file diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/invalid-__artifactId__.xml b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/invalid-__artifactId__.xml new file mode 100644 index 000000000..a912ef877 --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/invalid-__artifactId__.xml @@ -0,0 +1,23 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Dave + + 503-245-2345 + + + + + + + + + diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/valid-__artifactId__.xml b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/valid-__artifactId__.xml new file mode 100644 index 000000000..7fd53d021 --- /dev/null +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/test/resources/__packageInPathFormat__/valid-__artifactId__.xml @@ -0,0 +1,36 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Dave + + 503-245-2345 + 607-777-1369 + + + + + + + + + + 603-868-1932 + 765-497-8254 + + + + + + + + From 763da56cb167e2d0d6c3ba03b4c6610cb83095c2 Mon Sep 17 00:00:00 2001 From: David Whitlock Date: Fri, 28 Nov 2025 05:37:36 -0800 Subject: [PATCH 2/2] Fix field description Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../archetype-resources/src/main/java/PhoneBillXmlHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java index e1d005314..78ce6a19a 100644 --- a/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java +++ b/projects-parent/archetypes-parent/phonebill-archetype/src/main/resources/archetype-resources/src/main/java/PhoneBillXmlHelper.java @@ -8,7 +8,7 @@ public class PhoneBillXmlHelper extends ProjectXmlHelper { /** - * The Public ID for the Family Tree DTD + * The Public ID for the Phone Bill DTD */ protected static final String PUBLIC_ID = "-//Joy of Coding at PSU//DTD Phone Bill//EN";