Commits

Sam Adams committed 566ca29

Removed client utils

Comments (0)

Files changed (76)

client-cli/pom.xml

-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-    <parent>
-        <groupId>net.chempound.client</groupId>
-        <artifactId>client</artifactId>
-        <version>0.1-SNAPSHOT</version>
-    </parent>
-
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>client-cli</artifactId>
-
-    <name>Chempound Client CLI</name>
-
-    <dependencies>
-
-        <dependency>
-            <groupId>net.chempound.client</groupId>
-            <artifactId>client-utils</artifactId>
-            <version>0.1-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-            <version>[1.6.1]</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.beust</groupId>
-            <artifactId>jcommander</artifactId>
-            <version>1.20</version>
-        </dependency>
-
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>net.chempound</groupId>
-            <artifactId>chempound-webapp</artifactId>
-            <version>0.1-SNAPSHOT</version>
-            <scope>test</scope>
-        </dependency>
-
-    </dependencies>
-
-    <build>
-
-        <plugins>
-
-            <plugin>
-                <artifactId>maven-assembly-plugin</artifactId>
-                <configuration>
-                    <descriptors>
-                        <descriptor>src/main/assembly/bin-dist.xml</descriptor>
-                    </descriptors>
-                    <appendAssemblyId>false</appendAssemblyId>
-                    <attach>false</attach>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>single</goal>
-                        </goals>
-                        <phase>package</phase>
-                    </execution>
-                </executions>
-            </plugin>
-
-        </plugins>
-    </build>
-
-</project>

client-cli/src/checkstyle/suppressions.xml

-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE suppressions PUBLIC
-        "-//Puppy Crawl//DTD Suppressions 1.1//EN"
-        "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
-<suppressions>
-    <suppress files="src/main/.*\.java$" id="sysout"/>
-    <suppress files="src/main/.*\.java$" checks="VisibilityModifier" />
-
-    <suppress files="src/main/java/net/chempound/client/cli/ChempoundClientCLI\.java" id="sysexit"/>
-</suppressions>

client-cli/src/main/assembly/bin-dist.xml

-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
-
-    <id>bin-dist</id>
-
-    <formats>
-        <format>tar.gz</format>
-        <format>zip</format>
-    </formats>
-
-    <baseDirectory>chempound-client-${project.version}</baseDirectory>
-
-    <fileSets>
-
-        <fileSet>
-            <includes>
-                <include>README*</include>
-                <include>LICENSE*</include>
-                <include>NOTICE*</include>
-            </includes>
-        </fileSet>
-
-        <fileSet>
-            <directory>src/main/bin</directory>
-            <includes>
-                <include>chempound.bat</include>
-            </includes>
-            <outputDirectory>bin</outputDirectory>
-            <filtered>true</filtered>
-            <lineEnding>dos</lineEnding>
-        </fileSet>
-
-        <fileSet>
-            <directory>src/main/bin</directory>
-            <includes>
-                <include>chempound.sh</include>
-            </includes>
-            <outputDirectory>bin</outputDirectory>
-            <filtered>true</filtered>
-            <lineEnding>unix</lineEnding>
-            <fileMode>0755</fileMode>
-        </fileSet>
-
-        <fileSet>
-            <directory>src/main/conf</directory>
-            <outputDirectory>conf</outputDirectory>
-        </fileSet>
-
-    </fileSets>
-
-    <dependencySets>
-        <dependencySet>
-            <useProjectArtifact>true</useProjectArtifact>
-            <outputDirectory>lib</outputDirectory>
-        </dependencySet>
-    </dependencySets>
-
-</assembly>

client-cli/src/main/bin/chempound.bat

-@REM Chempound Client CLI Start-up File
-@REM Copyright (c) Sam Adams 2011
-@REM Inspired by Apache Maven Project
-
-@REM Required ENV vars:
-@REM JAVA_HOME - location of a JDK home dir
-
-@echo off
-@setLocal
-
-set ERROR_CODE=0
-
-@REM ==== CHECK JAVA_HOME ====
-if not "%JAVA_HOME%" == "" goto OkJHome
-echo.
-echo ERROR: JAVA_HOME not found in your environment.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation
-echo.
-goto error
-
-:OkJHome
-@REM ==== CHECK java.exe ====
-if exist "%JAVA_HOME%\bin\java.exe" goto OkJavaExe
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory.
-echo JAVA_HOME = "%JAVA_HOME%"
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation
-echo.
-goto error
-
-:OkJavaExe
-if not "%CPCLIENT_HOME%" == "" goto StripCpClientHome
-@REM ==== Find Chempound Client installation ====
-set "CPCLIENT_HOME=%~dp0.."
-goto CheckCpClinetHome
-
-:StripCpClientHome
-@REM ==== Strip trailing slash ====
-if not "_%CPCLIENT_HOME:~-1%"=="_\" goto CheckCpClientHome
-set "CPCLIENT_HOME=%CPCLIENT_HOME:~0,-1%"
-goto StripLCpClientHome
-
-
-:CheckCpClientHome
-@REM ==== CHECK CPCLIENT_HOME ====
-if exist "%CPCLIENT_HOME%\bin\chempound.bat" goto CheckCpClientOpts
-echo.
-echo ERROR: CPCLIENT_HOME is set to an invalid directory.
-echo CPCLIENT_HOME = "%CPCLIENT_HOME%"
-echo Please set the CPCLIENT_HOME variable in your environment to match the
-echo location of the Chempound Client installation
-echo.
-goto error
-
-
-:CheckCpClientOpts
-if not "%CPCLIENT_OPTS%" == "" goto init
-set "CPCLIENT_OPTS=-Xmx128m"
-
-:init
-"%JAVA_HOME%/bin/java" %CPCLIENT_OPTS% -classpath "%CPCLIENT_HOME%\lib\*" -Dcpclient.home="%CPCLIENT_HOME%" net.chempound.client.cli.ChempoundClientCLI %*
-
-if ERRORLEVEL 1 goto error
-goto exit
-
-
-:error
-SET ERROR_CODE=1
-goto exit
-
-:exit
-@endlocal
-cmd /C exit /B %ERROR_CODE%

