forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/java/org/jabref/model/schema/DublinCoreSchemaCustom.java
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,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)); | ||
} | ||
} | ||
} |