Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all mistakes in the Item View page #551

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public ResponseEntity getCitationText(@RequestParam(name = "type") String type,
String outputString = updateOutput(type, output.toString());

// Wrap the String output to the class for better parsing in the FE
OaiMetadataWrapper oaiMetadataWrapper = new OaiMetadataWrapper(outputString);
OaiMetadataWrapper oaiMetadataWrapper = new OaiMetadataWrapper(StringUtils.defaultIfEmpty(outputString, ""));
return new ResponseEntity<>(oaiMetadataWrapper, HttpStatus.valueOf(SC_OK));
}

Expand Down Expand Up @@ -348,17 +348,19 @@ private List<ClarinFeaturedServiceLink> mapFeaturedServiceLinks(List<MetadataVal
}

/**
* Remove the unnecessary parts from the output. It is removing the XML header and the <bib:bibtex> tag.
* Remove the unnecessary parts from the output.
*/
private String updateOutput(String type, String output) {
try {
if (StringUtils.equals(type, BIBTEX_TYPE)) {
return removeBibtexTag(output);
// Remove the XML header tag and the <bib:bibtex> tag from the string.
return getXmlTextContent(output);
} else {
// Remove the XML header tag from the string.
return removeXmlHeaderTag(output);
}
} catch (Exception e) {
e.printStackTrace();
log.error("Cannot update the xml string for citation because of: " + e.getMessage());
milanmajchrak marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
}
Expand All @@ -381,9 +383,9 @@ private String removeXmlHeaderTag(String xml) {
}

/**
* Remove the <bib:bibtex> tag from the string.
* Get the text content from the xml string.
*/
private String removeBibtexTag(String xml) throws ParserConfigurationException, IOException, SAXException {
private String getXmlTextContent(String xml) throws ParserConfigurationException, IOException, SAXException {
// Parse the XML string
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Expand All @@ -395,7 +397,6 @@ private String removeBibtexTag(String xml) throws ParserConfigurationException,
// Get the text content of the root element
return root.getTextContent().trim();
}

}

/**
Expand Down
Loading