client-cli/src/main/bin/chempound.sh

-#!/bin/sh
-# Chempound Client CLI Start-up File
-# Copyright (c) Sam Adams 2011
-# Inspired by Apache Maven Project
-
-# Required ENV vars:
-# JAVA_HOME - location of a JDK home dir
-
-if [ -z "$JAVA_HOME" ] ; then
-  echo "Warning: JAVA_HOME environment variable is not set."
-fi
-
-
-if [ -z "$CPCLIENT_HOME" ] ; then
-  ## resolve links - $0 may be a link to Chempound Client's home
-  PRG="$0"
-
-  # need this for relative symlinks
-  while [ -h "$PRG" ] ; do
-    ls=`ls -ld "$PRG"`
-    link=`expr "$ls" : '.*-> \(.*\)$'`
-    if expr "$link" : '/.*' > /dev/null; then
-      PRG="$link"
-    else
-      PRG="`dirname "$PRG"`/$link"
-    fi
-  done
-
-  saveddir=`pwd`
-
-  CPCLIENT_HOME=`dirname "$PRG"`/..
-
-  # make it fully qualified
-  CPCLIENT_HOME=`cd "$CPCLIENT_HOME" && pwd`
-
-  cd "$saveddir"
-fi
-
-exec "$JAVA_HOME/bin/java" \
-  $CPCLIENT_OPTS \
-  -classpath "$CPCLIENT_HOME/lib/*" \
-  -Dcpclient.home="$CPCLIENT_HOME" \
-  net.chempound.client.cli.ChempoundClientCLI $*

client-cli/src/main/java/net/chempound/client/cli/ChempoundClientCLI.java

