Skip to content
Snippets Groups Projects
Commit 557a00ed authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- init

parents
No related branches found
No related tags found
No related merge requests found
Main-Class: org.slub.rosetta.dps.repository.plugin.SLUBTechnicalMetadataExtractorCheckItTiffPlugin
Makefile 0 → 100644
#!/bin/bash
# Andreas Romeyke, SLUB Dresden
# erzeugt Submission-Application, die vorbereitete Verzeichnisse per Java SDK
# von ExLibris an Rosetta übergibt.
# Pfad zu Java 7
JAVAPATH=$(wildcard /usr/lib/jvm/java-1.7.0-openjdk-*/bin/)
# Verwendete Rosetta-Version
ROSETTAVERSION=4.1.0
# Pfad zum Rosetta-SDK
ROSETTASDK=/exlibris/dps/d4_1/system.dir/dps-sdk-${ROSETTAVERSION}/lib/
# Pfad zum Rosetta-SDK, Deposit-Module
ROSETTASDKDEPOSIT=${ROSETTASDK}/../dps-sdk-projects/dps-sdk-deposit/lib
ROSETTASDKPLUGINS=${ROSETTASDK}/../../bundled_plugins/
# classpath
JUNITCLASSPATH=/usr/share/java/junit4.jar
#SOURCESCLASSPATH=org/slub/rosetta/dps/repository/plugin/storage/nfs
CLASSPATH=./java:${ROSETTASDKDEPOSIT}/../src/:${ROSETTASDKDEPOSIT}/xmlbeans-2.3.0.jar:${ROSETTASDKDEPOSIT}/dps-sdk-${ROSETTAVERSION}.jar:${ROSETTASDKDEPOSIT}/log4j-1.2.14.jar:${ROSETTASDKPLUGINS}/NFSStoragePlugin.jar
# sources
SOURCES=java/org/slub/rosetta/dps/repository/plugin/SLUBTechnicalMetadataExtractorCheckItTiffPlugin.java
OBJS=$(SOURCES:.java=.class)
JAR=SLUBTechnicalMetadataExtractorCheckItTiffPlugin.jar
all: $(JAR)
help:
@echo "erzeugt Storage-Plugin für Rosetta von Exlibris"
@echo ""
@echo "Das Argument 'clean' löscht temporäre Dateien, 'help' gibt diese Hilfe aus und"
@echo "'compile' erzeugt ein JAR-File und ein Bash-Script welches das Java-Programm"
@echo "aufruft."
jarclean:
@rm -Rf build
test: $(OBJS)
java -cp ${CLASSPATH}:$(JUNITCLASSPATH) org.junit.runner.JUnitCore
clean: jarclean
@rm -Rf doc/
find ./java/org/ -name "*.class" -exec rm -f \{\} \;
@rm -Rf $(JAR)
distclean: clean
find ./ -name "*~" -exec rm -f \{\} \;
@rm -Rf null
$(JAR): $(OBJS)
@mkdir build;
@cp -r PLUGIN-INF/ build/
@cp -r META-INF/ build/
@cd java; find ./ -name "*.class" -print -exec cp --parents -r \{\} $(PWD)/build \; ; cd ..
@cd build; ${JAVAPATH}/jar cfvM ../$@ ./* ; cd ..
%.class: %.java
${JAVAPATH}/javac -classpath ${CLASSPATH}:${JUNITCLASSPATH} -Xlint:all $<
doc: $(SOURCES)
javadoc -d doc/ $^
check_prerequisites:
@echo -n "### Checking java path: $(JAVAPATH) ...."
@if [ -e $(JAVAPATH) ]; then echo "fine :)"; else echo " not found! :("; fi
@echo -n "### Checking Exlibris Rosetta SDK path: $(ROSETTASDK) ...."
@if [ -e $(ROSETTASDK) ]; then echo "fine :)"; else echo " not found! :("; fi
.PHONY: help clean distclean jarclean test
<pl:metadata-config xmlns:pl="http://www.exlibrisgroup.com/Plugins/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<pl:pluginTypeName>checkit_tiff plugin</pl:pluginTypeName>
<pl:deployName>SLUBTechnicalMetadataExtractorCheckItTiffPlugin</pl:deployName>
<pl:className>org.slub.rosetta.dps.repository.plugin.SLUBTechnicalMetadataExtractorCheckItTiffPlugin</pl:className>
<pl:initParameters>
<fr:x_form xmlns:fr="http://com/exlibris/digitool/common/forms/xmlbeans">
<form_name>SLUBTechnicalMetadataExtractorCheckItTiffPlugin_Params</form_name>
<description>SLUBTechnicalMetadataExtractorCheckItTiffPlugin_parameters_form</description>
<version>0.1</version>
<grid_x>1</grid_x>
<md_format>1</md_format>
<x_fields>
<x_field>
<field_name>checkit_tiff</field_name>
<label>Path to checkit_tiff</label>
<ui_tool_tip>add full path to checkit_tiff</ui_tool_tip>
<mandatory>true</mandatory>
<x_logic_type>String</x_logic_type>
<x_ui_type>TextField</x_ui_type>
<default_value>/usr/bin/checkit_tiff</default_value>
<css_class>width40</css_class>
<x_options></x_options>
</x_field>
<x_field>
<field_name>config_file</field_name>
<label>Path to config file used for checkit_tiff</label>
<ui_tool_tip>add full path to configfile for checkit_tiff</ui_tool_tip>
<mandatory>true</mandatory>
<default_value>/etc/checkit_tiff/slub.cfg</default_value>
<x_logic_type>String</x_logic_type>
<x_ui_type>TextField</x_ui_type>
<css_class>width40</css_class>
<x_options></x_options>
</x_field>
</x_fields>
</fr:x_form>
</pl:initParameters>
<pl:description>SLUB Technical Metadata Extractor Plugin, using check_it_tiff to validate tiff-files</pl:description>
<pl:version>1.4</pl:version>
<pl:materialType>DIGITAL</pl:materialType>
<pl:module>Repository</pl:module>
<pl:generalType>TASK</pl:generalType>
<pl:publicApi>N</pl:publicApi>
<pl:implType>java</pl:implType>
<pl:contactPerson>
<contact_info xmlns="http://www.exlibrisgroup.com/Plugins/1.0/">
<contactType>admin</contactType>
<firstName></firstName>
<lastName>SLUB Dresden</lastName>
<telephone1></telephone1>
<telephone2></telephone2>
<email>rosetta@slub-dresden.de</email>
<address1>Zellescher Weg 17</address1>
<address2></address2>
<city>Dresden</city>
<zipCode>01069</zipCode>
<country>Germany</country>
</contact_info>
</pl:contactPerson>
</pl:metadata-config>
/*
2014 by Andreas Romeyke (SLUB Dresden)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.slub.rosetta.dps.repository.plugin.mdExtractor;
import com.exlibris.dps.sdk.techmd.MDExtractorPlugin;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.exlibris.core.infra.common.exceptions.logging.ExLogger;
import com.exlibris.core.sdk.strings.StringUtils;
import com.exlibris.digitool.common.streams.ScriptUtil;
import com.exlibris.digitool.exceptions.ScriptException;
/**
* SLUBTechnicalMetadataExtractorCheckItTiffPlugin
*
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
* @see com.exlibris.dps.sdk.techmd.MDExtractorPlugin
*/
public class SLUBTechnicalMetadataExtractorCheckItTiffPlugin implements MDExtractorPlugin {
private Status status = Status.FAILED;
private enum Status {PASSED, FAILED};
private String checkit_tiff_binary_path;
private String checkit_tiff_config_path;
private List<String> extractionErrors = new ArrayList<String>();
protected static final ExLogger log = ExLogger.getExLogger(SLUBTechnicalMetadataExtractorCheckItTiffPlugin.class, ExLogger.VALIDATIONSTACK);
/** constructor */
public SLUBTechnicalMetadataExtractorCheckItTiffPlugin() {
//log.info("SLUBVirusCheckPlugin instantiated with host=" + host + " port=" + port + " timeout=" + timeout);
System.out.println("SLUBTechnicalMetadataExtractorCheckItTiffPlugin instantiated");
}
/** init params to configure the plugin via xml forms
* @param initp parameter map
*/
public void initParams(Map<String, String> initp) {
this.checkit_tiff_binary_path = initp.get("checkit_tiff");
this.checkit_tiff_config_path = initp.get("config_file");
System.out.println("SLUBTechnicalMetadataExtractorCheckItTiffPlugin instantiated with checkit_tiff_binary_path=" + checkit_tiff_binary_path + " cfg=" + checkit_tiff_config_path);
}
/** stand alone check, main file to call local installed clamd
* @param args list of files which should be scanned
*/
public static void main(String[] args) {
SLUBTechnicalMetadataExtractorCheckItTiffPlugin plugin = new SLUBTechnicalMetadataExtractorCheckItTiffPlugin();
Map<String, String> initp = new HashMap<String, String>();
initp.put( "checkit_tiff", "/usr/bin/checkit_tiff");
initp.put( "config_file", "/etc/checkit_tiff/slub.cfg");
plugin.initParams( initp );
System.out.println("Agent: " + plugin.getAgent());
for (String file : args) {
plugin.extract(file);
System.out.println("RESULT: " + plugin.isValid + " SIGNATURE: " + plugin.getOutput());
}
}
@Override
public void extract(String filePath) throws Exception {
if(StringUtils.isEmptyString(checkit_tiff_binary_path)) {
log.error("No checkit_tiff_binary_path defined. Please set the plugin parameter to hold your checkit_tiff_binary_path.");
throw new Exception("path not found");
}
if(StringUtils.isEmptyString(checkit_tiff_config_path)) {
log.error("No checkit_tiff_config_path defined. Please set the plugin parameter to hold your checkit_tiff_config_path.");
throw new Exception("path not found");
}
try {
// FIXME:
String result = ""; //runScript(filePath);
if (result != null) {
parser.parse(result);
}
} catch (IOException excep) {
// OK IO error getting process output
System.err.println("checkit_tiff problem for file: " + filePath);
excep.printStackTrace();
throw excep;
}
}
public String getAgentName()
{
return "checkit_tiff";
}
/** get clamd agent version and signature version calling clamd-command VERSION
*
* @return string with clamd version and signature version
*/
public String getAgent() {
try {
Process p = Runtime.getRuntime().exec(this.checkit_tiff_binary_path);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
response+=line;
}
return response.trim();
} catch (IOException e) {
//log.error("exception creation socket, clamd not available at host=" + host + "port=" + port, e);
setStatus(Status.FAILED);
setSignature("ERROR: checkit_tiff not available");
return "ERROR: checkit_tiff not available";
}
}
@Override
public String getAttributeByName(String attribute) {
return (String) parser.getAttribute(attribute);
}
@Override
public List<String> getExtractionErrors() {
return extractionErrors;
}
@Override
public List<String> getSupportedAttributeNames() {
List<String> attributes = new ArrayList<String>();
return attributes;
}
@Override
public boolean isWellFormed() {
return true;
}
@Override
public boolean isValid() {
return parser.getValid();
}
@Override
public String getFormatName() {
return null;
}
@Override
public String getFormatVersion() {
return null;
}
@Override
public Integer getImageCount() {
return 0;
}
@Override
public String getMimeType() {
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment