id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
9,000
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/management/DBPIDGenerator.java
DBPIDGenerator.getHighestID
private int getHighestID(String namespace) { Integer i = (Integer) m_highestID.get(namespace); if (i == null) { return 0; } return i.intValue(); }
java
private int getHighestID(String namespace) { Integer i = (Integer) m_highestID.get(namespace); if (i == null) { return 0; } return i.intValue(); }
[ "private", "int", "getHighestID", "(", "String", "namespace", ")", "{", "Integer", "i", "=", "(", "Integer", ")", "m_highestID", ".", "get", "(", "namespace", ")", ";", "if", "(", "i", "==", "null", ")", "{", "return", "0", ";", "}", "return", "i", ".", "intValue", "(", ")", ";", "}" ]
Gets the highest id ever used for the given namespace.
[ "Gets", "the", "highest", "id", "ever", "used", "for", "the", "given", "namespace", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/management/DBPIDGenerator.java#L197-L203
9,001
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/management/DBPIDGenerator.java
DBPIDGenerator.setHighestID
private void setHighestID(String namespace, int id) throws IOException { logger.debug("Setting highest ID for {} to {}", namespace, id); m_highestID.put(namespace, new Integer(id)); // write the new highest id in the database, too Connection conn = null; try { conn = m_connectionPool.getReadWriteConnection(); SQLUtility.replaceInto(conn, "pidGen", new String[] {"namespace", "highestID"}, new String[] {namespace, "" + id}, "namespace", new boolean[] {false, true}); } catch (SQLException sqle) { throw new IOException("Error setting highest id for " + "namespace in db: " + sqle.getMessage()); } finally { if (conn != null) { m_connectionPool.free(conn); } } }
java
private void setHighestID(String namespace, int id) throws IOException { logger.debug("Setting highest ID for {} to {}", namespace, id); m_highestID.put(namespace, new Integer(id)); // write the new highest id in the database, too Connection conn = null; try { conn = m_connectionPool.getReadWriteConnection(); SQLUtility.replaceInto(conn, "pidGen", new String[] {"namespace", "highestID"}, new String[] {namespace, "" + id}, "namespace", new boolean[] {false, true}); } catch (SQLException sqle) { throw new IOException("Error setting highest id for " + "namespace in db: " + sqle.getMessage()); } finally { if (conn != null) { m_connectionPool.free(conn); } } }
[ "private", "void", "setHighestID", "(", "String", "namespace", ",", "int", "id", ")", "throws", "IOException", "{", "logger", ".", "debug", "(", "\"Setting highest ID for {} to {}\"", ",", "namespace", ",", "id", ")", ";", "m_highestID", ".", "put", "(", "namespace", ",", "new", "Integer", "(", "id", ")", ")", ";", "// write the new highest id in the database, too", "Connection", "conn", "=", "null", ";", "try", "{", "conn", "=", "m_connectionPool", ".", "getReadWriteConnection", "(", ")", ";", "SQLUtility", ".", "replaceInto", "(", "conn", ",", "\"pidGen\"", ",", "new", "String", "[", "]", "{", "\"namespace\"", ",", "\"highestID\"", "}", ",", "new", "String", "[", "]", "{", "namespace", ",", "\"\"", "+", "id", "}", ",", "\"namespace\"", ",", "new", "boolean", "[", "]", "{", "false", ",", "true", "}", ")", ";", "}", "catch", "(", "SQLException", "sqle", ")", "{", "throw", "new", "IOException", "(", "\"Error setting highest id for \"", "+", "\"namespace in db: \"", "+", "sqle", ".", "getMessage", "(", ")", ")", ";", "}", "finally", "{", "if", "(", "conn", "!=", "null", ")", "{", "m_connectionPool", ".", "free", "(", "conn", ")", ";", "}", "}", "}" ]
Sets the highest id ever used for the given namespace.
[ "Sets", "the", "highest", "id", "ever", "used", "for", "the", "given", "namespace", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/management/DBPIDGenerator.java#L208-L229
9,002
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileFollowingJournalReader.java
MultiFileFollowingJournalReader.openNextFile
@Override protected synchronized JournalInputFile openNextFile() throws JournalException { while (open) { JournalInputFile nextFile = super.openNextFile(); if (nextFile != null) { return nextFile; } try { wait(pollingIntervalMillis); } catch (InterruptedException e) { // no special action on interrupt. } } return null; }
java
@Override protected synchronized JournalInputFile openNextFile() throws JournalException { while (open) { JournalInputFile nextFile = super.openNextFile(); if (nextFile != null) { return nextFile; } try { wait(pollingIntervalMillis); } catch (InterruptedException e) { // no special action on interrupt. } } return null; }
[ "@", "Override", "protected", "synchronized", "JournalInputFile", "openNextFile", "(", ")", "throws", "JournalException", "{", "while", "(", "open", ")", "{", "JournalInputFile", "nextFile", "=", "super", ".", "openNextFile", "(", ")", ";", "if", "(", "nextFile", "!=", "null", ")", "{", "return", "nextFile", ";", "}", "try", "{", "wait", "(", "pollingIntervalMillis", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "// no special action on interrupt.", "}", "}", "return", "null", ";", "}" ]
Ask for a new file, using the superclass method, but if none is found, wait for a while and ask again. This will continue until we get a server shutdown signal.
[ "Ask", "for", "a", "new", "file", "using", "the", "superclass", "method", "but", "if", "none", "is", "found", "wait", "for", "a", "while", "and", "ask", "again", ".", "This", "will", "continue", "until", "we", "get", "a", "server", "shutdown", "signal", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileFollowingJournalReader.java#L50-L65
9,003
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/ingest/Ingest.java
Ingest.oneFromFile
public static String oneFromFile(File file, String ingestFormat, FedoraAPIAMTOM targetRepoAPIA, FedoraAPIMMTOM targetRepoAPIM, String logMessage) throws Exception { LAST_PATH = file.getPath(); String pid = AutoIngestor.ingestAndCommit(targetRepoAPIA, targetRepoAPIM, new FileInputStream(file), ingestFormat, getMessage(logMessage, file)); return pid; }
java
public static String oneFromFile(File file, String ingestFormat, FedoraAPIAMTOM targetRepoAPIA, FedoraAPIMMTOM targetRepoAPIM, String logMessage) throws Exception { LAST_PATH = file.getPath(); String pid = AutoIngestor.ingestAndCommit(targetRepoAPIA, targetRepoAPIM, new FileInputStream(file), ingestFormat, getMessage(logMessage, file)); return pid; }
[ "public", "static", "String", "oneFromFile", "(", "File", "file", ",", "String", "ingestFormat", ",", "FedoraAPIAMTOM", "targetRepoAPIA", ",", "FedoraAPIMMTOM", "targetRepoAPIM", ",", "String", "logMessage", ")", "throws", "Exception", "{", "LAST_PATH", "=", "file", ".", "getPath", "(", ")", ";", "String", "pid", "=", "AutoIngestor", ".", "ingestAndCommit", "(", "targetRepoAPIA", ",", "targetRepoAPIM", ",", "new", "FileInputStream", "(", "file", ")", ",", "ingestFormat", ",", "getMessage", "(", "logMessage", ",", "file", ")", ")", ";", "return", "pid", ";", "}" ]
if logMessage is null, will use original path in logMessage
[ "if", "logMessage", "is", "null", "will", "use", "original", "path", "in", "logMessage" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/ingest/Ingest.java#L46-L59
9,004
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/ingest/Ingest.java
Ingest.oneFromRepository
public static String oneFromRepository(FedoraAPIAMTOM sourceRepoAPIA, FedoraAPIMMTOM sourceRepoAPIM, String sourceExportFormat, String pid, FedoraAPIAMTOM targetRepoAPIA, FedoraAPIMMTOM targetRepoAPIM, String logMessage) throws Exception { // EXPORT from source repository // The export context is set to "migrate" since the intent // of ingest from repository is to migrate an object from // one repository to another. The "migrate" option will // ensure that URLs that were relative to the "exporting" // repository are made relative to the "importing" repository. ByteArrayOutputStream out = new ByteArrayOutputStream(); AutoExporter.export(sourceRepoAPIA, sourceRepoAPIM, pid, sourceExportFormat, "migrate", out); // Convert old format values to URIs for ingest String ingestFormat = sourceExportFormat; if (sourceExportFormat.equals(METS_EXT1_0_LEGACY)) { ingestFormat = METS_EXT1_0.uri; } else if (sourceExportFormat.equals(FOXML1_0_LEGACY)) { ingestFormat = FOXML1_0.uri; } // INGEST into target repository String realLogMessage = logMessage; if (realLogMessage == null) { realLogMessage = "Ingested from source repository with pid " + pid; } return AutoIngestor.ingestAndCommit(targetRepoAPIA, targetRepoAPIM, new ByteArrayInputStream(out .toByteArray()), ingestFormat, realLogMessage); }
java
public static String oneFromRepository(FedoraAPIAMTOM sourceRepoAPIA, FedoraAPIMMTOM sourceRepoAPIM, String sourceExportFormat, String pid, FedoraAPIAMTOM targetRepoAPIA, FedoraAPIMMTOM targetRepoAPIM, String logMessage) throws Exception { // EXPORT from source repository // The export context is set to "migrate" since the intent // of ingest from repository is to migrate an object from // one repository to another. The "migrate" option will // ensure that URLs that were relative to the "exporting" // repository are made relative to the "importing" repository. ByteArrayOutputStream out = new ByteArrayOutputStream(); AutoExporter.export(sourceRepoAPIA, sourceRepoAPIM, pid, sourceExportFormat, "migrate", out); // Convert old format values to URIs for ingest String ingestFormat = sourceExportFormat; if (sourceExportFormat.equals(METS_EXT1_0_LEGACY)) { ingestFormat = METS_EXT1_0.uri; } else if (sourceExportFormat.equals(FOXML1_0_LEGACY)) { ingestFormat = FOXML1_0.uri; } // INGEST into target repository String realLogMessage = logMessage; if (realLogMessage == null) { realLogMessage = "Ingested from source repository with pid " + pid; } return AutoIngestor.ingestAndCommit(targetRepoAPIA, targetRepoAPIM, new ByteArrayInputStream(out .toByteArray()), ingestFormat, realLogMessage); }
[ "public", "static", "String", "oneFromRepository", "(", "FedoraAPIAMTOM", "sourceRepoAPIA", ",", "FedoraAPIMMTOM", "sourceRepoAPIM", ",", "String", "sourceExportFormat", ",", "String", "pid", ",", "FedoraAPIAMTOM", "targetRepoAPIA", ",", "FedoraAPIMMTOM", "targetRepoAPIM", ",", "String", "logMessage", ")", "throws", "Exception", "{", "// EXPORT from source repository", "// The export context is set to \"migrate\" since the intent", "// of ingest from repository is to migrate an object from", "// one repository to another. The \"migrate\" option will", "// ensure that URLs that were relative to the \"exporting\"", "// repository are made relative to the \"importing\" repository.", "ByteArrayOutputStream", "out", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "AutoExporter", ".", "export", "(", "sourceRepoAPIA", ",", "sourceRepoAPIM", ",", "pid", ",", "sourceExportFormat", ",", "\"migrate\"", ",", "out", ")", ";", "// Convert old format values to URIs for ingest", "String", "ingestFormat", "=", "sourceExportFormat", ";", "if", "(", "sourceExportFormat", ".", "equals", "(", "METS_EXT1_0_LEGACY", ")", ")", "{", "ingestFormat", "=", "METS_EXT1_0", ".", "uri", ";", "}", "else", "if", "(", "sourceExportFormat", ".", "equals", "(", "FOXML1_0_LEGACY", ")", ")", "{", "ingestFormat", "=", "FOXML1_0", ".", "uri", ";", "}", "// INGEST into target repository", "String", "realLogMessage", "=", "logMessage", ";", "if", "(", "realLogMessage", "==", "null", ")", "{", "realLogMessage", "=", "\"Ingested from source repository with pid \"", "+", "pid", ";", "}", "return", "AutoIngestor", ".", "ingestAndCommit", "(", "targetRepoAPIA", ",", "targetRepoAPIM", ",", "new", "ByteArrayInputStream", "(", "out", ".", "toByteArray", "(", ")", ")", ",", "ingestFormat", ",", "realLogMessage", ")", ";", "}" ]
if logMessage is null, will make informative one up
[ "if", "logMessage", "is", "null", "will", "make", "informative", "one", "up" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/ingest/Ingest.java#L114-L155
9,005
beworker/tinybus
tinybus/src/main/java/de/halfbit/tinybus/TinyBus.java
TinyBus.from
public static synchronized TinyBus from(Context context) { final TinyBusDepot depot = TinyBusDepot.get(context); TinyBus bus = depot.getBusInContext(context); if (bus == null) { bus = depot.createBusInContext(context); } return bus; }
java
public static synchronized TinyBus from(Context context) { final TinyBusDepot depot = TinyBusDepot.get(context); TinyBus bus = depot.getBusInContext(context); if (bus == null) { bus = depot.createBusInContext(context); } return bus; }
[ "public", "static", "synchronized", "TinyBus", "from", "(", "Context", "context", ")", "{", "final", "TinyBusDepot", "depot", "=", "TinyBusDepot", ".", "get", "(", "context", ")", ";", "TinyBus", "bus", "=", "depot", ".", "getBusInContext", "(", "context", ")", ";", "if", "(", "bus", "==", "null", ")", "{", "bus", "=", "depot", ".", "createBusInContext", "(", "context", ")", ";", "}", "return", "bus", ";", "}" ]
Use this method to get a bus instance bound to the given context. If instance does not yet exist in the context, a new instance will be created. Otherwise existing instance gets returned. <p>Bus instance can be bound to a context. <p>If you need a singleton instance existing only once for the whole application, provide application context here. This option can be chosen for <code>Activity</code> to <code>Service</code> communication. <p> If you need a bus instance per <code>Activity</code>, you have to provide activity context in there. This option is perfect for <code>Activity</code> to <code>Fragment</code> or <code>Fragment</code> to <code>Fragment</code> communication. <p> Bus instance gets destroyed when your context is destroyed. @param context context to which this instance of bus has to be bound @return event bus instance, never null
[ "Use", "this", "method", "to", "get", "a", "bus", "instance", "bound", "to", "the", "given", "context", ".", "If", "instance", "does", "not", "yet", "exist", "in", "the", "context", "a", "new", "instance", "will", "be", "created", ".", "Otherwise", "existing", "instance", "gets", "returned", "." ]
37462b30d11388ad530070b2c8a765150b281757
https://github.com/beworker/tinybus/blob/37462b30d11388ad530070b2c8a765150b281757/tinybus/src/main/java/de/halfbit/tinybus/TinyBus.java#L121-L128
9,006
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/impl/AbstractAttribute.java
AbstractAttribute.encode
@Override public String encode() { ReadableByteArrayOutputStream out = new ReadableByteArrayOutputStream(); encode(out); return out.toString(); }
java
@Override public String encode() { ReadableByteArrayOutputStream out = new ReadableByteArrayOutputStream(); encode(out); return out.toString(); }
[ "@", "Override", "public", "String", "encode", "(", ")", "{", "ReadableByteArrayOutputStream", "out", "=", "new", "ReadableByteArrayOutputStream", "(", ")", ";", "encode", "(", "out", ")", ";", "return", "out", ".", "toString", "(", ")", ";", "}" ]
Simple encoding method that returns the text-encoded version of this attribute with no formatting. @return the text-encoded XML
[ "Simple", "encoding", "method", "that", "returns", "the", "text", "-", "encoded", "version", "of", "this", "attribute", "with", "no", "formatting", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/impl/AbstractAttribute.java#L125-L130
9,007
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java
DbXmlPolicyIndex.getQuery
private XmlQueryExpression getQuery(Map<String, Collection<AttributeBean>> attributeMap, XmlQueryContext context, int r) throws XmlException { // The dimensions for this query. StringBuilder sb = new StringBuilder(64 * attributeMap.size()); for (Collection<AttributeBean> attributeBeans : attributeMap.values()) { sb.append(attributeBeans.size() + ":"); for (AttributeBean bean : attributeBeans) { sb.append(bean.getValues().size() + "-"); } } // If a query of these dimensions already exists, then just return it. String hash = sb.toString() + r; XmlQueryExpression result = m_queries.get(hash); if (result != null) { return result; } // We do not have a query of those dimensions. We must make one. String query = createQuery(attributeMap); if (log.isDebugEnabled()) { log.debug("Query [{}]:\n{}", hash, query); } // Once we have created a query, we can parse it and store the // execution plan. This is an expensive operation that we do // not want to have to do more than once for each dimension result = m_dbXmlManager.manager.prepare(query, context); m_queries.put(hash, result); return result; }
java
private XmlQueryExpression getQuery(Map<String, Collection<AttributeBean>> attributeMap, XmlQueryContext context, int r) throws XmlException { // The dimensions for this query. StringBuilder sb = new StringBuilder(64 * attributeMap.size()); for (Collection<AttributeBean> attributeBeans : attributeMap.values()) { sb.append(attributeBeans.size() + ":"); for (AttributeBean bean : attributeBeans) { sb.append(bean.getValues().size() + "-"); } } // If a query of these dimensions already exists, then just return it. String hash = sb.toString() + r; XmlQueryExpression result = m_queries.get(hash); if (result != null) { return result; } // We do not have a query of those dimensions. We must make one. String query = createQuery(attributeMap); if (log.isDebugEnabled()) { log.debug("Query [{}]:\n{}", hash, query); } // Once we have created a query, we can parse it and store the // execution plan. This is an expensive operation that we do // not want to have to do more than once for each dimension result = m_dbXmlManager.manager.prepare(query, context); m_queries.put(hash, result); return result; }
[ "private", "XmlQueryExpression", "getQuery", "(", "Map", "<", "String", ",", "Collection", "<", "AttributeBean", ">", ">", "attributeMap", ",", "XmlQueryContext", "context", ",", "int", "r", ")", "throws", "XmlException", "{", "// The dimensions for this query.", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "64", "*", "attributeMap", ".", "size", "(", ")", ")", ";", "for", "(", "Collection", "<", "AttributeBean", ">", "attributeBeans", ":", "attributeMap", ".", "values", "(", ")", ")", "{", "sb", ".", "append", "(", "attributeBeans", ".", "size", "(", ")", "+", "\":\"", ")", ";", "for", "(", "AttributeBean", "bean", ":", "attributeBeans", ")", "{", "sb", ".", "append", "(", "bean", ".", "getValues", "(", ")", ".", "size", "(", ")", "+", "\"-\"", ")", ";", "}", "}", "// If a query of these dimensions already exists, then just return it.", "String", "hash", "=", "sb", ".", "toString", "(", ")", "+", "r", ";", "XmlQueryExpression", "result", "=", "m_queries", ".", "get", "(", "hash", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "return", "result", ";", "}", "// We do not have a query of those dimensions. We must make one.", "String", "query", "=", "createQuery", "(", "attributeMap", ")", ";", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "log", ".", "debug", "(", "\"Query [{}]:\\n{}\"", ",", "hash", ",", "query", ")", ";", "}", "// Once we have created a query, we can parse it and store the", "// execution plan. This is an expensive operation that we do", "// not want to have to do more than once for each dimension", "result", "=", "m_dbXmlManager", ".", "manager", ".", "prepare", "(", "query", ",", "context", ")", ";", "m_queries", ".", "put", "(", "hash", ",", "result", ")", ";", "return", "result", ";", "}" ]
Either returns a query that has previously been generated, or generates a new one if it has not. @param attributeMap the Map of attributes, type and values upon which this query is based @param context the context for the query @return an XmlQueryExpression that can be executed @throws XmlException @throws XmlException @throws PolicyIndexException
[ "Either", "returns", "a", "query", "that", "has", "previously", "been", "generated", "or", "generates", "a", "new", "one", "if", "it", "has", "not", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java#L216-L250
9,008
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java
DbXmlPolicyIndex.createQuery
private String createQuery(Map<String, Collection<AttributeBean>> attributeMap) { StringBuilder sb = new StringBuilder(256); sb.append("collection('"); sb.append(m_dbXmlManager.CONTAINER); sb.append("')"); getXpath(attributeMap, sb); return sb.toString(); }
java
private String createQuery(Map<String, Collection<AttributeBean>> attributeMap) { StringBuilder sb = new StringBuilder(256); sb.append("collection('"); sb.append(m_dbXmlManager.CONTAINER); sb.append("')"); getXpath(attributeMap, sb); return sb.toString(); }
[ "private", "String", "createQuery", "(", "Map", "<", "String", ",", "Collection", "<", "AttributeBean", ">", ">", "attributeMap", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "256", ")", ";", "sb", ".", "append", "(", "\"collection('\"", ")", ";", "sb", ".", "append", "(", "m_dbXmlManager", ".", "CONTAINER", ")", ";", "sb", ".", "append", "(", "\"')\"", ")", ";", "getXpath", "(", "attributeMap", ",", "sb", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Given a set of attributes this method generates a DBXML XPath query based on those attributes to extract a subset of policies from the database. @param attributeMap the Map of Attributes from which to generate the query @param r the number of components in the resource id @return the query as a String
[ "Given", "a", "set", "of", "attributes", "this", "method", "generates", "a", "DBXML", "XPath", "query", "based", "on", "those", "attributes", "to", "extract", "a", "subset", "of", "policies", "from", "the", "database", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java#L262-L269
9,009
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java
DbXmlPolicyIndex.makeDocument
private XmlDocument makeDocument(String name, String document) throws XmlException, PolicyIndexException { Map<String, String> metadata = m_utils.getDocumentMetadata(document .getBytes()); XmlDocument doc = m_dbXmlManager.manager.createDocument(); String docName = name; if (docName == null || docName.isEmpty()) { docName = metadata.get("PolicyId"); } if (docName == null || docName.isEmpty()) { throw new PolicyIndexException("Could not extract PolicyID from document."); } doc.setMetaData("metadata", "PolicyId", new XmlValue(XmlValue.STRING, docName)); doc.setContent(document); doc.setName(docName); // FIXME: // this is probably redundant as the xpath queries now directly query the policy // for the "any" scenarios String item = null; item = metadata.get("anySubject"); if (item != null) { doc.setMetaData("metadata", "anySubject", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyResource"); if (item != null) { doc.setMetaData("metadata", "anyResource", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyAction"); if (item != null) { doc.setMetaData("metadata", "anyAction", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyEnvironment"); if (item != null) { doc.setMetaData("metadata", "anyEnvironment", new XmlValue(XmlValue.STRING, item)); } return doc; }
java
private XmlDocument makeDocument(String name, String document) throws XmlException, PolicyIndexException { Map<String, String> metadata = m_utils.getDocumentMetadata(document .getBytes()); XmlDocument doc = m_dbXmlManager.manager.createDocument(); String docName = name; if (docName == null || docName.isEmpty()) { docName = metadata.get("PolicyId"); } if (docName == null || docName.isEmpty()) { throw new PolicyIndexException("Could not extract PolicyID from document."); } doc.setMetaData("metadata", "PolicyId", new XmlValue(XmlValue.STRING, docName)); doc.setContent(document); doc.setName(docName); // FIXME: // this is probably redundant as the xpath queries now directly query the policy // for the "any" scenarios String item = null; item = metadata.get("anySubject"); if (item != null) { doc.setMetaData("metadata", "anySubject", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyResource"); if (item != null) { doc.setMetaData("metadata", "anyResource", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyAction"); if (item != null) { doc.setMetaData("metadata", "anyAction", new XmlValue(XmlValue.STRING, item)); } item = metadata.get("anyEnvironment"); if (item != null) { doc.setMetaData("metadata", "anyEnvironment", new XmlValue(XmlValue.STRING, item)); } return doc; }
[ "private", "XmlDocument", "makeDocument", "(", "String", "name", ",", "String", "document", ")", "throws", "XmlException", ",", "PolicyIndexException", "{", "Map", "<", "String", ",", "String", ">", "metadata", "=", "m_utils", ".", "getDocumentMetadata", "(", "document", ".", "getBytes", "(", ")", ")", ";", "XmlDocument", "doc", "=", "m_dbXmlManager", ".", "manager", ".", "createDocument", "(", ")", ";", "String", "docName", "=", "name", ";", "if", "(", "docName", "==", "null", "||", "docName", ".", "isEmpty", "(", ")", ")", "{", "docName", "=", "metadata", ".", "get", "(", "\"PolicyId\"", ")", ";", "}", "if", "(", "docName", "==", "null", "||", "docName", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "PolicyIndexException", "(", "\"Could not extract PolicyID from document.\"", ")", ";", "}", "doc", ".", "setMetaData", "(", "\"metadata\"", ",", "\"PolicyId\"", ",", "new", "XmlValue", "(", "XmlValue", ".", "STRING", ",", "docName", ")", ")", ";", "doc", ".", "setContent", "(", "document", ")", ";", "doc", ".", "setName", "(", "docName", ")", ";", "// FIXME:", "// this is probably redundant as the xpath queries now directly query the policy", "// for the \"any\" scenarios", "String", "item", "=", "null", ";", "item", "=", "metadata", ".", "get", "(", "\"anySubject\"", ")", ";", "if", "(", "item", "!=", "null", ")", "{", "doc", ".", "setMetaData", "(", "\"metadata\"", ",", "\"anySubject\"", ",", "new", "XmlValue", "(", "XmlValue", ".", "STRING", ",", "item", ")", ")", ";", "}", "item", "=", "metadata", ".", "get", "(", "\"anyResource\"", ")", ";", "if", "(", "item", "!=", "null", ")", "{", "doc", ".", "setMetaData", "(", "\"metadata\"", ",", "\"anyResource\"", ",", "new", "XmlValue", "(", "XmlValue", ".", "STRING", ",", "item", ")", ")", ";", "}", "item", "=", "metadata", ".", "get", "(", "\"anyAction\"", ")", ";", "if", "(", "item", "!=", "null", ")", "{", "doc", ".", "setMetaData", "(", "\"metadata\"", ",", "\"anyAction\"", ",", "new", "XmlValue", "(", "XmlValue", ".", "STRING", ",", "item", ")", ")", ";", "}", "item", "=", "metadata", ".", "get", "(", "\"anyEnvironment\"", ")", ";", "if", "(", "item", "!=", "null", ")", "{", "doc", ".", "setMetaData", "(", "\"metadata\"", ",", "\"anyEnvironment\"", ",", "new", "XmlValue", "(", "XmlValue", ".", "STRING", ",", "item", ")", ")", ";", "}", "return", "doc", ";", "}" ]
Creates an instance of an XmlDocument for storage in the database. @param name the name of the document (policy) @param document the document data as a String @return the XmlDocument instance @throws XmlException @throws PolicyStoreException
[ "Creates", "an", "instance", "of", "an", "XmlDocument", "for", "storage", "in", "the", "database", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/DbXmlPolicyIndex.java#L450-L504
9,010
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.list
public Iterator<String> list() { try { final Enumeration<String> keys = pathRegistry.keys(); return new Iterator<String>() { public boolean hasNext() { return keys.hasMoreElements(); } public String next() { return keys.nextElement(); } public void remove() { throw new UnsupportedOperationException(); } }; } catch (LowlevelStorageException e) { throw new FaultException(e); } }
java
public Iterator<String> list() { try { final Enumeration<String> keys = pathRegistry.keys(); return new Iterator<String>() { public boolean hasNext() { return keys.hasMoreElements(); } public String next() { return keys.nextElement(); } public void remove() { throw new UnsupportedOperationException(); } }; } catch (LowlevelStorageException e) { throw new FaultException(e); } }
[ "public", "Iterator", "<", "String", ">", "list", "(", ")", "{", "try", "{", "final", "Enumeration", "<", "String", ">", "keys", "=", "pathRegistry", ".", "keys", "(", ")", ";", "return", "new", "Iterator", "<", "String", ">", "(", ")", "{", "public", "boolean", "hasNext", "(", ")", "{", "return", "keys", ".", "hasMoreElements", "(", ")", ";", "}", "public", "String", "next", "(", ")", "{", "return", "keys", ".", "nextElement", "(", ")", ";", "}", "public", "void", "remove", "(", ")", "{", "throw", "new", "UnsupportedOperationException", "(", ")", ";", "}", "}", ";", "}", "catch", "(", "LowlevelStorageException", "e", ")", "{", "throw", "new", "FaultException", "(", "e", ")", ";", "}", "}" ]
Gets the keys of all stored items. @return an iterator of all keys.
[ "Gets", "the", "keys", "of", "all", "stored", "items", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L72-L83
9,011
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.add
public final long add(String pid, InputStream content) throws LowlevelStorageException { String filePath; File file = null; //check that object is not already in store if (pathRegistry.exists(pid)){ throw new ObjectAlreadyInLowlevelStorageException(pid); } filePath = pathAlgorithm.get(pid); if (filePath == null || filePath.equals("")) { //guard against algorithm implementation throw new LowlevelStorageException(true, "null path from algorithm for pid " + pid); } try { file = new File(filePath); } catch (Exception eFile) { //purposefully general catch-all throw new LowlevelStorageException(true, "couldn't make File for " + filePath, eFile); } fileSystem.write(file, content); pathRegistry.put(pid, filePath); return file.length(); }
java
public final long add(String pid, InputStream content) throws LowlevelStorageException { String filePath; File file = null; //check that object is not already in store if (pathRegistry.exists(pid)){ throw new ObjectAlreadyInLowlevelStorageException(pid); } filePath = pathAlgorithm.get(pid); if (filePath == null || filePath.equals("")) { //guard against algorithm implementation throw new LowlevelStorageException(true, "null path from algorithm for pid " + pid); } try { file = new File(filePath); } catch (Exception eFile) { //purposefully general catch-all throw new LowlevelStorageException(true, "couldn't make File for " + filePath, eFile); } fileSystem.write(file, content); pathRegistry.put(pid, filePath); return file.length(); }
[ "public", "final", "long", "add", "(", "String", "pid", ",", "InputStream", "content", ")", "throws", "LowlevelStorageException", "{", "String", "filePath", ";", "File", "file", "=", "null", ";", "//check that object is not already in store", "if", "(", "pathRegistry", ".", "exists", "(", "pid", ")", ")", "{", "throw", "new", "ObjectAlreadyInLowlevelStorageException", "(", "pid", ")", ";", "}", "filePath", "=", "pathAlgorithm", ".", "get", "(", "pid", ")", ";", "if", "(", "filePath", "==", "null", "||", "filePath", ".", "equals", "(", "\"\"", ")", ")", "{", "//guard against algorithm implementation", "throw", "new", "LowlevelStorageException", "(", "true", ",", "\"null path from algorithm for pid \"", "+", "pid", ")", ";", "}", "try", "{", "file", "=", "new", "File", "(", "filePath", ")", ";", "}", "catch", "(", "Exception", "eFile", ")", "{", "//purposefully general catch-all", "throw", "new", "LowlevelStorageException", "(", "true", ",", "\"couldn't make File for \"", "+", "filePath", ",", "eFile", ")", ";", "}", "fileSystem", ".", "write", "(", "file", ",", "content", ")", ";", "pathRegistry", ".", "put", "(", "pid", ",", "filePath", ")", ";", "return", "file", ".", "length", "(", ")", ";", "}" ]
add to lowlevel store content of Fedora object not already in lowlevel store @return size - size of the object stored
[ "add", "to", "lowlevel", "store", "content", "of", "Fedora", "object", "not", "already", "in", "lowlevel", "store" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L104-L128
9,012
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.replace
public final long replace(String pid, InputStream content) throws LowlevelStorageException { File file = getFile(pid); fileSystem.rewrite(file, content); return file.length(); }
java
public final long replace(String pid, InputStream content) throws LowlevelStorageException { File file = getFile(pid); fileSystem.rewrite(file, content); return file.length(); }
[ "public", "final", "long", "replace", "(", "String", "pid", ",", "InputStream", "content", ")", "throws", "LowlevelStorageException", "{", "File", "file", "=", "getFile", "(", "pid", ")", ";", "fileSystem", ".", "rewrite", "(", "file", ",", "content", ")", ";", "return", "file", ".", "length", "(", ")", ";", "}" ]
replace into low-level store content of Fedora object already in lowlevel store
[ "replace", "into", "low", "-", "level", "store", "content", "of", "Fedora", "object", "already", "in", "lowlevel", "store" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L134-L139
9,013
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.retrieve
public final InputStream retrieve(String pid) throws LowlevelStorageException { File file = getFile(pid); return fileSystem.read(file); }
java
public final InputStream retrieve(String pid) throws LowlevelStorageException { File file = getFile(pid); return fileSystem.read(file); }
[ "public", "final", "InputStream", "retrieve", "(", "String", "pid", ")", "throws", "LowlevelStorageException", "{", "File", "file", "=", "getFile", "(", "pid", ")", ";", "return", "fileSystem", ".", "read", "(", "file", ")", ";", "}" ]
get content of Fedora object from low-level store
[ "get", "content", "of", "Fedora", "object", "from", "low", "-", "level", "store" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L142-L146
9,014
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.getSize
public final long getSize(String pid) throws LowlevelStorageException { File file = getFile(pid); return file.length(); }
java
public final long getSize(String pid) throws LowlevelStorageException { File file = getFile(pid); return file.length(); }
[ "public", "final", "long", "getSize", "(", "String", "pid", ")", "throws", "LowlevelStorageException", "{", "File", "file", "=", "getFile", "(", "pid", ")", ";", "return", "file", ".", "length", "(", ")", ";", "}" ]
get size of datastream
[ "get", "size", "of", "datastream" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L149-L152
9,015
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java
Store.remove
public final void remove(String pid) throws LowlevelStorageException { File file = getFile(pid); pathRegistry.remove(pid); fileSystem.delete(file); }
java
public final void remove(String pid) throws LowlevelStorageException { File file = getFile(pid); pathRegistry.remove(pid); fileSystem.delete(file); }
[ "public", "final", "void", "remove", "(", "String", "pid", ")", "throws", "LowlevelStorageException", "{", "File", "file", "=", "getFile", "(", "pid", ")", ";", "pathRegistry", ".", "remove", "(", "pid", ")", ";", "fileSystem", ".", "delete", "(", "file", ")", ";", "}" ]
remove Fedora object from low-level store
[ "remove", "Fedora", "object", "from", "low", "-", "level", "store" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/defaultstore/Store.java#L156-L161
9,016
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyManager.java
PolicyManager.getPolicy
public AbstractPolicy getPolicy(EvaluationCtx eval) throws TopLevelPolicyException, PolicyIndexException { Map<String, AbstractPolicy> potentialPolicies = m_policyIndex.getPolicies(eval, m_policyFinder); logger.debug("Obtained policies: {}", potentialPolicies.size()); AbstractPolicy policy = matchPolicies(eval, potentialPolicies); logger.debug("Matched policies and created abstract policy."); return policy; }
java
public AbstractPolicy getPolicy(EvaluationCtx eval) throws TopLevelPolicyException, PolicyIndexException { Map<String, AbstractPolicy> potentialPolicies = m_policyIndex.getPolicies(eval, m_policyFinder); logger.debug("Obtained policies: {}", potentialPolicies.size()); AbstractPolicy policy = matchPolicies(eval, potentialPolicies); logger.debug("Matched policies and created abstract policy."); return policy; }
[ "public", "AbstractPolicy", "getPolicy", "(", "EvaluationCtx", "eval", ")", "throws", "TopLevelPolicyException", ",", "PolicyIndexException", "{", "Map", "<", "String", ",", "AbstractPolicy", ">", "potentialPolicies", "=", "m_policyIndex", ".", "getPolicies", "(", "eval", ",", "m_policyFinder", ")", ";", "logger", ".", "debug", "(", "\"Obtained policies: {}\"", ",", "potentialPolicies", ".", "size", "(", ")", ")", ";", "AbstractPolicy", "policy", "=", "matchPolicies", "(", "eval", ",", "potentialPolicies", ")", ";", "logger", ".", "debug", "(", "\"Matched policies and created abstract policy.\"", ")", ";", "return", "policy", ";", "}" ]
Obtains a policy or policy set of matching policies from the policy store. If more than one policy is returned it creates a dynamic policy set that contains all the applicable policies. @param eval the Evaluation Context @return the Policy/PolicySet that applies to this EvaluationCtx @throws TopLevelPolicyException @throws PolicyIndexException
[ "Obtains", "a", "policy", "or", "policy", "set", "of", "matching", "policies", "from", "the", "policy", "store", ".", "If", "more", "than", "one", "policy", "is", "returned", "it", "creates", "a", "dynamic", "policy", "set", "that", "contains", "all", "the", "applicable", "policies", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyManager.java#L122-L132
9,017
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyManager.java
PolicyManager.matchPolicies
private AbstractPolicy matchPolicies(EvaluationCtx eval, Map<String, AbstractPolicy> policyList) throws TopLevelPolicyException { // setup a list of matching policies Map<String, AbstractPolicy> list = new HashMap<String, AbstractPolicy>(); // get an iterator over all the identifiers for (String policyId : policyList.keySet()) { AbstractPolicy policy = policyList.get(policyId); MatchResult match = policy.match(eval); int result = match.getResult(); if (result == MatchResult.INDETERMINATE) { throw new TopLevelPolicyException(match.getStatus()); } // if we matched, we keep track of the matching policy... if (result == MatchResult.MATCH) { // ...first checking if this is the first match and if // we automatically nest policies if (m_combiningAlg == null && list.size() > 0) { ArrayList<String> code = new ArrayList<String>(); code.add(Status.STATUS_PROCESSING_ERROR); Status status = new Status(code, "too many applicable" + " top-level policies"); throw new TopLevelPolicyException(status); } if (logger.isDebugEnabled()) { logger.debug("Matched policy: {}", policyId); } list.put(policyId, policy); } } // no errors happened during the search, so now take the right // action based on how many policies we found switch (list.size()) { case 0: return null; case 1: Iterator<AbstractPolicy> i = list.values().iterator(); AbstractPolicy p = i.next(); return p; default: return new PolicySet(parentPolicyId, m_combiningAlg, m_target, new ArrayList<AbstractPolicy>(list .values())); } }
java
private AbstractPolicy matchPolicies(EvaluationCtx eval, Map<String, AbstractPolicy> policyList) throws TopLevelPolicyException { // setup a list of matching policies Map<String, AbstractPolicy> list = new HashMap<String, AbstractPolicy>(); // get an iterator over all the identifiers for (String policyId : policyList.keySet()) { AbstractPolicy policy = policyList.get(policyId); MatchResult match = policy.match(eval); int result = match.getResult(); if (result == MatchResult.INDETERMINATE) { throw new TopLevelPolicyException(match.getStatus()); } // if we matched, we keep track of the matching policy... if (result == MatchResult.MATCH) { // ...first checking if this is the first match and if // we automatically nest policies if (m_combiningAlg == null && list.size() > 0) { ArrayList<String> code = new ArrayList<String>(); code.add(Status.STATUS_PROCESSING_ERROR); Status status = new Status(code, "too many applicable" + " top-level policies"); throw new TopLevelPolicyException(status); } if (logger.isDebugEnabled()) { logger.debug("Matched policy: {}", policyId); } list.put(policyId, policy); } } // no errors happened during the search, so now take the right // action based on how many policies we found switch (list.size()) { case 0: return null; case 1: Iterator<AbstractPolicy> i = list.values().iterator(); AbstractPolicy p = i.next(); return p; default: return new PolicySet(parentPolicyId, m_combiningAlg, m_target, new ArrayList<AbstractPolicy>(list .values())); } }
[ "private", "AbstractPolicy", "matchPolicies", "(", "EvaluationCtx", "eval", ",", "Map", "<", "String", ",", "AbstractPolicy", ">", "policyList", ")", "throws", "TopLevelPolicyException", "{", "// setup a list of matching policies", "Map", "<", "String", ",", "AbstractPolicy", ">", "list", "=", "new", "HashMap", "<", "String", ",", "AbstractPolicy", ">", "(", ")", ";", "// get an iterator over all the identifiers", "for", "(", "String", "policyId", ":", "policyList", ".", "keySet", "(", ")", ")", "{", "AbstractPolicy", "policy", "=", "policyList", ".", "get", "(", "policyId", ")", ";", "MatchResult", "match", "=", "policy", ".", "match", "(", "eval", ")", ";", "int", "result", "=", "match", ".", "getResult", "(", ")", ";", "if", "(", "result", "==", "MatchResult", ".", "INDETERMINATE", ")", "{", "throw", "new", "TopLevelPolicyException", "(", "match", ".", "getStatus", "(", ")", ")", ";", "}", "// if we matched, we keep track of the matching policy...", "if", "(", "result", "==", "MatchResult", ".", "MATCH", ")", "{", "// ...first checking if this is the first match and if", "// we automatically nest policies", "if", "(", "m_combiningAlg", "==", "null", "&&", "list", ".", "size", "(", ")", ">", "0", ")", "{", "ArrayList", "<", "String", ">", "code", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "code", ".", "add", "(", "Status", ".", "STATUS_PROCESSING_ERROR", ")", ";", "Status", "status", "=", "new", "Status", "(", "code", ",", "\"too many applicable\"", "+", "\" top-level policies\"", ")", ";", "throw", "new", "TopLevelPolicyException", "(", "status", ")", ";", "}", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"Matched policy: {}\"", ",", "policyId", ")", ";", "}", "list", ".", "put", "(", "policyId", ",", "policy", ")", ";", "}", "}", "// no errors happened during the search, so now take the right", "// action based on how many policies we found", "switch", "(", "list", ".", "size", "(", ")", ")", "{", "case", "0", ":", "return", "null", ";", "case", "1", ":", "Iterator", "<", "AbstractPolicy", ">", "i", "=", "list", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "AbstractPolicy", "p", "=", "i", ".", "next", "(", ")", ";", "return", "p", ";", "default", ":", "return", "new", "PolicySet", "(", "parentPolicyId", ",", "m_combiningAlg", ",", "m_target", ",", "new", "ArrayList", "<", "AbstractPolicy", ">", "(", "list", ".", "values", "(", ")", ")", ")", ";", "}", "}" ]
Given and Evaluation Context and a list of potential policies, this method matches each policy against the Evaluation Context and extracts only the ones that match. If there is more than one policy, a new dynamic policy set is created and returned. Otherwise the policy that is found is returned. @param eval the Evaluation Context @param policyList the list of policies as a map with PolicyId as key and policy as a byte array as the value @return the Policy/PolicySet that applies to this EvaluationCtx @throws {@link TopLevelPolicyException}
[ "Given", "and", "Evaluation", "Context", "and", "a", "list", "of", "potential", "policies", "this", "method", "matches", "each", "policy", "against", "the", "Evaluation", "Context", "and", "extracts", "only", "the", "ones", "that", "match", ".", "If", "there", "is", "more", "than", "one", "policy", "a", "new", "dynamic", "policy", "set", "is", "created", "and", "returned", ".", "Otherwise", "the", "policy", "that", "is", "found", "is", "returned", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyManager.java#L149-L204
9,018
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/ObjectFormatDialog.java
ObjectFormatDialog.actionPerformed
public void actionPerformed(ActionEvent e) { if (foxml11Button.isSelected()) { fmt_chosen = FOXML1_1.uri; } else if (foxml10Button.isSelected()) { fmt_chosen = FOXML1_0.uri; } else if (mets11Button.isSelected()) { fmt_chosen = METS_EXT1_1.uri; } else if (mets10Button.isSelected()) { fmt_chosen = METS_EXT1_0.uri; } else if (atomButton.isSelected()) { fmt_chosen = ATOM1_1.uri; } else if (atomZipButton.isSelected()) { fmt_chosen = ATOM_ZIP1_1.uri; } }
java
public void actionPerformed(ActionEvent e) { if (foxml11Button.isSelected()) { fmt_chosen = FOXML1_1.uri; } else if (foxml10Button.isSelected()) { fmt_chosen = FOXML1_0.uri; } else if (mets11Button.isSelected()) { fmt_chosen = METS_EXT1_1.uri; } else if (mets10Button.isSelected()) { fmt_chosen = METS_EXT1_0.uri; } else if (atomButton.isSelected()) { fmt_chosen = ATOM1_1.uri; } else if (atomZipButton.isSelected()) { fmt_chosen = ATOM_ZIP1_1.uri; } }
[ "public", "void", "actionPerformed", "(", "ActionEvent", "e", ")", "{", "if", "(", "foxml11Button", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "FOXML1_1", ".", "uri", ";", "}", "else", "if", "(", "foxml10Button", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "FOXML1_0", ".", "uri", ";", "}", "else", "if", "(", "mets11Button", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "METS_EXT1_1", ".", "uri", ";", "}", "else", "if", "(", "mets10Button", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "METS_EXT1_0", ".", "uri", ";", "}", "else", "if", "(", "atomButton", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "ATOM1_1", ".", "uri", ";", "}", "else", "if", "(", "atomZipButton", ".", "isSelected", "(", ")", ")", "{", "fmt_chosen", "=", "ATOM_ZIP1_1", ".", "uri", ";", "}", "}" ]
Listens to the radio buttons.
[ "Listens", "to", "the", "radio", "buttons", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/ObjectFormatDialog.java#L173-L187
9,019
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/TripleGeneratorBase.java
TripleGeneratorBase.getStateResource
protected RDFName getStateResource(String state) throws ResourceIndexException { if (state == null) { throw new ResourceIndexException("State cannot be null"); } else if (state.equals("A")) { return MODEL.ACTIVE; } else if (state.equals("D")) { return MODEL.DELETED; } else if (state.equals("I")) { return MODEL.INACTIVE; } else { throw new ResourceIndexException("Unrecognized state: " + state); } }
java
protected RDFName getStateResource(String state) throws ResourceIndexException { if (state == null) { throw new ResourceIndexException("State cannot be null"); } else if (state.equals("A")) { return MODEL.ACTIVE; } else if (state.equals("D")) { return MODEL.DELETED; } else if (state.equals("I")) { return MODEL.INACTIVE; } else { throw new ResourceIndexException("Unrecognized state: " + state); } }
[ "protected", "RDFName", "getStateResource", "(", "String", "state", ")", "throws", "ResourceIndexException", "{", "if", "(", "state", "==", "null", ")", "{", "throw", "new", "ResourceIndexException", "(", "\"State cannot be null\"", ")", ";", "}", "else", "if", "(", "state", ".", "equals", "(", "\"A\"", ")", ")", "{", "return", "MODEL", ".", "ACTIVE", ";", "}", "else", "if", "(", "state", ".", "equals", "(", "\"D\"", ")", ")", "{", "return", "MODEL", ".", "DELETED", ";", "}", "else", "if", "(", "state", ".", "equals", "(", "\"I\"", ")", ")", "{", "return", "MODEL", ".", "INACTIVE", ";", "}", "else", "{", "throw", "new", "ResourceIndexException", "(", "\"Unrecognized state: \"", "+", "state", ")", ";", "}", "}" ]
Helper methods for creating RDF components
[ "Helper", "methods", "for", "creating", "RDF", "components" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/TripleGeneratorBase.java#L28-L41
9,020
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/TripleGeneratorBase.java
TripleGeneratorBase.add
protected void add(SubjectNode subject, RDFName predicate, ObjectNode object, Set<Triple> set) throws ResourceIndexException { set.add(new SimpleTriple(subject, predicate, object)); }
java
protected void add(SubjectNode subject, RDFName predicate, ObjectNode object, Set<Triple> set) throws ResourceIndexException { set.add(new SimpleTriple(subject, predicate, object)); }
[ "protected", "void", "add", "(", "SubjectNode", "subject", ",", "RDFName", "predicate", ",", "ObjectNode", "object", ",", "Set", "<", "Triple", ">", "set", ")", "throws", "ResourceIndexException", "{", "set", ".", "add", "(", "new", "SimpleTriple", "(", "subject", ",", "predicate", ",", "object", ")", ")", ";", "}" ]
Helper methods for adding triples
[ "Helper", "methods", "for", "adding", "triples" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/TripleGeneratorBase.java#L45-L50
9,021
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/oai/OAIResponder.java
OAIResponder.enc
private static void enc(String in, StringBuilder out) { for (int i = 0; i < in.length(); i++) { enc(in.charAt(i), out); } }
java
private static void enc(String in, StringBuilder out) { for (int i = 0; i < in.length(); i++) { enc(in.charAt(i), out); } }
[ "private", "static", "void", "enc", "(", "String", "in", ",", "StringBuilder", "out", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "in", ".", "length", "(", ")", ";", "i", "++", ")", "{", "enc", "(", "in", ".", "charAt", "(", "i", ")", ",", "out", ")", ";", "}", "}" ]
Appends an XML-appropriate encoding of the given String to the given StringBuffer. @param in The String to encode. @param buf The StringBuffer to write to.
[ "Appends", "an", "XML", "-", "appropriate", "encoding", "of", "the", "given", "String", "to", "the", "given", "StringBuffer", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/oai/OAIResponder.java#L629-L633
9,022
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/oai/OAIResponder.java
OAIResponder.enc
private static void enc(char in, StringBuilder out) { if (in == '&') { out.append("&amp;"); } else if (in == '<') { out.append("&lt;"); } else if (in == '>') { out.append("&gt;"); } else if (in == '\"') { out.append("&quot;"); } else if (in == '\'') { out.append("&apos;"); } else { out.append(in); } }
java
private static void enc(char in, StringBuilder out) { if (in == '&') { out.append("&amp;"); } else if (in == '<') { out.append("&lt;"); } else if (in == '>') { out.append("&gt;"); } else if (in == '\"') { out.append("&quot;"); } else if (in == '\'') { out.append("&apos;"); } else { out.append(in); } }
[ "private", "static", "void", "enc", "(", "char", "in", ",", "StringBuilder", "out", ")", "{", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&amp;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&lt;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&gt;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&quot;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&apos;\"", ")", ";", "}", "else", "{", "out", ".", "append", "(", "in", ")", ";", "}", "}" ]
Appends an XML-appropriate encoding of the given character to the given StringBuffer. @param in The character. @param out The StringBuffer to write to.
[ "Appends", "an", "XML", "-", "appropriate", "encoding", "of", "the", "given", "character", "to", "the", "given", "StringBuffer", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/oai/OAIResponder.java#L644-L658
9,023
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/rebuild/Rebuild.java
Rebuild.getServer
public static Server getServer() throws InitializationException { if (server == null) { server = RebuildServer.getRebuildInstance(new File( Constants.FEDORA_HOME)); } return server; }
java
public static Server getServer() throws InitializationException { if (server == null) { server = RebuildServer.getRebuildInstance(new File( Constants.FEDORA_HOME)); } return server; }
[ "public", "static", "Server", "getServer", "(", ")", "throws", "InitializationException", "{", "if", "(", "server", "==", "null", ")", "{", "server", "=", "RebuildServer", ".", "getRebuildInstance", "(", "new", "File", "(", "Constants", ".", "FEDORA_HOME", ")", ")", ";", "}", "return", "server", ";", "}" ]
Gets the instance of the server appropriate for rebuilding. If no such instance has been initialized yet, initialize one. @return the server instance. @throws InitializationException if initialization fails.
[ "Gets", "the", "instance", "of", "the", "server", "appropriate", "for", "rebuilding", ".", "If", "no", "such", "instance", "has", "been", "initialized", "yet", "initialize", "one", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/rebuild/Rebuild.java#L212-L219
9,024
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/DOReaderCache.java
DOReaderCache.remove
public final void remove(final String pid) { mapLock.lock(); cacheMap.remove(pid); mapLock.unlock(); }
java
public final void remove(final String pid) { mapLock.lock(); cacheMap.remove(pid); mapLock.unlock(); }
[ "public", "final", "void", "remove", "(", "final", "String", "pid", ")", "{", "mapLock", ".", "lock", "(", ")", ";", "cacheMap", ".", "remove", "(", "pid", ")", ";", "mapLock", ".", "unlock", "(", ")", ";", "}" ]
remove an entry from the cache @param pid the entry's pid
[ "remove", "an", "entry", "from", "the", "cache" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/DOReaderCache.java#L99-L103
9,025
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/DOReaderCache.java
DOReaderCache.removeExpired
public final void removeExpired() { mapLock.lock(); Iterator<Entry<String, TimestampedCacheEntry<DOReader>>> entries = cacheMap.entrySet().iterator(); if (entries.hasNext()) { long now = System.currentTimeMillis(); while (entries.hasNext()) { Entry<String, TimestampedCacheEntry<DOReader>> entry = entries.next(); TimestampedCacheEntry<DOReader> e = entry.getValue(); long age = e.ageAt(now); if (age > (maxSeconds * 1000)) { entries.remove(); String pid = entry.getKey(); LOG.debug("removing entry {} after {} milliseconds", pid, age); } } } mapLock.unlock(); }
java
public final void removeExpired() { mapLock.lock(); Iterator<Entry<String, TimestampedCacheEntry<DOReader>>> entries = cacheMap.entrySet().iterator(); if (entries.hasNext()) { long now = System.currentTimeMillis(); while (entries.hasNext()) { Entry<String, TimestampedCacheEntry<DOReader>> entry = entries.next(); TimestampedCacheEntry<DOReader> e = entry.getValue(); long age = e.ageAt(now); if (age > (maxSeconds * 1000)) { entries.remove(); String pid = entry.getKey(); LOG.debug("removing entry {} after {} milliseconds", pid, age); } } } mapLock.unlock(); }
[ "public", "final", "void", "removeExpired", "(", ")", "{", "mapLock", ".", "lock", "(", ")", ";", "Iterator", "<", "Entry", "<", "String", ",", "TimestampedCacheEntry", "<", "DOReader", ">", ">", ">", "entries", "=", "cacheMap", ".", "entrySet", "(", ")", ".", "iterator", "(", ")", ";", "if", "(", "entries", ".", "hasNext", "(", ")", ")", "{", "long", "now", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "while", "(", "entries", ".", "hasNext", "(", ")", ")", "{", "Entry", "<", "String", ",", "TimestampedCacheEntry", "<", "DOReader", ">", ">", "entry", "=", "entries", ".", "next", "(", ")", ";", "TimestampedCacheEntry", "<", "DOReader", ">", "e", "=", "entry", ".", "getValue", "(", ")", ";", "long", "age", "=", "e", ".", "ageAt", "(", "now", ")", ";", "if", "(", "age", ">", "(", "maxSeconds", "*", "1000", ")", ")", "{", "entries", ".", "remove", "(", ")", ";", "String", "pid", "=", "entry", ".", "getKey", "(", ")", ";", "LOG", ".", "debug", "(", "\"removing entry {} after {} milliseconds\"", ",", "pid", ",", "age", ")", ";", "}", "}", "}", "mapLock", ".", "unlock", "(", ")", ";", "}" ]
remove expired entries from the cache
[ "remove", "expired", "entries", "from", "the", "cache" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/DOReaderCache.java#L141-L160
9,026
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/types/MIMETypedStream.java
MIMETypedStream.close
public void close() { if (this.m_stream != null) { try { this.m_stream.close(); this.m_stream = null; } catch (IOException e) { logger.warn("Error closing stream", e); } } }
java
public void close() { if (this.m_stream != null) { try { this.m_stream.close(); this.m_stream = null; } catch (IOException e) { logger.warn("Error closing stream", e); } } }
[ "public", "void", "close", "(", ")", "{", "if", "(", "this", ".", "m_stream", "!=", "null", ")", "{", "try", "{", "this", ".", "m_stream", ".", "close", "(", ")", ";", "this", ".", "m_stream", "=", "null", ";", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "warn", "(", "\"Error closing stream\"", ",", "e", ")", ";", "}", "}", "}" ]
Closes the underlying stream if it's not already closed. In the event of an error, a warning will be logged.
[ "Closes", "the", "underlying", "stream", "if", "it", "s", "not", "already", "closed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/types/MIMETypedStream.java#L118-L127
9,027
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Downloader.java
Downloader.get
public void get(String url, OutputStream out) throws IOException { InputStream in = get(url); StreamUtility.pipeStream(in, out, 4096); }
java
public void get(String url, OutputStream out) throws IOException { InputStream in = get(url); StreamUtility.pipeStream(in, out, 4096); }
[ "public", "void", "get", "(", "String", "url", ",", "OutputStream", "out", ")", "throws", "IOException", "{", "InputStream", "in", "=", "get", "(", "url", ")", ";", "StreamUtility", ".", "pipeStream", "(", "in", ",", "out", ",", "4096", ")", ";", "}" ]
Get data via HTTP and write it to an OutputStream, following redirects, and supplying credentials if the host is the Fedora server.
[ "Get", "data", "via", "HTTP", "and", "write", "it", "to", "an", "OutputStream", "following", "redirects", "and", "supplying", "credentials", "if", "the", "host", "is", "the", "Fedora", "server", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Downloader.java#L128-L131
9,028
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalWriter.java
SingleFileJournalWriter.writeJournalEntry
@Override public void writeJournalEntry(CreatorJournalEntry journalEntry) throws JournalException { try { super.writeJournalEntry(journalEntry, writer); writer.flush(); } catch (XMLStreamException e) { throw new JournalException(e); } }
java
@Override public void writeJournalEntry(CreatorJournalEntry journalEntry) throws JournalException { try { super.writeJournalEntry(journalEntry, writer); writer.flush(); } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "@", "Override", "public", "void", "writeJournalEntry", "(", "CreatorJournalEntry", "journalEntry", ")", "throws", "JournalException", "{", "try", "{", "super", ".", "writeJournalEntry", "(", "journalEntry", ",", "writer", ")", ";", "writer", ".", "flush", "(", ")", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Every journal entry just gets added to the file.
[ "Every", "journal", "entry", "just", "gets", "added", "to", "the", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalWriter.java#L85-L94
9,029
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalWriter.java
SingleFileJournalWriter.shutdown
@Override public void shutdown() throws JournalException { try { if (fileHasHeader) { super.writeDocumentTrailer(writer); } writer.close(); out.close(); } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }
java
@Override public void shutdown() throws JournalException { try { if (fileHasHeader) { super.writeDocumentTrailer(writer); } writer.close(); out.close(); } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }
[ "@", "Override", "public", "void", "shutdown", "(", ")", "throws", "JournalException", "{", "try", "{", "if", "(", "fileHasHeader", ")", "{", "super", ".", "writeDocumentTrailer", "(", "writer", ")", ";", "}", "writer", ".", "close", "(", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Add the document trailer and close the journal file.
[ "Add", "the", "document", "trailer", "and", "close", "the", "journal", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalWriter.java#L99-L112
9,030
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java
ValidatorProcessParameters.parseArgsIntoMap
private Map<String, String> parseArgsIntoMap(String[] args) { Map<String, String> parms = new HashMap<String, String>(); for (int i = 0; i < args.length; i++) { String key = args[i]; if (!isKeyword(key)) { throw new ValidatorProcessUsageException("'" + key + "' is not a keyword."); } if (!ALL_PARAMETERS.contains(key)) { throw new ValidatorProcessUsageException("'" + key + "' is not a recognized keyword."); } if (i >= args.length - 1) { parms.put(key, null); } else { String value = args[i + 1]; if (isKeyword(value)) { parms.put(key, null); } else { parms.put(key, value); i++; } } } return parms; }
java
private Map<String, String> parseArgsIntoMap(String[] args) { Map<String, String> parms = new HashMap<String, String>(); for (int i = 0; i < args.length; i++) { String key = args[i]; if (!isKeyword(key)) { throw new ValidatorProcessUsageException("'" + key + "' is not a keyword."); } if (!ALL_PARAMETERS.contains(key)) { throw new ValidatorProcessUsageException("'" + key + "' is not a recognized keyword."); } if (i >= args.length - 1) { parms.put(key, null); } else { String value = args[i + 1]; if (isKeyword(value)) { parms.put(key, null); } else { parms.put(key, value); i++; } } } return parms; }
[ "private", "Map", "<", "String", ",", "String", ">", "parseArgsIntoMap", "(", "String", "[", "]", "args", ")", "{", "Map", "<", "String", ",", "String", ">", "parms", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "String", "key", "=", "args", "[", "i", "]", ";", "if", "(", "!", "isKeyword", "(", "key", ")", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"'\"", "+", "key", "+", "\"' is not a keyword.\"", ")", ";", "}", "if", "(", "!", "ALL_PARAMETERS", ".", "contains", "(", "key", ")", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"'\"", "+", "key", "+", "\"' is not a recognized keyword.\"", ")", ";", "}", "if", "(", "i", ">=", "args", ".", "length", "-", "1", ")", "{", "parms", ".", "put", "(", "key", ",", "null", ")", ";", "}", "else", "{", "String", "value", "=", "args", "[", "i", "+", "1", "]", ";", "if", "(", "isKeyword", "(", "value", ")", ")", "{", "parms", ".", "put", "(", "key", ",", "null", ")", ";", "}", "else", "{", "parms", ".", "put", "(", "key", ",", "value", ")", ";", "i", "++", ";", "}", "}", "}", "return", "parms", ";", "}" ]
Decide which of the command line arguments are keywords and which are values, and build a map to hold them.
[ "Decide", "which", "of", "the", "command", "line", "arguments", "are", "keywords", "and", "which", "are", "values", "and", "build", "a", "map", "to", "hold", "them", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java#L166-L193
9,031
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java
ValidatorProcessParameters.getRequiredUrlParameter
private URL getRequiredUrlParameter(String keyword, Map<String, String> parms) { String urlString = getRequiredParameter(keyword, parms); try { return new URL(urlString); } catch (MalformedURLException e) { throw new ValidatorProcessUsageException("Value '" + urlString + "' for parameter '" + keyword + "' is not a valid URL: " + e.getMessage()); } }
java
private URL getRequiredUrlParameter(String keyword, Map<String, String> parms) { String urlString = getRequiredParameter(keyword, parms); try { return new URL(urlString); } catch (MalformedURLException e) { throw new ValidatorProcessUsageException("Value '" + urlString + "' for parameter '" + keyword + "' is not a valid URL: " + e.getMessage()); } }
[ "private", "URL", "getRequiredUrlParameter", "(", "String", "keyword", ",", "Map", "<", "String", ",", "String", ">", "parms", ")", "{", "String", "urlString", "=", "getRequiredParameter", "(", "keyword", ",", "parms", ")", ";", "try", "{", "return", "new", "URL", "(", "urlString", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"Value '\"", "+", "urlString", "+", "\"' for parameter '\"", "+", "keyword", "+", "\"' is not a valid URL: \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Get the requested parameter from the map. Complain if not found, or not a valid URL.
[ "Get", "the", "requested", "parameter", "from", "the", "map", ".", "Complain", "if", "not", "found", "or", "not", "a", "valid", "URL", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java#L223-L233
9,032
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java
ValidatorProcessParameters.getOptionalParameter
private String getOptionalParameter(String keyword, Map<String, String> parms) { if (!parms.containsKey(keyword)) { return null; } String value = parms.get(keyword); if (value == null) { throw new ValidatorProcessUsageException("If parameter '" + keyword + "' is provided, it must have a value."); } else { return value; } }
java
private String getOptionalParameter(String keyword, Map<String, String> parms) { if (!parms.containsKey(keyword)) { return null; } String value = parms.get(keyword); if (value == null) { throw new ValidatorProcessUsageException("If parameter '" + keyword + "' is provided, it must have a value."); } else { return value; } }
[ "private", "String", "getOptionalParameter", "(", "String", "keyword", ",", "Map", "<", "String", ",", "String", ">", "parms", ")", "{", "if", "(", "!", "parms", ".", "containsKey", "(", "keyword", ")", ")", "{", "return", "null", ";", "}", "String", "value", "=", "parms", ".", "get", "(", "keyword", ")", ";", "if", "(", "value", "==", "null", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"If parameter '\"", "+", "keyword", "+", "\"' is provided, it must have a value.\"", ")", ";", "}", "else", "{", "return", "value", ";", "}", "}" ]
Get the requested parameter from the map. If it's not there, return null, but if it's there with no value, complain.
[ "Get", "the", "requested", "parameter", "from", "the", "map", ".", "If", "it", "s", "not", "there", "return", "null", "but", "if", "it", "s", "there", "with", "no", "value", "complain", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java#L239-L252
9,033
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java
ValidatorProcessParameters.figureOutIteratorType
private IteratorType figureOutIteratorType(String query, String terms, String pidfileParm) { int howMany = (query == null ? 0 : 1) + (terms == null ? 0 : 1) + (pidfileParm == null ? 0 : 1); if (howMany == 0) { throw new ValidatorProcessUsageException("You must provide " + "either '" + PARAMETER_QUERY + "', '" + PARAMETER_TERMS + "' or '" + PARAMETER_PIDFILE + "'."); } if (howMany > 1) { throw new ValidatorProcessUsageException("You must provide only " + "one of these parameters: '" + PARAMETER_QUERY + "', '" + PARAMETER_TERMS + "' or '" + PARAMETER_PIDFILE + "'."); } return pidfileParm == null ? IteratorType.FS_QUERY : IteratorType.PIDFILE; }
java
private IteratorType figureOutIteratorType(String query, String terms, String pidfileParm) { int howMany = (query == null ? 0 : 1) + (terms == null ? 0 : 1) + (pidfileParm == null ? 0 : 1); if (howMany == 0) { throw new ValidatorProcessUsageException("You must provide " + "either '" + PARAMETER_QUERY + "', '" + PARAMETER_TERMS + "' or '" + PARAMETER_PIDFILE + "'."); } if (howMany > 1) { throw new ValidatorProcessUsageException("You must provide only " + "one of these parameters: '" + PARAMETER_QUERY + "', '" + PARAMETER_TERMS + "' or '" + PARAMETER_PIDFILE + "'."); } return pidfileParm == null ? IteratorType.FS_QUERY : IteratorType.PIDFILE; }
[ "private", "IteratorType", "figureOutIteratorType", "(", "String", "query", ",", "String", "terms", ",", "String", "pidfileParm", ")", "{", "int", "howMany", "=", "(", "query", "==", "null", "?", "0", ":", "1", ")", "+", "(", "terms", "==", "null", "?", "0", ":", "1", ")", "+", "(", "pidfileParm", "==", "null", "?", "0", ":", "1", ")", ";", "if", "(", "howMany", "==", "0", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"You must provide \"", "+", "\"either '\"", "+", "PARAMETER_QUERY", "+", "\"', '\"", "+", "PARAMETER_TERMS", "+", "\"' or '\"", "+", "PARAMETER_PIDFILE", "+", "\"'.\"", ")", ";", "}", "if", "(", "howMany", ">", "1", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"You must provide only \"", "+", "\"one of these parameters: '\"", "+", "PARAMETER_QUERY", "+", "\"', '\"", "+", "PARAMETER_TERMS", "+", "\"' or '\"", "+", "PARAMETER_PIDFILE", "+", "\"'.\"", ")", ";", "}", "return", "pidfileParm", "==", "null", "?", "IteratorType", ".", "FS_QUERY", ":", "IteratorType", ".", "PIDFILE", ";", "}" ]
Look at the parameters. Is this a query-based request or a pidfile-based request? If we put in too many parms, or not enough, that's a problem.
[ "Look", "at", "the", "parameters", ".", "Is", "this", "a", "query", "-", "based", "request", "or", "a", "pidfile", "-", "based", "request?", "If", "we", "put", "in", "too", "many", "parms", "or", "not", "enough", "that", "s", "a", "problem", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java#L258-L277
9,034
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java
ValidatorProcessParameters.assemblePidfile
private File assemblePidfile(String pidfileParm) { File pidfile = new File(pidfileParm); if (!pidfile.exists()) { throw new ValidatorProcessUsageException("-pidfile does not exist: '" + pidfileParm + "'"); } if (!pidfile.canRead()) { throw new ValidatorProcessUsageException("-pidfile is not readable: '" + pidfileParm + "'"); } return pidfile; }
java
private File assemblePidfile(String pidfileParm) { File pidfile = new File(pidfileParm); if (!pidfile.exists()) { throw new ValidatorProcessUsageException("-pidfile does not exist: '" + pidfileParm + "'"); } if (!pidfile.canRead()) { throw new ValidatorProcessUsageException("-pidfile is not readable: '" + pidfileParm + "'"); } return pidfile; }
[ "private", "File", "assemblePidfile", "(", "String", "pidfileParm", ")", "{", "File", "pidfile", "=", "new", "File", "(", "pidfileParm", ")", ";", "if", "(", "!", "pidfile", ".", "exists", "(", ")", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"-pidfile does not exist: '\"", "+", "pidfileParm", "+", "\"'\"", ")", ";", "}", "if", "(", "!", "pidfile", ".", "canRead", "(", ")", ")", "{", "throw", "new", "ValidatorProcessUsageException", "(", "\"-pidfile is not readable: '\"", "+", "pidfileParm", "+", "\"'\"", ")", ";", "}", "return", "pidfile", ";", "}" ]
Is there a valid file out there for this parm? We already know that the parms is not null.
[ "Is", "there", "a", "valid", "file", "out", "there", "for", "this", "parm?", "We", "already", "know", "that", "the", "parms", "is", "not", "null", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/process/ValidatorProcessParameters.java#L301-L312
9,035
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/SwingWorker.java
SwingWorker.interrupt
public void interrupt() { Thread t = threadVar.get(); if (t != null) { t.interrupt(); } threadVar.clear(); }
java
public void interrupt() { Thread t = threadVar.get(); if (t != null) { t.interrupt(); } threadVar.clear(); }
[ "public", "void", "interrupt", "(", ")", "{", "Thread", "t", "=", "threadVar", ".", "get", "(", ")", ";", "if", "(", "t", "!=", "null", ")", "{", "t", ".", "interrupt", "(", ")", ";", "}", "threadVar", ".", "clear", "(", ")", ";", "}" ]
A new method that interrupts the worker thread. Call this method to force the worker to stop what it's doing.
[ "A", "new", "method", "that", "interrupts", "the", "worker", "thread", ".", "Call", "this", "method", "to", "force", "the", "worker", "to", "stop", "what", "it", "s", "doing", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/SwingWorker.java#L83-L89
9,036
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/TypeUtility.java
TypeUtility.convertMIMETypedStreamToGenMIMETypedStreamMTOM
public static org.fcrepo.server.types.mtom.gen.MIMETypedStream convertMIMETypedStreamToGenMIMETypedStreamMTOM(org.fcrepo.server.storage.types.MIMETypedStream mimeTypedStream) { if (mimeTypedStream != null) { org.fcrepo.server.types.mtom.gen.MIMETypedStream genMIMETypedStream = new org.fcrepo.server.types.mtom.gen.MIMETypedStream(); genMIMETypedStream.setMIMEType(mimeTypedStream.getMIMEType()); org.fcrepo.server.storage.types.Property[] header = mimeTypedStream.header; org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header head = new org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header(); if (header != null) { for (org.fcrepo.server.storage.types.Property property : header) { head.getProperty() .add(convertPropertyToGenProperty(property)); } } genMIMETypedStream.setHeader(head); InputStreamDataSource ds = new InputStreamDataSource(mimeTypedStream.getStream(), mimeTypedStream.getMIMEType()); genMIMETypedStream .setStream(new DataHandler(ds)); return genMIMETypedStream; } else { return null; } }
java
public static org.fcrepo.server.types.mtom.gen.MIMETypedStream convertMIMETypedStreamToGenMIMETypedStreamMTOM(org.fcrepo.server.storage.types.MIMETypedStream mimeTypedStream) { if (mimeTypedStream != null) { org.fcrepo.server.types.mtom.gen.MIMETypedStream genMIMETypedStream = new org.fcrepo.server.types.mtom.gen.MIMETypedStream(); genMIMETypedStream.setMIMEType(mimeTypedStream.getMIMEType()); org.fcrepo.server.storage.types.Property[] header = mimeTypedStream.header; org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header head = new org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header(); if (header != null) { for (org.fcrepo.server.storage.types.Property property : header) { head.getProperty() .add(convertPropertyToGenProperty(property)); } } genMIMETypedStream.setHeader(head); InputStreamDataSource ds = new InputStreamDataSource(mimeTypedStream.getStream(), mimeTypedStream.getMIMEType()); genMIMETypedStream .setStream(new DataHandler(ds)); return genMIMETypedStream; } else { return null; } }
[ "public", "static", "org", ".", "fcrepo", ".", "server", ".", "types", ".", "mtom", ".", "gen", ".", "MIMETypedStream", "convertMIMETypedStreamToGenMIMETypedStreamMTOM", "(", "org", ".", "fcrepo", ".", "server", ".", "storage", ".", "types", ".", "MIMETypedStream", "mimeTypedStream", ")", "{", "if", "(", "mimeTypedStream", "!=", "null", ")", "{", "org", ".", "fcrepo", ".", "server", ".", "types", ".", "mtom", ".", "gen", ".", "MIMETypedStream", "genMIMETypedStream", "=", "new", "org", ".", "fcrepo", ".", "server", ".", "types", ".", "mtom", ".", "gen", ".", "MIMETypedStream", "(", ")", ";", "genMIMETypedStream", ".", "setMIMEType", "(", "mimeTypedStream", ".", "getMIMEType", "(", ")", ")", ";", "org", ".", "fcrepo", ".", "server", ".", "storage", ".", "types", ".", "Property", "[", "]", "header", "=", "mimeTypedStream", ".", "header", ";", "org", ".", "fcrepo", ".", "server", ".", "types", ".", "mtom", ".", "gen", ".", "MIMETypedStream", ".", "Header", "head", "=", "new", "org", ".", "fcrepo", ".", "server", ".", "types", ".", "mtom", ".", "gen", ".", "MIMETypedStream", ".", "Header", "(", ")", ";", "if", "(", "header", "!=", "null", ")", "{", "for", "(", "org", ".", "fcrepo", ".", "server", ".", "storage", ".", "types", ".", "Property", "property", ":", "header", ")", "{", "head", ".", "getProperty", "(", ")", ".", "add", "(", "convertPropertyToGenProperty", "(", "property", ")", ")", ";", "}", "}", "genMIMETypedStream", ".", "setHeader", "(", "head", ")", ";", "InputStreamDataSource", "ds", "=", "new", "InputStreamDataSource", "(", "mimeTypedStream", ".", "getStream", "(", ")", ",", "mimeTypedStream", ".", "getMIMEType", "(", ")", ")", ";", "genMIMETypedStream", ".", "setStream", "(", "new", "DataHandler", "(", "ds", ")", ")", ";", "return", "genMIMETypedStream", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
the standard and MTOM implementations
[ "the", "standard", "and", "MTOM", "implementations" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/TypeUtility.java#L312-L337
9,037
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java
GSearchDOManager.postInitModule
@Override public void postInitModule() throws ModuleInitializationException { super.postInitModule(); // validate required param: GSEARCH_REST_URL _gSearchRESTURL = getParameter(GSEARCH_REST_URL); if (_gSearchRESTURL == null) { throw new ModuleInitializationException("Required parameter, " + GSEARCH_REST_URL + " was not specified", getRole()); } else { try { new URL(_gSearchRESTURL); logger.debug("Configured GSearch REST URL: " + _gSearchRESTURL); } catch (MalformedURLException e) { throw new ModuleInitializationException("Malformed URL given " + "for " + GSEARCH_REST_URL + " parameter: " + _gSearchRESTURL, getRole()); } } // validate credentials: if GSEARCH_USERNAME is given, GSEARCH_PASSWORD // should also be. String user = getParameter(GSEARCH_USERNAME); if (user != null) { logger.debug("Will authenticate to GSearch service as user: " + user); String pass = getParameter(GSEARCH_PASSWORD); if (pass != null) { _gSearchCredentials = new UsernamePasswordCredentials(user, pass); } else { throw new ModuleInitializationException(GSEARCH_PASSWORD + " must be specified because " + GSEARCH_USERNAME + " was specified", getRole()); } } else { logger.debug(GSEARCH_USERNAME + " unspecified; will not attempt " + "to authenticate to GSearch service"); } // finally, init the http client we'll use _webClientConfig = getServer().getWebClientConfig(); _webClient = new WebClient(_webClientConfig); }
java
@Override public void postInitModule() throws ModuleInitializationException { super.postInitModule(); // validate required param: GSEARCH_REST_URL _gSearchRESTURL = getParameter(GSEARCH_REST_URL); if (_gSearchRESTURL == null) { throw new ModuleInitializationException("Required parameter, " + GSEARCH_REST_URL + " was not specified", getRole()); } else { try { new URL(_gSearchRESTURL); logger.debug("Configured GSearch REST URL: " + _gSearchRESTURL); } catch (MalformedURLException e) { throw new ModuleInitializationException("Malformed URL given " + "for " + GSEARCH_REST_URL + " parameter: " + _gSearchRESTURL, getRole()); } } // validate credentials: if GSEARCH_USERNAME is given, GSEARCH_PASSWORD // should also be. String user = getParameter(GSEARCH_USERNAME); if (user != null) { logger.debug("Will authenticate to GSearch service as user: " + user); String pass = getParameter(GSEARCH_PASSWORD); if (pass != null) { _gSearchCredentials = new UsernamePasswordCredentials(user, pass); } else { throw new ModuleInitializationException(GSEARCH_PASSWORD + " must be specified because " + GSEARCH_USERNAME + " was specified", getRole()); } } else { logger.debug(GSEARCH_USERNAME + " unspecified; will not attempt " + "to authenticate to GSearch service"); } // finally, init the http client we'll use _webClientConfig = getServer().getWebClientConfig(); _webClient = new WebClient(_webClientConfig); }
[ "@", "Override", "public", "void", "postInitModule", "(", ")", "throws", "ModuleInitializationException", "{", "super", ".", "postInitModule", "(", ")", ";", "// validate required param: GSEARCH_REST_URL", "_gSearchRESTURL", "=", "getParameter", "(", "GSEARCH_REST_URL", ")", ";", "if", "(", "_gSearchRESTURL", "==", "null", ")", "{", "throw", "new", "ModuleInitializationException", "(", "\"Required parameter, \"", "+", "GSEARCH_REST_URL", "+", "\" was not specified\"", ",", "getRole", "(", ")", ")", ";", "}", "else", "{", "try", "{", "new", "URL", "(", "_gSearchRESTURL", ")", ";", "logger", ".", "debug", "(", "\"Configured GSearch REST URL: \"", "+", "_gSearchRESTURL", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "throw", "new", "ModuleInitializationException", "(", "\"Malformed URL given \"", "+", "\"for \"", "+", "GSEARCH_REST_URL", "+", "\" parameter: \"", "+", "_gSearchRESTURL", ",", "getRole", "(", ")", ")", ";", "}", "}", "// validate credentials: if GSEARCH_USERNAME is given, GSEARCH_PASSWORD", "// should also be.", "String", "user", "=", "getParameter", "(", "GSEARCH_USERNAME", ")", ";", "if", "(", "user", "!=", "null", ")", "{", "logger", ".", "debug", "(", "\"Will authenticate to GSearch service as user: \"", "+", "user", ")", ";", "String", "pass", "=", "getParameter", "(", "GSEARCH_PASSWORD", ")", ";", "if", "(", "pass", "!=", "null", ")", "{", "_gSearchCredentials", "=", "new", "UsernamePasswordCredentials", "(", "user", ",", "pass", ")", ";", "}", "else", "{", "throw", "new", "ModuleInitializationException", "(", "GSEARCH_PASSWORD", "+", "\" must be specified because \"", "+", "GSEARCH_USERNAME", "+", "\" was specified\"", ",", "getRole", "(", ")", ")", ";", "}", "}", "else", "{", "logger", ".", "debug", "(", "GSEARCH_USERNAME", "+", "\" unspecified; will not attempt \"", "+", "\"to authenticate to GSearch service\"", ")", ";", "}", "// finally, init the http client we'll use", "_webClientConfig", "=", "getServer", "(", ")", ".", "getWebClientConfig", "(", ")", ";", "_webClient", "=", "new", "WebClient", "(", "_webClientConfig", ")", ";", "}" ]
Performs superclass post-initialization, then completes initialization using GSearch-specific parameters.
[ "Performs", "superclass", "post", "-", "initialization", "then", "completes", "initialization", "using", "GSearch", "-", "specific", "parameters", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java#L100-L143
9,038
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java
GSearchDOManager.doCommit
@Override public void doCommit(boolean cachedObjectRequired, Context context, DigitalObject obj, String logMessage, boolean remove) throws ServerException { super.doCommit(cachedObjectRequired, context, obj, logMessage, remove); // determine the url we need to invoke StringBuffer url = new StringBuffer(); url.append(_gSearchRESTURL + "?operation=updateIndex"); String pid = obj.getPid(); url.append("&value=" + urlEncode(pid)); if (remove) { logger.info("Signaling removal of {} to GSearch", pid); url.append("&action=deletePid"); } else { if (logger.isInfoEnabled()) { if (obj.isNew()) { logger.info("Signaling add of {} to GSearch", pid); } else { logger.info("Signaling mod of {} to GSearch", pid); } } url.append("&action=fromPid"); } // send the signal sendRESTMessage(url.toString()); }
java
@Override public void doCommit(boolean cachedObjectRequired, Context context, DigitalObject obj, String logMessage, boolean remove) throws ServerException { super.doCommit(cachedObjectRequired, context, obj, logMessage, remove); // determine the url we need to invoke StringBuffer url = new StringBuffer(); url.append(_gSearchRESTURL + "?operation=updateIndex"); String pid = obj.getPid(); url.append("&value=" + urlEncode(pid)); if (remove) { logger.info("Signaling removal of {} to GSearch", pid); url.append("&action=deletePid"); } else { if (logger.isInfoEnabled()) { if (obj.isNew()) { logger.info("Signaling add of {} to GSearch", pid); } else { logger.info("Signaling mod of {} to GSearch", pid); } } url.append("&action=fromPid"); } // send the signal sendRESTMessage(url.toString()); }
[ "@", "Override", "public", "void", "doCommit", "(", "boolean", "cachedObjectRequired", ",", "Context", "context", ",", "DigitalObject", "obj", ",", "String", "logMessage", ",", "boolean", "remove", ")", "throws", "ServerException", "{", "super", ".", "doCommit", "(", "cachedObjectRequired", ",", "context", ",", "obj", ",", "logMessage", ",", "remove", ")", ";", "// determine the url we need to invoke", "StringBuffer", "url", "=", "new", "StringBuffer", "(", ")", ";", "url", ".", "append", "(", "_gSearchRESTURL", "+", "\"?operation=updateIndex\"", ")", ";", "String", "pid", "=", "obj", ".", "getPid", "(", ")", ";", "url", ".", "append", "(", "\"&value=\"", "+", "urlEncode", "(", "pid", ")", ")", ";", "if", "(", "remove", ")", "{", "logger", ".", "info", "(", "\"Signaling removal of {} to GSearch\"", ",", "pid", ")", ";", "url", ".", "append", "(", "\"&action=deletePid\"", ")", ";", "}", "else", "{", "if", "(", "logger", ".", "isInfoEnabled", "(", ")", ")", "{", "if", "(", "obj", ".", "isNew", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Signaling add of {} to GSearch\"", ",", "pid", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"Signaling mod of {} to GSearch\"", ",", "pid", ")", ";", "}", "}", "url", ".", "append", "(", "\"&action=fromPid\"", ")", ";", "}", "// send the signal", "sendRESTMessage", "(", "url", ".", "toString", "(", ")", ")", ";", "}" ]
Commits the changes to the given object as usual, then attempts to propagate the change to the GSearch service.
[ "Commits", "the", "changes", "to", "the", "given", "object", "as", "usual", "then", "attempts", "to", "propagate", "the", "change", "to", "the", "GSearch", "service", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java#L149-L179
9,039
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java
GSearchDOManager.sendRESTMessage
private void sendRESTMessage(String url) { HttpInputStream response = null; try { logger.debug("Getting " + url); response = _webClient.get(url, false, _gSearchCredentials); int code = response.getStatusCode(); if (code != 200) { logger.warn("Error sending update to GSearch service (url=" + url + "). HTTP response code was " + code + ". " + "Body of response from GSearch follows:\n" + getString(response)); } } catch (Exception e) { logger.warn("Error sending update to GSearch service via URL: " + url, e); } finally { if (response != null) { try { response.close(); } catch (Exception e) { logger.warn("Error closing GSearch response", e); } } } }
java
private void sendRESTMessage(String url) { HttpInputStream response = null; try { logger.debug("Getting " + url); response = _webClient.get(url, false, _gSearchCredentials); int code = response.getStatusCode(); if (code != 200) { logger.warn("Error sending update to GSearch service (url=" + url + "). HTTP response code was " + code + ". " + "Body of response from GSearch follows:\n" + getString(response)); } } catch (Exception e) { logger.warn("Error sending update to GSearch service via URL: " + url, e); } finally { if (response != null) { try { response.close(); } catch (Exception e) { logger.warn("Error closing GSearch response", e); } } } }
[ "private", "void", "sendRESTMessage", "(", "String", "url", ")", "{", "HttpInputStream", "response", "=", "null", ";", "try", "{", "logger", ".", "debug", "(", "\"Getting \"", "+", "url", ")", ";", "response", "=", "_webClient", ".", "get", "(", "url", ",", "false", ",", "_gSearchCredentials", ")", ";", "int", "code", "=", "response", ".", "getStatusCode", "(", ")", ";", "if", "(", "code", "!=", "200", ")", "{", "logger", ".", "warn", "(", "\"Error sending update to GSearch service (url=\"", "+", "url", "+", "\"). HTTP response code was \"", "+", "code", "+", "\". \"", "+", "\"Body of response from GSearch follows:\\n\"", "+", "getString", "(", "response", ")", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "\"Error sending update to GSearch service via URL: \"", "+", "url", ",", "e", ")", ";", "}", "finally", "{", "if", "(", "response", "!=", "null", ")", "{", "try", "{", "response", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "\"Error closing GSearch response\"", ",", "e", ")", ";", "}", "}", "}", "}" ]
Performs the given HTTP request, logging a warning if we don't get a 200 OK response.
[ "Performs", "the", "given", "HTTP", "request", "logging", "a", "warning", "if", "we", "don", "t", "get", "a", "200", "OK", "response", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java#L189-L213
9,040
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java
GSearchDOManager.getString
private static String getString(InputStream in) { try { StringBuffer out = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); while (line != null) { out.append(line + "\n"); line = reader.readLine(); } return out.toString(); } catch (Exception e) { return "[Error reading response body: " + e.getClass().getName() + ": " + e.getMessage() + "]"; } }
java
private static String getString(InputStream in) { try { StringBuffer out = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); while (line != null) { out.append(line + "\n"); line = reader.readLine(); } return out.toString(); } catch (Exception e) { return "[Error reading response body: " + e.getClass().getName() + ": " + e.getMessage() + "]"; } }
[ "private", "static", "String", "getString", "(", "InputStream", "in", ")", "{", "try", "{", "StringBuffer", "out", "=", "new", "StringBuffer", "(", ")", ";", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "in", ")", ")", ";", "String", "line", "=", "reader", ".", "readLine", "(", ")", ";", "while", "(", "line", "!=", "null", ")", "{", "out", ".", "append", "(", "line", "+", "\"\\n\"", ")", ";", "line", "=", "reader", ".", "readLine", "(", ")", ";", "}", "return", "out", ".", "toString", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "\"[Error reading response body: \"", "+", "e", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", "+", "\"]\"", ";", "}", "}" ]
Read the remainder of the given stream as a String and return it, or an error message if we encounter an error.
[ "Read", "the", "remainder", "of", "the", "given", "stream", "as", "a", "String", "and", "return", "it", "or", "an", "error", "message", "if", "we", "encounter", "an", "error", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java#L219-L234
9,041
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java
GSearchDOManager.urlEncode
private static final String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); } catch (Exception e) { logger.warn("Failed to encode '" + s + "'", e); return s; } }
java
private static final String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); } catch (Exception e) { logger.warn("Failed to encode '" + s + "'", e); return s; } }
[ "private", "static", "final", "String", "urlEncode", "(", "String", "s", ")", "{", "try", "{", "return", "URLEncoder", ".", "encode", "(", "s", ",", "\"UTF-8\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "\"Failed to encode '\"", "+", "s", "+", "\"'\"", ",", "e", ")", ";", "return", "s", ";", "}", "}" ]
URL-encode the given string using UTF-8 encoding.
[ "URL", "-", "encode", "the", "given", "string", "using", "UTF", "-", "8", "encoding", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/GSearchDOManager.java#L239-L246
9,042
fcrepo3/fcrepo
fcrepo-installer/src/main/java/org/fcrepo/utilities/install/FedoraHome.java
FedoraHome.unpack
private void unpack() throws InstallationFailedException { System.out.println("Preparing FEDORA_HOME..."); if (!_installDir.exists() && !_installDir.mkdirs()) { throw new InstallationFailedException( "Unable to create FEDORA_HOME: " + _installDir.getAbsolutePath()); } if (!_installDir.isDirectory()) { throw new InstallationFailedException(_installDir.getAbsolutePath() + " is not a directory"); } try { Zip.unzip(_dist.get(Distribution.FEDORA_HOME), _installDir); setScriptsExecutable(new File(_installDir, "client" + File.separator + "bin")); File serverDir = new File(_installDir, "server"); if (_clientOnlyInstall) { FileUtils.delete(serverDir); } else { setScriptsExecutable(new File(serverDir, "bin")); } } catch (IOException e) { throw new InstallationFailedException(e.getMessage(), e); } }
java
private void unpack() throws InstallationFailedException { System.out.println("Preparing FEDORA_HOME..."); if (!_installDir.exists() && !_installDir.mkdirs()) { throw new InstallationFailedException( "Unable to create FEDORA_HOME: " + _installDir.getAbsolutePath()); } if (!_installDir.isDirectory()) { throw new InstallationFailedException(_installDir.getAbsolutePath() + " is not a directory"); } try { Zip.unzip(_dist.get(Distribution.FEDORA_HOME), _installDir); setScriptsExecutable(new File(_installDir, "client" + File.separator + "bin")); File serverDir = new File(_installDir, "server"); if (_clientOnlyInstall) { FileUtils.delete(serverDir); } else { setScriptsExecutable(new File(serverDir, "bin")); } } catch (IOException e) { throw new InstallationFailedException(e.getMessage(), e); } }
[ "private", "void", "unpack", "(", ")", "throws", "InstallationFailedException", "{", "System", ".", "out", ".", "println", "(", "\"Preparing FEDORA_HOME...\"", ")", ";", "if", "(", "!", "_installDir", ".", "exists", "(", ")", "&&", "!", "_installDir", ".", "mkdirs", "(", ")", ")", "{", "throw", "new", "InstallationFailedException", "(", "\"Unable to create FEDORA_HOME: \"", "+", "_installDir", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "if", "(", "!", "_installDir", ".", "isDirectory", "(", ")", ")", "{", "throw", "new", "InstallationFailedException", "(", "_installDir", ".", "getAbsolutePath", "(", ")", "+", "\" is not a directory\"", ")", ";", "}", "try", "{", "Zip", ".", "unzip", "(", "_dist", ".", "get", "(", "Distribution", ".", "FEDORA_HOME", ")", ",", "_installDir", ")", ";", "setScriptsExecutable", "(", "new", "File", "(", "_installDir", ",", "\"client\"", "+", "File", ".", "separator", "+", "\"bin\"", ")", ")", ";", "File", "serverDir", "=", "new", "File", "(", "_installDir", ",", "\"server\"", ")", ";", "if", "(", "_clientOnlyInstall", ")", "{", "FileUtils", ".", "delete", "(", "serverDir", ")", ";", "}", "else", "{", "setScriptsExecutable", "(", "new", "File", "(", "serverDir", ",", "\"bin\"", ")", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "InstallationFailedException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Unpacks the contents of the FEDORA_HOME directory from the Distribution. @throws InstallationFailedException
[ "Unpacks", "the", "contents", "of", "the", "FEDORA_HOME", "directory", "from", "the", "Distribution", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-installer/src/main/java/org/fcrepo/utilities/install/FedoraHome.java#L78-L104
9,043
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java
Zip.zip
public static void zip(File destination, File[] source) throws FileNotFoundException, IOException { FileOutputStream dest = new FileOutputStream(destination); ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(dest)); for (File element : source) { zip(null, element, zout); } zout.close(); }
java
public static void zip(File destination, File[] source) throws FileNotFoundException, IOException { FileOutputStream dest = new FileOutputStream(destination); ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(dest)); for (File element : source) { zip(null, element, zout); } zout.close(); }
[ "public", "static", "void", "zip", "(", "File", "destination", ",", "File", "[", "]", "source", ")", "throws", "FileNotFoundException", ",", "IOException", "{", "FileOutputStream", "dest", "=", "new", "FileOutputStream", "(", "destination", ")", ";", "ZipOutputStream", "zout", "=", "new", "ZipOutputStream", "(", "new", "BufferedOutputStream", "(", "dest", ")", ")", ";", "for", "(", "File", "element", ":", "source", ")", "{", "zip", "(", "null", ",", "element", ",", "zout", ")", ";", "}", "zout", ".", "close", "(", ")", ";", "}" ]
Create a zip file. @param destination The zip file to create. @param source The File array to be zipped. @throws FileNotFoundException @throws IOException
[ "Create", "a", "zip", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java#L55-L64
9,044
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java
Zip.extractFile
public static void extractFile(File zipFile, String entryName, File destination) throws IOException { ZipFile zip = new ZipFile(zipFile); try { ZipEntry entry = zip.getEntry(entryName); if (entry != null) { // Get an input stream for the entry. InputStream entryStream = zip.getInputStream(entry); try { // Create the output file File parent = destination.getParentFile(); if (parent != null) { parent.mkdirs(); } FileOutputStream file = new FileOutputStream(destination); try { // Allocate a buffer for reading the entry data. byte[] data = new byte[BUFFER]; int bytesRead; // Read the entry data and write it to the output file. while ((bytesRead = entryStream.read(data)) != -1) { file.write(data, 0, bytesRead); } } finally { file.close(); } } finally { entryStream.close(); } } else { throw new IOException(zipFile.getName() + " does not contain: " + entryName); } } finally { zip.close(); } }
java
public static void extractFile(File zipFile, String entryName, File destination) throws IOException { ZipFile zip = new ZipFile(zipFile); try { ZipEntry entry = zip.getEntry(entryName); if (entry != null) { // Get an input stream for the entry. InputStream entryStream = zip.getInputStream(entry); try { // Create the output file File parent = destination.getParentFile(); if (parent != null) { parent.mkdirs(); } FileOutputStream file = new FileOutputStream(destination); try { // Allocate a buffer for reading the entry data. byte[] data = new byte[BUFFER]; int bytesRead; // Read the entry data and write it to the output file. while ((bytesRead = entryStream.read(data)) != -1) { file.write(data, 0, bytesRead); } } finally { file.close(); } } finally { entryStream.close(); } } else { throw new IOException(zipFile.getName() + " does not contain: " + entryName); } } finally { zip.close(); } }
[ "public", "static", "void", "extractFile", "(", "File", "zipFile", ",", "String", "entryName", ",", "File", "destination", ")", "throws", "IOException", "{", "ZipFile", "zip", "=", "new", "ZipFile", "(", "zipFile", ")", ";", "try", "{", "ZipEntry", "entry", "=", "zip", ".", "getEntry", "(", "entryName", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "// Get an input stream for the entry.", "InputStream", "entryStream", "=", "zip", ".", "getInputStream", "(", "entry", ")", ";", "try", "{", "// Create the output file", "File", "parent", "=", "destination", ".", "getParentFile", "(", ")", ";", "if", "(", "parent", "!=", "null", ")", "{", "parent", ".", "mkdirs", "(", ")", ";", "}", "FileOutputStream", "file", "=", "new", "FileOutputStream", "(", "destination", ")", ";", "try", "{", "// Allocate a buffer for reading the entry data.", "byte", "[", "]", "data", "=", "new", "byte", "[", "BUFFER", "]", ";", "int", "bytesRead", ";", "// Read the entry data and write it to the output file.", "while", "(", "(", "bytesRead", "=", "entryStream", ".", "read", "(", "data", ")", ")", "!=", "-", "1", ")", "{", "file", ".", "write", "(", "data", ",", "0", ",", "bytesRead", ")", ";", "}", "}", "finally", "{", "file", ".", "close", "(", ")", ";", "}", "}", "finally", "{", "entryStream", ".", "close", "(", ")", ";", "}", "}", "else", "{", "throw", "new", "IOException", "(", "zipFile", ".", "getName", "(", ")", "+", "\" does not contain: \"", "+", "entryName", ")", ";", "}", "}", "finally", "{", "zip", ".", "close", "(", ")", ";", "}", "}" ]
Extracts the file given by entryName to destination. @param zipFile @param entryName @param destination The extracted destination File. @throws IOException
[ "Extracts", "the", "file", "given", "by", "entryName", "to", "destination", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java#L75-L117
9,045
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java
Zip.unzip
public static void unzip(InputStream is, File destDir) throws FileNotFoundException, IOException { BufferedOutputStream dest = null; ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { //System.out.println("Extracting: " + entry); if (entry.isDirectory()) { // Otherwise, empty directories do not get created (new File(destDir, entry.getName())).mkdirs(); } else { File f = new File(destDir, entry.getName()); f.getParentFile().mkdirs(); int count; byte data[] = new byte[BUFFER]; // write the files to the disk FileOutputStream fos = new FileOutputStream(f); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } } zis.close(); }
java
public static void unzip(InputStream is, File destDir) throws FileNotFoundException, IOException { BufferedOutputStream dest = null; ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { //System.out.println("Extracting: " + entry); if (entry.isDirectory()) { // Otherwise, empty directories do not get created (new File(destDir, entry.getName())).mkdirs(); } else { File f = new File(destDir, entry.getName()); f.getParentFile().mkdirs(); int count; byte data[] = new byte[BUFFER]; // write the files to the disk FileOutputStream fos = new FileOutputStream(f); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } } zis.close(); }
[ "public", "static", "void", "unzip", "(", "InputStream", "is", ",", "File", "destDir", ")", "throws", "FileNotFoundException", ",", "IOException", "{", "BufferedOutputStream", "dest", "=", "null", ";", "ZipInputStream", "zis", "=", "new", "ZipInputStream", "(", "new", "BufferedInputStream", "(", "is", ")", ")", ";", "ZipEntry", "entry", ";", "while", "(", "(", "entry", "=", "zis", ".", "getNextEntry", "(", ")", ")", "!=", "null", ")", "{", "//System.out.println(\"Extracting: \" + entry);", "if", "(", "entry", ".", "isDirectory", "(", ")", ")", "{", "// Otherwise, empty directories do not get created", "(", "new", "File", "(", "destDir", ",", "entry", ".", "getName", "(", ")", ")", ")", ".", "mkdirs", "(", ")", ";", "}", "else", "{", "File", "f", "=", "new", "File", "(", "destDir", ",", "entry", ".", "getName", "(", ")", ")", ";", "f", ".", "getParentFile", "(", ")", ".", "mkdirs", "(", ")", ";", "int", "count", ";", "byte", "data", "[", "]", "=", "new", "byte", "[", "BUFFER", "]", ";", "// write the files to the disk", "FileOutputStream", "fos", "=", "new", "FileOutputStream", "(", "f", ")", ";", "dest", "=", "new", "BufferedOutputStream", "(", "fos", ",", "BUFFER", ")", ";", "while", "(", "(", "count", "=", "zis", ".", "read", "(", "data", ",", "0", ",", "BUFFER", ")", ")", "!=", "-", "1", ")", "{", "dest", ".", "write", "(", "data", ",", "0", ",", "count", ")", ";", "}", "dest", ".", "flush", "(", ")", ";", "dest", ".", "close", "(", ")", ";", "}", "}", "zis", ".", "close", "(", ")", ";", "}" ]
Unzips the InputStream to the given destination directory. @param is @param destDir @throws FileNotFoundException @throws IOException
[ "Unzips", "the", "InputStream", "to", "the", "given", "destination", "directory", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Zip.java#L127-L153
9,046
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java
PolicyFinderModule.init
@Override public void init(PolicyFinder finder) { try { logger.info("Loading repository policies..."); setupActivePolicyDirectories(); m_repositoryPolicies.clear(); Map<String,AbstractPolicy> repositoryPolicies = m_policyLoader.loadPolicies(m_policyParser, m_validateRepositoryPolicies, new File(m_repositoryBackendPolicyDirectoryPath)); repositoryPolicies.putAll( m_policyLoader.loadPolicies(m_policyParser, m_validateRepositoryPolicies, new File(m_repositoryPolicyDirectoryPath))); m_repositoryPolicies.addAll(repositoryPolicies.values()); m_repositoryPolicySet = toPolicySet(m_repositoryPolicies, m_combiningAlgorithm); } catch (Throwable t) { logger.error("Error loading repository policies: " + t.toString(), t); } }
java
@Override public void init(PolicyFinder finder) { try { logger.info("Loading repository policies..."); setupActivePolicyDirectories(); m_repositoryPolicies.clear(); Map<String,AbstractPolicy> repositoryPolicies = m_policyLoader.loadPolicies(m_policyParser, m_validateRepositoryPolicies, new File(m_repositoryBackendPolicyDirectoryPath)); repositoryPolicies.putAll( m_policyLoader.loadPolicies(m_policyParser, m_validateRepositoryPolicies, new File(m_repositoryPolicyDirectoryPath))); m_repositoryPolicies.addAll(repositoryPolicies.values()); m_repositoryPolicySet = toPolicySet(m_repositoryPolicies, m_combiningAlgorithm); } catch (Throwable t) { logger.error("Error loading repository policies: " + t.toString(), t); } }
[ "@", "Override", "public", "void", "init", "(", "PolicyFinder", "finder", ")", "{", "try", "{", "logger", ".", "info", "(", "\"Loading repository policies...\"", ")", ";", "setupActivePolicyDirectories", "(", ")", ";", "m_repositoryPolicies", ".", "clear", "(", ")", ";", "Map", "<", "String", ",", "AbstractPolicy", ">", "repositoryPolicies", "=", "m_policyLoader", ".", "loadPolicies", "(", "m_policyParser", ",", "m_validateRepositoryPolicies", ",", "new", "File", "(", "m_repositoryBackendPolicyDirectoryPath", ")", ")", ";", "repositoryPolicies", ".", "putAll", "(", "m_policyLoader", ".", "loadPolicies", "(", "m_policyParser", ",", "m_validateRepositoryPolicies", ",", "new", "File", "(", "m_repositoryPolicyDirectoryPath", ")", ")", ")", ";", "m_repositoryPolicies", ".", "addAll", "(", "repositoryPolicies", ".", "values", "(", ")", ")", ";", "m_repositoryPolicySet", "=", "toPolicySet", "(", "m_repositoryPolicies", ",", "m_combiningAlgorithm", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "logger", ".", "error", "(", "\"Error loading repository policies: \"", "+", "t", ".", "toString", "(", ")", ",", "t", ")", ";", "}", "}" ]
Does nothing at init time.
[ "Does", "nothing", "at", "init", "time", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java#L193-L212
9,047
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java
PolicyFinderModule.findPolicy
@Override public PolicyFinderResult findPolicy(EvaluationCtx context) { PolicyFinderResult policyFinderResult = null; PolicySet policySet = m_repositoryPolicySet; try { String pid = getPid(context); if (pid != null && !pid.isEmpty()) { AbstractPolicy objectPolicyFromObject = m_policyLoader.loadObjectPolicy(m_policyParser.copy(), pid, m_validateObjectPoliciesFromDatastream); if (objectPolicyFromObject != null) { List<AbstractPolicy> policies = new ArrayList<AbstractPolicy>(m_repositoryPolicies); policies.add(objectPolicyFromObject); policySet = toPolicySet(policies, m_combiningAlgorithm); } } policyFinderResult = new PolicyFinderResult(policySet); } catch (Exception e) { logger.warn("PolicyFinderModule seriously failed to evaluate a policy ", e); policyFinderResult = new PolicyFinderResult(new Status(ERROR_CODE_LIST, e .getMessage())); } return policyFinderResult; }
java
@Override public PolicyFinderResult findPolicy(EvaluationCtx context) { PolicyFinderResult policyFinderResult = null; PolicySet policySet = m_repositoryPolicySet; try { String pid = getPid(context); if (pid != null && !pid.isEmpty()) { AbstractPolicy objectPolicyFromObject = m_policyLoader.loadObjectPolicy(m_policyParser.copy(), pid, m_validateObjectPoliciesFromDatastream); if (objectPolicyFromObject != null) { List<AbstractPolicy> policies = new ArrayList<AbstractPolicy>(m_repositoryPolicies); policies.add(objectPolicyFromObject); policySet = toPolicySet(policies, m_combiningAlgorithm); } } policyFinderResult = new PolicyFinderResult(policySet); } catch (Exception e) { logger.warn("PolicyFinderModule seriously failed to evaluate a policy ", e); policyFinderResult = new PolicyFinderResult(new Status(ERROR_CODE_LIST, e .getMessage())); } return policyFinderResult; }
[ "@", "Override", "public", "PolicyFinderResult", "findPolicy", "(", "EvaluationCtx", "context", ")", "{", "PolicyFinderResult", "policyFinderResult", "=", "null", ";", "PolicySet", "policySet", "=", "m_repositoryPolicySet", ";", "try", "{", "String", "pid", "=", "getPid", "(", "context", ")", ";", "if", "(", "pid", "!=", "null", "&&", "!", "pid", ".", "isEmpty", "(", ")", ")", "{", "AbstractPolicy", "objectPolicyFromObject", "=", "m_policyLoader", ".", "loadObjectPolicy", "(", "m_policyParser", ".", "copy", "(", ")", ",", "pid", ",", "m_validateObjectPoliciesFromDatastream", ")", ";", "if", "(", "objectPolicyFromObject", "!=", "null", ")", "{", "List", "<", "AbstractPolicy", ">", "policies", "=", "new", "ArrayList", "<", "AbstractPolicy", ">", "(", "m_repositoryPolicies", ")", ";", "policies", ".", "add", "(", "objectPolicyFromObject", ")", ";", "policySet", "=", "toPolicySet", "(", "policies", ",", "m_combiningAlgorithm", ")", ";", "}", "}", "policyFinderResult", "=", "new", "PolicyFinderResult", "(", "policySet", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "\"PolicyFinderModule seriously failed to evaluate a policy \"", ",", "e", ")", ";", "policyFinderResult", "=", "new", "PolicyFinderResult", "(", "new", "Status", "(", "ERROR_CODE_LIST", ",", "e", ".", "getMessage", "(", ")", ")", ")", ";", "}", "return", "policyFinderResult", ";", "}" ]
Gets a deny-biased policy set that includes all repository-wide and object-specific policies.
[ "Gets", "a", "deny", "-", "biased", "policy", "set", "that", "includes", "all", "repository", "-", "wide", "and", "object", "-", "specific", "policies", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java#L278-L303
9,048
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java
PolicyFinderModule.getPid
public static String getPid(EvaluationCtx context) { EvaluationResult attribute = context.getResourceAttribute(STRING_ATTRIBUTE, Constants.OBJECT.PID.attributeId, null); BagAttribute element = getAttributeFromEvaluationResult(attribute); if (element == null) { logger.debug("PolicyFinderModule:getPid exit on can't get pid on request callback"); return null; } if (!(element.getType().equals(STRING_ATTRIBUTE))) { logger.debug("PolicyFinderModule:getPid exit on couldn't get pid from xacml request non-string returned"); return null; } return (element.size() == 1) ? (String) element.getValue() : null; }
java
public static String getPid(EvaluationCtx context) { EvaluationResult attribute = context.getResourceAttribute(STRING_ATTRIBUTE, Constants.OBJECT.PID.attributeId, null); BagAttribute element = getAttributeFromEvaluationResult(attribute); if (element == null) { logger.debug("PolicyFinderModule:getPid exit on can't get pid on request callback"); return null; } if (!(element.getType().equals(STRING_ATTRIBUTE))) { logger.debug("PolicyFinderModule:getPid exit on couldn't get pid from xacml request non-string returned"); return null; } return (element.size() == 1) ? (String) element.getValue() : null; }
[ "public", "static", "String", "getPid", "(", "EvaluationCtx", "context", ")", "{", "EvaluationResult", "attribute", "=", "context", ".", "getResourceAttribute", "(", "STRING_ATTRIBUTE", ",", "Constants", ".", "OBJECT", ".", "PID", ".", "attributeId", ",", "null", ")", ";", "BagAttribute", "element", "=", "getAttributeFromEvaluationResult", "(", "attribute", ")", ";", "if", "(", "element", "==", "null", ")", "{", "logger", ".", "debug", "(", "\"PolicyFinderModule:getPid exit on can't get pid on request callback\"", ")", ";", "return", "null", ";", "}", "if", "(", "!", "(", "element", ".", "getType", "(", ")", ".", "equals", "(", "STRING_ATTRIBUTE", ")", ")", ")", "{", "logger", ".", "debug", "(", "\"PolicyFinderModule:getPid exit on couldn't get pid from xacml request non-string returned\"", ")", ";", "return", "null", ";", "}", "return", "(", "element", ".", "size", "(", ")", "==", "1", ")", "?", "(", "String", ")", "element", ".", "getValue", "(", ")", ":", "null", ";", "}" ]
get the pid from the context, or null if unable
[ "get", "the", "pid", "from", "the", "context", "or", "null", "if", "unable" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java#L306-L323
9,049
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java
PolicyFinderModule.getAttributeFromEvaluationResult
private static final BagAttribute getAttributeFromEvaluationResult(EvaluationResult attribute) { if (attribute.indeterminate()) { return null; } if (attribute.getStatus() != null && !Status.STATUS_OK.equals(attribute.getStatus())) { return null; } AttributeValue attributeValue = attribute.getAttributeValue(); if (!(attributeValue instanceof BagAttribute)) { return null; } return (BagAttribute) attributeValue; }
java
private static final BagAttribute getAttributeFromEvaluationResult(EvaluationResult attribute) { if (attribute.indeterminate()) { return null; } if (attribute.getStatus() != null && !Status.STATUS_OK.equals(attribute.getStatus())) { return null; } AttributeValue attributeValue = attribute.getAttributeValue(); if (!(attributeValue instanceof BagAttribute)) { return null; } return (BagAttribute) attributeValue; }
[ "private", "static", "final", "BagAttribute", "getAttributeFromEvaluationResult", "(", "EvaluationResult", "attribute", ")", "{", "if", "(", "attribute", ".", "indeterminate", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "attribute", ".", "getStatus", "(", ")", "!=", "null", "&&", "!", "Status", ".", "STATUS_OK", ".", "equals", "(", "attribute", ".", "getStatus", "(", ")", ")", ")", "{", "return", "null", ";", "}", "AttributeValue", "attributeValue", "=", "attribute", ".", "getAttributeValue", "(", ")", ";", "if", "(", "!", "(", "attributeValue", "instanceof", "BagAttribute", ")", ")", "{", "return", "null", ";", "}", "return", "(", "BagAttribute", ")", "attributeValue", ";", "}" ]
copy of code in AttributeFinderModule; consider refactoring
[ "copy", "of", "code", "in", "AttributeFinderModule", ";", "consider", "refactoring" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyFinderModule.java#L326-L342
9,050
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/util/DataFileUtils.java
DataFileUtils.byte2hex
private static String byte2hex(byte[] bytes) { char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; StringBuffer sb = new StringBuffer(); for (byte b : bytes) { sb.append(hexChars[b >> 4 & 0xf]); sb.append(hexChars[b & 0xf]); } return new String(sb); }
java
private static String byte2hex(byte[] bytes) { char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; StringBuffer sb = new StringBuffer(); for (byte b : bytes) { sb.append(hexChars[b >> 4 & 0xf]); sb.append(hexChars[b & 0xf]); } return new String(sb); }
[ "private", "static", "String", "byte2hex", "(", "byte", "[", "]", "bytes", ")", "{", "char", "[", "]", "hexChars", "=", "{", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", "}", ";", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", ")", ";", "for", "(", "byte", "b", ":", "bytes", ")", "{", "sb", ".", "append", "(", "hexChars", "[", "b", ">>", "4", "&", "0xf", "]", ")", ";", "sb", ".", "append", "(", "hexChars", "[", "b", "&", "0xf", "]", ")", ";", "}", "return", "new", "String", "(", "sb", ")", ";", "}" ]
Converts a hash into its hexadecimal string representation. @param bytes the byte array to convert @return the hexadecimal string representation
[ "Converts", "a", "hash", "into", "its", "hexadecimal", "string", "representation", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/util/DataFileUtils.java#L182-L194
9,051
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/recoverylog/RenamingJournalRecoveryLog.java
RenamingJournalRecoveryLog.shutdown
@Override public synchronized void shutdown() { try { if (open) { open = false; writer.close(); logFile.renameTo(new File(fileName)); } } catch (IOException e) { logger.error("Error shutting down", e); } }
java
@Override public synchronized void shutdown() { try { if (open) { open = false; writer.close(); logFile.renameTo(new File(fileName)); } } catch (IOException e) { logger.error("Error shutting down", e); } }
[ "@", "Override", "public", "synchronized", "void", "shutdown", "(", ")", "{", "try", "{", "if", "(", "open", ")", "{", "open", "=", "false", ";", "writer", ".", "close", "(", ")", ";", "logFile", ".", "renameTo", "(", "new", "File", "(", "fileName", ")", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "error", "(", "\"Error shutting down\"", ",", "e", ")", ";", "}", "}" ]
On the first call to this method, close the log file and rename it. Set the flag so no more logging calls will be accepted.
[ "On", "the", "first", "call", "to", "this", "method", "close", "the", "log", "file", "and", "rename", "it", ".", "Set", "the", "flag", "so", "no", "more", "logging", "calls", "will", "be", "accepted", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/recoverylog/RenamingJournalRecoveryLog.java#L115-L126
9,052
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/filters/AbstractFilter.java
AbstractFilter.getEnvironment
protected Map<URI, AttributeValue> getEnvironment(HttpServletRequest request) { Map<URI, AttributeValue> envAttr = new HashMap<URI, AttributeValue>(); String ip = request.getRemoteAddr(); if (ip != null && !ip.isEmpty()) { envAttr.put(Constants.HTTP_REQUEST.CLIENT_IP_ADDRESS.getURI(), new StringAttribute(ip)); } return envAttr; }
java
protected Map<URI, AttributeValue> getEnvironment(HttpServletRequest request) { Map<URI, AttributeValue> envAttr = new HashMap<URI, AttributeValue>(); String ip = request.getRemoteAddr(); if (ip != null && !ip.isEmpty()) { envAttr.put(Constants.HTTP_REQUEST.CLIENT_IP_ADDRESS.getURI(), new StringAttribute(ip)); } return envAttr; }
[ "protected", "Map", "<", "URI", ",", "AttributeValue", ">", "getEnvironment", "(", "HttpServletRequest", "request", ")", "{", "Map", "<", "URI", ",", "AttributeValue", ">", "envAttr", "=", "new", "HashMap", "<", "URI", ",", "AttributeValue", ">", "(", ")", ";", "String", "ip", "=", "request", ".", "getRemoteAddr", "(", ")", ";", "if", "(", "ip", "!=", "null", "&&", "!", "ip", ".", "isEmpty", "(", ")", ")", "{", "envAttr", ".", "put", "(", "Constants", ".", "HTTP_REQUEST", ".", "CLIENT_IP_ADDRESS", ".", "getURI", "(", ")", ",", "new", "StringAttribute", "(", "ip", ")", ")", ";", "}", "return", "envAttr", ";", "}" ]
Returns a map of environment attributes. @param request the servlet request from which to obtain the attributes @return a list of environment attributes
[ "Returns", "a", "map", "of", "environment", "attributes", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/filters/AbstractFilter.java#L156-L166
9,053
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/filters/AbstractFilter.java
AbstractFilter.isDate
protected boolean isDate(String item) { if (item == null) { return false; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z$")) { return true; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$")) { return true; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}$")) { return true; } return false; }
java
protected boolean isDate(String item) { if (item == null) { return false; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z$")) { return true; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$")) { return true; } if (item.matches("^\\d{4}-\\d{2}-\\d{2}$")) { return true; } return false; }
[ "protected", "boolean", "isDate", "(", "String", "item", ")", "{", "if", "(", "item", "==", "null", ")", "{", "return", "false", ";", "}", "if", "(", "item", ".", "matches", "(", "\"^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}.\\\\d{3}Z$\"", ")", ")", "{", "return", "true", ";", "}", "if", "(", "item", ".", "matches", "(", "\"^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}Z$\"", ")", ")", "{", "return", "true", ";", "}", "if", "(", "item", ".", "matches", "(", "\"^\\\\d{4}-\\\\d{2}-\\\\d{2}$\"", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks whether a parameter fits the date pattern. @param item the date @return returns true if the string is a date or else false
[ "Checks", "whether", "a", "parameter", "fits", "the", "date", "pattern", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/filters/AbstractFilter.java#L208-L226
9,054
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java
Base64.encode
public static byte[] encode(byte[] in) { return org.apache.commons.codec.binary.Base64.encodeBase64(in); }
java
public static byte[] encode(byte[] in) { return org.apache.commons.codec.binary.Base64.encodeBase64(in); }
[ "public", "static", "byte", "[", "]", "encode", "(", "byte", "[", "]", "in", ")", "{", "return", "org", ".", "apache", ".", "commons", ".", "codec", ".", "binary", ".", "Base64", ".", "encodeBase64", "(", "in", ")", ";", "}" ]
Encodes bytes to base 64, returning bytes. @param in bytes to encode @return encoded bytes
[ "Encodes", "bytes", "to", "base", "64", "returning", "bytes", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java#L29-L31
9,055
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java
Base64.decode
public static byte[] decode(byte[] in) { return org.apache.commons.codec.binary.Base64.decodeBase64(in); }
java
public static byte[] decode(byte[] in) { return org.apache.commons.codec.binary.Base64.decodeBase64(in); }
[ "public", "static", "byte", "[", "]", "decode", "(", "byte", "[", "]", "in", ")", "{", "return", "org", ".", "apache", ".", "commons", ".", "codec", ".", "binary", ".", "Base64", ".", "decodeBase64", "(", "in", ")", ";", "}" ]
Decodes bytes from base 64, returning bytes. @param in bytes to decode @return decoded bytes
[ "Decodes", "bytes", "from", "base", "64", "returning", "bytes", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java#L100-L102
9,056
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java
Base64.decode
public static byte[] decode(InputStream in) { try { return IOUtils.toByteArray(decodeToStream(in)); } catch (IOException e) { e.printStackTrace(); return null; } }
java
public static byte[] decode(InputStream in) { try { return IOUtils.toByteArray(decodeToStream(in)); } catch (IOException e) { e.printStackTrace(); return null; } }
[ "public", "static", "byte", "[", "]", "decode", "(", "InputStream", "in", ")", "{", "try", "{", "return", "IOUtils", ".", "toByteArray", "(", "decodeToStream", "(", "in", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "}" ]
Decode an input stream of b64-encoded data to an array of bytes. @param in @return the decoded bytes, or null if there was an error reading the bytes
[ "Decode", "an", "input", "stream", "of", "b64", "-", "encoded", "data", "to", "an", "array", "of", "bytes", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/Base64.java#L119-L126
9,057
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java
StreamUtility.enc
public static void enc(char[] in, int start, int length, StringBuffer out) { for (int i = start; i < length + start; i++) { enc(in[i], out); } }
java
public static void enc(char[] in, int start, int length, StringBuffer out) { for (int i = start; i < length + start; i++) { enc(in[i], out); } }
[ "public", "static", "void", "enc", "(", "char", "[", "]", "in", ",", "int", "start", ",", "int", "length", ",", "StringBuffer", "out", ")", "{", "for", "(", "int", "i", "=", "start", ";", "i", "<", "length", "+", "start", ";", "i", "++", ")", "{", "enc", "(", "in", "[", "i", "]", ",", "out", ")", ";", "}", "}" ]
Prints an XML-appropriate encoding of the given range of characters to the given Writer. @param in The char buffer to read from. @param start The starting index. @param length The number of characters in the range. @param out The Appendable to write to.
[ "Prints", "an", "XML", "-", "appropriate", "encoding", "of", "the", "given", "range", "of", "characters", "to", "the", "given", "Writer", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java#L142-L146
9,058
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java
StreamUtility.enc
public static void enc(char in, StringBuffer out) { if (in == '&') { out.append("&amp;"); } else if (in == '<') { out.append("&lt;"); } else if (in == '>') { out.append("&gt;"); } else if (in == '"') { out.append("&quot;"); } else if (in == '\'') { out.append("&apos;"); } else { out.append(in); } }
java
public static void enc(char in, StringBuffer out) { if (in == '&') { out.append("&amp;"); } else if (in == '<') { out.append("&lt;"); } else if (in == '>') { out.append("&gt;"); } else if (in == '"') { out.append("&quot;"); } else if (in == '\'') { out.append("&apos;"); } else { out.append(in); } }
[ "public", "static", "void", "enc", "(", "char", "in", ",", "StringBuffer", "out", ")", "{", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&amp;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&lt;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&gt;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&quot;\"", ")", ";", "}", "else", "if", "(", "in", "==", "'", "'", ")", "{", "out", ".", "append", "(", "\"&apos;\"", ")", ";", "}", "else", "{", "out", ".", "append", "(", "in", ")", ";", "}", "}" ]
Appends an XML-appropriate encoding of the given character to the given Appendable. @param in The character. @param out The Appendable to write to. Since we expect only PrintStream, PrintWriter, and the String-building classes, we wrap the IOException in a RuntimeException
[ "Appends", "an", "XML", "-", "appropriate", "encoding", "of", "the", "given", "character", "to", "the", "given", "Appendable", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java#L169-L183
9,059
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java
StreamUtility.getBytes
public static byte[] getBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); pipeStream(in, out, 4096); return out.toByteArray(); }
java
public static byte[] getBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); pipeStream(in, out, 4096); return out.toByteArray(); }
[ "public", "static", "byte", "[", "]", "getBytes", "(", "InputStream", "in", ")", "throws", "IOException", "{", "ByteArrayOutputStream", "out", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "pipeStream", "(", "in", ",", "out", ",", "4096", ")", ";", "return", "out", ".", "toByteArray", "(", ")", ";", "}" ]
Gets a byte array for the given input stream.
[ "Gets", "a", "byte", "array", "for", "the", "given", "input", "stream", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java#L271-L275
9,060
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java
StreamUtility.getStream
public static InputStream getStream(String string) { try { return new ByteArrayInputStream(string.getBytes("UTF-8")); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
java
public static InputStream getStream(String string) { try { return new ByteArrayInputStream(string.getBytes("UTF-8")); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
[ "public", "static", "InputStream", "getStream", "(", "String", "string", ")", "{", "try", "{", "return", "new", "ByteArrayInputStream", "(", "string", ".", "getBytes", "(", "\"UTF-8\"", ")", ")", ";", "}", "catch", "(", "UnsupportedEncodingException", "wontHappen", ")", "{", "throw", "new", "FaultException", "(", "wontHappen", ")", ";", "}", "}" ]
Gets a stream for the given string.
[ "Gets", "a", "stream", "for", "the", "given", "string", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/StreamUtility.java#L280-L286
9,061
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/console/ConsoleCommandInvoker.java
ConsoleCommandInvoker.invoke
public void invoke() { try { m_console.setBusy(true); m_console.print("Invoking " + m_command.toString() + "\n"); Object[] parameters = new Object[m_command.getParameterTypes().length]; if (m_command.getParameterTypes().length > 0) { for (int i = 0; i < m_command.getParameterTypes().length; i++) { m_console.print(m_command.getParameterNames()[i]); m_console.print("="); Object paramValue = m_inputPanels[i].getValue(); parameters[i] = paramValue; if (paramValue == null) { m_console.print("<null>"); } else { m_console.print(stringify(paramValue)); } m_console.print("\n"); } } long startms = new Date().getTime(); Object returned = m_command.invoke(m_console.getInvocationTarget(m_command), parameters); long endms = new Date().getTime(); long totalms = endms - startms; if (returned != null) { m_console.print("Returned: " + stringify(returned) + "\n"); } else { if (m_command.getReturnType() == null) { m_console.print("Returned.\n"); } else { m_console.print("Returned: <null>\n"); } } String duration; if (totalms == 0) { duration = "< 0.001 seconds."; } else { double secs = totalms / 1000.0; duration = secs + " seconds."; } m_console.print("Roundtrip time: "); m_console.print(duration); m_console.print("\n"); } catch (InvocationTargetException ite) { m_console.print("ERROR (" + ite.getTargetException().getClass().getName() + ") : " + ite.getTargetException().getMessage() + "\n"); } catch (Throwable th) { m_console.print("ERROR (" + th.getClass().getName() + ") : " + th.getMessage() + "\n"); StringWriter sw = new StringWriter(); th.printStackTrace(new PrintWriter(sw)); m_console.print(sw.toString()); } finally { m_console.setBusy(false); } }
java
public void invoke() { try { m_console.setBusy(true); m_console.print("Invoking " + m_command.toString() + "\n"); Object[] parameters = new Object[m_command.getParameterTypes().length]; if (m_command.getParameterTypes().length > 0) { for (int i = 0; i < m_command.getParameterTypes().length; i++) { m_console.print(m_command.getParameterNames()[i]); m_console.print("="); Object paramValue = m_inputPanels[i].getValue(); parameters[i] = paramValue; if (paramValue == null) { m_console.print("<null>"); } else { m_console.print(stringify(paramValue)); } m_console.print("\n"); } } long startms = new Date().getTime(); Object returned = m_command.invoke(m_console.getInvocationTarget(m_command), parameters); long endms = new Date().getTime(); long totalms = endms - startms; if (returned != null) { m_console.print("Returned: " + stringify(returned) + "\n"); } else { if (m_command.getReturnType() == null) { m_console.print("Returned.\n"); } else { m_console.print("Returned: <null>\n"); } } String duration; if (totalms == 0) { duration = "< 0.001 seconds."; } else { double secs = totalms / 1000.0; duration = secs + " seconds."; } m_console.print("Roundtrip time: "); m_console.print(duration); m_console.print("\n"); } catch (InvocationTargetException ite) { m_console.print("ERROR (" + ite.getTargetException().getClass().getName() + ") : " + ite.getTargetException().getMessage() + "\n"); } catch (Throwable th) { m_console.print("ERROR (" + th.getClass().getName() + ") : " + th.getMessage() + "\n"); StringWriter sw = new StringWriter(); th.printStackTrace(new PrintWriter(sw)); m_console.print(sw.toString()); } finally { m_console.setBusy(false); } }
[ "public", "void", "invoke", "(", ")", "{", "try", "{", "m_console", ".", "setBusy", "(", "true", ")", ";", "m_console", ".", "print", "(", "\"Invoking \"", "+", "m_command", ".", "toString", "(", ")", "+", "\"\\n\"", ")", ";", "Object", "[", "]", "parameters", "=", "new", "Object", "[", "m_command", ".", "getParameterTypes", "(", ")", ".", "length", "]", ";", "if", "(", "m_command", ".", "getParameterTypes", "(", ")", ".", "length", ">", "0", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_command", ".", "getParameterTypes", "(", ")", ".", "length", ";", "i", "++", ")", "{", "m_console", ".", "print", "(", "m_command", ".", "getParameterNames", "(", ")", "[", "i", "]", ")", ";", "m_console", ".", "print", "(", "\"=\"", ")", ";", "Object", "paramValue", "=", "m_inputPanels", "[", "i", "]", ".", "getValue", "(", ")", ";", "parameters", "[", "i", "]", "=", "paramValue", ";", "if", "(", "paramValue", "==", "null", ")", "{", "m_console", ".", "print", "(", "\"<null>\"", ")", ";", "}", "else", "{", "m_console", ".", "print", "(", "stringify", "(", "paramValue", ")", ")", ";", "}", "m_console", ".", "print", "(", "\"\\n\"", ")", ";", "}", "}", "long", "startms", "=", "new", "Date", "(", ")", ".", "getTime", "(", ")", ";", "Object", "returned", "=", "m_command", ".", "invoke", "(", "m_console", ".", "getInvocationTarget", "(", "m_command", ")", ",", "parameters", ")", ";", "long", "endms", "=", "new", "Date", "(", ")", ".", "getTime", "(", ")", ";", "long", "totalms", "=", "endms", "-", "startms", ";", "if", "(", "returned", "!=", "null", ")", "{", "m_console", ".", "print", "(", "\"Returned: \"", "+", "stringify", "(", "returned", ")", "+", "\"\\n\"", ")", ";", "}", "else", "{", "if", "(", "m_command", ".", "getReturnType", "(", ")", "==", "null", ")", "{", "m_console", ".", "print", "(", "\"Returned.\\n\"", ")", ";", "}", "else", "{", "m_console", ".", "print", "(", "\"Returned: <null>\\n\"", ")", ";", "}", "}", "String", "duration", ";", "if", "(", "totalms", "==", "0", ")", "{", "duration", "=", "\"< 0.001 seconds.\"", ";", "}", "else", "{", "double", "secs", "=", "totalms", "/", "1000.0", ";", "duration", "=", "secs", "+", "\" seconds.\"", ";", "}", "m_console", ".", "print", "(", "\"Roundtrip time: \"", ")", ";", "m_console", ".", "print", "(", "duration", ")", ";", "m_console", ".", "print", "(", "\"\\n\"", ")", ";", "}", "catch", "(", "InvocationTargetException", "ite", ")", "{", "m_console", ".", "print", "(", "\"ERROR (\"", "+", "ite", ".", "getTargetException", "(", ")", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\") : \"", "+", "ite", ".", "getTargetException", "(", ")", ".", "getMessage", "(", ")", "+", "\"\\n\"", ")", ";", "}", "catch", "(", "Throwable", "th", ")", "{", "m_console", ".", "print", "(", "\"ERROR (\"", "+", "th", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\") : \"", "+", "th", ".", "getMessage", "(", ")", "+", "\"\\n\"", ")", ";", "StringWriter", "sw", "=", "new", "StringWriter", "(", ")", ";", "th", ".", "printStackTrace", "(", "new", "PrintWriter", "(", "sw", ")", ")", ";", "m_console", ".", "print", "(", "sw", ".", "toString", "(", ")", ")", ";", "}", "finally", "{", "m_console", ".", "setBusy", "(", "false", ")", ";", "}", "}" ]
Invokes the console command with whatever parameters have been set thus far, sending any errors to the console.
[ "Invokes", "the", "console", "command", "with", "whatever", "parameters", "have", "been", "set", "thus", "far", "sending", "any", "errors", "to", "the", "console", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/console/ConsoleCommandInvoker.java#L73-L131
9,062
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java
PolicyReader.readPolicy
public synchronized Document readPolicy(File file) throws ParsingException { try { return builder.parse(file); } catch (IOException ioe) { throw new ParsingException("Failed to read the file", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the file", saxe); } }
java
public synchronized Document readPolicy(File file) throws ParsingException { try { return builder.parse(file); } catch (IOException ioe) { throw new ParsingException("Failed to read the file", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the file", saxe); } }
[ "public", "synchronized", "Document", "readPolicy", "(", "File", "file", ")", "throws", "ParsingException", "{", "try", "{", "return", "builder", ".", "parse", "(", "file", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "ParsingException", "(", "\"Failed to read the file\"", ",", "ioe", ")", ";", "}", "catch", "(", "SAXException", "saxe", ")", "{", "throw", "new", "ParsingException", "(", "\"Failed to parse the file\"", ",", "saxe", ")", ";", "}", "}" ]
Tries to read an XACML policy or policy set from the given file. @param file the file containing the policy to read @return a (potentially schema-validated) policy loaded from the given file @throws ParsingException if an error occurs while reading or parsing the policy
[ "Tries", "to", "read", "an", "XACML", "policy", "or", "policy", "set", "from", "the", "given", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java#L150-L159
9,063
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java
PolicyReader.readPolicy
public synchronized Document readPolicy(InputStream input) throws ParsingException { try { return builder.parse(input); } catch (IOException ioe) { throw new ParsingException("Failed to read the stream", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the stream", saxe); } }
java
public synchronized Document readPolicy(InputStream input) throws ParsingException { try { return builder.parse(input); } catch (IOException ioe) { throw new ParsingException("Failed to read the stream", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the stream", saxe); } }
[ "public", "synchronized", "Document", "readPolicy", "(", "InputStream", "input", ")", "throws", "ParsingException", "{", "try", "{", "return", "builder", ".", "parse", "(", "input", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "ParsingException", "(", "\"Failed to read the stream\"", ",", "ioe", ")", ";", "}", "catch", "(", "SAXException", "saxe", ")", "{", "throw", "new", "ParsingException", "(", "\"Failed to parse the stream\"", ",", "saxe", ")", ";", "}", "}" ]
Tries to read an XACML policy or policy set from the given stream. @param input the stream containing the policy to read @return a (potentially schema-validated) policy loaded from the given file @throws ParsingException if an error occurs while reading or parsing the policy
[ "Tries", "to", "read", "an", "XACML", "policy", "or", "policy", "set", "from", "the", "given", "stream", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java#L171-L180
9,064
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java
PolicyReader.readPolicy
public synchronized Document readPolicy(URL url) throws ParsingException { try { return readPolicy(url.openStream()); } catch (IOException ioe) { throw new ParsingException("Failed to resolve the URL: " + url.toString(), ioe); } }
java
public synchronized Document readPolicy(URL url) throws ParsingException { try { return readPolicy(url.openStream()); } catch (IOException ioe) { throw new ParsingException("Failed to resolve the URL: " + url.toString(), ioe); } }
[ "public", "synchronized", "Document", "readPolicy", "(", "URL", "url", ")", "throws", "ParsingException", "{", "try", "{", "return", "readPolicy", "(", "url", ".", "openStream", "(", ")", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "ParsingException", "(", "\"Failed to resolve the URL: \"", "+", "url", ".", "toString", "(", ")", ",", "ioe", ")", ";", "}", "}" ]
Tries to read an XACML policy or policy set based on the given URL. This may be any resolvable URL, like a file or http pointer. @param url a URL pointing to the policy to read @return a (potentially schema-validated) policy loaded from the given file @throws ParsingException if an error occurs while reading or parsing the policy, or if the URL can't be resolved
[ "Tries", "to", "read", "an", "XACML", "policy", "or", "policy", "set", "based", "on", "the", "given", "URL", ".", "This", "may", "be", "any", "resolvable", "URL", "like", "a", "file", "or", "http", "pointer", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/finder/policy/PolicyReader.java#L199-L207
9,065
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java
EncodingBase64InputStream.read
public String read(int maxStringLength) throws IOException { if (maxStringLength < 4) { throw new IllegalArgumentException("maxStringLength must be 4 or more, not " + maxStringLength); } if (!open) { throw new IllegalStateException("Stream has already been closed."); } int bytesRequestedForEncoding = maxStringLength / 4 * 3; if (bytesRequestedForEncoding > bytesInBuffer) { readMoreBytesFromStream(); } if (bytesInBuffer == 0 && !innerStreamHasMoreData) { return null; } int bytesToEncode = Math.min(bytesRequestedForEncoding, bytesInBuffer); String result = encodeBytesFromBuffer(bytesToEncode); return result; }
java
public String read(int maxStringLength) throws IOException { if (maxStringLength < 4) { throw new IllegalArgumentException("maxStringLength must be 4 or more, not " + maxStringLength); } if (!open) { throw new IllegalStateException("Stream has already been closed."); } int bytesRequestedForEncoding = maxStringLength / 4 * 3; if (bytesRequestedForEncoding > bytesInBuffer) { readMoreBytesFromStream(); } if (bytesInBuffer == 0 && !innerStreamHasMoreData) { return null; } int bytesToEncode = Math.min(bytesRequestedForEncoding, bytesInBuffer); String result = encodeBytesFromBuffer(bytesToEncode); return result; }
[ "public", "String", "read", "(", "int", "maxStringLength", ")", "throws", "IOException", "{", "if", "(", "maxStringLength", "<", "4", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"maxStringLength must be 4 or more, not \"", "+", "maxStringLength", ")", ";", "}", "if", "(", "!", "open", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Stream has already been closed.\"", ")", ";", "}", "int", "bytesRequestedForEncoding", "=", "maxStringLength", "/", "4", "*", "3", ";", "if", "(", "bytesRequestedForEncoding", ">", "bytesInBuffer", ")", "{", "readMoreBytesFromStream", "(", ")", ";", "}", "if", "(", "bytesInBuffer", "==", "0", "&&", "!", "innerStreamHasMoreData", ")", "{", "return", "null", ";", "}", "int", "bytesToEncode", "=", "Math", ".", "min", "(", "bytesRequestedForEncoding", ",", "bytesInBuffer", ")", ";", "String", "result", "=", "encodeBytesFromBuffer", "(", "bytesToEncode", ")", ";", "return", "result", ";", "}" ]
Read encoded data from the stream. Data is read in 3-byte multiples and encoded into 4-character sequences, per the Base64 specification. As many bytes as possible will be read, limited by the amount of data available and by the limitation of maxStringLength on the size of the resulting encoded String. Since the smallest unit of encoded data is 4 characters, maxStringLength must not be less than 4. @param maxStringLength the resulting String will be no longer than this. @return a String that is no longer than maxStringLength, or null if no data remains to be read. @throws IllegalArgumentException if maxStringLength is less than 4. @throws IllegalStateException if called after the stream is closed. @throws IOException from inner InputStream.
[ "Read", "encoded", "data", "from", "the", "stream", ".", "Data", "is", "read", "in", "3", "-", "byte", "multiples", "and", "encoded", "into", "4", "-", "character", "sequences", "per", "the", "Base64", "specification", ".", "As", "many", "bytes", "as", "possible", "will", "be", "read", "limited", "by", "the", "amount", "of", "data", "available", "and", "by", "the", "limitation", "of", "maxStringLength", "on", "the", "size", "of", "the", "resulting", "encoded", "String", ".", "Since", "the", "smallest", "unit", "of", "encoded", "data", "is", "4", "characters", "maxStringLength", "must", "not", "be", "less", "than", "4", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java#L81-L104
9,066
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java
EncodingBase64InputStream.readMoreBytesFromStream
private void readMoreBytesFromStream() throws IOException { if (!innerStreamHasMoreData) { return; } int bufferSpaceAvailable = buffer.length - bytesInBuffer; if (bufferSpaceAvailable <= 0) { return; } int bytesRead = stream.read(buffer, bytesInBuffer, bufferSpaceAvailable); if (bytesRead == -1) { innerStreamHasMoreData = false; } else { bytesInBuffer += bytesRead; } }
java
private void readMoreBytesFromStream() throws IOException { if (!innerStreamHasMoreData) { return; } int bufferSpaceAvailable = buffer.length - bytesInBuffer; if (bufferSpaceAvailable <= 0) { return; } int bytesRead = stream.read(buffer, bytesInBuffer, bufferSpaceAvailable); if (bytesRead == -1) { innerStreamHasMoreData = false; } else { bytesInBuffer += bytesRead; } }
[ "private", "void", "readMoreBytesFromStream", "(", ")", "throws", "IOException", "{", "if", "(", "!", "innerStreamHasMoreData", ")", "{", "return", ";", "}", "int", "bufferSpaceAvailable", "=", "buffer", ".", "length", "-", "bytesInBuffer", ";", "if", "(", "bufferSpaceAvailable", "<=", "0", ")", "{", "return", ";", "}", "int", "bytesRead", "=", "stream", ".", "read", "(", "buffer", ",", "bytesInBuffer", ",", "bufferSpaceAvailable", ")", ";", "if", "(", "bytesRead", "==", "-", "1", ")", "{", "innerStreamHasMoreData", "=", "false", ";", "}", "else", "{", "bytesInBuffer", "+=", "bytesRead", ";", "}", "}" ]
Fill the buffer with more data from the InputStream, if there is any. @throws IOException from the inner InputStream
[ "Fill", "the", "buffer", "with", "more", "data", "from", "the", "InputStream", "if", "there", "is", "any", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java#L123-L141
9,067
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java
EncodingBase64InputStream.encodeBytesFromBuffer
private String encodeBytesFromBuffer(int howMany) { String result; if (innerStreamHasMoreData) { howMany = howMany - howMany % 3; } if (howMany == 0) { return ""; } byte[] encodeBuffer = new byte[howMany]; System.arraycopy(buffer, 0, encodeBuffer, 0, howMany); result = Base64.encodeToString(encodeBuffer); bytesInBuffer -= howMany; if (bytesInBuffer != 0) { System.arraycopy(buffer, howMany, buffer, 0, bytesInBuffer); } return result; }
java
private String encodeBytesFromBuffer(int howMany) { String result; if (innerStreamHasMoreData) { howMany = howMany - howMany % 3; } if (howMany == 0) { return ""; } byte[] encodeBuffer = new byte[howMany]; System.arraycopy(buffer, 0, encodeBuffer, 0, howMany); result = Base64.encodeToString(encodeBuffer); bytesInBuffer -= howMany; if (bytesInBuffer != 0) { System.arraycopy(buffer, howMany, buffer, 0, bytesInBuffer); } return result; }
[ "private", "String", "encodeBytesFromBuffer", "(", "int", "howMany", ")", "{", "String", "result", ";", "if", "(", "innerStreamHasMoreData", ")", "{", "howMany", "=", "howMany", "-", "howMany", "%", "3", ";", "}", "if", "(", "howMany", "==", "0", ")", "{", "return", "\"\"", ";", "}", "byte", "[", "]", "encodeBuffer", "=", "new", "byte", "[", "howMany", "]", ";", "System", ".", "arraycopy", "(", "buffer", ",", "0", ",", "encodeBuffer", ",", "0", ",", "howMany", ")", ";", "result", "=", "Base64", ".", "encodeToString", "(", "encodeBuffer", ")", ";", "bytesInBuffer", "-=", "howMany", ";", "if", "(", "bytesInBuffer", "!=", "0", ")", "{", "System", ".", "arraycopy", "(", "buffer", ",", "howMany", ",", "buffer", ",", "0", ",", "bytesInBuffer", ")", ";", "}", "return", "result", ";", "}" ]
Encode a group of bytes and remove them from the buffer. If the input stream has more data, we need to limit the encoding to a multiple of 3, to avoid prematurely padding the result with equals signs. @param howMany how many bytes should be encoded and remove from the buffer. @return the Base64-encoded characters.
[ "Encode", "a", "group", "of", "bytes", "and", "remove", "them", "from", "the", "buffer", ".", "If", "the", "input", "stream", "has", "more", "data", "we", "need", "to", "limit", "the", "encoding", "to", "a", "multiple", "of", "3", "to", "avoid", "prematurely", "padding", "the", "result", "with", "equals", "signs", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/EncodingBase64InputStream.java#L152-L173
9,068
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/remote/RemoteObjectSource.java
RemoteObjectSource.getContentModelInfo
@Override public ContentModelInfo getContentModelInfo(String pid) throws ObjectSourceException, InvalidContentModelException { try { ObjectInfo object = getValidationObject(pid); if (object == null) { return null; } DatastreamInfo dsInfo = object.getDatastreamInfo(DS_COMPOSITE_MODEL); if (dsInfo == null) { throw new InvalidContentModelException(pid, "Content model has no '" + DS_COMPOSITE_MODEL + "' datastream."); } if (!DS_COMPOSITE_MODEL_FORMAT.equals(dsInfo.getFormatUri())) { throw new InvalidContentModelException(pid, "Datastream '" + DS_COMPOSITE_MODEL + "' has incorrect format URI: '" + dsInfo.getFormatUri() + "'."); } MIMETypedStream ds = apia.getDatastreamDissemination(pid, DS_COMPOSITE_MODEL, null); DsCompositeModelDoc model = new DsCompositeModelDoc(pid, org.fcrepo.server.utilities.TypeUtility .convertDataHandlerToBytes(ds .getStream())); return new BasicContentModelInfo(object, model.getTypeModels()); } catch (Exception e) { throw new ObjectSourceException("Problem fetching '" + DS_COMPOSITE_MODEL + "' datastream for pid='" + pid + "'", e); } }
java
@Override public ContentModelInfo getContentModelInfo(String pid) throws ObjectSourceException, InvalidContentModelException { try { ObjectInfo object = getValidationObject(pid); if (object == null) { return null; } DatastreamInfo dsInfo = object.getDatastreamInfo(DS_COMPOSITE_MODEL); if (dsInfo == null) { throw new InvalidContentModelException(pid, "Content model has no '" + DS_COMPOSITE_MODEL + "' datastream."); } if (!DS_COMPOSITE_MODEL_FORMAT.equals(dsInfo.getFormatUri())) { throw new InvalidContentModelException(pid, "Datastream '" + DS_COMPOSITE_MODEL + "' has incorrect format URI: '" + dsInfo.getFormatUri() + "'."); } MIMETypedStream ds = apia.getDatastreamDissemination(pid, DS_COMPOSITE_MODEL, null); DsCompositeModelDoc model = new DsCompositeModelDoc(pid, org.fcrepo.server.utilities.TypeUtility .convertDataHandlerToBytes(ds .getStream())); return new BasicContentModelInfo(object, model.getTypeModels()); } catch (Exception e) { throw new ObjectSourceException("Problem fetching '" + DS_COMPOSITE_MODEL + "' datastream for pid='" + pid + "'", e); } }
[ "@", "Override", "public", "ContentModelInfo", "getContentModelInfo", "(", "String", "pid", ")", "throws", "ObjectSourceException", ",", "InvalidContentModelException", "{", "try", "{", "ObjectInfo", "object", "=", "getValidationObject", "(", "pid", ")", ";", "if", "(", "object", "==", "null", ")", "{", "return", "null", ";", "}", "DatastreamInfo", "dsInfo", "=", "object", ".", "getDatastreamInfo", "(", "DS_COMPOSITE_MODEL", ")", ";", "if", "(", "dsInfo", "==", "null", ")", "{", "throw", "new", "InvalidContentModelException", "(", "pid", ",", "\"Content model has no '\"", "+", "DS_COMPOSITE_MODEL", "+", "\"' datastream.\"", ")", ";", "}", "if", "(", "!", "DS_COMPOSITE_MODEL_FORMAT", ".", "equals", "(", "dsInfo", ".", "getFormatUri", "(", ")", ")", ")", "{", "throw", "new", "InvalidContentModelException", "(", "pid", ",", "\"Datastream '\"", "+", "DS_COMPOSITE_MODEL", "+", "\"' has incorrect format URI: '\"", "+", "dsInfo", ".", "getFormatUri", "(", ")", "+", "\"'.\"", ")", ";", "}", "MIMETypedStream", "ds", "=", "apia", ".", "getDatastreamDissemination", "(", "pid", ",", "DS_COMPOSITE_MODEL", ",", "null", ")", ";", "DsCompositeModelDoc", "model", "=", "new", "DsCompositeModelDoc", "(", "pid", ",", "org", ".", "fcrepo", ".", "server", ".", "utilities", ".", "TypeUtility", ".", "convertDataHandlerToBytes", "(", "ds", ".", "getStream", "(", ")", ")", ")", ";", "return", "new", "BasicContentModelInfo", "(", "object", ",", "model", ".", "getTypeModels", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ObjectSourceException", "(", "\"Problem fetching '\"", "+", "DS_COMPOSITE_MODEL", "+", "\"' datastream for pid='\"", "+", "pid", "+", "\"'\"", ",", "e", ")", ";", "}", "}" ]
A content model must exist as an object. If must have a (@link DS_COMPOSITE_MODEL} datastream.
[ "A", "content", "model", "must", "exist", "as", "an", "object", ".", "If", "must", "have", "a", "(" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/utility/validate/remote/RemoteObjectSource.java#L108-L149
9,069
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java
PolicyObject.isDatastreamActive
public boolean isDatastreamActive() throws ServerException { if (m_dsState == null && getDatastream() != null) m_dsState = m_datastream.DSState; return m_dsState != null && m_dsState.equals("A"); }
java
public boolean isDatastreamActive() throws ServerException { if (m_dsState == null && getDatastream() != null) m_dsState = m_datastream.DSState; return m_dsState != null && m_dsState.equals("A"); }
[ "public", "boolean", "isDatastreamActive", "(", ")", "throws", "ServerException", "{", "if", "(", "m_dsState", "==", "null", "&&", "getDatastream", "(", ")", "!=", "null", ")", "m_dsState", "=", "m_datastream", ".", "DSState", ";", "return", "m_dsState", "!=", "null", "&&", "m_dsState", ".", "equals", "(", "\"A\"", ")", ";", "}" ]
determines if the policy datastream in this object is active @return boolean @throws ServerException
[ "determines", "if", "the", "policy", "datastream", "in", "this", "object", "is", "active" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java#L114-L119
9,070
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java
PolicyObject.hasPolicyDatastream
public boolean hasPolicyDatastream() throws ServerException { if (m_hasPolicyDatastream == null) { m_hasPolicyDatastream = false; Datastream[] allDs = getReader().GetDatastreams(null, null); for (int i = 0; i < allDs.length; i++) { if (allDs[i].DatastreamID.equals(POLICY_DATASTREAM)) { m_hasPolicyDatastream = true; // also have the datastream now m_datastream = allDs[i]; break; } } } return m_hasPolicyDatastream; }
java
public boolean hasPolicyDatastream() throws ServerException { if (m_hasPolicyDatastream == null) { m_hasPolicyDatastream = false; Datastream[] allDs = getReader().GetDatastreams(null, null); for (int i = 0; i < allDs.length; i++) { if (allDs[i].DatastreamID.equals(POLICY_DATASTREAM)) { m_hasPolicyDatastream = true; // also have the datastream now m_datastream = allDs[i]; break; } } } return m_hasPolicyDatastream; }
[ "public", "boolean", "hasPolicyDatastream", "(", ")", "throws", "ServerException", "{", "if", "(", "m_hasPolicyDatastream", "==", "null", ")", "{", "m_hasPolicyDatastream", "=", "false", ";", "Datastream", "[", "]", "allDs", "=", "getReader", "(", ")", ".", "GetDatastreams", "(", "null", ",", "null", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "allDs", ".", "length", ";", "i", "++", ")", "{", "if", "(", "allDs", "[", "i", "]", ".", "DatastreamID", ".", "equals", "(", "POLICY_DATASTREAM", ")", ")", "{", "m_hasPolicyDatastream", "=", "true", ";", "// also have the datastream now", "m_datastream", "=", "allDs", "[", "i", "]", ";", "break", ";", "}", "}", "}", "return", "m_hasPolicyDatastream", ";", "}" ]
determines if this object contains a policy datastream @return boolean @throws ServerException
[ "determines", "if", "this", "object", "contains", "a", "policy", "datastream" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java#L126-L141
9,071
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java
PolicyObject.getDsContent
public InputStream getDsContent() throws ServerException { if (m_dsContent == null && getDatastream() != null) { m_dsContent = getDatastream().getContentStream(); // remember we found the policy datastream m_hasPolicyDatastream = true; } return m_dsContent; }
java
public InputStream getDsContent() throws ServerException { if (m_dsContent == null && getDatastream() != null) { m_dsContent = getDatastream().getContentStream(); // remember we found the policy datastream m_hasPolicyDatastream = true; } return m_dsContent; }
[ "public", "InputStream", "getDsContent", "(", ")", "throws", "ServerException", "{", "if", "(", "m_dsContent", "==", "null", "&&", "getDatastream", "(", ")", "!=", "null", ")", "{", "m_dsContent", "=", "getDatastream", "(", ")", ".", "getContentStream", "(", ")", ";", "// remember we found the policy datastream", "m_hasPolicyDatastream", "=", "true", ";", "}", "return", "m_dsContent", ";", "}" ]
get the policy datastream content @return InputStream @throws ServerException
[ "get", "the", "policy", "datastream", "content" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyObject.java#L155-L163
9,072
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/managementmethods/ManagementMethod.java
ManagementMethod.getInstance
public static ManagementMethod getInstance(String methodName, JournalEntry parent) { if (METHOD_INGEST.equals(methodName)) { return new IngestMethod(parent); } else if (METHOD_MODIFY_OBJECT.equals(methodName)) { return new ModifyObjectMethod(parent); } else if (METHOD_PURGE_OBJECT.equals(methodName)) { return new PurgeObjectMethod(parent); } else if (METHOD_ADD_DATASTREAM.equals(methodName)) { return new AddDatastreamMethod(parent); } else if (METHOD_MODIFY_DATASTREAM_BY_REFERENCE.equals(methodName)) { return new ModifyDatastreamByReferenceMethod(parent); } else if (METHOD_MODIFY_DATASTREAM_BY_VALUE.equals(methodName)) { return new ModifyDatastreamByValueMethod(parent); } else if (METHOD_SET_DATASTREAM_STATE.equals(methodName)) { return new SetDatastreamStateMethod(parent); } else if (METHOD_SET_DATASTREAM_VERSIONABLE.equals(methodName)) { return new SetDatastreamVersionableMethod(parent); } else if (METHOD_PURGE_DATASTREAM.equals(methodName)) { return new PurgeDatastreamMethod(parent); } else if (METHOD_PURGE_RELATIONSHIP.equals(methodName)) { return new PurgeRelationshipMethod(parent); } else if (METHOD_PUT_TEMP_STREAM.equals(methodName)) { return new PutTempStreamMethod(parent); } else if (METHOD_GET_NEXT_PID.equals(methodName)) { return new GetNextPidMethod(parent); } else if (METHOD_ADD_RELATIONSHIP.equals(methodName)) { return new AddRelationshipMethod(parent); } else { throw new IllegalArgumentException("Unrecognized method name: '" + methodName + "'"); } }
java
public static ManagementMethod getInstance(String methodName, JournalEntry parent) { if (METHOD_INGEST.equals(methodName)) { return new IngestMethod(parent); } else if (METHOD_MODIFY_OBJECT.equals(methodName)) { return new ModifyObjectMethod(parent); } else if (METHOD_PURGE_OBJECT.equals(methodName)) { return new PurgeObjectMethod(parent); } else if (METHOD_ADD_DATASTREAM.equals(methodName)) { return new AddDatastreamMethod(parent); } else if (METHOD_MODIFY_DATASTREAM_BY_REFERENCE.equals(methodName)) { return new ModifyDatastreamByReferenceMethod(parent); } else if (METHOD_MODIFY_DATASTREAM_BY_VALUE.equals(methodName)) { return new ModifyDatastreamByValueMethod(parent); } else if (METHOD_SET_DATASTREAM_STATE.equals(methodName)) { return new SetDatastreamStateMethod(parent); } else if (METHOD_SET_DATASTREAM_VERSIONABLE.equals(methodName)) { return new SetDatastreamVersionableMethod(parent); } else if (METHOD_PURGE_DATASTREAM.equals(methodName)) { return new PurgeDatastreamMethod(parent); } else if (METHOD_PURGE_RELATIONSHIP.equals(methodName)) { return new PurgeRelationshipMethod(parent); } else if (METHOD_PUT_TEMP_STREAM.equals(methodName)) { return new PutTempStreamMethod(parent); } else if (METHOD_GET_NEXT_PID.equals(methodName)) { return new GetNextPidMethod(parent); } else if (METHOD_ADD_RELATIONSHIP.equals(methodName)) { return new AddRelationshipMethod(parent); } else { throw new IllegalArgumentException("Unrecognized method name: '" + methodName + "'"); } }
[ "public", "static", "ManagementMethod", "getInstance", "(", "String", "methodName", ",", "JournalEntry", "parent", ")", "{", "if", "(", "METHOD_INGEST", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "IngestMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_MODIFY_OBJECT", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "ModifyObjectMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_PURGE_OBJECT", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "PurgeObjectMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_ADD_DATASTREAM", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "AddDatastreamMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_MODIFY_DATASTREAM_BY_REFERENCE", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "ModifyDatastreamByReferenceMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_MODIFY_DATASTREAM_BY_VALUE", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "ModifyDatastreamByValueMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_SET_DATASTREAM_STATE", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "SetDatastreamStateMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_SET_DATASTREAM_VERSIONABLE", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "SetDatastreamVersionableMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_PURGE_DATASTREAM", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "PurgeDatastreamMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_PURGE_RELATIONSHIP", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "PurgeRelationshipMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_PUT_TEMP_STREAM", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "PutTempStreamMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_GET_NEXT_PID", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "GetNextPidMethod", "(", "parent", ")", ";", "}", "else", "if", "(", "METHOD_ADD_RELATIONSHIP", ".", "equals", "(", "methodName", ")", ")", "{", "return", "new", "AddRelationshipMethod", "(", "parent", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unrecognized method name: '\"", "+", "methodName", "+", "\"'\"", ")", ";", "}", "}" ]
Get an instance of the proper class, based on the method name.
[ "Get", "an", "instance", "of", "the", "proper", "class", "based", "on", "the", "method", "name", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/managementmethods/ManagementMethod.java#L33-L65
9,073
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/SpaceCharacters.java
SpaceCharacters.indent
public static void indent(int num, PrintWriter out) { if (num <= SIXTY_FOUR) { out.write(SIXTY_FOUR_SPACES, 0, num); return; } else if (num <= 128){ out.write(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); out.write(SIXTY_FOUR_SPACES, 0, num - SIXTY_FOUR); } else { int times = num / SIXTY_FOUR; int rem = num % SIXTY_FOUR; for (int i = 0; i< times; i++) { out.write(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); } out.write(SIXTY_FOUR_SPACES, 0, rem); return; } }
java
public static void indent(int num, PrintWriter out) { if (num <= SIXTY_FOUR) { out.write(SIXTY_FOUR_SPACES, 0, num); return; } else if (num <= 128){ out.write(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); out.write(SIXTY_FOUR_SPACES, 0, num - SIXTY_FOUR); } else { int times = num / SIXTY_FOUR; int rem = num % SIXTY_FOUR; for (int i = 0; i< times; i++) { out.write(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); } out.write(SIXTY_FOUR_SPACES, 0, rem); return; } }
[ "public", "static", "void", "indent", "(", "int", "num", ",", "PrintWriter", "out", ")", "{", "if", "(", "num", "<=", "SIXTY_FOUR", ")", "{", "out", ".", "write", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "num", ")", ";", "return", ";", "}", "else", "if", "(", "num", "<=", "128", ")", "{", "out", ".", "write", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "SIXTY_FOUR", ")", ";", "out", ".", "write", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "num", "-", "SIXTY_FOUR", ")", ";", "}", "else", "{", "int", "times", "=", "num", "/", "SIXTY_FOUR", ";", "int", "rem", "=", "num", "%", "SIXTY_FOUR", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "times", ";", "i", "++", ")", "{", "out", ".", "write", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "SIXTY_FOUR", ")", ";", "}", "out", ".", "write", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "rem", ")", ";", "return", ";", "}", "}" ]
Write a number of whitespaces to a writer @param num @param out
[ "Write", "a", "number", "of", "whitespaces", "to", "a", "writer" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/SpaceCharacters.java#L28-L44
9,074
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/utilities/SpaceCharacters.java
SpaceCharacters.indent
public static void indent(int num, StringBuilder out) { if (num <= SIXTY_FOUR) { out.append(SIXTY_FOUR_SPACES, 0, num); return; } else if (num <= 128){ // avoid initializing loop counters if only one iteration out.append(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); out.append(SIXTY_FOUR_SPACES, 0, num - SIXTY_FOUR); } else { int times = num / SIXTY_FOUR; int rem = num % SIXTY_FOUR; for (int i = 0; i< times; i++) { out.append(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); } out.append(SIXTY_FOUR_SPACES, 0, rem); return; } }
java
public static void indent(int num, StringBuilder out) { if (num <= SIXTY_FOUR) { out.append(SIXTY_FOUR_SPACES, 0, num); return; } else if (num <= 128){ // avoid initializing loop counters if only one iteration out.append(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); out.append(SIXTY_FOUR_SPACES, 0, num - SIXTY_FOUR); } else { int times = num / SIXTY_FOUR; int rem = num % SIXTY_FOUR; for (int i = 0; i< times; i++) { out.append(SIXTY_FOUR_SPACES, 0, SIXTY_FOUR); } out.append(SIXTY_FOUR_SPACES, 0, rem); return; } }
[ "public", "static", "void", "indent", "(", "int", "num", ",", "StringBuilder", "out", ")", "{", "if", "(", "num", "<=", "SIXTY_FOUR", ")", "{", "out", ".", "append", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "num", ")", ";", "return", ";", "}", "else", "if", "(", "num", "<=", "128", ")", "{", "// avoid initializing loop counters if only one iteration", "out", ".", "append", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "SIXTY_FOUR", ")", ";", "out", ".", "append", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "num", "-", "SIXTY_FOUR", ")", ";", "}", "else", "{", "int", "times", "=", "num", "/", "SIXTY_FOUR", ";", "int", "rem", "=", "num", "%", "SIXTY_FOUR", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "times", ";", "i", "++", ")", "{", "out", ".", "append", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "SIXTY_FOUR", ")", ";", "}", "out", ".", "append", "(", "SIXTY_FOUR_SPACES", ",", "0", ",", "rem", ")", ";", "return", ";", "}", "}" ]
Write a number of whitespaces to a StringBuffer @param num @param out
[ "Write", "a", "number", "of", "whitespaces", "to", "a", "StringBuffer" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/utilities/SpaceCharacters.java#L51-L68
9,075
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Module.java
Module.shutdownModule
@SuppressWarnings("unused") public void shutdownModule() throws ModuleShutdownException { logger.info("Shutting down " + getClass().getName()); if (1 == 2) { throw new ModuleShutdownException(null, null); } }
java
@SuppressWarnings("unused") public void shutdownModule() throws ModuleShutdownException { logger.info("Shutting down " + getClass().getName()); if (1 == 2) { throw new ModuleShutdownException(null, null); } }
[ "@", "SuppressWarnings", "(", "\"unused\"", ")", "public", "void", "shutdownModule", "(", ")", "throws", "ModuleShutdownException", "{", "logger", ".", "info", "(", "\"Shutting down \"", "+", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "if", "(", "1", "==", "2", ")", "{", "throw", "new", "ModuleShutdownException", "(", "null", ",", "null", ")", ";", "}", "}" ]
Frees system resources allocated by this Module. @throws ModuleShutdownException If there is a problem freeing system resources. Note that if there is a problem, it won't end up aborting the shutdown process. Therefore, this method should do everything possible to recover from exceptional situations before throwing an exception.
[ "Frees", "system", "resources", "allocated", "by", "this", "Module", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Module.java#L133-L139
9,076
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Server.java
Server.getServerConfigurationBeanDefinition
protected static BeanDefinition getServerConfigurationBeanDefinition(){ String className = ServerConfiguration.class.getName(); GenericBeanDefinition result = new GenericBeanDefinition(); result.setAutowireCandidate(true); result.setScope(BeanDefinition.SCOPE_SINGLETON); result.setBeanClass(Server.class); result.setFactoryMethodName("getConfig"); result.setAttribute("id", className); result.setAttribute("name", className); return result; }
java
protected static BeanDefinition getServerConfigurationBeanDefinition(){ String className = ServerConfiguration.class.getName(); GenericBeanDefinition result = new GenericBeanDefinition(); result.setAutowireCandidate(true); result.setScope(BeanDefinition.SCOPE_SINGLETON); result.setBeanClass(Server.class); result.setFactoryMethodName("getConfig"); result.setAttribute("id", className); result.setAttribute("name", className); return result; }
[ "protected", "static", "BeanDefinition", "getServerConfigurationBeanDefinition", "(", ")", "{", "String", "className", "=", "ServerConfiguration", ".", "class", ".", "getName", "(", ")", ";", "GenericBeanDefinition", "result", "=", "new", "GenericBeanDefinition", "(", ")", ";", "result", ".", "setAutowireCandidate", "(", "true", ")", ";", "result", ".", "setScope", "(", "BeanDefinition", ".", "SCOPE_SINGLETON", ")", ";", "result", ".", "setBeanClass", "(", "Server", ".", "class", ")", ";", "result", ".", "setFactoryMethodName", "(", "\"getConfig\"", ")", ";", "result", ".", "setAttribute", "(", "\"id\"", ",", "className", ")", ";", "result", ".", "setAttribute", "(", "\"name\"", ",", "className", ")", ";", "return", "result", ";", "}" ]
Provide a generic bean definition if the Server was not created by Spring @return
[ "Provide", "a", "generic", "bean", "definition", "if", "the", "Server", "was", "not", "created", "by", "Spring" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Server.java#L740-L750
9,077
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Server.java
Server.createModuleBeanDefinition
protected static GenericBeanDefinition createModuleBeanDefinition(String className, Map<String,String> params, String role) throws IOException { ScannedGenericBeanDefinition result = getScannedBeanDefinition(className); result.setParentName(Module.class.getName()); result.setScope(BeanDefinition.SCOPE_SINGLETON); result.setAttribute("id", role); result.setAttribute("name", role); result.setAttribute("init-method", "initModule"); result.setEnforceInitMethod(true); result.setAttribute("destroy-method", "shutdownModule"); result.setEnforceDestroyMethod(true); ConstructorArgumentValues cArgs = new ConstructorArgumentValues(); cArgs.addIndexedArgumentValue(0, params,MODULE_CONSTRUCTOR_PARAM1_CLASS); // one server bean in context BeanReference serverRef = new RuntimeBeanReference(MODULE_CONSTRUCTOR_PARAM2_CLASS); cArgs.addIndexedArgumentValue(1, serverRef); cArgs.addIndexedArgumentValue(2, role,MODULE_CONSTRUCTOR_PARAM3_CLASS); result.setConstructorArgumentValues(cArgs); return result; }
java
protected static GenericBeanDefinition createModuleBeanDefinition(String className, Map<String,String> params, String role) throws IOException { ScannedGenericBeanDefinition result = getScannedBeanDefinition(className); result.setParentName(Module.class.getName()); result.setScope(BeanDefinition.SCOPE_SINGLETON); result.setAttribute("id", role); result.setAttribute("name", role); result.setAttribute("init-method", "initModule"); result.setEnforceInitMethod(true); result.setAttribute("destroy-method", "shutdownModule"); result.setEnforceDestroyMethod(true); ConstructorArgumentValues cArgs = new ConstructorArgumentValues(); cArgs.addIndexedArgumentValue(0, params,MODULE_CONSTRUCTOR_PARAM1_CLASS); // one server bean in context BeanReference serverRef = new RuntimeBeanReference(MODULE_CONSTRUCTOR_PARAM2_CLASS); cArgs.addIndexedArgumentValue(1, serverRef); cArgs.addIndexedArgumentValue(2, role,MODULE_CONSTRUCTOR_PARAM3_CLASS); result.setConstructorArgumentValues(cArgs); return result; }
[ "protected", "static", "GenericBeanDefinition", "createModuleBeanDefinition", "(", "String", "className", ",", "Map", "<", "String", ",", "String", ">", "params", ",", "String", "role", ")", "throws", "IOException", "{", "ScannedGenericBeanDefinition", "result", "=", "getScannedBeanDefinition", "(", "className", ")", ";", "result", ".", "setParentName", "(", "Module", ".", "class", ".", "getName", "(", ")", ")", ";", "result", ".", "setScope", "(", "BeanDefinition", ".", "SCOPE_SINGLETON", ")", ";", "result", ".", "setAttribute", "(", "\"id\"", ",", "role", ")", ";", "result", ".", "setAttribute", "(", "\"name\"", ",", "role", ")", ";", "result", ".", "setAttribute", "(", "\"init-method\"", ",", "\"initModule\"", ")", ";", "result", ".", "setEnforceInitMethod", "(", "true", ")", ";", "result", ".", "setAttribute", "(", "\"destroy-method\"", ",", "\"shutdownModule\"", ")", ";", "result", ".", "setEnforceDestroyMethod", "(", "true", ")", ";", "ConstructorArgumentValues", "cArgs", "=", "new", "ConstructorArgumentValues", "(", ")", ";", "cArgs", ".", "addIndexedArgumentValue", "(", "0", ",", "params", ",", "MODULE_CONSTRUCTOR_PARAM1_CLASS", ")", ";", "// one server bean in context", "BeanReference", "serverRef", "=", "new", "RuntimeBeanReference", "(", "MODULE_CONSTRUCTOR_PARAM2_CLASS", ")", ";", "cArgs", ".", "addIndexedArgumentValue", "(", "1", ",", "serverRef", ")", ";", "cArgs", ".", "addIndexedArgumentValue", "(", "2", ",", "role", ",", "MODULE_CONSTRUCTOR_PARAM3_CLASS", ")", ";", "result", ".", "setConstructorArgumentValues", "(", "cArgs", ")", ";", "return", "result", ";", "}" ]
Generates Spring Bean definitions for Fedora Modules. Server param should be unnecessary if autowired. @param className @param params @param role @return
[ "Generates", "Spring", "Bean", "definitions", "for", "Fedora", "Modules", ".", "Server", "param", "should", "be", "unnecessary", "if", "autowired", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Server.java#L787-L807
9,078
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Server.java
Server.getPID
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
java
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
[ "public", "static", "PID", "getPID", "(", "String", "pidString", ")", "throws", "MalformedPidException", "{", "try", "{", "return", "new", "PID", "(", "pidString", ")", ";", "}", "catch", "(", "MalformedPIDException", "e", ")", "{", "throw", "new", "MalformedPidException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Wraps PID constructor, throwing a ServerException instead
[ "Wraps", "PID", "constructor", "throwing", "a", "ServerException", "instead" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Server.java#L1495-L1501
9,079
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Server.java
Server.pidFromFilename
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
java
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
[ "public", "static", "PID", "pidFromFilename", "(", "String", "filename", ")", "throws", "MalformedPidException", "{", "try", "{", "return", "PID", ".", "fromFilename", "(", "filename", ")", ";", "}", "catch", "(", "MalformedPIDException", "e", ")", "{", "throw", "new", "MalformedPidException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Wraps PID.fromFilename, throwing a ServerException instead
[ "Wraps", "PID", ".", "fromFilename", "throwing", "a", "ServerException", "instead" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Server.java#L1504-L1511
9,080
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/Server.java
Server.getCurrentDate
public static Date getCurrentDate(Context context) throws GeneralException { URI propName = Constants.ENVIRONMENT.CURRENT_DATE_TIME.attributeId; String dateTimeValue = context.getEnvironmentValue(propName); if (dateTimeValue == null) { throw new GeneralException("Missing value for environment " + "context attribute: " + propName); } try { return DateUtility.parseDateStrict(dateTimeValue); } catch (ParseException e) { throw new GeneralException(e.getMessage()); } }
java
public static Date getCurrentDate(Context context) throws GeneralException { URI propName = Constants.ENVIRONMENT.CURRENT_DATE_TIME.attributeId; String dateTimeValue = context.getEnvironmentValue(propName); if (dateTimeValue == null) { throw new GeneralException("Missing value for environment " + "context attribute: " + propName); } try { return DateUtility.parseDateStrict(dateTimeValue); } catch (ParseException e) { throw new GeneralException(e.getMessage()); } }
[ "public", "static", "Date", "getCurrentDate", "(", "Context", "context", ")", "throws", "GeneralException", "{", "URI", "propName", "=", "Constants", ".", "ENVIRONMENT", ".", "CURRENT_DATE_TIME", ".", "attributeId", ";", "String", "dateTimeValue", "=", "context", ".", "getEnvironmentValue", "(", "propName", ")", ";", "if", "(", "dateTimeValue", "==", "null", ")", "{", "throw", "new", "GeneralException", "(", "\"Missing value for environment \"", "+", "\"context attribute: \"", "+", "propName", ")", ";", "}", "try", "{", "return", "DateUtility", ".", "parseDateStrict", "(", "dateTimeValue", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "throw", "new", "GeneralException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Get the current date from the context. If the context doesn't specify a value for the current date, or the specified value cannot be parsed as an ISO8601 date string, a GeneralException will be thrown.
[ "Get", "the", "current", "date", "from", "the", "context", ".", "If", "the", "context", "doesn", "t", "specify", "a", "value", "for", "the", "current", "date", "or", "the", "specified", "value", "cannot", "be", "parsed", "as", "an", "ISO8601", "date", "string", "a", "GeneralException", "will", "be", "thrown", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/Server.java#L1518-L1532
9,081
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java
AtomDODeserializer.addObjectProperties
private void addObjectProperties(Feed feed, DigitalObject obj) throws ObjectIntegrityException { PID pid; try { pid = new PID(feed.getId().toString()); } catch (MalformedPIDException e) { throw new ObjectIntegrityException(e.getMessage(), e); } String label = feed.getTitle(); String state = m_xpath.valueOf("/a:feed/a:category[@scheme='" + MODEL.STATE.uri + "']/@term", feed); String createDate = m_xpath.valueOf("/a:feed/a:category[@scheme='" + MODEL.CREATED_DATE.uri + "']/@term", feed); obj.setPid(pid.toString()); try { obj.setState(DOTranslationUtility.readStateAttribute(state)); } catch (ParseException e) { throw new ObjectIntegrityException("Could not read object state", e); } obj.setLabel(label); obj.setOwnerId(getOwnerId(feed)); obj.setCreateDate(DateUtility.convertStringToDate(createDate)); obj.setLastModDate(feed.getUpdated()); setExtProps(obj, feed); }
java
private void addObjectProperties(Feed feed, DigitalObject obj) throws ObjectIntegrityException { PID pid; try { pid = new PID(feed.getId().toString()); } catch (MalformedPIDException e) { throw new ObjectIntegrityException(e.getMessage(), e); } String label = feed.getTitle(); String state = m_xpath.valueOf("/a:feed/a:category[@scheme='" + MODEL.STATE.uri + "']/@term", feed); String createDate = m_xpath.valueOf("/a:feed/a:category[@scheme='" + MODEL.CREATED_DATE.uri + "']/@term", feed); obj.setPid(pid.toString()); try { obj.setState(DOTranslationUtility.readStateAttribute(state)); } catch (ParseException e) { throw new ObjectIntegrityException("Could not read object state", e); } obj.setLabel(label); obj.setOwnerId(getOwnerId(feed)); obj.setCreateDate(DateUtility.convertStringToDate(createDate)); obj.setLastModDate(feed.getUpdated()); setExtProps(obj, feed); }
[ "private", "void", "addObjectProperties", "(", "Feed", "feed", ",", "DigitalObject", "obj", ")", "throws", "ObjectIntegrityException", "{", "PID", "pid", ";", "try", "{", "pid", "=", "new", "PID", "(", "feed", ".", "getId", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "catch", "(", "MalformedPIDException", "e", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "String", "label", "=", "feed", ".", "getTitle", "(", ")", ";", "String", "state", "=", "m_xpath", ".", "valueOf", "(", "\"/a:feed/a:category[@scheme='\"", "+", "MODEL", ".", "STATE", ".", "uri", "+", "\"']/@term\"", ",", "feed", ")", ";", "String", "createDate", "=", "m_xpath", ".", "valueOf", "(", "\"/a:feed/a:category[@scheme='\"", "+", "MODEL", ".", "CREATED_DATE", ".", "uri", "+", "\"']/@term\"", ",", "feed", ")", ";", "obj", ".", "setPid", "(", "pid", ".", "toString", "(", ")", ")", ";", "try", "{", "obj", ".", "setState", "(", "DOTranslationUtility", ".", "readStateAttribute", "(", "state", ")", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Could not read object state\"", ",", "e", ")", ";", "}", "obj", ".", "setLabel", "(", "label", ")", ";", "obj", ".", "setOwnerId", "(", "getOwnerId", "(", "feed", ")", ")", ";", "obj", ".", "setCreateDate", "(", "DateUtility", ".", "convertStringToDate", "(", "createDate", ")", ")", ";", "obj", ".", "setLastModDate", "(", "feed", ".", "getUpdated", "(", ")", ")", ";", "setExtProps", "(", "obj", ",", "feed", ")", ";", "}" ]
Set the Fedora Object properties from the Feed metadata. @throws ObjectIntegrityException
[ "Set", "the", "Fedora", "Object", "properties", "from", "the", "Feed", "metadata", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java#L160-L191
9,082
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java
AtomDODeserializer.getDatastreamId
private String getDatastreamId(DigitalObject obj, Entry entry) { String entryId = entry.getId().toString(); // matches info:fedora/pid/dsid/timestamp Pattern pattern = Pattern.compile("^" + Constants.FEDORA.uri + ".+?/([^/]+)/?.*"); Matcher matcher = pattern.matcher(entryId); if (matcher.find()) { return matcher.group(1); } else { return obj.newDatastreamID(); } }
java
private String getDatastreamId(DigitalObject obj, Entry entry) { String entryId = entry.getId().toString(); // matches info:fedora/pid/dsid/timestamp Pattern pattern = Pattern.compile("^" + Constants.FEDORA.uri + ".+?/([^/]+)/?.*"); Matcher matcher = pattern.matcher(entryId); if (matcher.find()) { return matcher.group(1); } else { return obj.newDatastreamID(); } }
[ "private", "String", "getDatastreamId", "(", "DigitalObject", "obj", ",", "Entry", "entry", ")", "{", "String", "entryId", "=", "entry", ".", "getId", "(", ")", ".", "toString", "(", ")", ";", "// matches info:fedora/pid/dsid/timestamp", "Pattern", "pattern", "=", "Pattern", ".", "compile", "(", "\"^\"", "+", "Constants", ".", "FEDORA", ".", "uri", "+", "\".+?/([^/]+)/?.*\"", ")", ";", "Matcher", "matcher", "=", "pattern", ".", "matcher", "(", "entryId", ")", ";", "if", "(", "matcher", ".", "find", "(", ")", ")", "{", "return", "matcher", ".", "group", "(", "1", ")", ";", "}", "else", "{", "return", "obj", ".", "newDatastreamID", "(", ")", ";", "}", "}" ]
Parses the id to determine a datastreamId. @param id @return
[ "Parses", "the", "id", "to", "determine", "a", "datastreamId", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java#L390-L402
9,083
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java
AtomDODeserializer.getContentSrcAsFile
protected File getContentSrcAsFile(IRI contentSrc, File tempDir) throws ObjectIntegrityException, IOException { if (contentSrc.isAbsolute() || contentSrc.isPathAbsolute()) { throw new ObjectIntegrityException("contentSrc must not be absolute"); } try { // Normalize the IRI to resolve percent-encoding and // backtracking (e.g. "../") NormalizedURI nUri = new NormalizedURI(tempDir.toURI().toString() + contentSrc.toString()); nUri.normalize(); File f = new File(nUri.toURI()); if (f.getParentFile().equals(tempDir)) { File temp = File.createTempFile("binary-datastream", null); FileUtils.move(f, temp); temp.deleteOnExit(); return temp; //return f; } else { throw new ObjectIntegrityException(contentSrc.toString() + " is not a valid path."); } } catch (URISyntaxException e) { throw new ObjectIntegrityException(e.getMessage(), e); } }
java
protected File getContentSrcAsFile(IRI contentSrc, File tempDir) throws ObjectIntegrityException, IOException { if (contentSrc.isAbsolute() || contentSrc.isPathAbsolute()) { throw new ObjectIntegrityException("contentSrc must not be absolute"); } try { // Normalize the IRI to resolve percent-encoding and // backtracking (e.g. "../") NormalizedURI nUri = new NormalizedURI(tempDir.toURI().toString() + contentSrc.toString()); nUri.normalize(); File f = new File(nUri.toURI()); if (f.getParentFile().equals(tempDir)) { File temp = File.createTempFile("binary-datastream", null); FileUtils.move(f, temp); temp.deleteOnExit(); return temp; //return f; } else { throw new ObjectIntegrityException(contentSrc.toString() + " is not a valid path."); } } catch (URISyntaxException e) { throw new ObjectIntegrityException(e.getMessage(), e); } }
[ "protected", "File", "getContentSrcAsFile", "(", "IRI", "contentSrc", ",", "File", "tempDir", ")", "throws", "ObjectIntegrityException", ",", "IOException", "{", "if", "(", "contentSrc", ".", "isAbsolute", "(", ")", "||", "contentSrc", ".", "isPathAbsolute", "(", ")", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"contentSrc must not be absolute\"", ")", ";", "}", "try", "{", "// Normalize the IRI to resolve percent-encoding and", "// backtracking (e.g. \"../\")", "NormalizedURI", "nUri", "=", "new", "NormalizedURI", "(", "tempDir", ".", "toURI", "(", ")", ".", "toString", "(", ")", "+", "contentSrc", ".", "toString", "(", ")", ")", ";", "nUri", ".", "normalize", "(", ")", ";", "File", "f", "=", "new", "File", "(", "nUri", ".", "toURI", "(", ")", ")", ";", "if", "(", "f", ".", "getParentFile", "(", ")", ".", "equals", "(", "tempDir", ")", ")", "{", "File", "temp", "=", "File", ".", "createTempFile", "(", "\"binary-datastream\"", ",", "null", ")", ";", "FileUtils", ".", "move", "(", "f", ",", "temp", ")", ";", "temp", ".", "deleteOnExit", "(", ")", ";", "return", "temp", ";", "//return f;", "}", "else", "{", "throw", "new", "ObjectIntegrityException", "(", "contentSrc", ".", "toString", "(", ")", "+", "\" is not a valid path.\"", ")", ";", "}", "}", "catch", "(", "URISyntaxException", "e", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Returns the an Entry's contentSrc as a File relative to the tempDir param. @param contentSrc @param tempDir @return the contentSrc as a File relative to tempDir. @throws ObjectIntegrityException
[ "Returns", "the", "an", "Entry", "s", "contentSrc", "as", "a", "File", "relative", "to", "the", "tempDir", "param", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/AtomDODeserializer.java#L607-L631
9,084
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOReader.java
SimpleDOReader.GetObjectXML
@Override public InputStream GetObjectXML() throws ObjectIntegrityException, StreamIOException, UnsupportedTranslationException, ServerException { ReadableByteArrayOutputStream bytes = new ReadableByteArrayOutputStream(4096); m_translator.serialize(m_obj, bytes, m_storageFormat, "UTF-8", DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL); return bytes.toInputStream(); }
java
@Override public InputStream GetObjectXML() throws ObjectIntegrityException, StreamIOException, UnsupportedTranslationException, ServerException { ReadableByteArrayOutputStream bytes = new ReadableByteArrayOutputStream(4096); m_translator.serialize(m_obj, bytes, m_storageFormat, "UTF-8", DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL); return bytes.toInputStream(); }
[ "@", "Override", "public", "InputStream", "GetObjectXML", "(", ")", "throws", "ObjectIntegrityException", ",", "StreamIOException", ",", "UnsupportedTranslationException", ",", "ServerException", "{", "ReadableByteArrayOutputStream", "bytes", "=", "new", "ReadableByteArrayOutputStream", "(", "4096", ")", ";", "m_translator", ".", "serialize", "(", "m_obj", ",", "bytes", ",", "m_storageFormat", ",", "\"UTF-8\"", ",", "DOTranslationUtility", ".", "SERIALIZE_STORAGE_INTERNAL", ")", ";", "return", "bytes", ".", "toInputStream", "(", ")", ";", "}" ]
Return the object as an XML input stream in the internal serialization format.
[ "Return", "the", "object", "as", "an", "XML", "input", "stream", "in", "the", "internal", "serialization", "format", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOReader.java#L164-L174
9,085
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/rest/MethodResource.java
MethodResource.getAllObjectMethods
@GET @Produces({ HTML, XML }) public Response getAllObjectMethods( @PathParam(RestParam.PID) String pid, @QueryParam(RestParam.AS_OF_DATE_TIME) String dTime, @QueryParam(RestParam.FORMAT) @DefaultValue(HTML) String format, @QueryParam(RestParam.FLASH) @DefaultValue("false") boolean flash) { return getObjectMethodsForSDefImpl(pid, null, dTime, format, flash); }
java
@GET @Produces({ HTML, XML }) public Response getAllObjectMethods( @PathParam(RestParam.PID) String pid, @QueryParam(RestParam.AS_OF_DATE_TIME) String dTime, @QueryParam(RestParam.FORMAT) @DefaultValue(HTML) String format, @QueryParam(RestParam.FLASH) @DefaultValue("false") boolean flash) { return getObjectMethodsForSDefImpl(pid, null, dTime, format, flash); }
[ "@", "GET", "@", "Produces", "(", "{", "HTML", ",", "XML", "}", ")", "public", "Response", "getAllObjectMethods", "(", "@", "PathParam", "(", "RestParam", ".", "PID", ")", "String", "pid", ",", "@", "QueryParam", "(", "RestParam", ".", "AS_OF_DATE_TIME", ")", "String", "dTime", ",", "@", "QueryParam", "(", "RestParam", ".", "FORMAT", ")", "@", "DefaultValue", "(", "HTML", ")", "String", "format", ",", "@", "QueryParam", "(", "RestParam", ".", "FLASH", ")", "@", "DefaultValue", "(", "\"false\"", ")", "boolean", "flash", ")", "{", "return", "getObjectMethodsForSDefImpl", "(", "pid", ",", "null", ",", "dTime", ",", "format", ",", "flash", ")", ";", "}" ]
Lists all Service Definitions methods that can be invoked on a digital object. GET /objects/{pid}/methods ? format asOfDateTime
[ "Lists", "all", "Service", "Definitions", "methods", "that", "can", "be", "invoked", "on", "a", "digital", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/rest/MethodResource.java#L51-L65
9,086
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/rest/MethodResource.java
MethodResource.getObjectMethodsForSDef
@Path("/{sDef}") @GET @Produces({ HTML, XML }) public Response getObjectMethodsForSDef( @PathParam(RestParam.PID) String pid, @PathParam(RestParam.SDEF) String sDef, @QueryParam(RestParam.AS_OF_DATE_TIME) String dTime, @QueryParam(RestParam.FORMAT) @DefaultValue(HTML) String format, @QueryParam(RestParam.FLASH) @DefaultValue("false") boolean flash) { return getObjectMethodsForSDefImpl(pid, sDef, dTime, format, flash); }
java
@Path("/{sDef}") @GET @Produces({ HTML, XML }) public Response getObjectMethodsForSDef( @PathParam(RestParam.PID) String pid, @PathParam(RestParam.SDEF) String sDef, @QueryParam(RestParam.AS_OF_DATE_TIME) String dTime, @QueryParam(RestParam.FORMAT) @DefaultValue(HTML) String format, @QueryParam(RestParam.FLASH) @DefaultValue("false") boolean flash) { return getObjectMethodsForSDefImpl(pid, sDef, dTime, format, flash); }
[ "@", "Path", "(", "\"/{sDef}\"", ")", "@", "GET", "@", "Produces", "(", "{", "HTML", ",", "XML", "}", ")", "public", "Response", "getObjectMethodsForSDef", "(", "@", "PathParam", "(", "RestParam", ".", "PID", ")", "String", "pid", ",", "@", "PathParam", "(", "RestParam", ".", "SDEF", ")", "String", "sDef", ",", "@", "QueryParam", "(", "RestParam", ".", "AS_OF_DATE_TIME", ")", "String", "dTime", ",", "@", "QueryParam", "(", "RestParam", ".", "FORMAT", ")", "@", "DefaultValue", "(", "HTML", ")", "String", "format", ",", "@", "QueryParam", "(", "RestParam", ".", "FLASH", ")", "@", "DefaultValue", "(", "\"false\"", ")", "boolean", "flash", ")", "{", "return", "getObjectMethodsForSDefImpl", "(", "pid", ",", "sDef", ",", "dTime", ",", "format", ",", "flash", ")", ";", "}" ]
Lists all Service Definitions methods that can be invoked on a digital object, for the supplied Service Definition. GET /objects/{pid}/methods/{sDef} ? format asOfDateTime
[ "Lists", "all", "Service", "Definitions", "methods", "that", "can", "be", "invoked", "on", "a", "digital", "object", "for", "the", "supplied", "Service", "Definition", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/rest/MethodResource.java#L73-L90
9,087
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.getInstance
public static JournalWriter getInstance(Map<String, String> parameters, String role, ServerInterface server) throws JournalException { Object journalWriter = JournalHelper .createInstanceAccordingToParameter(PARAMETER_JOURNAL_WRITER_CLASSNAME, new Class[] { Map.class, String.class, ServerInterface.class}, new Object[] { parameters, role, server}, parameters); logger.info("JournalWriter is " + journalWriter.toString()); return (JournalWriter) journalWriter; }
java
public static JournalWriter getInstance(Map<String, String> parameters, String role, ServerInterface server) throws JournalException { Object journalWriter = JournalHelper .createInstanceAccordingToParameter(PARAMETER_JOURNAL_WRITER_CLASSNAME, new Class[] { Map.class, String.class, ServerInterface.class}, new Object[] { parameters, role, server}, parameters); logger.info("JournalWriter is " + journalWriter.toString()); return (JournalWriter) journalWriter; }
[ "public", "static", "JournalWriter", "getInstance", "(", "Map", "<", "String", ",", "String", ">", "parameters", ",", "String", "role", ",", "ServerInterface", "server", ")", "throws", "JournalException", "{", "Object", "journalWriter", "=", "JournalHelper", ".", "createInstanceAccordingToParameter", "(", "PARAMETER_JOURNAL_WRITER_CLASSNAME", ",", "new", "Class", "[", "]", "{", "Map", ".", "class", ",", "String", ".", "class", ",", "ServerInterface", ".", "class", "}", ",", "new", "Object", "[", "]", "{", "parameters", ",", "role", ",", "server", "}", ",", "parameters", ")", ";", "logger", ".", "info", "(", "\"JournalWriter is \"", "+", "journalWriter", ".", "toString", "(", ")", ")", ";", "return", "(", "JournalWriter", ")", "journalWriter", ";", "}" ]
Create an instance of the proper JournalWriter child class, as determined by the server parameters.
[ "Create", "an", "instance", "of", "the", "proper", "JournalWriter", "child", "class", "as", "determined", "by", "the", "server", "parameters", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L86-L104
9,088
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.writeDocumentHeader
protected void writeDocumentHeader(XMLEventWriter writer, String repositoryHash, Date currentDate) throws JournalException { try { putStartDocument(writer); putStartTag(writer, QNAME_TAG_JOURNAL); putAttribute(writer, QNAME_ATTR_REPOSITORY_HASH, repositoryHash); putAttribute(writer, QNAME_ATTR_TIMESTAMP, JournalHelper .formatDate(currentDate)); } catch (XMLStreamException e) { throw new JournalException(e); } }
java
protected void writeDocumentHeader(XMLEventWriter writer, String repositoryHash, Date currentDate) throws JournalException { try { putStartDocument(writer); putStartTag(writer, QNAME_TAG_JOURNAL); putAttribute(writer, QNAME_ATTR_REPOSITORY_HASH, repositoryHash); putAttribute(writer, QNAME_ATTR_TIMESTAMP, JournalHelper .formatDate(currentDate)); } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "protected", "void", "writeDocumentHeader", "(", "XMLEventWriter", "writer", ",", "String", "repositoryHash", ",", "Date", "currentDate", ")", "throws", "JournalException", "{", "try", "{", "putStartDocument", "(", "writer", ")", ";", "putStartTag", "(", "writer", ",", "QNAME_TAG_JOURNAL", ")", ";", "putAttribute", "(", "writer", ",", "QNAME_ATTR_REPOSITORY_HASH", ",", "repositoryHash", ")", ";", "putAttribute", "(", "writer", ",", "QNAME_ATTR_TIMESTAMP", ",", "JournalHelper", ".", "formatDate", "(", "currentDate", ")", ")", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Subclasses should call this method to initialize a new Journal file, if they already know the repository hash and the current date.
[ "Subclasses", "should", "call", "this", "method", "to", "initialize", "a", "new", "Journal", "file", "if", "they", "already", "know", "the", "repository", "hash", "and", "the", "current", "date", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L156-L169
9,089
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.writeDocumentTrailer
protected void writeDocumentTrailer(XMLEventWriter writer) throws JournalException { try { putEndDocument(writer); } catch (XMLStreamException e) { throw new JournalException(e); } }
java
protected void writeDocumentTrailer(XMLEventWriter writer) throws JournalException { try { putEndDocument(writer); } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "protected", "void", "writeDocumentTrailer", "(", "XMLEventWriter", "writer", ")", "throws", "JournalException", "{", "try", "{", "putEndDocument", "(", "writer", ")", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Subclasses should call this method to close a Journal file.
[ "Subclasses", "should", "call", "this", "method", "to", "close", "a", "Journal", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L174-L181
9,090
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.writeJournalEntry
protected void writeJournalEntry(CreatorJournalEntry journalEntry, XMLEventWriter writer) throws JournalException { try { writeJournaEntryStartTag(journalEntry, writer); new ContextXmlWriter().writeContext(journalEntry.getContext(), writer); writeArguments(journalEntry.getArgumentsMap(), writer); putEndTag(writer, QNAME_TAG_JOURNAL_ENTRY); writer.flush(); } catch (XMLStreamException e) { throw new JournalException(e); } }
java
protected void writeJournalEntry(CreatorJournalEntry journalEntry, XMLEventWriter writer) throws JournalException { try { writeJournaEntryStartTag(journalEntry, writer); new ContextXmlWriter().writeContext(journalEntry.getContext(), writer); writeArguments(journalEntry.getArgumentsMap(), writer); putEndTag(writer, QNAME_TAG_JOURNAL_ENTRY); writer.flush(); } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "protected", "void", "writeJournalEntry", "(", "CreatorJournalEntry", "journalEntry", ",", "XMLEventWriter", "writer", ")", "throws", "JournalException", "{", "try", "{", "writeJournaEntryStartTag", "(", "journalEntry", ",", "writer", ")", ";", "new", "ContextXmlWriter", "(", ")", ".", "writeContext", "(", "journalEntry", ".", "getContext", "(", ")", ",", "writer", ")", ";", "writeArguments", "(", "journalEntry", ".", "getArgumentsMap", "(", ")", ",", "writer", ")", ";", "putEndTag", "(", "writer", ",", "QNAME_TAG_JOURNAL_ENTRY", ")", ";", "writer", ".", "flush", "(", ")", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Format a JournalEntry object and write a JournalEntry tag to the journal.
[ "Format", "a", "JournalEntry", "object", "and", "write", "a", "JournalEntry", "tag", "to", "the", "journal", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L186-L202
9,091
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.writeFileArgument
private void writeFileArgument(String key, File file, XMLEventWriter writer) throws XMLStreamException, JournalException { try { putStartTag(writer, QNAME_TAG_ARGUMENT); putAttribute(writer, QNAME_ATTR_NAME, key); putAttribute(writer, QNAME_ATTR_TYPE, ARGUMENT_TYPE_STREAM); EncodingBase64InputStream encoder = new EncodingBase64InputStream(new BufferedInputStream(new FileInputStream(file))); String encodedChunk; while (null != (encodedChunk = encoder.read(1000))) { putCharacters(writer, encodedChunk); } encoder.close(); putEndTag(writer, QNAME_TAG_ARGUMENT); } catch (IOException e) { throw new JournalException("IO Exception on temp file", e); } }
java
private void writeFileArgument(String key, File file, XMLEventWriter writer) throws XMLStreamException, JournalException { try { putStartTag(writer, QNAME_TAG_ARGUMENT); putAttribute(writer, QNAME_ATTR_NAME, key); putAttribute(writer, QNAME_ATTR_TYPE, ARGUMENT_TYPE_STREAM); EncodingBase64InputStream encoder = new EncodingBase64InputStream(new BufferedInputStream(new FileInputStream(file))); String encodedChunk; while (null != (encodedChunk = encoder.read(1000))) { putCharacters(writer, encodedChunk); } encoder.close(); putEndTag(writer, QNAME_TAG_ARGUMENT); } catch (IOException e) { throw new JournalException("IO Exception on temp file", e); } }
[ "private", "void", "writeFileArgument", "(", "String", "key", ",", "File", "file", ",", "XMLEventWriter", "writer", ")", "throws", "XMLStreamException", ",", "JournalException", "{", "try", "{", "putStartTag", "(", "writer", ",", "QNAME_TAG_ARGUMENT", ")", ";", "putAttribute", "(", "writer", ",", "QNAME_ATTR_NAME", ",", "key", ")", ";", "putAttribute", "(", "writer", ",", "QNAME_ATTR_TYPE", ",", "ARGUMENT_TYPE_STREAM", ")", ";", "EncodingBase64InputStream", "encoder", "=", "new", "EncodingBase64InputStream", "(", "new", "BufferedInputStream", "(", "new", "FileInputStream", "(", "file", ")", ")", ")", ";", "String", "encodedChunk", ";", "while", "(", "null", "!=", "(", "encodedChunk", "=", "encoder", ".", "read", "(", "1000", ")", ")", ")", "{", "putCharacters", "(", "writer", ",", "encodedChunk", ")", ";", "}", "encoder", ".", "close", "(", ")", ";", "putEndTag", "(", "writer", ",", "QNAME_TAG_ARGUMENT", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "\"IO Exception on temp file\"", ",", "e", ")", ";", "}", "}" ]
An InputStream argument must be written as a Base64-encoded String. It is read from the temp file in segments. Each segment is encoded and written to the XML writer as a series of character events.
[ "An", "InputStream", "argument", "must", "be", "written", "as", "a", "Base64", "-", "encoded", "String", ".", "It", "is", "read", "from", "the", "temp", "file", "in", "segments", ".", "Each", "segment", "is", "encoded", "and", "written", "to", "the", "XML", "writer", "as", "a", "series", "of", "character", "events", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L327-L345
9,092
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java
JournalWriter.getRepositoryHash
private String getRepositoryHash() throws JournalException { if (!server.hasInitialized()) { throw new IllegalStateException("The repository hash is not available until " + "the server is fully initialized."); } try { return server.getRepositoryHash(); } catch (ServerException e) { throw new JournalException(e); } }
java
private String getRepositoryHash() throws JournalException { if (!server.hasInitialized()) { throw new IllegalStateException("The repository hash is not available until " + "the server is fully initialized."); } try { return server.getRepositoryHash(); } catch (ServerException e) { throw new JournalException(e); } }
[ "private", "String", "getRepositoryHash", "(", ")", "throws", "JournalException", "{", "if", "(", "!", "server", ".", "hasInitialized", "(", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "\"The repository hash is not available until \"", "+", "\"the server is fully initialized.\"", ")", ";", "}", "try", "{", "return", "server", ".", "getRepositoryHash", "(", ")", ";", "}", "catch", "(", "ServerException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
This method must not be called before the server has completed initialization. That's the only way we can be confident that the DOManager is present, and ready to create the repository has that we will compare to.
[ "This", "method", "must", "not", "be", "called", "before", "the", "server", "has", "completed", "initialization", ".", "That", "s", "the", "only", "way", "we", "can", "be", "confident", "that", "the", "DOManager", "is", "present", "and", "ready", "to", "create", "the", "repository", "has", "that", "we", "will", "compare", "to", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalWriter.java#L353-L364
9,093
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchSQLImpl.java
FieldSearchSQLImpl.closeAndForgetOldResults
private void closeAndForgetOldResults() { Iterator<FieldSearchResultSQLImpl> iter = m_currentResults.values().iterator(); while (iter.hasNext()) { FieldSearchResultSQLImpl r = iter.next(); if (r.isExpired()) { logger.debug("listSession " + r.getToken() + " expired; will forget it."); iter.remove(); } } }
java
private void closeAndForgetOldResults() { Iterator<FieldSearchResultSQLImpl> iter = m_currentResults.values().iterator(); while (iter.hasNext()) { FieldSearchResultSQLImpl r = iter.next(); if (r.isExpired()) { logger.debug("listSession " + r.getToken() + " expired; will forget it."); iter.remove(); } } }
[ "private", "void", "closeAndForgetOldResults", "(", ")", "{", "Iterator", "<", "FieldSearchResultSQLImpl", ">", "iter", "=", "m_currentResults", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "iter", ".", "hasNext", "(", ")", ")", "{", "FieldSearchResultSQLImpl", "r", "=", "iter", ".", "next", "(", ")", ";", "if", "(", "r", ".", "isExpired", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"listSession \"", "+", "r", ".", "getToken", "(", ")", "+", "\" expired; will forget it.\"", ")", ";", "iter", ".", "remove", "(", ")", ";", "}", "}", "}" ]
erase and cleanup expired stuff
[ "erase", "and", "cleanup", "expired", "stuff" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchSQLImpl.java#L387-L398
9,094
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchSQLImpl.java
FieldSearchSQLImpl.getDbValue
private static String getDbValue(List<DCField> dcFields) { if (dcFields.size() == 0) { return null; } StringBuilder out = new StringBuilder(64 * dcFields.size()); for (DCField dcField : dcFields) { out.append(' '); out.append(dcField.getValue().toLowerCase()); } out.append(" ."); return out.toString(); }
java
private static String getDbValue(List<DCField> dcFields) { if (dcFields.size() == 0) { return null; } StringBuilder out = new StringBuilder(64 * dcFields.size()); for (DCField dcField : dcFields) { out.append(' '); out.append(dcField.getValue().toLowerCase()); } out.append(" ."); return out.toString(); }
[ "private", "static", "String", "getDbValue", "(", "List", "<", "DCField", ">", "dcFields", ")", "{", "if", "(", "dcFields", ".", "size", "(", ")", "==", "0", ")", "{", "return", "null", ";", "}", "StringBuilder", "out", "=", "new", "StringBuilder", "(", "64", "*", "dcFields", ".", "size", "(", ")", ")", ";", "for", "(", "DCField", "dcField", ":", "dcFields", ")", "{", "out", ".", "append", "(", "'", "'", ")", ";", "out", ".", "append", "(", "dcField", ".", "getValue", "(", ")", ".", "toLowerCase", "(", ")", ")", ";", "}", "out", ".", "append", "(", "\" .\"", ")", ";", "return", "out", ".", "toString", "(", ")", ";", "}" ]
Get the string that should be inserted for a repeating-value column, given a list of values. Turn each value to lowercase and separate them all by space characters. If the list is empty, return null. @param dcFields a list of dublin core values @return String the string to insert
[ "Get", "the", "string", "that", "should", "be", "inserted", "for", "a", "repeating", "-", "value", "column", "given", "a", "list", "of", "values", ".", "Turn", "each", "value", "to", "lowercase", "and", "separate", "them", "all", "by", "space", "characters", ".", "If", "the", "list", "is", "empty", "return", "null", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchSQLImpl.java#L409-L421
9,095
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java
SingleFileJournalReader.advanceIntoFile
private void advanceIntoFile() throws XMLStreamException, JournalException { XMLEvent event = reader.nextEvent(); if (!event.isStartDocument()) { throw new JournalException("Expecting XML document header, but event was '" + event + "'"); } event = reader.nextTag(); if (!isStartTagEvent(event, QNAME_TAG_JOURNAL)) { throw new JournalException("Expecting FedoraJournal start tag, but event was '" + event + "'"); } String hash = getOptionalAttributeValue(event.asStartElement(), QNAME_ATTR_REPOSITORY_HASH); checkRepositoryHash(hash); }
java
private void advanceIntoFile() throws XMLStreamException, JournalException { XMLEvent event = reader.nextEvent(); if (!event.isStartDocument()) { throw new JournalException("Expecting XML document header, but event was '" + event + "'"); } event = reader.nextTag(); if (!isStartTagEvent(event, QNAME_TAG_JOURNAL)) { throw new JournalException("Expecting FedoraJournal start tag, but event was '" + event + "'"); } String hash = getOptionalAttributeValue(event.asStartElement(), QNAME_ATTR_REPOSITORY_HASH); checkRepositoryHash(hash); }
[ "private", "void", "advanceIntoFile", "(", ")", "throws", "XMLStreamException", ",", "JournalException", "{", "XMLEvent", "event", "=", "reader", ".", "nextEvent", "(", ")", ";", "if", "(", "!", "event", ".", "isStartDocument", "(", ")", ")", "{", "throw", "new", "JournalException", "(", "\"Expecting XML document header, but event was '\"", "+", "event", "+", "\"'\"", ")", ";", "}", "event", "=", "reader", ".", "nextTag", "(", ")", ";", "if", "(", "!", "isStartTagEvent", "(", "event", ",", "QNAME_TAG_JOURNAL", ")", ")", "{", "throw", "new", "JournalException", "(", "\"Expecting FedoraJournal start tag, but event was '\"", "+", "event", "+", "\"'\"", ")", ";", "}", "String", "hash", "=", "getOptionalAttributeValue", "(", "event", ".", "asStartElement", "(", ")", ",", "QNAME_ATTR_REPOSITORY_HASH", ")", ";", "checkRepositoryHash", "(", "hash", ")", ";", "}" ]
Advance past the document header to the first JournalEntry.
[ "Advance", "past", "the", "document", "header", "to", "the", "first", "JournalEntry", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java#L105-L122
9,096
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java
SingleFileJournalReader.readJournalEntry
@Override public synchronized ConsumerJournalEntry readJournalEntry() throws JournalException, XMLStreamException { if (!open) { return null; } if (!advancedPastHeader) { advanceIntoFile(); advancedPastHeader = true; } XMLEvent next = reader.peek(); // advance past any whitespace events. while (next.isCharacters() && next.asCharacters().isWhiteSpace()) { reader.nextEvent(); next = reader.peek(); } if (isStartTagEvent(next, QNAME_TAG_JOURNAL_ENTRY)) { String identifier = peekAtJournalEntryIdentifier(); ConsumerJournalEntry journalEntry = super.readJournalEntry(reader); journalEntry.setIdentifier(identifier); return journalEntry; } else if (isEndTagEvent(next, QNAME_TAG_JOURNAL)) { return null; } else { throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL, QNAME_TAG_JOURNAL_ENTRY, next); } }
java
@Override public synchronized ConsumerJournalEntry readJournalEntry() throws JournalException, XMLStreamException { if (!open) { return null; } if (!advancedPastHeader) { advanceIntoFile(); advancedPastHeader = true; } XMLEvent next = reader.peek(); // advance past any whitespace events. while (next.isCharacters() && next.asCharacters().isWhiteSpace()) { reader.nextEvent(); next = reader.peek(); } if (isStartTagEvent(next, QNAME_TAG_JOURNAL_ENTRY)) { String identifier = peekAtJournalEntryIdentifier(); ConsumerJournalEntry journalEntry = super.readJournalEntry(reader); journalEntry.setIdentifier(identifier); return journalEntry; } else if (isEndTagEvent(next, QNAME_TAG_JOURNAL)) { return null; } else { throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL, QNAME_TAG_JOURNAL_ENTRY, next); } }
[ "@", "Override", "public", "synchronized", "ConsumerJournalEntry", "readJournalEntry", "(", ")", "throws", "JournalException", ",", "XMLStreamException", "{", "if", "(", "!", "open", ")", "{", "return", "null", ";", "}", "if", "(", "!", "advancedPastHeader", ")", "{", "advanceIntoFile", "(", ")", ";", "advancedPastHeader", "=", "true", ";", "}", "XMLEvent", "next", "=", "reader", ".", "peek", "(", ")", ";", "// advance past any whitespace events.", "while", "(", "next", ".", "isCharacters", "(", ")", "&&", "next", ".", "asCharacters", "(", ")", ".", "isWhiteSpace", "(", ")", ")", "{", "reader", ".", "nextEvent", "(", ")", ";", "next", "=", "reader", ".", "peek", "(", ")", ";", "}", "if", "(", "isStartTagEvent", "(", "next", ",", "QNAME_TAG_JOURNAL_ENTRY", ")", ")", "{", "String", "identifier", "=", "peekAtJournalEntryIdentifier", "(", ")", ";", "ConsumerJournalEntry", "journalEntry", "=", "super", ".", "readJournalEntry", "(", "reader", ")", ";", "journalEntry", ".", "setIdentifier", "(", "identifier", ")", ";", "return", "journalEntry", ";", "}", "else", "if", "(", "isEndTagEvent", "(", "next", ",", "QNAME_TAG_JOURNAL", ")", ")", "{", "return", "null", ";", "}", "else", "{", "throw", "getNotNextMemberOrEndOfGroupException", "(", "QNAME_TAG_JOURNAL", ",", "QNAME_TAG_JOURNAL_ENTRY", ",", "next", ")", ";", "}", "}" ]
Advance past any white space, and then see whether we have any more JournalEntry tags. If we don't, just return null.
[ "Advance", "past", "any", "white", "space", "and", "then", "see", "whether", "we", "have", "any", "more", "JournalEntry", "tags", ".", "If", "we", "don", "t", "just", "return", "null", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java#L128-L159
9,097
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java
SingleFileJournalReader.shutdown
@Override public synchronized void shutdown() throws JournalException { try { if (open) { reader.close(); open = false; } } catch (XMLStreamException e) { throw new JournalException(e); } }
java
@Override public synchronized void shutdown() throws JournalException { try { if (open) { reader.close(); open = false; } } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "@", "Override", "public", "synchronized", "void", "shutdown", "(", ")", "throws", "JournalException", "{", "try", "{", "if", "(", "open", ")", "{", "reader", ".", "close", "(", ")", ";", "open", "=", "false", ";", "}", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
On the first call, Just close the reader.
[ "On", "the", "first", "call", "Just", "close", "the", "reader", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/singlefile/SingleFileJournalReader.java#L188-L198
9,098
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyUtils.java
PolicyUtils.fileToString
public String fileToString(File f) throws MelcoePDPException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; try { FileInputStream fis = new FileInputStream(f); int count = fis.read(bytes); while (count > -1) { out.write(bytes, 0, count); count = fis.read(bytes); } fis.close(); } catch (IOException e) { throw new MelcoePDPException("Error reading file: " + f.getName(), e); } return out.toString(); }
java
public String fileToString(File f) throws MelcoePDPException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; try { FileInputStream fis = new FileInputStream(f); int count = fis.read(bytes); while (count > -1) { out.write(bytes, 0, count); count = fis.read(bytes); } fis.close(); } catch (IOException e) { throw new MelcoePDPException("Error reading file: " + f.getName(), e); } return out.toString(); }
[ "public", "String", "fileToString", "(", "File", "f", ")", "throws", "MelcoePDPException", "{", "ByteArrayOutputStream", "out", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "byte", "[", "]", "bytes", "=", "new", "byte", "[", "1024", "]", ";", "try", "{", "FileInputStream", "fis", "=", "new", "FileInputStream", "(", "f", ")", ";", "int", "count", "=", "fis", ".", "read", "(", "bytes", ")", ";", "while", "(", "count", ">", "-", "1", ")", "{", "out", ".", "write", "(", "bytes", ",", "0", ",", "count", ")", ";", "count", "=", "fis", ".", "read", "(", "bytes", ")", ";", "}", "fis", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "MelcoePDPException", "(", "\"Error reading file: \"", "+", "f", ".", "getName", "(", ")", ",", "e", ")", ";", "}", "return", "out", ".", "toString", "(", ")", ";", "}" ]
Read file and return contents as a string @param f File to read @return string contents of file @throws MelcoePDPException
[ "Read", "file", "and", "return", "contents", "as", "a", "string" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyUtils.java#L50-L70
9,099
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyUtils.java
PolicyUtils.getDocumentMetadata
public Map<String, String> getDocumentMetadata(InputStream docIS) { Map<String, String> metadata = new HashMap<String, String>(); try { // Create instance of DocumentBuilderFactory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Get the DocumentBuilder DocumentBuilder docBuilder = factory.newDocumentBuilder(); // Create blank DOM Document and parse contents of input stream Document doc = docBuilder.parse(docIS); NodeList nodes = null; metadata.put("PolicyId", doc.getDocumentElement() .getAttribute("PolicyId")); nodes = doc.getElementsByTagName("Subjects"); if (nodes.getLength() == 0) { metadata.put("anySubject", "T"); } nodes = doc.getElementsByTagName("Resources"); if (nodes.getLength() == 0) { metadata.put("anyResource", "T"); } nodes = doc.getElementsByTagName("Actions"); if (nodes.getLength() == 0) { metadata.put("anyAction", "T"); } nodes = doc.getElementsByTagName("Environments"); if (nodes.getLength() == 0) { metadata.put("anyEnvironment", "T"); } } catch (Exception e) { log.error(e.getMessage()); } return metadata; }
java
public Map<String, String> getDocumentMetadata(InputStream docIS) { Map<String, String> metadata = new HashMap<String, String>(); try { // Create instance of DocumentBuilderFactory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Get the DocumentBuilder DocumentBuilder docBuilder = factory.newDocumentBuilder(); // Create blank DOM Document and parse contents of input stream Document doc = docBuilder.parse(docIS); NodeList nodes = null; metadata.put("PolicyId", doc.getDocumentElement() .getAttribute("PolicyId")); nodes = doc.getElementsByTagName("Subjects"); if (nodes.getLength() == 0) { metadata.put("anySubject", "T"); } nodes = doc.getElementsByTagName("Resources"); if (nodes.getLength() == 0) { metadata.put("anyResource", "T"); } nodes = doc.getElementsByTagName("Actions"); if (nodes.getLength() == 0) { metadata.put("anyAction", "T"); } nodes = doc.getElementsByTagName("Environments"); if (nodes.getLength() == 0) { metadata.put("anyEnvironment", "T"); } } catch (Exception e) { log.error(e.getMessage()); } return metadata; }
[ "public", "Map", "<", "String", ",", "String", ">", "getDocumentMetadata", "(", "InputStream", "docIS", ")", "{", "Map", "<", "String", ",", "String", ">", "metadata", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "try", "{", "// Create instance of DocumentBuilderFactory", "DocumentBuilderFactory", "factory", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ";", "// Get the DocumentBuilder", "DocumentBuilder", "docBuilder", "=", "factory", ".", "newDocumentBuilder", "(", ")", ";", "// Create blank DOM Document and parse contents of input stream", "Document", "doc", "=", "docBuilder", ".", "parse", "(", "docIS", ")", ";", "NodeList", "nodes", "=", "null", ";", "metadata", ".", "put", "(", "\"PolicyId\"", ",", "doc", ".", "getDocumentElement", "(", ")", ".", "getAttribute", "(", "\"PolicyId\"", ")", ")", ";", "nodes", "=", "doc", ".", "getElementsByTagName", "(", "\"Subjects\"", ")", ";", "if", "(", "nodes", ".", "getLength", "(", ")", "==", "0", ")", "{", "metadata", ".", "put", "(", "\"anySubject\"", ",", "\"T\"", ")", ";", "}", "nodes", "=", "doc", ".", "getElementsByTagName", "(", "\"Resources\"", ")", ";", "if", "(", "nodes", ".", "getLength", "(", ")", "==", "0", ")", "{", "metadata", ".", "put", "(", "\"anyResource\"", ",", "\"T\"", ")", ";", "}", "nodes", "=", "doc", ".", "getElementsByTagName", "(", "\"Actions\"", ")", ";", "if", "(", "nodes", ".", "getLength", "(", ")", "==", "0", ")", "{", "metadata", ".", "put", "(", "\"anyAction\"", ",", "\"T\"", ")", ";", "}", "nodes", "=", "doc", ".", "getElementsByTagName", "(", "\"Environments\"", ")", ";", "if", "(", "nodes", ".", "getLength", "(", ")", "==", "0", ")", "{", "metadata", ".", "put", "(", "\"anyEnvironment\"", ",", "\"T\"", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "log", ".", "error", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "return", "metadata", ";", "}" ]
Obtains the metadata for the given document. @param docIS the document as an InputStream @return the document metadata as a Map
[ "Obtains", "the", "metadata", "for", "the", "given", "document", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyUtils.java#L110-L151