-package net.chempound.client.cli;
-
-import com.beust.jcommander.JCommander;
-import com.beust.jcommander.ParameterException;
-import net.chempound.client.cli.command.Command;
-import net.chempound.client.cli.command.CreateCollectionCommand;
-import net.chempound.client.cli.command.DepositCommand;
-import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.client.cli.types.URIConverter;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class ChempoundClientCLI {
-
-    private static final String CHEMPOUND = "chempound";
-        
-    private static final String C_DEPOSIT = "deposit";
-    private static final String C_CREATE_COLLECTION = "create-collection";
-    private static final String C_COPY = "copy";
-    private static final String C_DELETE = "delete";
-    private static final String C_EXPORT = "export";
-    private static final String C_HELP = "help";
-    private static final String C_MOVE = "move";
-
-    private final Map<String,Command> commands = new LinkedHashMap<String, Command>();
-
-    protected final GlobalOptions globalOptions = new GlobalOptions();
-
-    protected final JCommander jCommander;
-
-    public static void main(final String[] args) {
-        final ChempoundClientCLI depositCli = new ChempoundClientCLI();
-        depositCli.runMain(args);
-    }
-
-    public ChempoundClientCLI() {
-        jCommander = initialiseCommandLineParser();
-    }
-
-    public void runMain(final String... args) {
-
-        try {
-            jCommander.parse(args);
-        } catch (ParameterException e) {
-            exitWithError(e);
-        }
-
-        if (globalOptions.version) {
-            displayVersionAndExit();
-        }
-
-        else if (jCommander.getParsedCommand() == null) {
-            displayUsageAndExit();
-        }
-        else {
-            final Command command = commands.get(jCommander.getParsedAlias());
-            if (command != null) {
-                invokeCommand(command);
-            } else {
-                throw new UnsupportedOperationException("Unsupported command: " + jCommander.getParsedCommand());
-            }
-        }
-    }
-
-    protected void invokeCommand(final Command command) {
-        command.invoke(globalOptions);
-    }
-
-    protected void exitWithError(final ParameterException e) {
-        System.err.println(e.getMessage());
-        jCommander.usage();
-        exit(1);
-    }
-
-    protected void displayUsageAndExit() {
-        basicUsage();
-        exit(1);
-    }
-
-    protected void displayVersionAndExit() {
-        exit(0);
-    }
-
-    protected void exit(final int returnStatus) {
-        System.exit(returnStatus);
-    }
-
-    private JCommander initialiseCommandLineParser() {
-        final JCommander jCommander = new JCommander(globalOptions);
-        jCommander.addConverterFactory(new URIConverter.Factory());
-
-        jCommander.setProgramName(CHEMPOUND);
-
-        installCommands(jCommander);
-
-        return jCommander;
-    }
-
-    protected void installCommands(final JCommander jCommander) {
-//        addCommand(jCommander, C_COPY, new CopyCommand());
-        addCommand(jCommander, C_CREATE_COLLECTION, new CreateCollectionCommand());
-//        addCommand(jCommander, C_DELETE, new DeleteCommand());
-        addCommand(jCommander, C_DEPOSIT, new DepositCommand());
-//        addCommand(jCommander, C_EXPORT, new ExportCommand());
-//        addCommand(jCommander, C_HELP, new HelpCommand());
-//        addCommand(jCommander, C_MOVE, new MoveCommand());
-    }
-
-    protected void addCommand(final JCommander jCommander, final String alias, final Command<?> command) {
-        commands.put(alias, command);
-        jCommander.addCommand(alias, command.getOptions());
-    }
-
-    protected void basicUsage() {
-        System.out.println("Chempound Client CLI");
-        System.out.println();
-//        System.out.println("basic commands:");
-//        System.out.println();
-
-        final int maxLen = getMaxCommandLength();
-        for (final String command : jCommander.getCommands().keySet()) {
-            System.out.printf(" %-" + maxLen + "s   %s%n", command, jCommander.getCommandDescription(command));
-        }
-
-        System.out.println();
-//        System.out.println("use \"chempound help\" for the full list of commands");
-    }
-
-    private int getMaxCommandLength() {
-        int max = -1;
-        for (String command : commands.keySet()) {
-            max = Math.max(max, command.length());
-        }
-        return max;
-    }
-
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/Command.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public interface Command<T> {
-
-    void invoke(GlobalOptions globalOptions);
-
-    T getOptions();
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/CopyCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.CopyOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public class CopyCommand implements Command<CopyOptions> {
-
-    private final CopyOptions options = new CopyOptions();
-
-    @Override
-    public CopyOptions getOptions() {
-        return options;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        throw new UnsupportedOperationException();
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/CreateCollectionCommand.java

-package net.chempound.client.cli.command;
-
-import com.hp.hpl.jena.vocabulary.RDF;
-import net.chempound.client.SwordClient;
-import net.chempound.client.cli.options.CreateCollectionOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.content.DefaultDepositRequest;
-import net.chempound.content.DepositRequest;
-import net.chempound.rdf.CPTerms;
-
-import java.net.URI;
-
-/**
- * @author Sam Adams
- */
-public class CreateCollectionCommand implements Command<CreateCollectionOptions> {
-
-    private final CreateCollectionOptions options = new CreateCollectionOptions();
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        final SwordClient swordClient = new SwordClient();
-        final DepositRequest depositRequest = new DefaultDepositRequest();
-        if (options.args.isEmpty()) {
-            throw new RuntimeException("Title must be specified");
-        }
-        final String title = options.args.get(0);
-        depositRequest.setTitle(title);
-        if (options.slug == null) {
-            depositRequest.setSlug(title);
-        } else {
-            depositRequest.setSlug(options.slug);
-        }
-        depositRequest.getMetadataModel().getResource("").addProperty(RDF.type, CPTerms.Collection);
-
-        final URI uri = URI.create(globalOptions.repository);
-
-        try {
-            swordClient.deposit(uri, depositRequest);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Override
-    public CreateCollectionOptions getOptions() {
-        return options;
-    }
-}

client-cli/src/main/java/net/chempound/client/cli/command/DeleteCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.DeleteOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public class DeleteCommand implements Command<DeleteOptions> {
-
-    private final DeleteOptions options = new DeleteOptions();
-
-    @Override
-    public DeleteOptions getOptions() {
-        return options;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        throw new UnsupportedOperationException();
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/DepositCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.DepositBuilder;
-import net.chempound.client.SwordClient;
-import net.chempound.client.cli.options.DepositOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.client.sword.DepositReceipt;
-import net.chempound.storage.LocalFileResource;
-import net.chempound.storage.LocalResource;
-import org.apache.commons.io.FilenameUtils;
-
-import java.io.File;
-import java.net.URI;
-
-/**
- * @author Sam Adams
- */
-public class DepositCommand implements Command<DepositOptions> {
-
-    protected final DepositOptions depositOptions;
-    protected final SwordClient swordClient;
-
-    public DepositCommand() {
-        this(new DepositOptions());
-    }
-
-    protected DepositCommand(final DepositOptions depositOptions) {
-        this(depositOptions, new SwordClient());
-    }
-
-    protected DepositCommand(final DepositOptions depositOptions, final SwordClient swordClient) {
-        this.depositOptions = depositOptions;
-        this.swordClient = swordClient;
-    }
-
-    @Override
-    public DepositOptions getOptions() {
-        return depositOptions;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-
-        final DepositBuilder depositBuilder = new DepositBuilder();
-
-        attachFiles(globalOptions, depositBuilder);
-        setTitle(depositBuilder);
-        setSlug(depositBuilder);
-
-        final String url = globalOptions.repository;
-        try {
-            final DepositReceipt depositReceipt = swordClient.deposit(URI.create(url), depositBuilder.buildDepositRequest());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-    }
-
-    protected void setTitle(final DepositBuilder depositBuilder) {
-        if (depositOptions.title != null) {
-            depositBuilder.setTitle(depositOptions.title);
-        }
-    }
-
-    protected void setSlug(final DepositBuilder depositBuilder) {
-        if (depositOptions.slug != null) {
-            depositBuilder.setSlug(depositOptions.slug);
-        }
-    }
-
-    protected void attachFiles(final GlobalOptions globalOptions, final DepositBuilder depositBuilder) {
-        if (depositOptions.files != null) {
-            for (final String filename : depositOptions.files) {
-                final File file = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
-                final String depositFilename = FilenameUtils.getName(filename);
-                final LocalResource resource = new LocalFileResource(depositFilename, file);
-                depositBuilder.addResource(resource);
-            }
-        }
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/ExportCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.ExportOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public class ExportCommand implements Command<ExportOptions> {
-
-    private final ExportOptions options = new ExportOptions();
-
-    @Override
-    public ExportOptions getOptions() {
-        return options;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        throw new UnsupportedOperationException();
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/HelpCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.HelpOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public class HelpCommand implements Command<HelpOptions> {
-
-    private final HelpOptions options = new HelpOptions();
-
-    @Override
-    public HelpOptions getOptions() {
-        return options;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        throw new UnsupportedOperationException();
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/command/MoveCommand.java

-package net.chempound.client.cli.command;
-
-import net.chempound.client.cli.options.MoveOptions;
-import net.chempound.client.cli.options.GlobalOptions;
-
-/**
- * @author Sam Adams
- */
-public class MoveCommand implements Command<MoveOptions> {
-
-    private final MoveOptions options = new MoveOptions();
-
-    @Override
-    public MoveOptions getOptions() {
-        return options;
-    }
-
-    @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        throw new UnsupportedOperationException();
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/CopyOptions.java

-package net.chempound.client.cli.options;
-
-import com.beust.jcommander.Parameter;
-
-/**
- * @author Sam Adams
- */
-public class CopyOptions {
-
-    @Parameter(names = { "-s", "--source" }, required = true)
-    public String source;
-
-    @Parameter(names = { "-t", "--target" }, required = true)
-    public String target;
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/CreateCollectionOptions.java

-package net.chempound.client.cli.options;
-
-import com.beust.jcommander.Parameter;
-
-import java.util.List;
-
-/**
- * @author Sam Adams
- */
-public class CreateCollectionOptions {
-
-    @Parameter(names = { "-s", "--slug" })
-    public String slug;
-
-    @Parameter(names = { "-d", "--description" })
-    public String description;
-
-    @Parameter(names = { "-a", "--accepts" })
-    public List<String> accepts;
-
-    @Parameter(description = "The title", arity = 1)
-    public List<String> args;
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/DeleteOptions.java

-package net.chempound.client.cli.options;
-
-/**
- * @author Sam Adams
- */
-public class DeleteOptions {
-}

client-cli/src/main/java/net/chempound/client/cli/options/DepositOptions.java

-package net.chempound.client.cli.options;
-
-import com.beust.jcommander.Parameter;
-
-import java.util.List;
-
-public class DepositOptions {
-
-    @Parameter(names = { "-s", "--slug" })
-    public String slug;
-
-    @Parameter(names = { "-t", "--title" }, description = "Title")
-    public String title;
-
-    @Parameter(description = "The list of files")
-    public List<String> files;
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/ExportOptions.java

-package net.chempound.client.cli.options;
-
-/**
- * @author Sam Adams
- */
-public class ExportOptions {
-}

client-cli/src/main/java/net/chempound/client/cli/options/GlobalOptions.java

-package net.chempound.client.cli.options;
-
-import com.beust.jcommander.Parameter;
-
-import java.io.File;
-
-public class GlobalOptions {
-
-    @Parameter(names = { "-q", "--quiet" }, description = "enable additional output")
-    public boolean quiet;
-
-    @Parameter(names = { "-v", "--verbose" }, description = "enable additional output")
-    public boolean verbose;
-
-    @Parameter(names = { "--version" }, description = "output version information and exit")
-    public boolean version;
-
-    @Parameter(names = { "-h", "--help" }, description = "display help and exit")
-    public boolean help;
-
-    @Parameter(names = { "-R", "--repository" }, description = "target repository")
-    public String repository;
-
-    @Parameter(names = { "--cwd" }, description = "change working directory")
-    public File workingDirectory;
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/HelpOptions.java

-package net.chempound.client.cli.options;
-
-import com.beust.jcommander.Parameter;
-
-/**
- * @author Sam Adams
- */
-public class HelpOptions {
-
-    @Parameter(description = "Topic")
-    public String topic;
-
-}

client-cli/src/main/java/net/chempound/client/cli/options/MoveOptions.java

-package net.chempound.client.cli.options;
-
-/**
- * @author Sam Adams
- */
-public class MoveOptions {
-}

client-cli/src/main/java/net/chempound/client/cli/types/PersonConverter.java

-package net.chempound.client.cli.types;
-
-import com.beust.jcommander.IStringConverter;
-import com.beust.jcommander.IStringConverterFactory;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import net.chempound.rdf.foaf.FoafUtil;
-import net.chempound.rdf.foaf.Person;
-
-public class PersonConverter implements IStringConverter<Person> {
-
-    private final Model model = ModelFactory.createDefaultModel();
-
-    public Person convert(final String value) {
-        final Person person = FoafUtil.createPerson(model);
-        person.setName(value);
-        return person;
-    }
-
-    public static class Factory implements IStringConverterFactory {
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public Class<? extends IStringConverter<?>> getConverter(final Class forType) {
-            if (Person.class.equals(forType)) {
-                return PersonConverter.class;
-            }
-            return null;
-        }
-
-    }
-
-}

client-cli/src/main/java/net/chempound/client/cli/types/URIConverter.java

-package net.chempound.client.cli.types;
-
-import com.beust.jcommander.IStringConverter;
-import com.beust.jcommander.IStringConverterFactory;
-
-import java.net.URI;
-
-/**
- * @author Sam Adams
- */
-public class URIConverter implements IStringConverter<URI> {
-
-    @Override
-    public URI convert(final String value) {
-        return URI.create(value);
-    }
-
-    public static class Factory implements IStringConverterFactory {
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public Class<? extends IStringConverter<?>> getConverter(final Class forType) {
-            if (URI.class.equals(forType)) {
-                return URIConverter.class;
-            }
-            return null;
-        }
-
-    }
-
-}

client-cli/src/test/java/net/chempound/client/cli/ChempoundClientCLIIntegrationTest.java

-package net.chempound.client.cli;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Stage;
-import net.chempound.ChempoundConfigurationModule;
-import net.chempound.DefaultChempoundModule;
-import net.chempound.config.ChempoundConfiguration;
-import net.chempound.config.DefaultChempoundConfiguration;
-import net.chempound.datastore.TripleStore;
-import net.chempound.rdf.ORE;
-import net.chempound.webapp.DefaultChempoundWebModule;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.junit.*;
-import org.restlet.Application;
-import org.restlet.Component;
-import org.restlet.data.Protocol;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.UUID;
-
-import static com.hp.hpl.jena.rdf.model.ResourceFactory.createPlainLiteral;
-import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
-import static com.hp.hpl.jena.vocabulary.RDF.type;
-import static net.chempound.rdf.CPTerms.Collection;
-import static net.chempound.rdf.CPTerms.Item;
-import static net.chempound.rdf.DCTerms.title;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.spy;
-
-/**
- * @author Sam Adams
- */
-public class ChempoundClientCLIIntegrationTest {
-
-    private static Component component;
-    private static TripleStore tripleStore;
-    private static File workspace;
-
-    private ChempoundClientCLI client;
-    private File tmpDir;
-
-    @BeforeClass
-    public static void setUpChempound() throws Exception {
-        final URI baseUri = URI.create("http://localhost:12080/repo/");
-        workspace = new File("target", UUID.randomUUID().toString());
-
-        final ChempoundConfiguration configuration = new DefaultChempoundConfiguration(baseUri, workspace);
-        final Injector injector = Guice.createInjector(Stage.DEVELOPMENT,
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new ChempoundConfigurationModule(configuration)
-        );
-
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 12080)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost().attach("/repo", injector.getInstance(Application.class));
-        component.start();
-
-        tripleStore = injector.getInstance(TripleStore.class);
-    }
-
-    @AfterClass
-    public static void tearDownChempound() throws Exception {
-        if (component != null) {
-            try {
-                component.stop();
-            } finally {
-                component = null;
-            }
-        }
-        FileUtils.deleteQuietly(workspace);
-        workspace = null;
-        tripleStore = null;
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        client = spy(new ChempoundClientCLI());
-        doNothing().when(client).exit(anyInt());
-
-        tmpDir = new File("target/" + UUID.randomUUID());
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        FileUtils.deleteQuietly(tmpDir);
-    }
-
-    @Test
-    public void testCreateCollection() throws Exception {
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
-                "create-collection", "FooBar");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/FooBar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/FooBar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/FooBar/")));
-    }
-
-    @Test
-    public void testCreateCollectionWithTitle() throws Exception {
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
-                "create-collection", "--slug", "foobar", "FooBar");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/")));
-    }
-
-    @Test
-    public void testDepositItem() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
-        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
-
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
-                "deposit", "wibble.txt");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/")));
-    }
-
-    @Test
-    public void testDepositItemWithSlugAndTitle() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
-        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
-
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
-                "deposit", "-s", "flob", "-t", "##title##", "wibble.txt");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), type, Item));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), title, createPlainLiteral("##title##")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/flob/wibble.txt")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/flob/")));
-
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/flob/wibble.txt")));
-    }
-
-    @Test
-    public void testDepositMultipleItems() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
-        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
-        FileUtils.writeStringToFile(new File(tmpDir, "wobble.txt"), "wobble");
-
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
-                "deposit", "-s", "test", "wibble.txt", "wobble.txt");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/test/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/test/wibble.txt")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/test/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/test/wobble.txt")));
-
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/test/wibble.txt")));
-        assertEquals("wobble", fetchUrl(URI.create("http://localhost:12080/repo/content/test/wobble.txt")));
-    }
-
-    @Test
-    public void testDepositItemToRootCollectionWithoutSlash() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
-        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
-
-        client.runMain("-R", "http://localhost:12080/repo/content", "--cwd", tmpDir.getAbsolutePath(),
-            "deposit", "-s", "abc", "wibble.txt");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/abc/")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/abc/"), type, Item));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/abc/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/abc/wibble.txt")));
-
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/abc/wibble.txt")));
-    }
-
-    @Test
-    public void testDepositItemToChildCollectionWithoutSlash() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
-        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
-
-        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
-            "create-collection", "--slug", "xyz", "XYZ");
-
-        client = new ChempoundClientCLI();
-
-        client.runMain("-R", "http://localhost:12080/repo/content/xyz", "--cwd", tmpDir.getAbsolutePath(),
-            "deposit", "-s", "xyzzy", "wibble.txt");
-
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/xyz/xyzzy/")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/xyzzy/"), type, Item));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/xyzzy/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/xyz/xyzzy/wibble.txt")));
-
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/xyz/xyzzy/wibble.txt")));
-    }
-
-
-    private static String fetchUrl(final URI uri) throws IOException {
-        InputStream in = uri.toURL().openStream();
-        try {
-            return IOUtils.toString(in);
-        } finally {
-            in.close();
-        }
-    }
-
-}

