-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (core): Introduce XmlThingConverter
- Loading branch information
Showing
38 changed files
with
660 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2024 The Enola <https://enola.dev> Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.enola.common.xml; | ||
|
||
import com.google.common.net.MediaType; | ||
|
||
import dev.enola.common.convert.CatchingConverterInto; | ||
import dev.enola.common.io.mediatype.MediaTypes; | ||
import dev.enola.common.io.resource.ReadableResource; | ||
|
||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
import javax.xml.parsers.SAXParser; | ||
import javax.xml.parsers.SAXParserFactory; | ||
|
||
public class XmlResourceParser implements CatchingConverterInto<ReadableResource, DefaultHandler> { | ||
|
||
@Override | ||
public boolean convertIntoThrows(ReadableResource from, DefaultHandler into) throws Exception { | ||
if (!MediaTypes.normalizedNoParamsEquals(from.mediaType(), MediaType.XML_UTF_8)) | ||
return false; | ||
|
||
if (from.byteSource().isEmpty()) return true; | ||
|
||
SAXParserFactory factory = SAXParserFactory.newInstance(); | ||
factory.setNamespaceAware(true); | ||
factory.setXIncludeAware(false); | ||
factory.setValidating(false); | ||
SAXParser saxParser = factory.newSAXParser(); | ||
|
||
try (var is = from.byteSource().openStream()) { | ||
saxParser.parse(is, into); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Copyright 2023 The Enola <https://enola.dev> Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@rules_java//java:defs.bzl", "java_library") | ||
load("//tools/bazel:junit.bzl", "junit_tests") | ||
|
||
java_library( | ||
name = "xml", | ||
srcs = glob( | ||
["*.java"], | ||
exclude = [ | ||
"*Test.java", | ||
"Test*.java", | ||
], | ||
), | ||
plugins = ["//tools/bazel/java_plugin:autoservice"], | ||
resource_strip_prefix = "java/", | ||
resources = glob(["**/*.html"]), | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//java/dev/enola/common/context", | ||
"//java/dev/enola/common/convert", | ||
"//java/dev/enola/common/io", | ||
"//java/dev/enola/common/xml", | ||
"//java/dev/enola/thing:thing_java", | ||
"@maven//:com_google_auto_service_auto_service_annotations", | ||
"@maven//:com_google_errorprone_error_prone_annotations", | ||
"@maven//:com_google_errorprone_error_prone_type_annotations", | ||
"@maven//:com_google_guava_guava", | ||
"@maven//:org_jspecify_jspecify", | ||
"@maven//:org_slf4j_slf4j_api", | ||
], | ||
) | ||
|
||
junit_tests( | ||
name = "tests", | ||
srcs = glob([ | ||
"*Test.java", | ||
]), | ||
deps = [ | ||
":xml", | ||
"//java/dev/enola/common/context", | ||
"//java/dev/enola/common/io", | ||
"//java/dev/enola/thing:thing_java", | ||
"//java/dev/enola/thing/testlib", | ||
"//test", | ||
], | ||
) |
Oops, something went wrong.