Skip to content

Commit

Permalink
JabRef#8491 : Add Forgotten File
Browse files Browse the repository at this point in the history
  • Loading branch information
addak committed Feb 26, 2022
1 parent bd0d436 commit 1aa0870
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/main/java/org/jabref/model/schema/DublinCoreSchemaCustom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.jabref.model.schema;

import com.fasterxml.jackson.databind.util.BeanUtil;
import com.microsoft.applicationinsights.internal.config.ReflectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.XmpConstants;
import org.apache.xmpbox.schema.DublinCoreSchema;
import org.apache.xmpbox.type.*;
import org.jabref.logic.xmp.XmpUtilReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.XMLConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@StructuredType(preferedPrefix = "dc", namespace = "http://purl.org/dc/elements/1.1/")
public class DublinCoreSchemaCustom extends DublinCoreSchema {

private static final Logger LOGGER = LoggerFactory.getLogger(DublinCoreSchemaCustom.class);

public DublinCoreSchemaCustom(XMPMetadata metadata)
{
super(metadata);
}

public static DublinCoreSchemaCustom copyDublinCoreSchema(DublinCoreSchema dcSchema){

if( Objects.isNull(dcSchema) )
return null;

DublinCoreSchemaCustom dublinCoreSchemaCustom = new DublinCoreSchemaCustom(dcSchema.getMetadata());

try{
FieldUtils.writeField(dublinCoreSchemaCustom, "container", dcSchema.getContainer(), true);
FieldUtils.writeField(dublinCoreSchemaCustom, "attributes", FieldUtils.readField(dcSchema, "attributes", true), true);
System.out.println("lol");
} catch (Exception e){
LOGGER.error("Error making custom DC Schema\n {}", ExceptionUtils.getStackTrace(e));
}

return dublinCoreSchemaCustom;
}

public String getDateAttributeFormatQualifier(){
AbstractField abstractProperty = getAbstractProperty("date");

if(abstractProperty instanceof ArrayProperty){
return ((ArrayProperty) abstractProperty)
.getContainer()
.getAllProperties()
.get(0).getAttribute("format").getValue();
}

return null;
}

public void setDateAttributeFormatQualifier(String value){
AbstractField abstractProperty = getAbstractProperty("date");

if(abstractProperty instanceof ArrayProperty){
var properties = ((ArrayProperty) abstractProperty)
.getContainer()
.getAllProperties();
properties.get(properties.size()-1).setAttribute(new Attribute(XMLConstants.XML_NS_URI, "format", value));
}
}
}

0 comments on commit 1aa0870

Please sign in to comment.