Skip to content

Commit

Permalink
Remove some unused code and add more spaces on the log statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
taojing2002 committed May 29, 2019
1 parent 882c62b commit 087c076
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 84 deletions.
Expand Up @@ -65,53 +65,8 @@
*
*/
public abstract class DataCiteMetadataFactory {

public static final String XML_DECLARATION = "<?xml version=\"1.0\"?> ";
public static final String OPEN_RESOURCE = "<resource xmlns=\"http://datacite.org/schema/kernel-3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://datacite.org/schema/kernel-3 https://schema.datacite.org/meta/kernel-3.1/metadata.xsd\">";
public static final String CLOSE_RESOURCE = "</resource>";
public static final String OPEN_IDENTIFIER = "<identifier identifierType=\"DOI\">";
public static final String CLOSE_IDENTIFIER = "</identifier>";
public static final String OPEN_CREATORS = "<creators>";
public static final String CLOSE_CREATORS = "</creators>";
public static final String OPEN_CREATOR = "<creator>";
public static final String CLOSE_CREATOR = "</creator>";
public static final String OPEN_CREATORNAME = "<creatorName>";
public static final String CLOSE_CREATORNAME = "</creatorName>";
public static final String OPEN_NAMEIDENTIFIER = "<nameIdentifier schemeURI=\"http://orcid.org/\" nameIdentifierScheme=\"ORCID\">";
public static final String CLOSE_NAMEIDENTIFIER = "</nameIdentifier>";
public static final String OPEN_AFFILICATION = "<affiliation>";
public static final String CLOSE_AFFILICATION = "/affiliation>";
public static final String OPEN_TITLES = "<titles>";
public static final String CLOSE_TITLES = "</titles>";
public static final String OPEN_TITLE_WITHLONG_ATTR = "<title xml:lang=\"";
public static final String CLOSE_TITLE= "</title>";
public static final String OPEN_PUBLISHER = "<publisher>";
public static final String CLOSE_PUBLISHER = "</publisher>";
public static final String OPEN_PUBLISHYEAR = "<publicationYear>";
public static final String CLOSE_PUBLISHYEAR = "</publicationYear>";
public static final String OPEN_SUBJECTS = "<subjects>";
public static final String CLOSE_SUBJECTS = "</subjects>";
public static final String OPEN_SUBJECT_WITHLONGATT = "<subject xml:lang=\"";
public static final String CLOSE_SUBJECT = "</subject>";
public static final String OPEN_LANGUAGE = "<language>";
public static final String CLOSE_LANGUAGE = "</language>";
public static final String OPEN_RESOURCETYPE_WITHTYPEGENERALATT = "<resourceType resourceTypeGeneral=\"";
public static final String CLOSE_RESROUCETYPE = "</resourceType>";
public static final String OPEN_FORMATS = "<formats>";
public static final String CLOSE_FORMATS = "</formats>";
public static final String OPEN_FORMAT = "<format>";
public static final String CLOSE_FORMAT = "</format>";
public static final String OPEN_VERSION = "<version>";
public static final String CLOSE_VERSION = "</version>";
public static final String OPEN_DESCRIPTIONS = "<descriptions>";
public static final String CLOSE_DESCRIPTIONS = "</descriptions>";
public static final String OPEN_DESCRITPION_WITHLANGATT = "<description descriptionType=\"Abstract\" xml:lang=\"";
public static final String CLOSE_DESCRIPTION = "</description>";

public static final String CLOSE_ATT="\">";
public static final String EN = "en";
public static final String XML_LANG= "xml:lang";

public static final String NAMESPACE = "http://datacite.org/schema/kernel-3";
public static final String SCHEMALOCATION = "https://schema.datacite.org/meta/kernel-3.1/metadata.xsd";
public static final String RESOURCE = "resource";
Expand Down Expand Up @@ -162,7 +117,7 @@ protected Document generateROOTDoc() throws Exception {
Document doc = builder.newDocument();
Element root = doc.createElementNS(NAMESPACE, RESOURCE);
root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation", NAMESPACE + " "+SCHEMALOCATION);
"xsi:schemaLocation", NAMESPACE + " " + SCHEMALOCATION);
doc.appendChild(root);
return doc;
}
Expand All @@ -180,7 +135,7 @@ protected Document addIdentifier(Document doc, String identifier, String scheme)
}
if(scheme == null || !scheme.equals(DOI)) {
//now it only supports doi.
throw new InvalidRequest(INVALIDCODE, "The scheme of the identifier element only can be "+DOI+ " and the specified one "+scheme +" is not allowed.");
throw new InvalidRequest(INVALIDCODE, "The scheme of the identifier element only can be " + DOI + " and the specified one " + scheme + " is not allowed.");
}
Element identifierEle = doc.createElement("identifier");
identifierEle.setAttribute("identifierType", scheme);
Expand Down Expand Up @@ -259,7 +214,7 @@ public Document appendTitle (String title, Document doc, String language) throws
titleEle.setAttribute(XML_LANG, code);
titleEle.appendChild(doc.createTextNode(title));

