
java.fedora.server.test.TranslatorTest Maven / Gradle / Ivy
Show all versions of fcrepo-client Show documentation
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to 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.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server.test;
import fedora.common.Constants;
import fedora.server.storage.types.*;
import fedora.server.storage.translation.*;
import fedora.server.*;
import java.io.*;
/**
*
* Title: Translator.java
* Description: Tests the configured DOTranslator instance,
* deserializing, then re-serializing and printing the bytes from the file
* whose name is passed in.
*
* Since DOTranslator is a Module, it's more appropriate to test it
* by starting up the configured server instance.
*
* @author [email protected]
* @version $Id: TranslatorTest.java 5313 2006-12-06 12:14:27Z cwilper $
*/
public class TranslatorTest {
public static void main(String args[]) {
FileInputStream in=null;
try {
if (args.length!=3) {
throw new IOException("*Three* parameters needed, filename, format, and encoding.");
}
if (Constants.FEDORA_HOME == null) {
throw new IOException("FEDORA_HOME is not set. Try using -Dfedora.home=path/to/fedorahome");
}
in=new FileInputStream(new File(args[0]));
Server server;
server=Server.getInstance(new File(Constants.FEDORA_HOME));
DOTranslator trans=(DOTranslator) server.getModule("fedora.server.storage.translation.DOTranslator");
if (trans==null) {
throw new IOException("DOTranslator module not found via getModule");
}
DigitalObject obj=new BasicDigitalObject();
System.out.println("Deserializing...");
trans.deserialize(in, obj, args[1], args[2], DOTranslationUtility.DESERIALIZE_INSTANCE);
System.out.println("Done.");
ByteArrayOutputStream outStream=new ByteArrayOutputStream();
System.out.println("Re-serializing...");
trans.serialize(obj, outStream, args[1], args[2], DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL);
System.out.println("Done. Here it is:");
System.out.println(outStream.toString(args[2]));
server.shutdown(null); //fixup for xacml
} catch (Exception e) {
System.out.println("Error: " + e.getClass().getName() + " " + e.getMessage() + "\n");
e.printStackTrace();
}
}
}