client-cli/src/test/java/net/chempound/client/cli/ChempoundClientCLITest.java

-package net.chempound.client.cli;
-
-import net.chempound.client.cli.command.Command;
-import net.chempound.client.cli.command.CreateCollectionCommand;
-import net.chempound.client.cli.command.DepositCommand;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.*;
-
-/**
- * @author Sam Adams
- */
-public class ChempoundClientCLITest {
-
-    private ChempoundClientCLI chempoundClient;
-
-    private Command<?> command;
-
-    @Before
-    public void setUp() throws Exception {
-        chempoundClient = spy(new ChempoundClientCLI());
-
-        doNothing().when(chempoundClient).displayVersionAndExit();
-        doNothing().when(chempoundClient).displayUsageAndExit();
-        doNothing().when(chempoundClient).exit(anyInt());
-
-        doAnswer(new Answer() {
-            @Override
-            public Object answer(final InvocationOnMock invocation) throws Throwable {
-                command = (Command) invocation.getArguments()[0];
-                return null;
-            }
-        }).when(chempoundClient).invokeCommand(any(Command.class));
-    }
-
-    @Test
-    public void testParseVerboseFlag() {
-        chempoundClient.runMain("-v");
-
-        assertEquals(true, chempoundClient.globalOptions.verbose);
-    }
-
-    @Test
-    public void testDisplayVersion() {
-        chempoundClient.runMain("--version");
-
-        verify(chempoundClient).displayVersionAndExit();
-    }
-
-    @Test
-    public void testDeposit() {
-        chempoundClient.runMain("deposit");
-
-        verify(chempoundClient).invokeCommand(any(DepositCommand.class));
-    }
-
-    @Test
-    public void testDepositWithRepositoryShortArg() {
-        chempoundClient.runMain("-R", "http://repo.example.com/", "deposit");
-
-        verify(chempoundClient).invokeCommand(any(DepositCommand.class));
-        assertEquals("http://repo.example.com/", chempoundClient.globalOptions.repository);
-    }
-
-    @Test
-    public void testDepositWithRepositoryLongArg() {
-        chempoundClient.runMain("--repository", "http://repo.example.com/", "deposit");
-
-        verify(chempoundClient).invokeCommand(any(DepositCommand.class));
-        assertEquals("http://repo.example.com/", chempoundClient.globalOptions.repository);
-    }
-
-    @Test
-    public void testDepositFileList() {
-        chempoundClient.runMain("deposit", "file1.foo", "file2.bar");
-
-        verify(chempoundClient).invokeCommand(any(DepositCommand.class));
-        DepositCommand depositCommand = (DepositCommand) command;
-        assertEquals(asList("file1.foo", "file2.bar"), depositCommand.getOptions().files);
-    }
-
-    @Test
-    public void testDepositWithTitleAndSlug() {
-        chempoundClient.runMain("deposit", "-t", "##title##", "-s", "##slug##", "file1.foo", "file2.bar");
-        verify(chempoundClient).invokeCommand(any(DepositCommand.class));
-        DepositCommand depositCommand = (DepositCommand) command;
-        assertEquals("##title##", depositCommand.getOptions().title);
-        assertEquals("##slug##", depositCommand.getOptions().slug);
-        assertEquals(asList("file1.foo", "file2.bar"), depositCommand.getOptions().files);
-    }
-
-    @Test
-    public void testCreateCollection() {
-        chempoundClient.runMain("create-collection", "##title##");
-
-        verify(chempoundClient).invokeCommand(any(CreateCollectionCommand.class));
-        CreateCollectionCommand createCollection = (CreateCollectionCommand) command;
-        assertEquals(asList("##title##"), createCollection.getOptions().args);
-    }
-
-    @Test
-    public void testCreateCollectionWithTitle() {
-        chempoundClient.runMain("create-collection", "-s", "##id##", "##title##");
-
-        verify(chempoundClient).invokeCommand(any(CreateCollectionCommand.class));
-        CreateCollectionCommand createCollection = (CreateCollectionCommand) command;
-        assertEquals("##id##", createCollection.getOptions().slug);
-        assertEquals(asList("##title##"), createCollection.getOptions().args);
-    }
-
-}

