use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManager method reload.
/**
* Reads configuration properties, checks and creates base directories and builds the singleton
*/
public synchronized void reload() {
MCRConfiguration config = MCRConfiguration.instance();
String pattern = config.getString("MCR.Metadata.ObjectID.NumberPattern", "0000000000");
defaultLayout = pattern.length() - 4 + "-2-2";
String base = config.getString("MCR.Metadata.Store.BaseDir");
baseDir = new File(base);
checkDir(baseDir, "base");
defaultClass = config.getClass("MCR.Metadata.Store.DefaultClass", MCRVersioningMetadataStore.class);
if (MCRVersioningMetadataStore.class.isAssignableFrom(defaultClass)) {
try {
String svnBaseValue = config.getString("MCR.Metadata.Store.SVNBase");
if (!svnBaseValue.endsWith("/")) {
svnBaseValue += '/';
}
svnBase = new URI(svnBaseValue);
LOGGER.info("SVN Base: {}", svnBase);
if (svnBase.getScheme() == null) {
String workingDirectory = (new File(".")).getAbsolutePath();
URI root = new File(MCRConfiguration.instance().getString("MCR.datadir", workingDirectory)).toURI();
URI resolved = root.resolve(svnBase);
LOGGER.warn("Resolved {} to {}", svnBase, resolved);
svnBase = resolved;
}
} catch (URISyntaxException ex) {
String msg = "Syntax error in MCR.Metadata.Store.SVNBase property: " + svnBase;
throw new MCRConfigurationException(msg, ex);
}
if (svnBase.getScheme().equals("file")) {
svnDir = new File(svnBase);
checkDir(svnDir, "svn");
}
}
closeCreatedStores();
}
use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManager method setupStore.
@SuppressWarnings("unchecked")
private void setupStore(String project, String objectType, String configPrefix) throws ReflectiveOperationException {
MCRConfiguration config = MCRConfiguration.instance();
String baseID = getStoryKey(project, objectType);
Class clazz = config.getClass(configPrefix + "Class", null);
if (clazz == null) {
config.set(configPrefix + "Class", defaultClass.getName());
clazz = defaultClass;
}
if (MCRVersioningMetadataStore.class.isAssignableFrom(clazz)) {
String property = configPrefix + "SVNRepositoryURL";
String svnURL = config.getString(property, null);
if (svnURL == null) {
String relativeURI = MessageFormat.format("{0}/{1}/", project, objectType);
URI repURI = svnBase.resolve(relativeURI);
LOGGER.info("Resolved {} to {} for {}", relativeURI, repURI.toASCIIString(), property);
config.set(property, repURI.toASCIIString());
File projectDir = new File(svnDir, project);
if (!projectDir.exists() && !projectDir.mkdirs()) {
throwStoreDirException(projectDir, project, objectType, configPrefix);
}
}
}
String slotLayout = config.getString(configPrefix + "SlotLayout", null);
if (slotLayout == null) {
config.set(configPrefix + "SlotLayout", defaultLayout);
}
File projectDir = new File(baseDir, project);
File typeDir = new File(projectDir, objectType);
if (!typeDir.exists() && !typeDir.mkdirs()) {
throwStoreDirException(typeDir, project, objectType, configPrefix);
}
config.set(configPrefix + "BaseDir", typeDir.getAbsolutePath());
config.set(configPrefix + "ForceXML", true);
config.set(configPrefix + "ForceDocType", objectType.equals("derivate") ? "mycorederivate" : "mycoreobject");
createdStores.add(baseID);
MCRStoreManager.createStore(baseID, clazz);
}
use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.
the class MCRPackerManagerTest method testPackerConfigurationStart.
@Test
public void testPackerConfigurationStart() throws Exception {
MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
String testPackerPrefix = MCRPacker.PACKER_CONFIGURATION_PREFIX + TEST_PACKER_ID + ".";
Map<String, String> parameterMap = new Hashtable<>();
// add packer parameter
parameterMap.put("packer", TEST_PACKER_ID);
// add test parameter
parameterMap.put(MCRPackerMock.TEST_PARAMETER_KEY, MCRPackerMock.TEST_VALUE);
MCRJob packerJob = MCRPackerManager.startPacking(parameterMap);
Assert.assertNotNull("The Packer job is not present!", packerJob);
endTransaction();
Thread.sleep(1000);
startNewTransaction();
int waitTime = 10;
while (waitTime > 0 && !mcrConfiguration.getBoolean(MCRPackerMock.FINISHED_PROPERTY, false) && !mcrConfiguration.getBoolean(MCRPackerMock.SETUP_CHECKED_PROPERTY, false)) {
Thread.sleep(1000);
waitTime -= 1;
}
Assert.assertTrue("PackerJob did not finish in time!", waitTime > 0);
}
use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.
the class MCRIdentifierTypeFactory method buildIdentifierType.
private MCRIdentifierType buildIdentifierType(String typeID) {
MCRConfiguration config = MCRConfiguration.instance();
String defaultXPath = MessageFormat.format(DEFAULT_XPATH, typeID);
String xPath = config.getString("MCR.MODS.EnrichmentResolver.IdentifierType." + typeID, defaultXPath);
return new MCRIdentifierType(typeID, xPath);
}
use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.
the class MCRAVExtRealHelix method init.
@Override
public void init(MCRFile file) throws MCRPersistenceException {
super.init(file);
MCRConfiguration config = MCRConfiguration.instance();
String prefix = "MCR.IFS.AVExtender." + file.getStoreID() + ".";
baseMetadata = config.getString(prefix + "ViewSourceBaseURL");
try {
String data = getMetadata(baseMetadata + file.getStorageID());
String sSize = getBetween("File Size:</strong>", "Bytes", data, "0");
String sBitRate = getBetween("Bit Rate:</strong>", "Kbps", data, "0.0");
String sFrameRate = getBetween("Frame Rate: </strong>", "fps", data, "0.0");
String sDuration = getBetween("Duration:</strong>", "<br>", data, "0:0.0");
String sType = getBetween("Stream:</strong>", "<br>", data, "");
bitRate = Math.round(1024 * Float.valueOf(sBitRate));
StringTokenizer st1 = new StringTokenizer(sFrameRate, " ,");
while (st1.hasMoreTokens()) {
double value = Double.valueOf(st1.nextToken());
frameRate = Math.max(frameRate, value);
}
hasVideo = frameRate > 0;
StringTokenizer st2 = new StringTokenizer(sDuration, ":.");
durationMinutes = Integer.parseInt(st2.nextToken());
durationSeconds = Integer.parseInt(st2.nextToken());
if (Integer.parseInt(st2.nextToken()) > 499) {
durationSeconds += 1;
if (durationSeconds > 59) {
durationMinutes += 1;
durationSeconds = 0;
}
}
StringTokenizer st3 = new StringTokenizer(sSize, ",");
StringBuilder sb = new StringBuilder();
while (st3.hasMoreTokens()) {
sb.append(st3.nextToken());
}
size = Long.parseLong(sb.toString());
durationHours = durationMinutes / 60;
durationMinutes = durationMinutes - durationHours * 60;
if (sType.contains("MPEG Layer 3")) {
contentTypeID = "mp3";
hasVideo = false;
} else if (sType.contains("3GPP")) {
contentTypeID = "3gp";
hasVideo = true;
} else if (sType.contains("MPEG4")) {
contentTypeID = "mpeg4";
hasVideo = true;
} else if (sType.contains("MPEG")) {
contentTypeID = "mpegvid";
hasVideo = true;
} else if (sType.contains("RealVideo")) {
contentTypeID = "realvid";
} else if (sType.contains("RealAudio")) {
contentTypeID = "realaud";
} else if (sType.contains("Wave File")) {
contentTypeID = "wav";
hasVideo = false;
} else // should be one of "wma" "wmv" "asf"
{
contentTypeID = file.getContentTypeID();
hasVideo = !contentTypeID.equals("wma");
}
if (" wma wmv asf asx ".contains(" " + contentTypeID + " ")) {
basePlayerStarter = config.getString(prefix + "AsxGenBaseURL");
playerDownloadURL = config.getString(prefix + "MediaPlayerURL");
} else {
basePlayerStarter = config.getString(prefix + "RamGenBaseURL");
playerDownloadURL = config.getString(prefix + "RealPlayerURL");
}
URLConnection con = getConnection(basePlayerStarter + file.getStorageID());
playerStarterCT = con.getContentType();
} catch (Exception exc) {
String msg = "Error parsing metadata from Real Server ViewSource: " + file.getStorageID();
LOGGER.warn(msg, exc);
}
}
Aggregations