mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Package name 'gr.ekt.repositories.dspace.utils' removed.
All functions in gr.ekt.repositories.dspace.utils.Utilities.java were transfered in org.dspace.app.util.Util.java Documentation added for the above functions
This commit is contained in:
@@ -1,272 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
||||
package gr.ekt.repositories.dspace.utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.dspace.app.util.DCInput;
|
||||
import org.dspace.app.util.DCInputSet;
|
||||
import org.dspace.app.util.DCInputsReader;
|
||||
import org.dspace.app.util.DCInputsReaderException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.DCValue;
|
||||
import org.dspace.content.Item;
|
||||
import java.util.Locale;
|
||||
import org.dspace.core.I18nUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author iostath
|
||||
*/
|
||||
public class Utilities {
|
||||
|
||||
|
||||
public static List getControlledVocabulariesDisplayValue(Item item, DCValue[] values, String schema, String element, String qualifier) throws SQLException, DCInputsReaderException{
|
||||
|
||||
List toReturn=new ArrayList<String>();
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader();
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
toReturn.add(displayVal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static String getControlledVocabulariesDisplayValueLocalized(Item item, DCValue[] values, String schema, String element, String qualifier, Locale locale) throws SQLException, DCInputsReaderException{
|
||||
|
||||
String toReturn="";
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
String formFileName = I18nUtil.getInputFormsFileName(locale);
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader(formFileName);
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
return displayVal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static List getControlledVocabulariesMultilingualValues(Item item, DCValue[] values, String schema, String element, String qualifier, Locale[] supportedLanguages) throws SQLException, DCInputsReaderException{
|
||||
|
||||
List toReturn=new ArrayList<String>();
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader();
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
|
||||
for (int i=0;i<supportedLanguages.length;i++){
|
||||
Locale locale= (Locale) supportedLanguages[i];
|
||||
toReturn.add(I18nUtil.getMessage(displayVal,locale));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -9,16 +9,23 @@ package org.dspace.app.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.DCValue;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.I18nUtil;
|
||||
|
||||
|
||||
/**
|
||||
@@ -350,4 +357,303 @@ public class Util {
|
||||
}
|
||||
return sourceVersion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all the respective "displayed-value(s)" from the given
|
||||
* "stored-value(s)" for a specific metadata field of a DSpace Item, by reading
|
||||
* input-forms.xml
|
||||
*
|
||||
* @param item
|
||||
* The Dspace Item
|
||||
* @param values
|
||||
* A DCValue[] array of the specific "stored-value(s)"
|
||||
* @param schema
|
||||
* A String with the schema name of the metadata field
|
||||
* @param element
|
||||
* A String with the element name of the metadata field
|
||||
* @param qualifier
|
||||
* A String with the qualifier name of the metadata field
|
||||
* @return A list of the respective "displayed-values"
|
||||
*/
|
||||
public static List getControlledVocabulariesDisplayValue(Item item, DCValue[] values, String schema, String element, String qualifier) throws SQLException, DCInputsReaderException{
|
||||
|
||||
List toReturn=new ArrayList<String>();
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader();
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
toReturn.add(displayVal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the localized respective "displayed-value" from the given
|
||||
* "stored-value" for a specific metadata field of a DSpace Item, by reading
|
||||
* input-forms.xml. In this case the localized input-forms is used, e.g. input-forms_el.xml
|
||||
*
|
||||
* @param item
|
||||
* The Dspace Item
|
||||
* @param values
|
||||
* A DCValue[] array of the specific "stored-value(s)"
|
||||
* @param schema
|
||||
* A String with the schema name of the metadata field
|
||||
* @param element
|
||||
* A String with the element name of the metadata field
|
||||
* @param qualifier
|
||||
* A String with the qualifier name of the metadata field
|
||||
* @param Locale
|
||||
* The given locale
|
||||
* @return A String of the respective "displayed-value"
|
||||
*/
|
||||
|
||||
public static String getControlledVocabulariesDisplayValueLocalized(Item item, DCValue[] values, String schema, String element, String qualifier, Locale locale) throws SQLException, DCInputsReaderException{
|
||||
|
||||
String toReturn="";
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
String formFileName = I18nUtil.getInputFormsFileName(locale);
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader(formFileName);
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
return displayVal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all the localized respective "displayed-value(s)" from the given
|
||||
* "stored-value(s)" for a specific metadata field of a DSpace Item, by reading
|
||||
* input-forms.xml. In this case the displayed-values are given as message keys (message.properties) and
|
||||
* the returned list contains the message values for all repository supported locales
|
||||
*
|
||||
* @param item
|
||||
* The Dspace Item
|
||||
* @param values
|
||||
* A DCValue[] array of the specific "stored-value(s)"
|
||||
* @param schema
|
||||
* A String with the schema name of the metadata field
|
||||
* @param element
|
||||
* A String with the element name of the metadata field
|
||||
* @param qualifier
|
||||
* A String with the qualifier name of the metadata field
|
||||
* @param Locale[]
|
||||
* An array with the repository supported locales
|
||||
* @return A list of the respective "displayed-values"
|
||||
*/
|
||||
|
||||
public static List getControlledVocabulariesMultilingualValues(Item item, DCValue[] values, String schema, String element, String qualifier, Locale[] supportedLanguages) throws SQLException, DCInputsReaderException{
|
||||
|
||||
List toReturn=new ArrayList<String>();
|
||||
DCInput myInputs = null;
|
||||
boolean myInputsFound=false;
|
||||
|
||||
DCInputSet inputSet = null;
|
||||
|
||||
//Read the input form file for the specific collection
|
||||
DCInputsReader inputsReader = null;
|
||||
String col_handle = "";
|
||||
|
||||
Collection collection = item.getOwningCollection();
|
||||
|
||||
if (collection==null)
|
||||
{
|
||||
col_handle = "db-id/" + item.getID();
|
||||
}
|
||||
else {
|
||||
col_handle = collection.getHandle();
|
||||
}
|
||||
if (inputsReader == null) {
|
||||
// read configurable submissions forms data
|
||||
inputsReader = new DCInputsReader();
|
||||
|
||||
}
|
||||
inputSet = inputsReader.getInputs(col_handle);
|
||||
|
||||
|
||||
//Replace the values of DCValue[] with the correct ones in case of controlled vocabularies
|
||||
String currentField = schema+"."+element+(qualifier==null?"":"."+qualifier);
|
||||
|
||||
if (inputSet!=null){
|
||||
|
||||
int pageNums= inputSet.getNumberPages();
|
||||
|
||||
for (int p=0;p<pageNums;p++){
|
||||
|
||||
DCInput[] inputs = inputSet.getPageRows(p, false, false);
|
||||
|
||||
if (inputs!=null){
|
||||
|
||||
for (int i=0; i<inputs.length;i++){
|
||||
String inputField=inputs[i].getSchema()+"."+inputs[i].getElement()+(inputs[i].getQualifier()==null?"":"."+inputs[i].getQualifier());
|
||||
if (currentField.equals(inputField)){
|
||||
|
||||
myInputs = inputs[i];
|
||||
myInputsFound=true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myInputsFound) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myInputsFound) {
|
||||
|
||||
for (int j = 0; j < values.length; j++){
|
||||
|
||||
String pairsName = myInputs.getPairsType();
|
||||
String stored_value = values[j].value;
|
||||
String displayVal = myInputs.getDisplayString(pairsName,stored_value);
|
||||
|
||||
if (displayVal!=null && !"".equals(displayVal)){
|
||||
|
||||
|
||||
for (int i=0;i<supportedLanguages.length;i++){
|
||||
Locale locale= (Locale) supportedLanguages[i];
|
||||
toReturn.add(I18nUtil.getMessage(displayVal,locale));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@@ -1075,7 +1075,7 @@ public class DSIndexer
|
||||
List newValues=new ArrayList<String>();
|
||||
|
||||
//Get the display value of the respective stored value
|
||||
newValues = gr.ekt.repositories.dspace.utils.Utilities.getControlledVocabulariesDisplayValue(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier);
|
||||
newValues = org.dspace.app.util.Util.getControlledVocabulariesDisplayValue(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier);
|
||||
|
||||
if (newValues!=null){
|
||||
for (int m=0;m<newValues.size();m++){
|
||||
@@ -1103,7 +1103,7 @@ public class DSIndexer
|
||||
|
||||
for (int k=0;k<supportedLocales.length;k++){
|
||||
|
||||
displayValue = gr.ekt.repositories.dspace.utils.Utilities.getControlledVocabulariesDisplayValueLocalized(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, supportedLocales[k]);
|
||||
displayValue = org.dspace.app.util.Util.getControlledVocabulariesDisplayValueLocalized(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, supportedLocales[k]);
|
||||
newValues.add(displayValue);
|
||||
}
|
||||
|
||||
@@ -1129,7 +1129,7 @@ public class DSIndexer
|
||||
List newValues=new ArrayList<String>();
|
||||
Locale[] supportedLocales=I18nUtil.getSupportedLocales();
|
||||
//Get the display value of the respective stored value
|
||||
newValues = gr.ekt.repositories.dspace.utils.Utilities.getControlledVocabulariesMultilingualValues(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, supportedLocales);
|
||||
newValues = org.dspace.app.util.Util.getControlledVocabulariesMultilingualValues(item, mydc,indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, supportedLocales);
|
||||
|
||||
if (newValues!=null){
|
||||
for (int m=0;m<newValues.size();m++){
|
||||
|
Reference in New Issue
Block a user