client-cli/src/test/java/net/chempound/client/cli/command/CreateCollectionCommandTest.java

-package net.chempound.client.cli.command;
-
-/**
- * @author Sam Adams
- */
-public class CreateCollectionCommandTest {
-}

client-cli/src/test/java/net/chempound/client/cli/command/DepositCommandTest.java

-package net.chempound.client.cli.command;
-
-/**
- * @author Sam Adams
- */
-public class DepositCommandTest {
-}

client-utils/LICENSE.txt

Empty file removed.

client-utils/README.txt

Empty file removed.

client-utils/pom.xml

-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-    <parent>
-        <groupId>net.chempound.client</groupId>
-        <artifactId>client</artifactId>
-        <version>0.1-SNAPSHOT</version>
-    </parent>
-
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>client-utils</artifactId>
-
-    <name>Chempound Client Utils</name>
-
-    <dependencies>
-
-        <dependency>
-            <groupId>net.chempound</groupId>
-            <artifactId>chempound-api</artifactId>
-            <version>0.1-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>net.sf.atomxom</groupId>
-            <artifactId>atomxom-core</artifactId>
-            <version>${atomxom.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.swordapp</groupId>
-            <artifactId>sword-client</artifactId>
-            <version>2.0-r339</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>junit</groupId>
-                    <artifactId>junit</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpmime</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.ccil.cowan.tagsoup</groupId>
-            <artifactId>tagsoup</artifactId>
-            <version>1.2.1</version>
-        </dependency>
-
-
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-            <version>[1.6.1]</version>
-        </dependency>
-
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-    </dependencies>
-
-</project>

client-utils/src/main/java/net/chempound/client/AttachmentBodyPart.java

-package net.chempound.client;
-
-import org.apache.http.entity.mime.FormBodyPart;
-import org.apache.http.entity.mime.MIME;
-import org.apache.http.entity.mime.content.ContentBody;
-
-/**
- * @author Sam Adams
- */
-public class AttachmentBodyPart extends FormBodyPart {
-
-    private final String md5;
-
-    public AttachmentBodyPart(final String name, final ContentBody body, final String md5) {
-        super(name, body);
-        if (name == null) {
-            throw new IllegalArgumentException("Name may not be null");
-        }
-        if (body == null) {
-            throw new IllegalArgumentException("Body may not be null");
-        }
-        this.md5 = md5;
-    }
-
-    @Override
-    protected void generateContentDisp(final ContentBody body) {
-        final StringBuilder buffer = new StringBuilder();
-        buffer.append("form-data; name=\"");
-        buffer.append(getName());
-        buffer.append("\"");
-        if (body.getFilename() != null) {
-            buffer.append("; filename=\"");
-            buffer.append(body.getFilename());
-            buffer.append("\"");
-        }
-        addField(MIME.CONTENT_DISPOSITION, buffer.toString());
-        if (md5 != null) {
-            addField("Content-MD5", md5);
-        }
-    }
-
-}

client-utils/src/main/java/net/chempound/client/ByteArrayBody.java

-package net.chempound.client;
-
-import org.apache.http.entity.mime.MIME;
-import org.apache.http.entity.mime.content.AbstractContentBody;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * @author Sam Adams
- */
-public class ByteArrayBody extends AbstractContentBody {
-
-    private static final String NULL_CHARSET = null;
-
-    private final byte[] bytes;
-    private final String filename;
-    private final String charset;
-
-    public ByteArrayBody(final byte[] bytes, final String mimeType, final String filename, final String charset) {
-        super(mimeType);
-        this.charset = charset;
-        if (bytes == null) {
-            throw new IllegalArgumentException("Byte array may not be null");
-        }
-        this.bytes = new byte[bytes.length];
-        System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
-        this.filename = filename;
-    }
-
-    public ByteArrayBody(final byte[] bytes, final String mimeType, final String filename) {
-        this(bytes, mimeType, filename, NULL_CHARSET);
-    }
-
-    @Override
-    public void writeTo(final OutputStream out) throws IOException {
-        if (out == null) {
-            throw new IllegalArgumentException("Output stream may not be null");
-        }
-        out.write(bytes);
-        out.flush();
-    }
-
-    @Override
-    public String getTransferEncoding() {
-        return MIME.ENC_BINARY;
-    }
-
-    @Override
-    public String getCharset() {
-        return charset;
-    }
-
-    @Override
-    public long getContentLength() {
-        return bytes.length;
-    }
-
-    @Override
-    public String getFilename() {
-        return this.filename;
-    }
-
-}

client-utils/src/main/java/net/chempound/client/DepositBuilder.java

-package net.chempound.client;
-
-import net.chempound.content.DefaultDepositRequest;
-import net.chempound.content.DepositRequest;
-import net.chempound.storage.LocalResource;
-import org.swordapp.client.Deposit;
-
-/**
- * @author Sam Adams
- */
-public class DepositBuilder {
-
-    private DepositRequest depositRequest = new DefaultDepositRequest();
-
-    public void setTitle(final String title) {
-        depositRequest.setTitle(title);
-    }
-
-    public void setSlug(final String slug) {
-        depositRequest.setSlug(slug);
-    }
-
-    protected String getSlug() {
-        return depositRequest.getSlug();
-    }
-
-    public void addResource(final LocalResource resource) {
-        depositRequest.addResource(resource);
-    }
-
-    public DepositRequest buildDepositRequest() {
-        return depositRequest;
-    }
-
-    public Deposit build() throws Exception {
-        return SwordUtil.createSwordDeposit(depositRequest);
-    }
-
-    public void setImage(final LocalResource imageResource) {
-        depositRequest.setImage(imageResource);
-    }
-}

client-utils/src/main/java/net/chempound/client/MultipartRelatedEntity.java

-package net.chempound.client;
-
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.entity.mime.HttpMultipart;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.content.ContentBody;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.HTTP;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-
-/**
- * @author Sam Adams
- */
-public class MultipartRelatedEntity implements HttpEntity {
-
-    /**
-     * The pool of ASCII chars to be used for generating a multipart boundary.
-     */
-    private final static char[] MULTIPART_CHARS =
-        "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
-            .toCharArray();
-
-    private final HttpMultipart multipart;
-    private final Header contentType;
-
-    private long length;
-    private volatile boolean dirty; // used to decide whether to recalculate length
-
-    public MultipartRelatedEntity(
-            final HttpMultipartMode mode,
-            final String boundary,
-            final Charset charset) {
-        super();
-        final String bdry = boundary == null ? generateBoundary() : boundary;
-        this.multipart = new HttpMultipart("related", charset, bdry, mode == null ? HttpMultipartMode.STRICT : mode);
-        this.contentType = new BasicHeader(
-            HTTP.CONTENT_TYPE,
-            generateContentType(bdry, charset));
-        this.dirty = true;
-    }
-
-    public MultipartRelatedEntity(final HttpMultipartMode mode) {
-        this(mode, null, null);
-    }
-
-    public MultipartRelatedEntity() {
-        this(HttpMultipartMode.STRICT, null, null);
-    }
-
-    protected String generateContentType(
-            final String boundary,
-            final Charset charset) {
-        final StringBuilder buffer = new StringBuilder();
-        buffer.append("multipart/related; boundary=");
-        if (boundary != null) {
-            buffer.append(boundary);
-        } else {
-            final Random rand = new Random();
-            final int count = rand.nextInt(11) + 30; // a random size from 30 to 40
-            for (int i = 0; i < count; i++) {
-                buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
-            }
-        }
-        if (charset != null) {
-            buffer.append("; charset=");
-            buffer.append(charset.name());
-        }
-        return buffer.toString();
-    }
-
-    protected String generateBoundary() {
-        final StringBuilder buffer = new StringBuilder();
-        final Random rand = new Random();
-        final int count = rand.nextInt(11) + 30; // a random size from 30 to 40
-        for (int i = 0; i < count; i++) {
-            buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
-        }
-        return buffer.toString();
-    }
-
-    public void addPart(final String name, final ContentBody contentBody) {
-        addPart(new AttachmentBodyPart(name, contentBody, null));
-    }
-
-    public void addPart(final AttachmentBodyPart part) {
-        this.multipart.addBodyPart(part);
-        this.dirty = true;
-    }
-
-    public boolean isRepeatable() {
-        final List<?> parts = this.multipart.getBodyParts();
-        for (final Iterator<?> it = parts.iterator(); it.hasNext();) {
-            final AttachmentBodyPart part = (AttachmentBodyPart) it.next();
-            final ContentBody body = part.getBody();
-            if (body.getContentLength() < 0) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    public boolean isChunked() {
-        return !isRepeatable();
-    }
-
-    public boolean isStreaming() {
-        return !isRepeatable();
-    }
-
-    public long getContentLength() {
-        if (this.dirty) {
-            this.length = this.multipart.getTotalLength();
-            this.dirty = false;
-        }
-        return this.length;
-    }
-
-    public Header getContentType() {
-        return this.contentType;
-    }
-
-    public Header getContentEncoding() {
-        return null;
-    }
-
-    public void consumeContent() {
-        if (isStreaming()) {
-            throw new UnsupportedOperationException(
-                    "Streaming entity does not implement #consumeContent()");
-        }
-    }
-
-    public InputStream getContent() {
-        throw new UnsupportedOperationException(
-                    "Multipart related entity does not implement #getContent()");
-    }
-
-    public void writeTo(final OutputStream outstream) throws IOException {
-        this.multipart.writeTo(outstream);
-    }
-
-}

client-utils/src/main/java/net/chempound/client/SilentErrorHandler.java

-package net.chempound.client;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * @author Sam Adams
- */
-public class SilentErrorHandler implements ErrorHandler {
-
-    @Override
-    public void warning(final SAXParseException exception) throws SAXException {
-    }
-
-    @Override
-    public void error(final SAXParseException exception) throws SAXException {
-    }
-
-    @Override
-    public void fatalError(final SAXParseException exception) throws SAXException {
-    }
-
-}

client-utils/src/main/java/net/chempound/client/SwordClient.java

-package net.chempound.client;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import net.chempound.client.sword.DepositReceipt;
-import net.chempound.client.sword.SwordEntry;
-import net.chempound.client.sword.SwordService;
-import net.chempound.content.DepositRequest;
-import net.chempound.rdf.RdfIO;
-import net.chempound.storage.DepositResource;
-import net.chempound.storage.LocalResource;
-import net.sf.atomxom.AtomBuilder;
-import nu.xom.*;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.mime.Field;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.content.ContentBody;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import static net.chempound.client.atom.AtomPub.ATOMPUB_NAMESPACE;
-import static org.apache.commons.httpclient.HttpStatus.SC_CREATED;
-import static org.apache.commons.httpclient.HttpStatus.SC_OK;
-
-/**
- * @author Sam Adams
- */
-public class SwordClient {
-
-    private static final XPathContext HTML_CONTEXT = new XPathContext("h", "http://www.w3.org/1999/xhtml");
-
-    private static final String SLUG = "Slug";
-    private static final String PACKAGING = "Packaging";
-    private static final String IN_PROGRESS = "In-Progress";
-    private static final String ON_BEHALF_OF = "On-Behalf-Of";
-    private static final String METADATA_RELEVANT = "Metadata-Relevant";
-
-    private static final String PACKAGING_SIMPLE_ZIP = "http://purl.org/net/sword/package/SimpleZip";
-
-    private final HttpClient httpClient;
-
-    public SwordClient() {
-        this(new DefaultHttpClient());
-    }
-
-    protected SwordClient(final HttpClient httpClient) {
-        this.httpClient = httpClient;