Compare commits

..

No commits in common. "main" and "log" have entirely different histories.
main ... log

207 changed files with 2763 additions and 1367 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA" serialisationVersion="2">
<checkstyleVersion>10.23.0</checkstyleVersion>
<checkstyleVersion>10.14.2</checkstyleVersion>
<scanScope>JavaOnly</scanScope>
<copyLibs>true</copyLibs>
<option name="thirdPartyClasspath" />

24
.idea/compiler.xml generated
View File

@ -9,49 +9,59 @@
<outputRelativeToContentRoot value="true" />
<module name="assertion-libraries" />
<module name="core-java-serialization" />
<module name="lucene" />
<module name="core-java-annotations" />
<module name="core-java-uuid" />
<module name="core-java-numbers" />
<module name="jackson-polymorphic-deserialization" />
<module name="ethereum" />
<module name="core-java-strings" />
<module name="jackson" />
<module name="core-java-11" />
<module name="core-java-collections-conversions" />
<module name="xml" />
<module name="core-java-collections" />
<module name="core-java-datetime-conversion" />
<module name="core-java-lambdas" />
<module name="junit-5-basics" />
<module name="activejdbc" />
<module name="spring-data-jpa-repo" />
<module name="apache-velocity" />
<module name="jackson-conversions-2" />
<module name="activejdbc" />
<module name="codebank" />
<module name="core-java-collections-list" />
<module name="image-compressing" />
<module name="spring-data-jpa-repo-2" />
<module name="core-java-streams" />
<module name="core-java-io-2" />
<module name="core-java-io" />
<module name="core-java-8-datetime" />
<module name="discourse" />
<module name="image-processing" />
<module name="jackson-jr" />
<module name="spring-data-redis" />
<module name="xml-2" />
<module name="core-java" />
<module name="jackson-custom-conversions" />
<module name="core-java-collections-list-2" />
<module name="core-java-collections-conversions-2" />
<module name="jackson-exceptions" />
<module name="xstream" />
<module name="apache-httpclient" />
<module name="core-java-8" />
<module name="apache-httpclient" />
<module name="core-java-collections-3" />
<module name="core-java-9" />
<module name="jackson-conversions" />
<module name="core-java-collections-2" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="core-java-10" target="17" />
<module name="core-java-11-2" target="11" />
<module name="core-java-8-2" target="11" />
<module name="core-java-collections-list-3" target="11" />
<module name="jackson-annotations" target="17" />
<module name="spring-data-jpa-repo-2" target="17" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="core-java-9" options="" />
<module name="core-java-streams" options="-parameters" />
</option>
</component>

32
.idea/encodings.xml generated
View File

@ -7,8 +7,14 @@
<file url="file://$PROJECT_DIR$/apache/apache-velocity/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/apache/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/apache/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-10/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-10/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-datetime/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-datetime/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8/src/main/java" charset="UTF-8" />
@ -25,6 +31,10 @@
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-conversions-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-conversions/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-conversions/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections/src/main/java" charset="UTF-8" />
@ -37,6 +47,8 @@
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-io/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-lambdas/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-lambdas/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-serialization/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-serialization/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-streams/src/main/java" charset="UTF-8" />
@ -49,12 +61,12 @@
<file url="file://$PROJECT_DIR$/core-java-modules/core-java/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ethereum/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ethereum/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/image-compressing/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/image-compressing/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/image-processing/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/image-processing/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson-annotations/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson-annotations/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson-conversions-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson-conversions-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson-conversions/src/main/java" charset="UTF-8" />
@ -71,14 +83,16 @@
<file url="file://$PROJECT_DIR$/libraries-jackson/jackson/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/libraries-jackson/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/lucene/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/lucene/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-3/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-3/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/src/main/java" charset="UTF-8" />
@ -92,11 +106,9 @@
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/test/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/testing-modules/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/testing-modules/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xml-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xml-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xml/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xml/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xstream/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/xstream/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@ -2,29 +2,84 @@
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="iSharkFly Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/isharkfly-maven-releases/" />
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="OSSEZ Private Snapshots" />
<option name="url" value="https://repo.ossez.com/repository/maven-snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.isharkfly.com/repository/maven/" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="iSharkFly Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/isharkfly-maven-snapshots/" />
<option name="id" value="ossez-repo-releases" />
<option name="name" value="OSSEZ Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.ossez.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="iSharkFly Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="OSSEZ Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="iSharkFly Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-public/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="iSharkFly Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="" />
<option name="name" value="" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="OSSEZ Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="OSSEZ Private Releases" />
<option name="url" value="https://repo.ossez.com/repository/maven-releases/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="iSharkFly Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-releases/" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="OSSEZ Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/maven-releases/" />
</remote-repository>
</component>
</project>

7
.idea/jpa.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
<option name="renamerInitialized" value="true" />
</component>
</project>

6
.idea/prettier.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PrettierConfiguration">
<option name="myConfigurationMode" value="AUTOMATIC" />
</component>
</project>

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 iSharkFly
Copyright (c) 2024 iSharkFly
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -76,7 +76,7 @@
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<version>${version.slf4j}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

12
ethereum/.idea/.gitignore generated vendored
View File

@ -1,12 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Zeppelin ignored files
/ZeppelinRemoteNotebooks/

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA" serialisationVersion="2">
<checkstyleVersion>10.23.0</checkstyleVersion>
<scanScope>JavaOnly</scanScope>
<copyLibs>true</copyLibs>
<option name="thirdPartyClasspath" />
<option name="activeLocationIds" />
<option name="locations">
<list>
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
</list>
</option>
</component>
</project>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="ethereum" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="Ethereum" />
<option name="name" value="Ethereum" />
<option name="url" value="https://dl.bintray.com/ethereum/maven/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-releases" />
<option name="name" value="iSharkFly Private Releases" />
<option name="url" value="https://repo.isharkfly.com/repository/isharkfly-maven-releases/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.isharkfly.com/repository/maven/" />
</remote-repository>
<remote-repository>
<option name="id" value="ossez-repo-snapshots" />
<option name="name" value="iSharkFly Private Snapshots" />
<option name="url" value="https://repo.isharkfly.com/repository/isharkfly-maven-snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK" />
<component name="ThriftCompiler">
<compilers />
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -3,14 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ossez.ethereum</groupId>
<groupId>com.baeldung.ethereum</groupId>
<artifactId>ethereum</artifactId>
<name>ethereum</name>
<parent>
<groupId>com.ossez</groupId>
<artifactId>parent-modules</artifactId>
<version>0.0.2-SNAPSHOT</version>
<groupId>com.baeldung</groupId>
<artifactId>parent-spring-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring-5</relativePath>
</parent>
<dependencies>
@ -75,15 +76,14 @@
</dependency>
<!-- Servlet -->
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>3.0.2</version>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
@ -91,10 +91,9 @@
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>${javax.servlet.jsp-api.version}</version>
</dependency>
<!-- Spring Testing -->
<dependency>
@ -114,19 +113,19 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>7.0.0-M4</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>7.0.0-M4</version>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.17.0</version>
<version>${mockito.version}</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
@ -171,16 +170,15 @@
</build>
<repositories>
<!-- <repository>-->
<!-- <id>Ethereum</id>-->
<!-- <name>Ethereum</name>-->
<!-- <url>https://dl.bintray.com/ethereum/maven/</url>-->
<!-- </repository>-->
<repository>
<id>Ethereum</id>
<name>Ethereum</name>
<url>https://dl.bintray.com/ethereum/maven/</url>
</repository>
</repositories>
<properties>
<spring.version>7.0.0-M4</spring.version>
<ethereumj-core.version>1.9.0-RELEASE</ethereumj-core.version>
<ethereumj-core.version>1.5.0-RELEASE</ethereumj-core.version>
<web3j.core.version>3.3.1</web3j.core.version>
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
<jsonpath.version>2.8.0</jsonpath.version>