String path = "//"+TITLES;
String path = "//" + TITLES;
XPathExpression expr = xpath.compile(path);
NodeList titlesList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
if(titlesList == null ||titlesList.getLength() == 0) {
Expand Down Expand Up @@ -325,7 +280,7 @@ protected Document appendSubject(String subject, Document doc, String language)
subjectEle.setAttribute(XML_LANG, code);
subjectEle.appendChild(doc.createTextNode(subject));

String path = "//"+SUBJECTS;
String path = "//" + SUBJECTS;
XPathExpression expr = xpath.compile(path);
NodeList subjectsList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
if(subjectsList == null ||subjectsList.getLength() == 0) {
Expand Down Expand Up @@ -397,7 +352,7 @@ protected Document appendFormat(Document doc, String format) throws XPathExpress
if(format != null && !format.trim().equals("")) {
Element formatEle = doc.createElement("format");
formatEle.appendChild(doc.createTextNode(format));
String path = "//"+FORMATS;
String path = "//" + FORMATS;
XPathExpression expr = xpath.compile(path);
NodeList formatsList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
if(formatsList == null || formatsList.getLength() == 0) {
Expand Down Expand Up @@ -454,7 +409,7 @@ protected Document appendDescription(String description, Document doc, String la
descriptionEle.setAttribute("descriptionType", descriptionType);
descriptionEle.appendChild(doc.createTextNode(description));

String path = "//"+DESCRIPTIONS;
String path = "//" + DESCRIPTIONS;
XPathExpression expr = xpath.compile(path);
NodeList descriptionsList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
if(descriptionsList == null || descriptionsList.getLength() == 0) {
Expand Down Expand Up @@ -502,25 +457,6 @@ static String getISOLanguageCode(String language) {
return EN;
}


/**
* Figure out the resource type of the data object
* @param sysMeta
* @return
*/
public static String lookupResourceType(SystemMetadata sysMeta) {
String resourceType = DataCiteProfileResourceTypeValues.DATASET.toString();
try {
ObjectFormat objectFormat = D1Client.getCN().getFormat(sysMeta.getFormatId());
resourceType = objectFormat.getFormatType().toLowerCase();
} catch (Exception e) {
// ignore
logMetacat.warn("Could not lookup resource type for formatId" + e.getMessage());
}

return resourceType;
}

/**
* Figure out the format (mime type) of the data object
* @param sysMeta
Expand All @@ -546,9 +482,9 @@ public static String lookupFormat(SystemMetadata sysMeta) {
*/
protected String removeIdSchemePrefix(String id, String scheme) {
if(id.startsWith(scheme.toLowerCase())) {
id = id.replaceFirst(scheme.toLowerCase()+":", "");
id = id.replaceFirst(scheme.toLowerCase() + ":", "");
} else if (id.startsWith(scheme)) {
id = id.replaceFirst(scheme+":", "");
id = id.replaceFirst(scheme + ":", "");
}
return id;
}
Expand Down
Expand Up @@ -24,51 +24,51 @@ public void initialize() {
public void testGetISOLanguageCode() {
String language = "English";
String code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("en"));
language = null;
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("en"));
language = "unknown";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("en"));
language = "French";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("fr"));
language = "Chinese";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("zh"));
language = "spanish";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("es"));
language = "es";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("es"));
language = "spa";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("es"));
language = "en";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("en"));
language = "German";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("de"));
language = "de";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("de"));
language = "deu";
code = DataCiteMetadataFactory.getISOLanguageCode(language);
System.out.println("the code for "+language+" is "+code);
System.out.println("the code for " + language + " is " + code);
assertTrue(code.equals("de"));
}

Expand Down

0 comments on commit 087c076

Please sign in to comment.