
java.fedora.oai.sample.RandomDCMetadataFactory 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.oai.sample;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* Title: RandomDCmetadataFactory.java
* Description:
*
* @author [email protected]
* @version $Id: RandomDCMetadataFactory.java 3965 2005-04-21 12:52:40Z rlw $
*/
public class RandomDCMetadataFactory {
private static String[] s_dcElements=new String[] {"title", "creator",
"subject", "description", "publisher", "contributor", "date",
"type", "format", "identifier", "source", "language", "relation",
"coverage", "rights"};
private ArrayList m_wordList=new ArrayList();
public RandomDCMetadataFactory(File dictionaryFile)
throws IOException {
BufferedReader in=new BufferedReader(new FileReader(dictionaryFile));
String nextLine="";
while (nextLine!=null) {
nextLine=in.readLine();
if (nextLine!=null) {
String[] words=nextLine.split(" ");
for (int i=0; i\n");
// + " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n"
// + " http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n");
for (int x=0; x"
+ getRandomWords(wordMax, wordList)
+ "\n");
}
}
out.append("");
return out.toString();
}
private static String getRandomWords(int wordMax, List wordList) {
int count=1+getRandom(wordMax);
StringBuffer out=new StringBuffer();
for (int i=0; i0) {
out.append(" ");
}
out.append((String) wordList.get(getRandom(wordList.size())));
}
return out.toString();
}
public static int getRandom(int belowThis) {
return (int) (Math.random() * belowThis);
}
private static boolean allLetters(String w) {
if (w.length()==0) return false;
String l=w.toLowerCase();
for (int i=0; i'z') {
return false;
}
}
return true;
}
}