Skip to content

Commit

Permalink
INSPIRE Atom feeds parsing - handle optional elements / attributes an…
Browse files Browse the repository at this point in the history
…d update xslt to extract feed url and dataset id to work with Anchor elements (#5018)

* INSPIRE Atom feeds parsing - handle optional elements / attributes

* INSPIRE Atom feeds - update xslt to extract feed url and dataset id to work with Anchor elements
  • Loading branch information
josegar74 authored Sep 17, 2020
1 parent 3eb68c4 commit 8d681d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions domain/src/main/java/org/fao/geonet/domain/InspireAtomFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,37 @@ public static InspireAtomFeed build(Element atomDoc) {
Namespace nsXml = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace");

inspireAtomFeed.setTitle(atomDoc.getChildText("title", ns));
inspireAtomFeed.setSubtitle(atomDoc.getChildText("subtitle", ns));
inspireAtomFeed.setRights(atomDoc.getChildText("rights", ns));
inspireAtomFeed.setLang(atomDoc.getAttributeValue("lang", ns));

if (atomDoc.getChildText("subtitle", ns) != null) {
inspireAtomFeed.setSubtitle(atomDoc.getChildText("subtitle", ns));
}

if (atomDoc.getChildText("rights", ns) != null) {
inspireAtomFeed.setRights(atomDoc.getChildText("rights", ns));
}

inspireAtomFeed.setLang(atomDoc.getAttributeValue("lang", ns, ""));
Element authorEl = atomDoc.getChild("author", ns);
if (authorEl != null) {
inspireAtomFeed.setAuthorName(atomDoc.getChild("author", ns).getChildText("name", ns));
inspireAtomFeed.setAuthorEmail(atomDoc.getChild("author", ns).getChildText("email", ns));
}
inspireAtomFeed.setLang(atomDoc.getAttributeValue("lang", nsXml));
inspireAtomFeed.setLang(atomDoc.getAttributeValue("lang", nsXml, ""));

List<Element> entryList = atomDoc.getChildren("entry", ns);
for (Element entry : entryList) {
for (Element linkEl : (List<Element>) entry.getChildren("link", ns)) {
if (linkEl.getAttributeValue("rel").equals("alternate")) {
if (linkEl.getAttributeValue("rel", "").equals("alternate")) {
InspireAtomFeedEntry inspireAtomFeedEntry = new InspireAtomFeedEntry();

inspireAtomFeedEntry.setTitle(entry.getChildText("title", ns));
inspireAtomFeedEntry.setCrs(entry.getChild("category", ns).getAttributeValue("term"));

inspireAtomFeedEntry.setType(linkEl.getAttributeValue("type"));
inspireAtomFeedEntry.setLang(linkEl.getAttributeValue("hreflang"));
if (entry.getChildText("category", ns) != null) {
inspireAtomFeedEntry.setCrs(entry.getChild("category", ns).getAttributeValue("term"));
}

inspireAtomFeedEntry.setType(linkEl.getAttributeValue("type", ""));
inspireAtomFeedEntry.setLang(linkEl.getAttributeValue("hreflang", ""));
inspireAtomFeedEntry.setUrl(linkEl.getAttributeValue("href"));

inspireAtomFeed.addEntry(inspireAtomFeedEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- Get first element -->
<atomfeed>
<xsl:value-of
select="gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource[lower-case(gmd:protocol/gco:CharacterString) = lower-case($atomProtocol)]/gmd:linkage/gmd:URL"/>
select="gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource[lower-case(gmd:protocol/*/text()) = lower-case($atomProtocol)]/gmd:linkage/gmd:URL"/>
</atomfeed>

</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<xsl:template match="gmd:MD_Metadata">
<identifier>
<xsl:value-of
select="gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString|gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString"/>
select="gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/*/text()|gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/*/text()"/>
</identifier>
</xsl:template>

Expand Down

0 comments on commit 8d681d0

Please sign in to comment.