View File

@ -1,4 +1,4 @@
package com.isharkfly.ethereumj;
package com.baeldung.ethereumj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -8,7 +8,7 @@ import org.springframework.boot.web.support.SpringBootServletInitializer;
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@SpringBootApplication
public abstract class ApplicationMain extends SpringBootServletInitializer {
public class ApplicationMain extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ApplicationMain.class, args);

View File

@ -1,4 +1,4 @@
package com.isharkfly.ethereumj;
package com.baeldung.ethereumj;
public class Constants {

View File

@ -1,6 +1,6 @@
package com.isharkfly.ethereumj.beans;
package com.baeldung.ethereumj.beans;
import com.isharkfly.ethereumj.listeners.EthListener;
import com.baeldung.ethereumj.listeners.EthListener;
import org.ethereum.core.Block;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumFactory;

View File

@ -1,6 +1,6 @@
package com.isharkfly.ethereumj.config;
package com.baeldung.ethereumj.config;
import com.isharkfly.ethereumj.beans.EthBean;
import com.baeldung.ethereumj.beans.EthBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -1,8 +1,8 @@
package com.isharkfly.ethereumj.controllers;
package com.baeldung.ethereumj.controllers;
import com.isharkfly.ethereumj.Constants;
import com.isharkfly.ethereumj.beans.EthBean;
import com.isharkfly.ethereumj.transfer.EthResponse;
import com.baeldung.ethereumj.Constants;
import com.baeldung.ethereumj.beans.EthBean;
import com.baeldung.ethereumj.transfer.EthResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,4 +1,4 @@
package com.isharkfly.ethereumj.listeners;
package com.baeldung.ethereumj.listeners;
import org.ethereum.core.Block;
import org.ethereum.core.TransactionReceipt;

View File

@ -1,4 +1,4 @@
package com.isharkfly.ethereumj.transfer;
package com.baeldung.ethereumj.transfer;
public class EthResponse {

View File

@ -1,6 +1,6 @@
package com.isharkfly.web3j;
package com.baeldung.web3j;
import com.isharkfly.web3j.contracts.Greeting;
import com.baeldung.web3j.contracts.Greeting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.crypto.Credentials;

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.config;
package com.baeldung.web3j.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -18,7 +18,7 @@ import java.util.concurrent.Executor;
@Configuration
@EnableWebMvc
@EnableAsync
@ComponentScan("com.isharkfly.web3j")
@ComponentScan("com.baeldung.web3j")
public class AppConfig implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.config;
package com.baeldung.web3j.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.constants;
package com.baeldung.web3j.constants;
public class Constants {

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.contracts;
package com.baeldung.web3j.contracts;
import java.math.BigInteger;
import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.contracts;
package com.baeldung.web3j.contracts;
import java.math.BigInteger;
import java.util.Arrays;

View File

@ -1,9 +1,9 @@
package com.isharkfly.web3j.controllers;
package com.baeldung.web3j.controllers;
import com.isharkfly.web3j.constants.Constants;
import com.isharkfly.web3j.helpers.TimeHelper;
import com.isharkfly.web3j.services.Web3Service;
import com.isharkfly.web3j.transfers.ResponseTransfer;
import com.baeldung.web3j.constants.Constants;
import com.baeldung.web3j.helpers.TimeHelper;
import com.baeldung.web3j.services.Web3Service;
import com.baeldung.web3j.transfers.ResponseTransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -17,7 +17,7 @@ import java.time.Instant;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import static com.isharkfly.web3j.constants.Constants.GENERIC_EXCEPTION;
import static com.baeldung.web3j.constants.Constants.GENERIC_EXCEPTION;
@RestController
public class EthereumRestController {

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.helpers;
package com.baeldung.web3j.helpers;
import java.time.Duration;
import java.time.Instant;

View File

@ -1,6 +1,6 @@
package com.isharkfly.web3j.services;
package com.baeldung.web3j.services;
import com.isharkfly.web3j.contracts.Example;
import com.baeldung.web3j.contracts.Example;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.web3j.abi.FunctionEncoder;
@ -22,10 +22,11 @@ import java.io.File;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import static com.isharkfly.web3j.constants.Constants.DEFAULT_ADDRESS;
import static com.isharkfly.web3j.constants.Constants.GENERIC_EXCEPTION;
import static com.isharkfly.web3j.constants.Constants.PLEASE_SUPPLY_REAL_DATA;
import static com.baeldung.web3j.constants.Constants.DEFAULT_ADDRESS;
import static com.baeldung.web3j.constants.Constants.GENERIC_EXCEPTION;
import static com.baeldung.web3j.constants.Constants.PLEASE_SUPPLY_REAL_DATA;
@Service
public class Web3Service {

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.transfers;
package com.baeldung.web3j.transfers;
import java.time.Duration;

View File

@ -1,4 +1,4 @@
package com.isharkfly.ethereumj.controllers;
package com.baeldung.ethereumj.controllers;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertNotNull;
@ -17,9 +17,9 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import com.isharkfly.ethereumj.ApplicationMain;
import com.isharkfly.ethereumj.Constants;
import com.isharkfly.ethereumj.transfer.EthResponse;
import com.baeldung.ethereumj.ApplicationMain;
import com.baeldung.ethereumj.Constants;
import com.baeldung.ethereumj.transfer.EthResponse;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApplicationMain.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

View File

@ -1,8 +1,8 @@
package com.isharkfly.web3j.controllers;
package com.baeldung.web3j.controllers;
import com.isharkfly.web3j.config.AppConfig;
import com.isharkfly.web3j.constants.Constants;
import com.baeldung.web3j.config.AppConfig;
import com.baeldung.web3j.constants.Constants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@ -1,7 +1,7 @@
package com.isharkfly.web3j.controllers;
package com.baeldung.web3j.controllers;
import com.isharkfly.web3j.constants.Constants;
import com.isharkfly.web3j.services.Web3Service;
import com.baeldung.web3j.constants.Constants;
import com.baeldung.web3j.services.Web3Service;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@ -1,4 +1,4 @@
package com.isharkfly.web3j.services;
package com.baeldung.web3j.services;
import org.junit.After;
import org.junit.Before;

View File

@ -7,7 +7,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Map;
@ -104,7 +103,7 @@ public class JavaReadWriteJsonExampleUnitTest {
@Test
public void wheReadFromUrl_thanCorrect() throws Exception {
URL resource = new URI("file:src/test/resources/json_car.json").toURL();
URL resource = new URL("file:src/test/resources/json_car.json");
ObjectMapper objectMapper = new ObjectMapper();
Car fromFile = objectMapper.readValue(resource, Car.class);

View File

@ -6,10 +6,6 @@
<artifactId>jackson-conversions</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jackson-conversions</name>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<parent>
<groupId>com.ossez</groupId>

View File

@ -9,9 +9,9 @@
<description>An Apache Lucene demo application</description>
<parent>
<groupId>com.ossez</groupId>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
@ -33,7 +33,7 @@
</dependencies>
<properties>
<lucene.version>8.0.0</lucene.version>
<lucene.version>7.4.0</lucene.version>
</properties>
</project>

View File

@ -4,10 +4,10 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.en.EnglishAnalyzer;
import org.apache.lucene.analysis.en.PorterStemFilter;
import org.apache.lucene.analysis.miscellaneous.CapitalizationFilter;
import org.apache.lucene.analysis.standard.ClassicFilter;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
public class MyCustomAnalyzer extends Analyzer{
@ -15,9 +15,9 @@ public class MyCustomAnalyzer extends Analyzer{
@Override
protected TokenStreamComponents createComponents(String fieldName) {
final StandardTokenizer src = new StandardTokenizer();
TokenStream result = new ClassicFilter(src);
TokenStream result = new StandardFilter(src);
result = new LowerCaseFilter(result);
result = new StopFilter(result, EnglishAnalyzer.ENGLISH_STOP_WORDS_SET);
result = new StopFilter(result, StandardAnalyzer.STOP_WORDS_SET);
result = new PorterStemFilter(result);
result = new CapitalizationFilter(result);
return new TokenStreamComponents(src, result);

View File

@ -42,7 +42,7 @@ public class LuceneAnalyzerIntegrationTest {
@Test
public void whenUseStopAnalyzer_thenAnalyzed() throws IOException {
List<String> result = analyze(SAMPLE_TEXT, new StopAnalyzer(EnglishAnalyzer.ENGLISH_STOP_WORDS_SET));
List<String> result = analyze(SAMPLE_TEXT, new StopAnalyzer());
assertThat(result, contains("baeldung", "com", "lucene", "analyzers", "test"));
}

View File

@ -34,7 +34,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<version>${version.slf4j}</version>
</dependency>
</dependencies>

22
pom.xml
View File

@ -41,12 +41,9 @@
<modules>
<module>apache</module>
<module>core-java-modules</module>
<module>ethereum</module>
<module>image-compressing</module>
<module>image-processing</module>
<module>libraries-jackson</module>
<module>lucene</module>
<!-- <module>jackson-simple</module>-->
<!-- <module>parent-java</module>-->
<module>parent-boot-2</module>
@ -54,9 +51,7 @@
<module>persistence-modules</module>
<module>testing-modules</module>
<module>toolkits</module>
<module>xml</module>
<module>xml-2</module>
<module>xstream</module>
<!-- <module>xml</module>-->
</modules>
<properties>
@ -66,9 +61,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Logging -->
<slf4j.version>2.0.0</slf4j.version>
<version.slf4j>1.7.36</version.slf4j>
<log4j.version>1.2.17</log4j.version>
<log4j-over-slf4j.version>2.0.17</log4j-over-slf4j.version>
<log4j-over-slf4j.version>2.0.7</log4j-over-slf4j.version>
<version.log4j2>2.18.0</version.log4j2>
<!-- APACHE COMMONS-->
@ -80,6 +75,8 @@
<commons-cli.version>1.4</commons-cli.version>
<commons-io.version>2.11.0</commons-io.version>
<!-- UTILS -->
<guava.version>31.1-jre</guava.version>
<lombok.version>1.18.28</lombok.version>
@ -87,7 +84,6 @@
<colt.version>1.2.0</colt.version>
<trove4j.version>3.0.3</trove4j.version>
<fastutil.version>5.0.9</fastutil.version>
<jstl.version>1.2</jstl.version>
<!-- Hibernate / JPA -->
<jakarta.persistence.version>3.2.0-M2</jakarta.persistence.version>
@ -135,8 +131,6 @@
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
@ -145,12 +139,6 @@
<!-- OSSEZ COMMON -->
<!-- LOG -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>

View File

@ -52,6 +52,14 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>

View File

@ -4,15 +4,12 @@ This module contains articles about eXtensible Markup Language (XML)
### Relevant Articles:
- [Pretty-Print XML in Java](https://www.baeldung.com/java-pretty-print-xml)
- [Validate an XML File Against an XSD File](https://www.baeldung.com/java-validate-xml-xsd)
- [Converting JSON to XML in Java](https://www.baeldung.com/java-convert-json-to-xml)
- [Convert an XML Object to a String in Java](https://www.baeldung.com/java-convert-xml-object-string)
- [Convert String Containing XML to org.w3c.dom.Document](https://www.baeldung.com/java-convert-string-xml-dom)
- [How to Parse XML to HashMap in Java](https://www.baeldung.com/java-xml-read-into-hashmap)
- [Convert an XML File to CSV File](https://www.baeldung.com/java-convert-xml-csv)
- [Invalid Characters in XML](https://www.baeldung.com/java-xml-invalid-characters)
- [How to Convert XML to PDF](https://www.baeldung.com/java-xml-pdf-conversion)
- [How to Convert org.w3c.dom.Document to String in Java](https://www.baeldung.com/java-convert-org-w3c-dom-document-string)
- [Introduction to JiBX](https://www.baeldung.com/jibx)
- [Write an org.w3.dom.Document to a File](https://www.baeldung.com/java-write-xml-document-file)
- [Modifying an XML Attribute in Java](https://www.baeldung.com/java-modify-xml-attribute)
- [Convert XML to HTML in Java](https://www.baeldung.com/java-convert-xml-to-html)
- - More articles: [[prev -->]](../xml)

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>xml-2</artifactId>
<version>0.1-SNAPSHOT</version>
<name>xml-2</name>
<parent>
<groupId>com.ossez</groupId>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
@ -26,6 +26,16 @@
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
@ -41,97 +51,15 @@
<artifactId>xstream</artifactId>
<version>${xstream.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>${fop.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itextpdf.version}</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>${jibx-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<version>${xmlunit-assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>joox-java-6</artifactId>
<version>${joox.version}</version>
</dependency>
<!-- JMH Libraries -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>${jaxen.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind-api.version}</version>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>${mustache.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb-impl.version}</version>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${jaxb-core.version}</version>
</dependency>
<dependency>
<groupId>net.htmlparser.jericho</groupId>
<artifactId>jericho-html</artifactId>
<version>${jericho.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlcleaner</groupId>
<artifactId>htmlcleaner</artifactId>
<version>${htmlcleaner.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>${xmlbeans.version}</version>
</dependency>
</dependencies>
@ -143,14 +71,6 @@
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -159,228 +79,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<configuration>
<directory>src/main/resources</directory>
<includes>
<includes>*-binding.xml</includes>
</includes>
<excludes>
<exclude>template-binding.xml</exclude>
</excludes>
<schemaBindingDirectory>src/main/resources</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*-binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
<execution>
<id>process-test-classes</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>${bcel.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>schemaGen</id>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<directory>src/main/resources</directory>
<includes>
<include>Order.xsd</include>
</includes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<directory>target/generated-sources</directory>
<load>true</load>
<validate>true</validate>
<!--<verbose>true</verbose> -->
<verify>true</verify>
</configuration>
</execution>
<execution>
<id>generate-test-code-from-schema</id>
<phase>generate-test-sources</phase>
<goals>
<goal>test-schema-codegen</goal>
</goals>
</execution>
<execution>
<id>compile-test-binding</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
<configuration>
<directory>target/generated-test-sources</directory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>CustomerTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>bindGen</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<configuration>
<directory>src/main/resources</directory>
<includes>
<includes>*-binding.xml</includes>
</includes>
<excludes>
<exclude>template-binding.xml</exclude>
</excludes>
<schemaBindingDirectory>src/main/resources</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*-binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
<execution>
<id>process-test-classes</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<!-- NOTE: We don't need a groupId specification because the group is org.apache.maven.plugins -->
<!--...which is assumed by default. -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>
com.baeldung.xml.jibx.JiBXDemoApplication
</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id><!-- this is used for inheritance merges -->
<phase>package</phase><!-- append to the packaging phase. -->
<goals>
<goal>attached</goal><!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<dom4j.version>2.1.3</dom4j.version>
<json.version>20240303</json.version>
<underscore.version>1.89</underscore.version>
<xstream.version>1.4.18</xstream.version>
<fop.version>2.9</fop.version>
<itextpdf.version>5.5.13.3</itextpdf.version>
<jibx-version>1.2.4.5</jibx-version>
<bcel.version>6.7.0</bcel.version>
<maven-jibx-plugin.version>1.3.1</maven-jibx-plugin.version>
<commons-lang3.version>3.14.0</commons-lang3.version>
<xmlunit-assertj.version>2.6.3</xmlunit-assertj.version>
<joox.version>1.6.2</joox.version>
<jaxen.version>1.2.0</jaxen.version>
<freemarker.version>2.3.29</freemarker.version>
<jakarta.xml.bind-api.version>4.0.2</jakarta.xml.bind-api.version>
<mustache.version>0.9.6</mustache.version>
<jaxb-core.version>2.3.0.1</jaxb-core.version>
<jaxb-impl.version>4.0.4</jaxb-impl.version>
<jaxb-runtime.version>4.0.3</jaxb-runtime.version>
<jericho.version>3.4</jericho.version>
<htmlcleaner.version>2.25</htmlcleaner.version>
<jsoup.version>1.17.2</jsoup.version>
<jaxb.version>2.3.3</jaxb.version>
<xmlbeans.version>5.0.2</xmlbeans.version>
<log4j-core.version>2.12.4</log4j-core.version>
</properties>
</project>

View File

@ -0,0 +1,91 @@
package com.baeldung.xml.prettyprint;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.*;
public class XmlPrettyPrinter {
public static String prettyPrintByTransformer(String xmlString, int indent, boolean ignoreDeclaration) {
try {
final InputSource src = new InputSource(new StringReader(xmlString));
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", indent);
Transformer transformer = transformerFactory.newTransformer(new StreamSource(new StringReader(readPrettyPrintXslt())));
// Using the default transformer will create empty lines in Java9+
// Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, ignoreDeclaration ? "yes" : "no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// Alternatively, we can set indent-size on the transformer object
// transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
Writer out = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(out));
return out.toString();
} catch (Exception e) {
throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e);
}
}
public static String prettyPrintByDom4j(String xmlString, int indent, boolean skipDeclaration) {
try {
final OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
format.setIndentSize(indent);
format.setSuppressDeclaration(skipDeclaration);
final org.dom4j.Document document = DocumentHelper.parseText(xmlString);
final StringWriter sw = new StringWriter();
final XMLWriter writer = new XMLWriter(sw, format);
writer.write(document);
return sw.toString();
} catch (Exception e) {
throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e);
}
}
public static void main(String[] args) throws IOException {
InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/emails.xml");
String xmlString = readFromInputStream(inputStream);
System.out.println("Pretty printing by Transformer");
System.out.println("=============================================");
System.out.println(prettyPrintByTransformer(xmlString, 2, true));
System.out.println("=============================================");
System.out.println("Pretty printing by Dom4j");
System.out.println("=============================================");
System.out.println(prettyPrintByDom4j(xmlString, 8, false));
System.out.println("=============================================");
}
private static String readPrettyPrintXslt() throws IOException {
InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/prettyprint.xsl");
return readFromInputStream(inputStream);
}
private static String readFromInputStream(InputStream inputStream) throws IOException {
StringBuilder resultStringBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = br.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
}
return resultStringBuilder.toString();
}
}

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.tohashmap;
package com.baeldung.xml.tohashmap;
public class Employee {
private String id;

View File

@ -1,10 +1,9 @@
package com.isharkfly.xml.tohashmap;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
package com.baeldung.xml.tohashmap;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "employees")
public class Employees {

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.tohashmap;
package com.baeldung.xml.tohashmap;
import java.io.IOException;
import java.io.StringReader;
@ -9,6 +9,9 @@ import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@ -18,9 +21,6 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

View File

@ -0,0 +1,35 @@
package com.baeldung.xml.validation;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;
import java.util.ArrayList;
import java.util.List;
public class XmlErrorHandler implements ErrorHandler {
private List<SAXParseException> exceptions;
public XmlErrorHandler() {
this.exceptions = new ArrayList<>();
}
public List<SAXParseException> getExceptions() {
return exceptions;
}
@Override
public void warning(SAXParseException exception) {
exceptions.add(exception);
}
@Override
public void error(SAXParseException exception) {
exceptions.add(exception);
}
@Override
public void fatalError(SAXParseException exception) {
exceptions.add(exception);
}
}

View File

@ -0,0 +1,62 @@
package com.baeldung.xml.validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class XmlValidator {
private static final Logger LOGGER = LoggerFactory.getLogger(XmlValidator.class);
private String xsdPath;
private String xmlPath;
public XmlValidator(String xsdPath, String xmlPath) {
this.xsdPath = xsdPath;
this.xmlPath = xmlPath;
}
public boolean isValid() throws IOException, SAXException {
Validator validator = initValidator(xsdPath);
try {
validator.validate(new StreamSource(getFile(xmlPath)));
return true;
} catch (SAXException e) {
return false;
}
}
public List<SAXParseException> listParsingExceptions() throws IOException, SAXException {
XmlErrorHandler xsdErrorHandler = new XmlErrorHandler();
Validator validator = initValidator(xsdPath);
validator.setErrorHandler(xsdErrorHandler);
try {
validator.validate(new StreamSource(getFile(xmlPath)));
} catch (SAXParseException e) {}
xsdErrorHandler.getExceptions().forEach(e -> LOGGER.info(String.format("Line number: %s, Column number: %s. %s", e.getLineNumber(), e.getColumnNumber(), e.getMessage())));
return xsdErrorHandler.getExceptions();
}
private Validator initValidator(String xsdPath) throws SAXException {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source schemaFile = new StreamSource(getFile(xsdPath));
Schema schema = factory.newSchema(schemaFile);
return schema.newValidator();
}
private File getFile(String location) {
return new File(getClass().getClassLoader().getResource(location).getFile());
}
}

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.xml2csv;
package com.baeldung.xml.xml2csv;
import java.io.BufferedWriter;
import java.io.File;

View File

@ -1,55 +0,0 @@
package com.isharkfly.xml.xml2pdf;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
public class XmlToPdfConverter {
public static void convertXMLtoPDFUsingFop(String xmlFilePath, String xsltFilePath, String pdfFilePath) throws Exception {
// Initialize FOP
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// Specify output stream for PDF
try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(new File(pdfFilePath).toPath()))) {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Create Transformer from XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(new File(xsltFilePath)));
// Apply transformation
Source src = new StreamSource(new File(xmlFilePath));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
}
}
public static void convertXMLtoPDFUsingIText(String xmlFilePath, String pdfFilePath) throws Exception {
try (FileOutputStream outputStream = new FileOutputStream(pdfFilePath)) {
Document document = new Document();
PdfWriter.getInstance(document, outputStream);
document.open();
// Read XML content and add it to the Document
String xmlContent = new String(Files.readAllBytes(Paths.get(xmlFilePath)));
document.add(new Paragraph(xmlContent));
document.close();
}
}
}

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding>
<mapping class="com.isharkfly.xml.jibx.Identity" abstract="true">
<value name="customer-id" field="customerId" />
</mapping>
<mapping name="customer" class="com.isharkfly.xml.jibx.Customer">
<structure field="person" />
<structure name="home-phone" field="homePhone" usage="optional" />
<structure name="office-phone" field="officePhone" usage="optional" />
<value name="city" field="city" />
</mapping>
<mapping name="person" class="com.isharkfly.xml.jibx.Person"
extends="com.isharkfly.xml.jibx.Identity">
<structure map-as="com.isharkfly.xml.jibx.Identity" />
<value name="name" field="name" />
</mapping>
<mapping class="com.isharkfly.xml.jibx.Phone" abstract="true">
<value name="number" field="number" />
</mapping>
</binding>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<notification id="5">
<to customer="true">john@email.com</to>
<from>mary@email.com</from>
</notification>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<notification id="5">
<to customer="false">john@email.com</to>
<from>mary@email.com</from>
</notification>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xmlexample>
<ancestor>
<descendantOne>Yo</descendantOne>
<descendantTwo>
<descendantThree>
DustyOrb
</descendantThree>
</descendantTwo>
</ancestor>
</xmlexample>

View File

@ -1,14 +0,0 @@
<html>
<head>
<meta title="example"/>
</head>
<body>
<p>descendantOne: Yo</p>
<div>
<p>descendantThree:
DustyOrb
</p>
</div>
</body>
</html>

View File

@ -1,13 +0,0 @@
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>descendantOne: Yo</p>
<div>
<p>descendantThree:
DustyOrb
</p>
</div>
</body>
</html>

View File

@ -0,0 +1,11 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,15 +0,0 @@
<html>
<head>
<meta></meta>
</head>
<body>
<p>descendantOne: Yo</p>
<div>
<p>
descendantThree:
DustyOrb
</p>
</div>
</body>
</html>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<individual>
<name>Baeldung</name>
<address>
<zip>00001</zip>
<city>New York</city>
</address>
</individual>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="individual">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="5" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="zip" type="xs:positiveInteger" />
<xs:element name="city" type="xs:string" />
<xs:element name="street" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="individual">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="zip" type="xs:positiveInteger" />
<xs:element name="city" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -1,26 +0,0 @@
<?xml version="1.0"?>
<Bookstores>
<Bookstore id="S001">
<Books>
<Book id="B001" category="Fiction">
<Title>Death and the Penguin</Title>
<Author id="A001">Andrey Kurkov</Author>
<Price>10.99</Price>
</Book>
<Book id="B002" category="Poetry">
<Title>Kobzar</Title>
<Author id="A002">Taras Shevchenko</Author>
<Price>8.50</Price>
</Book>
</Books>
</Bookstore>
<Bookstore id="S002">
<Books>
<Book id="B003" category="Novel">
<Title>Voroshilovgrad</Title>
<Author id="A003">Serhiy Zhadan</Author>
<Price>12.99</Price>
</Book>
</Books>
</Bookstore>
</Bookstores>

View File

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- Define the layout for the PDF -->
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4"
page-width="8.5in" page-height="11in" margin-top="0.5in"
margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in">
<fo:region-body margin-top="0.5in" margin-bottom="0.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- Define the content of the PDF -->
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="18pt" font-weight="bold" text-align="center">
Bookstore Inventory
</fo:block>
<fo:table table-layout="fixed" width="100%">
<fo:table-column column-width="20%"/>
<fo:table-column column-width="20%"/>
<fo:table-column column-width="20%"/>
<fo:table-column column-width="20%"/>
<fo:table-header>
<fo:table-row>
<fo:table-cell border="solid 1px" padding="5pt" background-color="#CCCCCC">
<fo:block>Bookstore ID</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt" background-color="#CCCCCC">
<fo:block>Book ID</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt" background-color="#CCCCCC">
<fo:block>Title</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt" background-color="#CCCCCC">
<fo:block>Author</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:apply-templates select="//Book"/>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="Book">
<fo:table-row>
<fo:table-cell border="solid 1px" padding="5pt">
<fo:block><xsl:value-of select="ancestor::Bookstore/@id"/></fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt">
<fo:block><xsl:value-of select="@id"/></fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt">
<fo:block><xsl:value-of select="Title"/></fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1px" padding="5pt">
<fo:block><xsl:value-of select="Author"/></fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.invalidcharacters;
package com.baeldung.xml.invalidcharacters;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

View File

@ -0,0 +1,77 @@
package com.baeldung.xml.json2xml;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import com.github.underscore.U;
import org.json.JSONObject;
import org.json.XML;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class JsonToXmlUnitTest {
@Test
public void givenJsonString_whenConvertToXMLUsingJsonJava_thenConverted() {
String jsonString = "{\"name\":\"John\", \"age\":20, \"address\":{\"street\":\"Wall Street\", \"city\":\"New York\"}}";
JSONObject jsonObject = new JSONObject(jsonString);
String xmlString = XML.toString(jsonObject);
Assertions.assertEquals("<address><city>New York</city><street>Wall Street</street></address><name>John</name><age>20</age>", xmlString);
}
@Test
public void givenJsonString_whenConvertToXMLUsingJackson_thenConverted() throws JsonProcessingException {
String jsonString = "{\"name\":\"John\", \"age\":20, \"address\":{\"street\":\"Wall Street\", \"city\":\"New York\"}}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonString);
String xmlString = new XmlMapper().writeValueAsString(jsonNode);
Assertions.assertEquals("<ObjectNode><name>John</name><age>20</age><address><street>Wall Street</street><city>New York</city></address></ObjectNode>", xmlString);
}
@Test
public void givenJsonString_whenConvertToXMLUsingJacksonWithXMLDeclarationAndRoot_thenConverted() throws JsonProcessingException {
String jsonString = "{\"name\":\"John\", \"age\":20, \"address\":{\"street\":\"Wall Street\", \"city\":\"New York\"}}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonString);
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);
String xmlString = xmlMapper.writer().withRootName("root").withDefaultPrettyPrinter().writeValueAsString(jsonNode);
Assertions.assertEquals("<?xml version='1.1' encoding='UTF-8'?>" + System.lineSeparator() +
"<root>" + System.lineSeparator() +
" <name>John</name>" + System.lineSeparator() +
" <age>20</age>" + System.lineSeparator() +
" <address>" + System.lineSeparator() +
" <street>Wall Street</street>" + System.lineSeparator() +
" <city>New York</city>" + System.lineSeparator() +
" </address>" + System.lineSeparator() +
"</root>" + System.lineSeparator(), xmlString);
}
@Test
public void givenJsonString_whenConvertToXMLUsingUnderscoreJava_thenConverted() {
String jsonString = "{\"name\":\"John\", \"age\":20}";
String xmlString = U.jsonToXml(jsonString);
Assertions.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<root>\n" +
" <name>John</name>\n" +
" <age number=\"true\">20</age>\n" +
"</root>", xmlString);
}
@Test
public void givenJsonString_whenConvertToXMLUsingUnderscoreJavaWithoutAttributes_thenConverted() {
String jsonString = "{\"name\":\"John\", \"age\":20}";
String xmlString = U.jsonToXml(jsonString, U.JsonToXmlMode.REMOVE_ATTRIBUTES);
Assertions.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<root>\n" +
" <name>John</name>\n" +
" <age>20</age>\n" +
"</root>", xmlString);
}
}

View File

@ -1,13 +1,13 @@
package com.isharkfly.xml.tohashmap;
package com.baeldung.xml.tohashmap;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Map;
import com.isharkfly.xml.tohashmap.Employee;
import com.isharkfly.xml.tohashmap.XmlToHashMap;
import jakarta.xml.bind.JAXBException;
import javax.xml.bind.JAXBException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -0,0 +1,35 @@
package com.baeldung.xml.validation;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
class XmlValidatorUnitTest {
private static final String BAELDUNG_XML_PATH = "xml/validation/baeldung.xml";
private static final String PERSON_XSD_PATH = "xml/validation/person.xsd";
private static final String FULL_PERSON_XSD_PATH = "xml/validation/full-person.xsd";
@Test
public void givenValidXML_WhenIsValid_ThenTrue() throws IOException, SAXException {
assertTrue(new XmlValidator(PERSON_XSD_PATH, BAELDUNG_XML_PATH).isValid());
}
@Test
public void givenInvalidXML_WhenIsValid_ThenFalse() throws IOException, SAXException {
assertFalse(new XmlValidator(FULL_PERSON_XSD_PATH, BAELDUNG_XML_PATH).isValid());
}
@Test
public void givenValidXML_WhenListParsingExceptions_ThenNone() throws IOException, SAXException {
assertEquals(0, new XmlValidator(PERSON_XSD_PATH, BAELDUNG_XML_PATH).listParsingExceptions().size());
}
@Test
public void givenInvalidXML_WhenListParsingExceptions_ThenHasThree() throws IOException, SAXException {
assertEquals(3, new XmlValidator(FULL_PERSON_XSD_PATH, BAELDUNG_XML_PATH).listParsingExceptions().size());
}
}

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.xml2csv;
package com.baeldung.xml.xml2csv;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -18,7 +18,6 @@ import java.util.concurrent.Executors;
import javax.xml.transform.TransformerException;
import com.isharkfly.xml.xml2csv.Xml2CsvExample;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

View File

@ -1,37 +1,37 @@
package com.isharkfly.xml.xml2document;
import org.junit.Test;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import static org.junit.Assert.assertEquals;
public class XMLStringToDocumentObjectUnitTest {
@Test
public void givenValidXMLString_whenParsing_thenDocumentIsCorrect() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
String xmlString = "<root><element>XML Parsing Example</element></root>";
InputSource is = new InputSource(new StringReader(xmlString));
Document xmlDoc = null;
try {
xmlDoc = builder.parse(is);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
assertEquals("root", xmlDoc.getDocumentElement().getNodeName());
assertEquals("element", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getNodeName());
assertEquals("XML Parsing Example", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getTextContent());
}
}
package com.baeldung.xml2document;
import org.junit.Test;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import static org.junit.Assert.assertEquals;
public class XMLStringToDocumentObjectUnitTest {
@Test
public void givenValidXMLString_whenParsing_thenDocumentIsCorrect() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
String xmlString = "<root><element>XML Parsing Example</element></root>";
InputSource is = new InputSource(new StringReader(xmlString));
Document xmlDoc = null;
try {
xmlDoc = builder.parse(is);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
assertEquals("root", xmlDoc.getDocumentElement().getNodeName());
assertEquals("element", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getNodeName());
assertEquals("XML Parsing Example", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getTextContent());
}
}

View File

@ -0,0 +1,87 @@
package com.baeldung.xml2string;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
import org.junit.Before;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;
import static org.junit.Assert.assertTrue;
public class XMLObjectToStringUnitTest {
private Document document;
@Before
public void setup() throws ParserConfigurationException {
// Create a DocumentBuilder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
// Create a new Document
document = builder.newDocument();
// Create the root element
Element rootElement = document.createElement("root");
document.appendChild(rootElement);
// Create child elements
Element childElement1 = document.createElement("child1");
Element childElement2 = document.createElement("child2");
// Add text content to the child elements
childElement1.appendChild(document.createTextNode("This is child element 1"));
childElement2.appendChild(document.createTextNode("This is child element 2"));
// Append child elements to the root element
rootElement.appendChild(childElement1);
rootElement.appendChild(childElement2);
}
@Test
public void givenXMLDocument_whenUsingTransformer_thenConvertXMLToString() throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
String result = stringWriter.toString();
assertTrue(result.contains("<root>"));
assertTrue(result.contains("This is child element 1"));
assertTrue(result.contains("This is child element 2"));
}
@Test
public void givenXMLDocument_whenUsingXmlBeans_thenConvertXMLToString() {
try {
XmlObject xmlObject = XmlObject.Factory.parse(document);
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
options.setUseDefaultNamespace();
options.setSaveAggressiveNamespaces();
String xmlString = xmlObject.xmlText(options);
xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + xmlString;
assertTrue(xmlString.contains("<root>"));
assertTrue(xmlString.contains("This is child element 1"));
assertTrue(xmlString.contains("This is child element 2"));
} catch (XmlException e) {
e.printStackTrace();
}
}
}

View File

@ -1,48 +0,0 @@
package com.isharkfly.xml.xml2pdf;
import com.isharkfly.xml.xml2pdf.XmlToPdfConverter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class XmlToPdfConverterUnitTest {
private static final String BASE_PATH = "src/main/resources/xmltopdf/";
private static final String STYLE_XSL = BASE_PATH + "style.xsl";
private static final String DATA_XML_INPUT = BASE_PATH + "data-input.xml";
private static final String DATA_PDF_OUTPUT = BASE_PATH + "data-output.pdf";
// Comment out this method if you need to keep the outputted PDF file.
@AfterEach
public void teardown() {
new File(DATA_PDF_OUTPUT).delete();
}
@Test
public void givenXmlFile_whenConvertToPdfUsingFop_thenPdfGenerated() throws Exception {
// Execute XML to PDF conversion
XmlToPdfConverter.convertXMLtoPDFUsingFop(DATA_XML_INPUT, STYLE_XSL, DATA_PDF_OUTPUT);
// Check if PDF file was created
File pdfFile = new File(DATA_PDF_OUTPUT);
assertTrue(pdfFile.exists());
assertTrue(pdfFile.isFile());
assertTrue(pdfFile.length() > 0);
}
@Test
public void givenXmlFile_whenConvertToPdfUsingIText_thenPdfGenerated() throws Exception {
// Execute XML to PDF conversion
XmlToPdfConverter.convertXMLtoPDFUsingIText(DATA_XML_INPUT, DATA_PDF_OUTPUT);
// Check if PDF file was created
File pdfFile = new File(DATA_PDF_OUTPUT);
assertTrue(pdfFile.exists());
assertTrue(pdfFile.isFile());
assertTrue(pdfFile.length() > 0);
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<person>
<customer-id>12345</customer-id>
<name>Stefan Jaeger</name>
</person>
<home-phone>
<number>234678</number>
</home-phone>
<office-phone>
<number>234678</number>
</office-phone>
<city>Davos Dorf</city>
</customer>

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${heading}</title>
</head>
<body>
<p>${from}</p>
<p>${content}</p>
</body>
</html>

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{{heading}}</title>
</head>
<body>
<p>{{from}}</p>
<p>{{content}}</p>
</body>
</html>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<notification id="5">
<to customer="true">john@email.com</to>
<from>mary@email.com</from>
</notification>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<notification id="5">
<to customer="false">john@email.com</to>
<from>mary@email.com</from>
</notification>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE notification [
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<notification id="5">
<bad_entry>&xxe;
</bad_entry>
<to customer="true">john@email.com</to>
<from>mary@email.com</from>
</notification>

View File

@ -1,15 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>This is the page title</title>
</head>
<body>
<p>
If the application X doesn't start, the possible causes could be:<br/>
1. <a href="maven.com">Maven</a> is not installed.<br/>
2. Not enough disk space.<br/>
3. Not enough memory.
</p>
</body>
</html>

View File

@ -1,22 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>This is the page title</title>
</head>
<script>
// some interesting script functions
</script>
<body>
<p>
If the application X doesn't start, the possible causes could be:<br/>
1. <a
id="link"
href="http://maven.apache.org/">
Maven
</a> is not installed.<br/>
2. Not enough (<1G) disk space.<br/>
3. Not enough (<64MB) memory.<br/>
</p>
</body>
</html>

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Build #7 passed</title>
</head>
<body>
<p>from: builds@baeldung.com</p>
<p>Success: The Jenkins CI build passed</p>
</body>
</html>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<notification>
<from>builds@baeldung.com</from>
<heading>Build #7 passed</heading>
<content>Success: The Jenkins CI build passed</content>
</notification>

View File

@ -4,14 +4,11 @@
### 相关文章:
- [Intro to XPath with Java](https://www.baeldung.com/java-xpath)
- [Introduction to JiBX](https://www.baeldung.com/jibx)
- [XML Libraries Support in Java](https://www.baeldung.com/java-xml-libraries)
- [Working with XML Files in Java Using DOM Parsing](https://www.baeldung.com/java-xerces-dom-parsing)
- [Write an org.w3.dom.Document to a File](https://www.baeldung.com/java-write-xml-document-file)
- [Modifying an XML Attribute in Java](https://www.baeldung.com/java-modify-xml-attribute)
- [Convert XML to HTML in Java](https://www.baeldung.com/java-convert-xml-to-html)
- [Parsing an XML File Using StAX](https://www.baeldung.com/java-stax)
- [Parsing an XML File Using SAX Parser](https://www.baeldung.com/java-sax-parser)
- [Remove HTML Tags Using Java](https://www.baeldung.com/java-remove-html-tags)
- [Pretty-Print XML in Java](https://www.baeldung.com/java-pretty-print-xml)
- [Validate an XML File Against an XSD File](https://www.baeldung.com/java-validate-xml-xsd)
- [Converting JSON to XML in Java](https://www.baeldung.com/java-convert-json-to-xml)
- [Convert an XML Object to a String in Java](https://www.baeldung.com/java-convert-xml-object-string)
- More articles: [[next -->]](../xml-2)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>xml</artifactId>
<version>${parent.version}</version>
@ -25,31 +25,41 @@
<artifactId>jaxen</artifactId>
<version>${jaxen.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>joox-java-6</artifactId>
<version>${joox.version}</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>${jdom2.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind-api.version}</version>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb-impl.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${jaxb-core.version}</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>${jaxp-api.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>${stax-api.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
@ -60,6 +70,17 @@
<artifactId>compiler</artifactId>
<version>${mustache.version}</version>
</dependency>
<!-- JMH Libraries -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
<!-- utils -->
<dependency>
<groupId>commons-io</groupId>
@ -76,70 +97,47 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.github.javadev</groupId>
<artifactId>underscore</artifactId>
<version>${underscore.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>${xmlbeans.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.37</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>joox</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.htmlparser.jericho</groupId>
<artifactId>jericho-html</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.htmlcleaner</groupId>
<artifactId>htmlcleaner</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>1.4.2</version>
<version>${jibx-version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<version>2.10.0</version>
<version>${xmlunit-assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
<build>
<finalName>xml</finalName>
<resources>
@ -148,33 +146,240 @@
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<configuration>
<directory>src/main/resources</directory>
<includes>
<includes>*-binding.xml</includes>
</includes>
<excludes>
<exclude>template-binding.xml</exclude>
</excludes>
<schemaBindingDirectory>src/main/resources</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*-binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
<execution>
<id>process-test-classes</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>schemaGen</id>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<directory>src/main/resources</directory>
<includes>
<include>Order.xsd</include>
</includes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<directory>target/generated-sources</directory>
<load>true</load>
<validate>true</validate>
<!--<verbose>true</verbose> -->
<verify>true</verify>
</configuration>
</execution>
<execution>
<id>generate-test-code-from-schema</id>
<phase>generate-test-sources</phase>
<goals>
<goal>test-schema-codegen</goal>
</goals>
</execution>
<execution>
<id>compile-test-binding</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
<configuration>
<directory>target/generated-test-sources</directory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>CustomerTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>bindGen</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>${maven-jibx-plugin.version}</version>
<configuration>
<directory>src/main/resources</directory>
<includes>
<includes>*-binding.xml</includes>
</includes>
<excludes>
<exclude>template-binding.xml</exclude>
</excludes>
<schemaBindingDirectory>src/main/resources</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*-binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
<execution>
<id>process-test-classes</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<!-- NOTE: We don't need a groupId specification because the group is org.apache.maven.plugins
...which is assumed by default. -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>
com.baeldung.xml.jibx.JiBXDemoApplication
</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id><!-- this is used for inheritance merges -->
<phase>package</phase><!-- append to the packaging phase. -->
<goals>
<goal>attached</goal><!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<dom4j.version>2.1.1</dom4j.version>
<dom4j.version>2.1.3</dom4j.version>
<jaxen.version>1.2.0</jaxen.version>
<jdom2.version>2.0.6</jdom2.version>
<joox.version>1.6.2</joox.version>
<commons-collections4.version>4.1</commons-collections4.version>
<jibx-version>1.2.4.5</jibx-version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<jaxp-api.version>1.4.2</jaxp-api.version>
<jaxb-core.version>2.3.0.1</jaxb-core.version>
<jaxb-impl.version>4.0.4</jaxb-impl.version>
<jaxb-impl.version>2.3.2</jaxb-impl.version>
<stax-api.version>1.0-2</stax-api.version>
<assertj-core.version>3.12.2</assertj-core.version>
<xmlunit-assertj.version>2.6.3</xmlunit-assertj.version>
<junit-jupiter.version>5.5.0</junit-jupiter.version>
<freemarker.version>2.3.29</freemarker.version>
<mustache.version>0.9.6</mustache.version>
<!-- util -->
<commons-lang.version>2.4</commons-lang.version>
<!-- maven plugins -->
<jakarta.xml.bind-api.version>4.0.2</jakarta.xml.bind-api.version>
<jaxb-runtime.version>4.0.3</jaxb-runtime.version>
<json.version>20240303</json.version>
<underscore.version>1.89</underscore.version>
<xmlbeans.version>5.0.2</xmlbeans.version>
<maven-jibx-plugin.version>1.3.1</maven-jibx-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,120 @@
package com.baeldung.sax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class SaxParserMain {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
BaeldungHandler baeldungHandler = new BaeldungHandler();
saxParser.parse("xml/src/main/resources/sax/baeldung.xml", baeldungHandler);
System.out.println(baeldungHandler.getWebsite());
}
public static class BaeldungHandler extends DefaultHandler {
private static final String ARTICLES = "articles";
private static final String ARTICLE = "article";
private static final String TITLE = "title";
private static final String CONTENT = "content";
private Baeldung website;
private StringBuilder elementValue;
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (elementValue == null) {
elementValue = new StringBuilder();
} else {
elementValue.append(ch, start, length);
}
}
@Override
public void startDocument() throws SAXException {
website = new Baeldung();
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
switch (qName) {
case ARTICLES:
website.setArticleList(new ArrayList<>());
break;
case ARTICLE:
website.getArticleList().add(new BaeldungArticle());
break;
case TITLE:
elementValue = new StringBuilder();
break;
case CONTENT:
elementValue = new StringBuilder();
break;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
switch (qName) {
case TITLE:
latestArticle().setTitle(elementValue.toString());
break;
case CONTENT:
latestArticle().setContent(elementValue.toString());
break;
}
}
private BaeldungArticle latestArticle() {
List<BaeldungArticle> articleList = website.getArticleList();
int latestArticleIndex = articleList.size() - 1;
return articleList.get(latestArticleIndex);
}
public Baeldung getWebsite() {
return website;
}
}
public static class Baeldung {
private List<BaeldungArticle> articleList;
public void setArticleList(List<BaeldungArticle> articleList) {
this.articleList = articleList;
}
public List<BaeldungArticle> getArticleList() {
return this.articleList;
}
}
public static class BaeldungArticle {
private String title;
private String content;
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return this.content;
}
}
}

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.FileInputStream;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.FileWriter;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.util.ArrayList;
@ -8,8 +8,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import com.isharkfly.xml.binding.Tutorial;
import com.isharkfly.xml.binding.Tutorials;
import com.baeldung.xml.binding.Tutorial;
import com.baeldung.xml.binding.Tutorials;
public class JaxbParser {

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.FileInputStream;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.FileNotFoundException;
@ -17,7 +17,7 @@ import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import com.isharkfly.xml.binding.Tutorial;
import com.baeldung.xml.binding.Tutorial;
public class StaxParser {

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml;
package com.baeldung.xml;
import java.io.File;
import java.io.FileWriter;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.attribute;
package com.baeldung.xml.attribute;
import org.dom4j.*;
import org.dom4j.io.DocumentSource;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.attribute;
package com.baeldung.xml.attribute;
import java.io.IOException;
import java.io.StringWriter;

View File

@ -1,4 +1,4 @@
package com.isharkfly.xml.attribute;
package com.baeldung.xml.attribute;
import org.joox.JOOX;
import org.joox.Match;

Some files were not shown because too many files have changed in this diff Show More