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,100
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java
ParameterHelper.getOptionalStringParameter
public static String getOptionalStringParameter(Map<String, String> parameters, String parameterName, String defaultValue) { validateParameters(parameters); validateParameterName(parameterName); String value = parameters.get(parameterName); return value == null ? defaultValue : value; }
java
public static String getOptionalStringParameter(Map<String, String> parameters, String parameterName, String defaultValue) { validateParameters(parameters); validateParameterName(parameterName); String value = parameters.get(parameterName); return value == null ? defaultValue : value; }
[ "public", "static", "String", "getOptionalStringParameter", "(", "Map", "<", "String", ",", "String", ">", "parameters", ",", "String", "parameterName", ",", "String", "defaultValue", ")", "{", "validateParameters", "(", "parameters", ")", ";", "validateParameterName", "(", "parameterName", ")", ";", "String", "value", "=", "parameters", ".", "get", "(", "parameterName", ")", ";", "return", "value", "==", "null", "?", "defaultValue", ":", "value", ";", "}" ]
Get an optional String parameter, If not found, use the default value. @throws NullPointerException if either 'parameters' or 'parameterName' is null.
[ "Get", "an", "optional", "String", "parameter", "If", "not", "found", "use", "the", "default", "value", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java#L48-L56
9,101
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java
ParameterHelper.getOptionalBooleanParameter
public static boolean getOptionalBooleanParameter(Map<String, String> parameters, String parameterName, boolean defaultValue) throws JournalException { validateParameters(parameters); validateParameterName(parameterName); String string = parameters.get(parameterName); if (string == null) { return defaultValue; } else if (string.equals(VALUE_FALSE)) { return false; } else if (string.equals(VALUE_TRUE)) { return true; } else { throw new JournalException("'" + parameterName + "' parameter must be '" + VALUE_FALSE + "'(default) or '" + VALUE_TRUE + "'"); } }
java
public static boolean getOptionalBooleanParameter(Map<String, String> parameters, String parameterName, boolean defaultValue) throws JournalException { validateParameters(parameters); validateParameterName(parameterName); String string = parameters.get(parameterName); if (string == null) { return defaultValue; } else if (string.equals(VALUE_FALSE)) { return false; } else if (string.equals(VALUE_TRUE)) { return true; } else { throw new JournalException("'" + parameterName + "' parameter must be '" + VALUE_FALSE + "'(default) or '" + VALUE_TRUE + "'"); } }
[ "public", "static", "boolean", "getOptionalBooleanParameter", "(", "Map", "<", "String", ",", "String", ">", "parameters", ",", "String", "parameterName", ",", "boolean", "defaultValue", ")", "throws", "JournalException", "{", "validateParameters", "(", "parameters", ")", ";", "validateParameterName", "(", "parameterName", ")", ";", "String", "string", "=", "parameters", ".", "get", "(", "parameterName", ")", ";", "if", "(", "string", "==", "null", ")", "{", "return", "defaultValue", ";", "}", "else", "if", "(", "string", ".", "equals", "(", "VALUE_FALSE", ")", ")", "{", "return", "false", ";", "}", "else", "if", "(", "string", ".", "equals", "(", "VALUE_TRUE", ")", ")", "{", "return", "true", ";", "}", "else", "{", "throw", "new", "JournalException", "(", "\"'\"", "+", "parameterName", "+", "\"' parameter must be '\"", "+", "VALUE_FALSE", "+", "\"'(default) or '\"", "+", "VALUE_TRUE", "+", "\"'\"", ")", ";", "}", "}" ]
Get an optional boolean parameter. If not found, use the default value. @throws JournalException if a value is supplied that is neither "true" nor "false". @throws NullPointerException if either 'parameters' or 'parameterName' is null.
[ "Get", "an", "optional", "boolean", "parameter", ".", "If", "not", "found", "use", "the", "default", "value", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java#L66-L86
9,102
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java
ParameterHelper.parseParametersForWritableDirectory
public static File parseParametersForWritableDirectory(Map<String, String> parameters, String parameterName) throws JournalException { String directoryString = parameters.get(parameterName); if (directoryString == null) { throw new JournalException("'" + parameterName + "' is required."); } File directory = new File(directoryString); if (!directory.exists()) { throw new JournalException("Directory '" + directory + "' does not exist."); } if (!directory.isDirectory()) { throw new JournalException("Directory '" + directory + "' is not a directory."); } if (!directory.canWrite()) { throw new JournalException("Directory '" + directory + "' is not writable."); } return directory; }
java
public static File parseParametersForWritableDirectory(Map<String, String> parameters, String parameterName) throws JournalException { String directoryString = parameters.get(parameterName); if (directoryString == null) { throw new JournalException("'" + parameterName + "' is required."); } File directory = new File(directoryString); if (!directory.exists()) { throw new JournalException("Directory '" + directory + "' does not exist."); } if (!directory.isDirectory()) { throw new JournalException("Directory '" + directory + "' is not a directory."); } if (!directory.canWrite()) { throw new JournalException("Directory '" + directory + "' is not writable."); } return directory; }
[ "public", "static", "File", "parseParametersForWritableDirectory", "(", "Map", "<", "String", ",", "String", ">", "parameters", ",", "String", "parameterName", ")", "throws", "JournalException", "{", "String", "directoryString", "=", "parameters", ".", "get", "(", "parameterName", ")", ";", "if", "(", "directoryString", "==", "null", ")", "{", "throw", "new", "JournalException", "(", "\"'\"", "+", "parameterName", "+", "\"' is required.\"", ")", ";", "}", "File", "directory", "=", "new", "File", "(", "directoryString", ")", ";", "if", "(", "!", "directory", ".", "exists", "(", ")", ")", "{", "throw", "new", "JournalException", "(", "\"Directory '\"", "+", "directory", "+", "\"' does not exist.\"", ")", ";", "}", "if", "(", "!", "directory", ".", "isDirectory", "(", ")", ")", "{", "throw", "new", "JournalException", "(", "\"Directory '\"", "+", "directory", "+", "\"' is not a directory.\"", ")", ";", "}", "if", "(", "!", "directory", ".", "canWrite", "(", ")", ")", "{", "throw", "new", "JournalException", "(", "\"Directory '\"", "+", "directory", "+", "\"' is not writable.\"", ")", ";", "}", "return", "directory", ";", "}" ]
Look in the parameters for the path to a writable directory. The parameter is required.
[ "Look", "in", "the", "parameters", "for", "the", "path", "to", "a", "writable", "directory", ".", "The", "parameter", "is", "required", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java#L92-L113
9,103
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java
ParameterHelper.parseParametersForFilenamePrefix
public static String parseParametersForFilenamePrefix(Map<String, String> parameters) { return getOptionalStringParameter(parameters, PARAMETER_JOURNAL_FILENAME_PREFIX, DEFAULT_FILENAME_PREFIX); }
java
public static String parseParametersForFilenamePrefix(Map<String, String> parameters) { return getOptionalStringParameter(parameters, PARAMETER_JOURNAL_FILENAME_PREFIX, DEFAULT_FILENAME_PREFIX); }
[ "public", "static", "String", "parseParametersForFilenamePrefix", "(", "Map", "<", "String", ",", "String", ">", "parameters", ")", "{", "return", "getOptionalStringParameter", "(", "parameters", ",", "PARAMETER_JOURNAL_FILENAME_PREFIX", ",", "DEFAULT_FILENAME_PREFIX", ")", ";", "}" ]
Look for a string to use as a prefix for the names of the journal files. Default is "fedoraJournal"
[ "Look", "for", "a", "string", "to", "use", "as", "a", "prefix", "for", "the", "names", "of", "the", "journal", "files", ".", "Default", "is", "fedoraJournal" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/helpers/ParameterHelper.java#L119-L123
9,104
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/NewObjectDialog.java
NewObjectDialog.itemStateChanged
public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.DESELECTED) { // disable text entry m_customPIDField.setEditable(false); } else if (e.getStateChange() == ItemEvent.SELECTED) { // enable text entry m_customPIDField.setEditable(true); } }
java
public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.DESELECTED) { // disable text entry m_customPIDField.setEditable(false); } else if (e.getStateChange() == ItemEvent.SELECTED) { // enable text entry m_customPIDField.setEditable(true); } }
[ "public", "void", "itemStateChanged", "(", "ItemEvent", "e", ")", "{", "if", "(", "e", ".", "getStateChange", "(", ")", "==", "ItemEvent", ".", "DESELECTED", ")", "{", "// disable text entry", "m_customPIDField", ".", "setEditable", "(", "false", ")", ";", "}", "else", "if", "(", "e", ".", "getStateChange", "(", ")", "==", "ItemEvent", ".", "SELECTED", ")", "{", "// enable text entry", "m_customPIDField", ".", "setEditable", "(", "true", ")", ";", "}", "}" ]
for the checkbox
[ "for", "the", "checkbox" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/NewObjectDialog.java#L63-L71
9,105
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyIndexBase.java
PolicyIndexBase.handleDocument
protected AbstractPolicy handleDocument(Document doc, PolicyFinder policyFinder) throws ParsingException { // handle the policy, if it's a known type Element root = doc.getDocumentElement(); String name = root.getTagName(); // see what type of policy this is if (name.equals("Policy")) { return Policy.getInstance(root); } else if (name.equals("PolicySet")) { return PolicySet.getInstance(root, policyFinder); } else { // this isn't a root type that we know how to handle throw new ParsingException("Unknown root document type: " + name); } }
java
protected AbstractPolicy handleDocument(Document doc, PolicyFinder policyFinder) throws ParsingException { // handle the policy, if it's a known type Element root = doc.getDocumentElement(); String name = root.getTagName(); // see what type of policy this is if (name.equals("Policy")) { return Policy.getInstance(root); } else if (name.equals("PolicySet")) { return PolicySet.getInstance(root, policyFinder); } else { // this isn't a root type that we know how to handle throw new ParsingException("Unknown root document type: " + name); } }
[ "protected", "AbstractPolicy", "handleDocument", "(", "Document", "doc", ",", "PolicyFinder", "policyFinder", ")", "throws", "ParsingException", "{", "// handle the policy, if it's a known type", "Element", "root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "String", "name", "=", "root", ".", "getTagName", "(", ")", ";", "// see what type of policy this is", "if", "(", "name", ".", "equals", "(", "\"Policy\"", ")", ")", "{", "return", "Policy", ".", "getInstance", "(", "root", ")", ";", "}", "else", "if", "(", "name", ".", "equals", "(", "\"PolicySet\"", ")", ")", "{", "return", "PolicySet", ".", "getInstance", "(", "root", ",", "policyFinder", ")", ";", "}", "else", "{", "// this isn't a root type that we know how to handle", "throw", "new", "ParsingException", "(", "\"Unknown root document type: \"", "+", "name", ")", ";", "}", "}" ]
A private method that handles reading the policy and creates the correct kind of AbstractPolicy. Because this makes use of the policyFinder, it cannot be reused between finders. Consider moving to policyManager, which is not intended to be reused outside of a policyFinderModule, which is not intended to be reused amongst PolicyFinder instances.
[ "A", "private", "method", "that", "handles", "reading", "the", "policy", "and", "creates", "the", "correct", "kind", "of", "AbstractPolicy", ".", "Because", "this", "makes", "use", "of", "the", "policyFinder", "it", "cannot", "be", "reused", "between", "finders", ".", "Consider", "moving", "to", "policyManager", "which", "is", "not", "intended", "to", "be", "reused", "outside", "of", "a", "policyFinderModule", "which", "is", "not", "intended", "to", "be", "reused", "amongst", "PolicyFinder", "instances", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyIndexBase.java#L271-L285
9,106
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyIndexBase.java
PolicyIndexBase.makeComponents
protected static String[] makeComponents(String resourceId) { if (resourceId == null || resourceId.isEmpty() || !resourceId.startsWith("/")) { return null; } List<String> components = new ArrayList<String>(); String[] parts = resourceId.split("\\/"); int bufPrimer = 0; for (int x = 1; x < parts.length; x++) { bufPrimer = Math.max(bufPrimer, (parts[x].length() + 1)); StringBuilder sb = new StringBuilder(bufPrimer); for (int y = 0; y < x; y++) { sb.append("/"); sb.append(parts[y + 1]); } String componentBase = sb.toString(); bufPrimer = componentBase.length() + 16; components.add(componentBase); if (x != parts.length - 1) { components.add(componentBase.concat("/.*")); } else { components.add(componentBase.concat("$")); } } return components.toArray(parts); }
java
protected static String[] makeComponents(String resourceId) { if (resourceId == null || resourceId.isEmpty() || !resourceId.startsWith("/")) { return null; } List<String> components = new ArrayList<String>(); String[] parts = resourceId.split("\\/"); int bufPrimer = 0; for (int x = 1; x < parts.length; x++) { bufPrimer = Math.max(bufPrimer, (parts[x].length() + 1)); StringBuilder sb = new StringBuilder(bufPrimer); for (int y = 0; y < x; y++) { sb.append("/"); sb.append(parts[y + 1]); } String componentBase = sb.toString(); bufPrimer = componentBase.length() + 16; components.add(componentBase); if (x != parts.length - 1) { components.add(componentBase.concat("/.*")); } else { components.add(componentBase.concat("$")); } } return components.toArray(parts); }
[ "protected", "static", "String", "[", "]", "makeComponents", "(", "String", "resourceId", ")", "{", "if", "(", "resourceId", "==", "null", "||", "resourceId", ".", "isEmpty", "(", ")", "||", "!", "resourceId", ".", "startsWith", "(", "\"/\"", ")", ")", "{", "return", "null", ";", "}", "List", "<", "String", ">", "components", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "String", "[", "]", "parts", "=", "resourceId", ".", "split", "(", "\"\\\\/\"", ")", ";", "int", "bufPrimer", "=", "0", ";", "for", "(", "int", "x", "=", "1", ";", "x", "<", "parts", ".", "length", ";", "x", "++", ")", "{", "bufPrimer", "=", "Math", ".", "max", "(", "bufPrimer", ",", "(", "parts", "[", "x", "]", ".", "length", "(", ")", "+", "1", ")", ")", ";", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "bufPrimer", ")", ";", "for", "(", "int", "y", "=", "0", ";", "y", "<", "x", ";", "y", "++", ")", "{", "sb", ".", "append", "(", "\"/\"", ")", ";", "sb", ".", "append", "(", "parts", "[", "y", "+", "1", "]", ")", ";", "}", "String", "componentBase", "=", "sb", ".", "toString", "(", ")", ";", "bufPrimer", "=", "componentBase", ".", "length", "(", ")", "+", "16", ";", "components", ".", "add", "(", "componentBase", ")", ";", "if", "(", "x", "!=", "parts", ".", "length", "-", "1", ")", "{", "components", ".", "add", "(", "componentBase", ".", "concat", "(", "\"/.*\"", ")", ")", ";", "}", "else", "{", "components", ".", "add", "(", "componentBase", ".", "concat", "(", "\"$\"", ")", ")", ";", "}", "}", "return", "components", ".", "toArray", "(", "parts", ")", ";", "}" ]
Splits a XACML hierarchical resource-id value into a set of resource-id values that can be matched against a policy. Eg an incoming request for /res1/res2/res3/.* should match /res1/.* /res1/res2/.* /res1/res2/res3/.* in policies. @param resourceId XACML hierarchical resource-id value @return array of individual resource-id values that can be used to match against policies
[ "Splits", "a", "XACML", "hierarchical", "resource", "-", "id", "value", "into", "a", "set", "of", "resource", "-", "id", "values", "that", "can", "be", "matched", "against", "a", "policy", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/data/PolicyIndexBase.java#L301-L332
9,107
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/errors/ServerException.java
ServerException.getDetails
public String[] getDetails(Locale locale) { if (m_details == null || m_details.length == 0) { return s_emptyStringArray; } String[] ret = new String[m_details.length]; for (int i = 0; i < m_details.length; i++) { ret[i] = getLocalizedOrCode(m_bundleName, locale, m_code, null); } return ret; }
java
public String[] getDetails(Locale locale) { if (m_details == null || m_details.length == 0) { return s_emptyStringArray; } String[] ret = new String[m_details.length]; for (int i = 0; i < m_details.length; i++) { ret[i] = getLocalizedOrCode(m_bundleName, locale, m_code, null); } return ret; }
[ "public", "String", "[", "]", "getDetails", "(", "Locale", "locale", ")", "{", "if", "(", "m_details", "==", "null", "||", "m_details", ".", "length", "==", "0", ")", "{", "return", "s_emptyStringArray", ";", "}", "String", "[", "]", "ret", "=", "new", "String", "[", "m_details", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_details", ".", "length", ";", "i", "++", ")", "{", "ret", "[", "i", "]", "=", "getLocalizedOrCode", "(", "m_bundleName", ",", "locale", ",", "m_code", ",", "null", ")", ";", "}", "return", "ret", ";", "}" ]
Gets any detail messages, preferring the provided locale. @return The detail messages, with {num}-indexed placeholders populated, if needed.
[ "Gets", "any", "detail", "messages", "preferring", "the", "provided", "locale", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/errors/ServerException.java#L176-L185
9,108
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/errors/ServerException.java
ServerException.getLocalizedOrCode
private static String getLocalizedOrCode(String bundleName, Locale locale, String code, String[] values) { ResourceBundle bundle = null; if (bundleName != null) { bundle = ResourceBundle.getBundle(bundleName, locale); } if (bundle == null) { return code; } String locMessage = bundle.getString(code); if (locMessage == null) { return code; } if (values == null) { return locMessage; } return MessageFormat.format(locMessage, (Object[]) values); }
java
private static String getLocalizedOrCode(String bundleName, Locale locale, String code, String[] values) { ResourceBundle bundle = null; if (bundleName != null) { bundle = ResourceBundle.getBundle(bundleName, locale); } if (bundle == null) { return code; } String locMessage = bundle.getString(code); if (locMessage == null) { return code; } if (values == null) { return locMessage; } return MessageFormat.format(locMessage, (Object[]) values); }
[ "private", "static", "String", "getLocalizedOrCode", "(", "String", "bundleName", ",", "Locale", "locale", ",", "String", "code", ",", "String", "[", "]", "values", ")", "{", "ResourceBundle", "bundle", "=", "null", ";", "if", "(", "bundleName", "!=", "null", ")", "{", "bundle", "=", "ResourceBundle", ".", "getBundle", "(", "bundleName", ",", "locale", ")", ";", "}", "if", "(", "bundle", "==", "null", ")", "{", "return", "code", ";", "}", "String", "locMessage", "=", "bundle", ".", "getString", "(", "code", ")", ";", "if", "(", "locMessage", "==", "null", ")", "{", "return", "code", ";", "}", "if", "(", "values", "==", "null", ")", "{", "return", "locMessage", ";", "}", "return", "MessageFormat", ".", "format", "(", "locMessage", ",", "(", "Object", "[", "]", ")", "values", ")", ";", "}" ]
Gets the message from the resource bundle, formatting it if needed, and on failure, just returns the code. @param bundleName The ResourceBundle where the message is defined. @param locale The preferred locale. @param code The message key. @param values The replacement values, assumed empty if null. @return The detail messages, with {num}-indexed placeholders populated, if needed.
[ "Gets", "the", "message", "from", "the", "resource", "bundle", "formatting", "it", "if", "needed", "and", "on", "failure", "just", "returns", "the", "code", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/errors/ServerException.java#L202-L221
9,109
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/CreatorJournalEntry.java
CreatorJournalEntry.invokeAndClose
public Object invokeAndClose(ManagementDelegate delegate, JournalWriter writer) throws ServerException, JournalException { Object result = invokeMethod(delegate, writer); close(); return result; }
java
public Object invokeAndClose(ManagementDelegate delegate, JournalWriter writer) throws ServerException, JournalException { Object result = invokeMethod(delegate, writer); close(); return result; }
[ "public", "Object", "invokeAndClose", "(", "ManagementDelegate", "delegate", ",", "JournalWriter", "writer", ")", "throws", "ServerException", ",", "JournalException", "{", "Object", "result", "=", "invokeMethod", "(", "delegate", ",", "writer", ")", ";", "close", "(", ")", ";", "return", "result", ";", "}" ]
A convenience method that invokes the management method and then closes the JournalEntry, thereby cleaning up any temp files.
[ "A", "convenience", "method", "that", "invokes", "the", "management", "method", "and", "then", "closes", "the", "JournalEntry", "thereby", "cleaning", "up", "any", "temp", "files", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/CreatorJournalEntry.java#L70-L76
9,110
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java
DOTranslationUtility.setDatastreamDefaults
public static Datastream setDatastreamDefaults(Datastream ds) throws ObjectIntegrityException { if ((ds.DSMIME == null || ds.DSMIME.isEmpty()) && ds.DSControlGrp.equalsIgnoreCase("X")) { ds.DSMIME = "text/xml"; } if (ds.DSState == null || ds.DSState.isEmpty()) { ds.DSState = "A"; } // For METS backward compatibility if (ds.DSInfoType == null || ds.DSInfoType.isEmpty() || ds.DSInfoType.equalsIgnoreCase("OTHER")) { ds.DSInfoType = "UNSPECIFIED"; } // LOOK! For METS backward compatibility: // If we have a METS MDClass value, and DSFormatURI isn't already // assigned, preserve MDClass and MDType in a DSFormatURI. // Note that the system is taking over the DSFormatURI in this case. // Therefore, if a client subsequently modifies the DSFormatURI // this METS legacy informatin will be lost, in which case the inline // datastream will default to amdSec/techMD in a subsequent METS export. if (ds.DSControlGrp.equalsIgnoreCase("X")) { if (((DatastreamXMLMetadata) ds).DSMDClass != 0 && ds.DSFormatURI == null) { String mdClassName = ""; String mdType = ds.DSInfoType; String otherType = ""; if (((DatastreamXMLMetadata) ds).DSMDClass == 1) { mdClassName = "techMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 2) { mdClassName = "sourceMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 3) { mdClassName = "rightsMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 4) { mdClassName = "digiprovMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 5) { mdClassName = "descMD"; } if (!mdType.equals("MARC") && !mdType.equals("EAD") && !mdType.equals("DC") && !mdType.equals("NISOIMG") && !mdType.equals("LC-AV") && !mdType.equals("VRA") && !mdType.equals("TEIHDR") && !mdType.equals("DDI") && !mdType.equals("FGDC")) { mdType = "OTHER"; otherType = ds.DSInfoType; } ds.DSFormatURI = "info:fedora/fedora-system:format/xml.mets." + mdClassName + "." + mdType + "." + otherType; } } return ds; }
java
public static Datastream setDatastreamDefaults(Datastream ds) throws ObjectIntegrityException { if ((ds.DSMIME == null || ds.DSMIME.isEmpty()) && ds.DSControlGrp.equalsIgnoreCase("X")) { ds.DSMIME = "text/xml"; } if (ds.DSState == null || ds.DSState.isEmpty()) { ds.DSState = "A"; } // For METS backward compatibility if (ds.DSInfoType == null || ds.DSInfoType.isEmpty() || ds.DSInfoType.equalsIgnoreCase("OTHER")) { ds.DSInfoType = "UNSPECIFIED"; } // LOOK! For METS backward compatibility: // If we have a METS MDClass value, and DSFormatURI isn't already // assigned, preserve MDClass and MDType in a DSFormatURI. // Note that the system is taking over the DSFormatURI in this case. // Therefore, if a client subsequently modifies the DSFormatURI // this METS legacy informatin will be lost, in which case the inline // datastream will default to amdSec/techMD in a subsequent METS export. if (ds.DSControlGrp.equalsIgnoreCase("X")) { if (((DatastreamXMLMetadata) ds).DSMDClass != 0 && ds.DSFormatURI == null) { String mdClassName = ""; String mdType = ds.DSInfoType; String otherType = ""; if (((DatastreamXMLMetadata) ds).DSMDClass == 1) { mdClassName = "techMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 2) { mdClassName = "sourceMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 3) { mdClassName = "rightsMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 4) { mdClassName = "digiprovMD"; } else if (((DatastreamXMLMetadata) ds).DSMDClass == 5) { mdClassName = "descMD"; } if (!mdType.equals("MARC") && !mdType.equals("EAD") && !mdType.equals("DC") && !mdType.equals("NISOIMG") && !mdType.equals("LC-AV") && !mdType.equals("VRA") && !mdType.equals("TEIHDR") && !mdType.equals("DDI") && !mdType.equals("FGDC")) { mdType = "OTHER"; otherType = ds.DSInfoType; } ds.DSFormatURI = "info:fedora/fedora-system:format/xml.mets." + mdClassName + "." + mdType + "." + otherType; } } return ds; }
[ "public", "static", "Datastream", "setDatastreamDefaults", "(", "Datastream", "ds", ")", "throws", "ObjectIntegrityException", "{", "if", "(", "(", "ds", ".", "DSMIME", "==", "null", "||", "ds", ".", "DSMIME", ".", "isEmpty", "(", ")", ")", "&&", "ds", ".", "DSControlGrp", ".", "equalsIgnoreCase", "(", "\"X\"", ")", ")", "{", "ds", ".", "DSMIME", "=", "\"text/xml\"", ";", "}", "if", "(", "ds", ".", "DSState", "==", "null", "||", "ds", ".", "DSState", ".", "isEmpty", "(", ")", ")", "{", "ds", ".", "DSState", "=", "\"A\"", ";", "}", "// For METS backward compatibility", "if", "(", "ds", ".", "DSInfoType", "==", "null", "||", "ds", ".", "DSInfoType", ".", "isEmpty", "(", ")", "||", "ds", ".", "DSInfoType", ".", "equalsIgnoreCase", "(", "\"OTHER\"", ")", ")", "{", "ds", ".", "DSInfoType", "=", "\"UNSPECIFIED\"", ";", "}", "// LOOK! For METS backward compatibility:", "// If we have a METS MDClass value, and DSFormatURI isn't already", "// assigned, preserve MDClass and MDType in a DSFormatURI.", "// Note that the system is taking over the DSFormatURI in this case.", "// Therefore, if a client subsequently modifies the DSFormatURI", "// this METS legacy informatin will be lost, in which case the inline", "// datastream will default to amdSec/techMD in a subsequent METS export.", "if", "(", "ds", ".", "DSControlGrp", ".", "equalsIgnoreCase", "(", "\"X\"", ")", ")", "{", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "!=", "0", "&&", "ds", ".", "DSFormatURI", "==", "null", ")", "{", "String", "mdClassName", "=", "\"\"", ";", "String", "mdType", "=", "ds", ".", "DSInfoType", ";", "String", "otherType", "=", "\"\"", ";", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "==", "1", ")", "{", "mdClassName", "=", "\"techMD\"", ";", "}", "else", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "==", "2", ")", "{", "mdClassName", "=", "\"sourceMD\"", ";", "}", "else", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "==", "3", ")", "{", "mdClassName", "=", "\"rightsMD\"", ";", "}", "else", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "==", "4", ")", "{", "mdClassName", "=", "\"digiprovMD\"", ";", "}", "else", "if", "(", "(", "(", "DatastreamXMLMetadata", ")", "ds", ")", ".", "DSMDClass", "==", "5", ")", "{", "mdClassName", "=", "\"descMD\"", ";", "}", "if", "(", "!", "mdType", ".", "equals", "(", "\"MARC\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"EAD\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"DC\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"NISOIMG\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"LC-AV\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"VRA\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"TEIHDR\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"DDI\"", ")", "&&", "!", "mdType", ".", "equals", "(", "\"FGDC\"", ")", ")", "{", "mdType", "=", "\"OTHER\"", ";", "otherType", "=", "ds", ".", "DSInfoType", ";", "}", "ds", ".", "DSFormatURI", "=", "\"info:fedora/fedora-system:format/xml.mets.\"", "+", "mdClassName", "+", "\".\"", "+", "mdType", "+", "\".\"", "+", "otherType", ";", "}", "}", "return", "ds", ";", "}" ]
Check for null values in attributes and set them to empty string so 'null' does not appear in XML attribute values. This helps in XML validation of required attributes. If 'null' is the attribute value then validation would incorrectly consider in a valid non-empty value. Also, we set some other default values here. @param ds The Datastream object to work on. @return The Datastream value with default set. @throws ObjectIntegrityException
[ "Check", "for", "null", "values", "in", "attributes", "and", "set", "them", "to", "empty", "string", "so", "null", "does", "not", "appear", "in", "XML", "attribute", "values", ".", "This", "helps", "in", "XML", "validation", "of", "required", "attributes", ".", "If", "null", "is", "the", "attribute", "value", "then", "validation", "would", "incorrectly", "consider", "in", "a", "valid", "non", "-", "empty", "value", ".", "Also", "we", "set", "some", "other", "default", "values", "here", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java#L618-L674
9,111
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java
DOTranslationUtility.appendXMLStream
protected static void appendXMLStream(InputStream in, PrintWriter writer, String encoding) throws ObjectIntegrityException, UnsupportedEncodingException, StreamIOException { if (in == null) { throw new ObjectIntegrityException("Object's inline xml " + "stream cannot be null."); } try { InputStreamReader chars = new InputStreamReader(in, Charset.forName(encoding)); /* Content buffer */ char[] charBuf = new char[4096]; /* Beginning/ending whitespace buffer */ char[] wsBuf = new char[4096]; int len; int start; int end; int wsLen = 0; boolean atBeginning = true; while ((len = chars.read(charBuf)) != -1) { start = 0; end = len - 1; /* Strip out any leading whitespace */ if (atBeginning) { while (start < len) { if (charBuf[start] > 0x20) break; start++; } if (start < len) atBeginning = false; } /* * Hold aside any whitespace at the end of the current chunk. If * we make it to the next chunk, then append our whitespace to * the buffer. Using this methodology, we may "trim" at most * {buffer length} characters from the end. */ if (wsLen > 0) { /* Commit previous ending whitespace */ writer.write(wsBuf, 0, wsLen); wsLen = 0; } while (end > start) { /* Buffer current ending whitespace */ if (charBuf[end] > 0x20) break; wsBuf[wsLen] = charBuf[end]; wsLen++; end--; } if (start < len) { writer.write(charBuf, start, end + 1 - start); } } } catch (UnsupportedEncodingException uee) { throw uee; } catch (IOException ioe) { throw new StreamIOException("Error reading from inline xml datastream."); } finally { try { in.close(); } catch (IOException closeProb) { throw new StreamIOException("Error closing read stream."); } } }
java
protected static void appendXMLStream(InputStream in, PrintWriter writer, String encoding) throws ObjectIntegrityException, UnsupportedEncodingException, StreamIOException { if (in == null) { throw new ObjectIntegrityException("Object's inline xml " + "stream cannot be null."); } try { InputStreamReader chars = new InputStreamReader(in, Charset.forName(encoding)); /* Content buffer */ char[] charBuf = new char[4096]; /* Beginning/ending whitespace buffer */ char[] wsBuf = new char[4096]; int len; int start; int end; int wsLen = 0; boolean atBeginning = true; while ((len = chars.read(charBuf)) != -1) { start = 0; end = len - 1; /* Strip out any leading whitespace */ if (atBeginning) { while (start < len) { if (charBuf[start] > 0x20) break; start++; } if (start < len) atBeginning = false; } /* * Hold aside any whitespace at the end of the current chunk. If * we make it to the next chunk, then append our whitespace to * the buffer. Using this methodology, we may "trim" at most * {buffer length} characters from the end. */ if (wsLen > 0) { /* Commit previous ending whitespace */ writer.write(wsBuf, 0, wsLen); wsLen = 0; } while (end > start) { /* Buffer current ending whitespace */ if (charBuf[end] > 0x20) break; wsBuf[wsLen] = charBuf[end]; wsLen++; end--; } if (start < len) { writer.write(charBuf, start, end + 1 - start); } } } catch (UnsupportedEncodingException uee) { throw uee; } catch (IOException ioe) { throw new StreamIOException("Error reading from inline xml datastream."); } finally { try { in.close(); } catch (IOException closeProb) { throw new StreamIOException("Error closing read stream."); } } }
[ "protected", "static", "void", "appendXMLStream", "(", "InputStream", "in", ",", "PrintWriter", "writer", ",", "String", "encoding", ")", "throws", "ObjectIntegrityException", ",", "UnsupportedEncodingException", ",", "StreamIOException", "{", "if", "(", "in", "==", "null", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Object's inline xml \"", "+", "\"stream cannot be null.\"", ")", ";", "}", "try", "{", "InputStreamReader", "chars", "=", "new", "InputStreamReader", "(", "in", ",", "Charset", ".", "forName", "(", "encoding", ")", ")", ";", "/* Content buffer */", "char", "[", "]", "charBuf", "=", "new", "char", "[", "4096", "]", ";", "/* Beginning/ending whitespace buffer */", "char", "[", "]", "wsBuf", "=", "new", "char", "[", "4096", "]", ";", "int", "len", ";", "int", "start", ";", "int", "end", ";", "int", "wsLen", "=", "0", ";", "boolean", "atBeginning", "=", "true", ";", "while", "(", "(", "len", "=", "chars", ".", "read", "(", "charBuf", ")", ")", "!=", "-", "1", ")", "{", "start", "=", "0", ";", "end", "=", "len", "-", "1", ";", "/* Strip out any leading whitespace */", "if", "(", "atBeginning", ")", "{", "while", "(", "start", "<", "len", ")", "{", "if", "(", "charBuf", "[", "start", "]", ">", "0x20", ")", "break", ";", "start", "++", ";", "}", "if", "(", "start", "<", "len", ")", "atBeginning", "=", "false", ";", "}", "/*\n * Hold aside any whitespace at the end of the current chunk. If\n * we make it to the next chunk, then append our whitespace to\n * the buffer. Using this methodology, we may \"trim\" at most\n * {buffer length} characters from the end.\n */", "if", "(", "wsLen", ">", "0", ")", "{", "/* Commit previous ending whitespace */", "writer", ".", "write", "(", "wsBuf", ",", "0", ",", "wsLen", ")", ";", "wsLen", "=", "0", ";", "}", "while", "(", "end", ">", "start", ")", "{", "/* Buffer current ending whitespace */", "if", "(", "charBuf", "[", "end", "]", ">", "0x20", ")", "break", ";", "wsBuf", "[", "wsLen", "]", "=", "charBuf", "[", "end", "]", ";", "wsLen", "++", ";", "end", "--", ";", "}", "if", "(", "start", "<", "len", ")", "{", "writer", ".", "write", "(", "charBuf", ",", "start", ",", "end", "+", "1", "-", "start", ")", ";", "}", "}", "}", "catch", "(", "UnsupportedEncodingException", "uee", ")", "{", "throw", "uee", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "StreamIOException", "(", "\"Error reading from inline xml datastream.\"", ")", ";", "}", "finally", "{", "try", "{", "in", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "closeProb", ")", "{", "throw", "new", "StreamIOException", "(", "\"Error closing read stream.\"", ")", ";", "}", "}", "}" ]
Appends XML to a PrintWriter. Essentially, just appends all text content of the inputStream, trimming any leading and trailing whitespace. It does his in a streaming fashion, with resource consumption entirely comprised of fixed internal buffers. @param in InputStreaming containing serialized XML. @param writer PrintWriter to write XML content to. @param encoding Character set encoding.
[ "Appends", "XML", "to", "a", "PrintWriter", ".", "Essentially", "just", "appends", "all", "text", "content", "of", "the", "inputStream", "trimming", "any", "leading", "and", "trailing", "whitespace", ".", "It", "does", "his", "in", "a", "streaming", "fashion", "with", "resource", "consumption", "entirely", "comprised", "of", "fixed", "internal", "buffers", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java#L689-L762
9,112
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java
DOTranslationUtility.validateAudit
protected static void validateAudit(AuditRecord audit) throws ObjectIntegrityException { if (audit.id == null || audit.id.isEmpty()) { throw new ObjectIntegrityException("Audit record must have id."); } if (audit.date == null) { throw new ObjectIntegrityException("Audit record must have date."); } if (audit.processType == null || audit.processType.isEmpty()) { throw new ObjectIntegrityException("Audit record must have processType."); } if (audit.action == null || audit.action.isEmpty()) { throw new ObjectIntegrityException("Audit record must have action."); } if (audit.componentID == null) { audit.componentID = ""; // for backwards compatibility, no error on null // throw new ObjectIntegrityException("Audit record must have componentID."); } if (audit.responsibility == null || audit.responsibility.isEmpty()) { throw new ObjectIntegrityException("Audit record must have responsibility."); } }
java
protected static void validateAudit(AuditRecord audit) throws ObjectIntegrityException { if (audit.id == null || audit.id.isEmpty()) { throw new ObjectIntegrityException("Audit record must have id."); } if (audit.date == null) { throw new ObjectIntegrityException("Audit record must have date."); } if (audit.processType == null || audit.processType.isEmpty()) { throw new ObjectIntegrityException("Audit record must have processType."); } if (audit.action == null || audit.action.isEmpty()) { throw new ObjectIntegrityException("Audit record must have action."); } if (audit.componentID == null) { audit.componentID = ""; // for backwards compatibility, no error on null // throw new ObjectIntegrityException("Audit record must have componentID."); } if (audit.responsibility == null || audit.responsibility.isEmpty()) { throw new ObjectIntegrityException("Audit record must have responsibility."); } }
[ "protected", "static", "void", "validateAudit", "(", "AuditRecord", "audit", ")", "throws", "ObjectIntegrityException", "{", "if", "(", "audit", ".", "id", "==", "null", "||", "audit", ".", "id", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Audit record must have id.\"", ")", ";", "}", "if", "(", "audit", ".", "date", "==", "null", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Audit record must have date.\"", ")", ";", "}", "if", "(", "audit", ".", "processType", "==", "null", "||", "audit", ".", "processType", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Audit record must have processType.\"", ")", ";", "}", "if", "(", "audit", ".", "action", "==", "null", "||", "audit", ".", "action", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Audit record must have action.\"", ")", ";", "}", "if", "(", "audit", ".", "componentID", "==", "null", ")", "{", "audit", ".", "componentID", "=", "\"\"", ";", "// for backwards compatibility, no error on null", "// throw new ObjectIntegrityException(\"Audit record must have componentID.\");", "}", "if", "(", "audit", ".", "responsibility", "==", "null", "||", "audit", ".", "responsibility", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Audit record must have responsibility.\"", ")", ";", "}", "}" ]
The audit record is created by the system, so programmatic validation here is o.k. Normally, validation takes place via XML Schema and Schematron. @param audit @throws ObjectIntegrityException
[ "The", "audit", "record", "is", "created", "by", "the", "system", "so", "programmatic", "validation", "here", "is", "o", ".", "k", ".", "Normally", "validation", "takes", "place", "via", "XML", "Schema", "and", "Schematron", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/DOTranslationUtility.java#L917-L938
9,113
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/config/Parameter.java
Parameter.getValue
public String getValue(boolean asAbsolutePath) { String path = m_value; if (asAbsolutePath) { if (path != null && m_isFilePath) { File f = new File(path); if (!f.isAbsolute()) { path = FEDORA_HOME + File.separator + path; } } } return path; }
java
public String getValue(boolean asAbsolutePath) { String path = m_value; if (asAbsolutePath) { if (path != null && m_isFilePath) { File f = new File(path); if (!f.isAbsolute()) { path = FEDORA_HOME + File.separator + path; } } } return path; }
[ "public", "String", "getValue", "(", "boolean", "asAbsolutePath", ")", "{", "String", "path", "=", "m_value", ";", "if", "(", "asAbsolutePath", ")", "{", "if", "(", "path", "!=", "null", "&&", "m_isFilePath", ")", "{", "File", "f", "=", "new", "File", "(", "path", ")", ";", "if", "(", "!", "f", ".", "isAbsolute", "(", ")", ")", "{", "path", "=", "FEDORA_HOME", "+", "File", ".", "separator", "+", "path", ";", "}", "}", "}", "return", "path", ";", "}" ]
Gets the value of the parameter. Prepends the location of FEDORA_HOME if asAbsolutePath is true and the parameter location does not already specify an absolute pathname. @param asAbsolutePath Whether to return the parameter value as an absolute file path relative to FEDORA_HOME. @return The value, null if undefined.
[ "Gets", "the", "value", "of", "the", "parameter", ".", "Prepends", "the", "location", "of", "FEDORA_HOME", "if", "asAbsolutePath", "is", "true", "and", "the", "parameter", "location", "does", "not", "already", "specify", "an", "absolute", "pathname", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/config/Parameter.java#L73-L84
9,114
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java
JournalEntry.addArgument
public void addArgument(String key, InputStream stream) throws JournalException { checkOpen(); if (stream == null) { arguments.put(key, null); } else { try { File tempFile = JournalHelper.copyToTempFile(stream); arguments.put(key, tempFile); } catch (IOException e) { throw new JournalException(e); } } }
java
public void addArgument(String key, InputStream stream) throws JournalException { checkOpen(); if (stream == null) { arguments.put(key, null); } else { try { File tempFile = JournalHelper.copyToTempFile(stream); arguments.put(key, tempFile); } catch (IOException e) { throw new JournalException(e); } } }
[ "public", "void", "addArgument", "(", "String", "key", ",", "InputStream", "stream", ")", "throws", "JournalException", "{", "checkOpen", "(", ")", ";", "if", "(", "stream", "==", "null", ")", "{", "arguments", ".", "put", "(", "key", ",", "null", ")", ";", "}", "else", "{", "try", "{", "File", "tempFile", "=", "JournalHelper", ".", "copyToTempFile", "(", "stream", ")", ";", "arguments", ".", "put", "(", "key", ",", "tempFile", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}", "}" ]
If handed an InputStream as an argument, copy it to a temp file and store that File in the arguments map instead. If the InputStream is null, store null in the arguments map.
[ "If", "handed", "an", "InputStream", "as", "an", "argument", "copy", "it", "to", "a", "temp", "file", "and", "store", "that", "File", "in", "the", "arguments", "map", "instead", ".", "If", "the", "InputStream", "is", "null", "store", "null", "in", "the", "arguments", "map", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java#L93-L106
9,115
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java
JournalEntry.getStreamArgument
public InputStream getStreamArgument(String name) throws JournalException { checkOpen(); File file = (File) arguments.get(name); if (file == null) { return null; } else { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new JournalException(e); } } }
java
public InputStream getStreamArgument(String name) throws JournalException { checkOpen(); File file = (File) arguments.get(name); if (file == null) { return null; } else { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new JournalException(e); } } }
[ "public", "InputStream", "getStreamArgument", "(", "String", "name", ")", "throws", "JournalException", "{", "checkOpen", "(", ")", ";", "File", "file", "=", "(", "File", ")", "arguments", ".", "get", "(", "name", ")", ";", "if", "(", "file", "==", "null", ")", "{", "return", "null", ";", "}", "else", "{", "try", "{", "return", "new", "FileInputStream", "(", "file", ")", ";", "}", "catch", "(", "FileNotFoundException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}", "}" ]
If they ask for an InputStream argument, get the File from the arguments map and create an InputStream on that file. If the value from the map is null, return null.
[ "If", "they", "ask", "for", "an", "InputStream", "argument", "get", "the", "File", "from", "the", "arguments", "map", "and", "create", "an", "InputStream", "on", "that", "file", ".", "If", "the", "value", "from", "the", "map", "is", "null", "return", "null", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java#L153-L165
9,116
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java
JournalEntry.close
public void close() { checkOpen(); open = false; for (Object arg : arguments.values()) { if (arg instanceof File) { File file = (File) arg; if (JournalHelper.isTempFile(file)) { if (file.exists()) { file.delete(); } } } } }
java
public void close() { checkOpen(); open = false; for (Object arg : arguments.values()) { if (arg instanceof File) { File file = (File) arg; if (JournalHelper.isTempFile(file)) { if (file.exists()) { file.delete(); } } } } }
[ "public", "void", "close", "(", ")", "{", "checkOpen", "(", ")", ";", "open", "=", "false", ";", "for", "(", "Object", "arg", ":", "arguments", ".", "values", "(", ")", ")", "{", "if", "(", "arg", "instanceof", "File", ")", "{", "File", "file", "=", "(", "File", ")", "arg", ";", "if", "(", "JournalHelper", ".", "isTempFile", "(", "file", ")", ")", "{", "if", "(", "file", ".", "exists", "(", ")", ")", "{", "file", ".", "delete", "(", ")", ";", "}", "}", "}", "}", "}" ]
This should be called when usage of the object is complete, to clean up any temporary files that were created for the journal entry to use.
[ "This", "should", "be", "called", "when", "usage", "of", "the", "object", "is", "complete", "to", "clean", "up", "any", "temporary", "files", "that", "were", "created", "for", "the", "journal", "entry", "to", "use", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/entry/JournalEntry.java#L171-L186
9,117
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java
JournalOutputFile.createTempFilename
private File createTempFilename(File permanentFile, File journalDirectory) { String tempFilename = "_" + permanentFile.getName(); File file2 = new File(journalDirectory, tempFilename); return file2; }
java
private File createTempFilename(File permanentFile, File journalDirectory) { String tempFilename = "_" + permanentFile.getName(); File file2 = new File(journalDirectory, tempFilename); return file2; }
[ "private", "File", "createTempFilename", "(", "File", "permanentFile", ",", "File", "journalDirectory", ")", "{", "String", "tempFilename", "=", "\"_\"", "+", "permanentFile", ".", "getName", "(", ")", ";", "File", "file2", "=", "new", "File", "(", "journalDirectory", ",", "tempFilename", ")", ";", "return", "file2", ";", "}" ]
The "temporary" filename is the permanent name preceded by an underscore.
[ "The", "temporary", "filename", "is", "the", "permanent", "name", "preceded", "by", "an", "underscore", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java#L131-L135
9,118
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java
JournalOutputFile.createTempFile
private FileWriter createTempFile(File tempfile) throws IOException, JournalException { boolean created = tempfile.createNewFile(); if (!created) { throw new JournalException("Unable to create file '" + tempfile.getPath() + "'."); } return new FileWriter(tempfile); }
java
private FileWriter createTempFile(File tempfile) throws IOException, JournalException { boolean created = tempfile.createNewFile(); if (!created) { throw new JournalException("Unable to create file '" + tempfile.getPath() + "'."); } return new FileWriter(tempfile); }
[ "private", "FileWriter", "createTempFile", "(", "File", "tempfile", ")", "throws", "IOException", ",", "JournalException", "{", "boolean", "created", "=", "tempfile", ".", "createNewFile", "(", ")", ";", "if", "(", "!", "created", ")", "{", "throw", "new", "JournalException", "(", "\"Unable to create file '\"", "+", "tempfile", ".", "getPath", "(", ")", "+", "\"'.\"", ")", ";", "}", "return", "new", "FileWriter", "(", "tempfile", ")", ";", "}" ]
Create and open the temporary file.
[ "Create", "and", "open", "the", "temporary", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java#L140-L148
9,119
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java
JournalOutputFile.createXmlEventWriter
private XMLEventWriter createXmlEventWriter(FileWriter fileWriter) throws FactoryConfigurationError, XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); return new IndentingXMLEventWriter(factory .createXMLEventWriter(fileWriter)); }
java
private XMLEventWriter createXmlEventWriter(FileWriter fileWriter) throws FactoryConfigurationError, XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); return new IndentingXMLEventWriter(factory .createXMLEventWriter(fileWriter)); }
[ "private", "XMLEventWriter", "createXmlEventWriter", "(", "FileWriter", "fileWriter", ")", "throws", "FactoryConfigurationError", ",", "XMLStreamException", "{", "XMLOutputFactory", "factory", "=", "XMLOutputFactory", ".", "newInstance", "(", ")", ";", "return", "new", "IndentingXMLEventWriter", "(", "factory", ".", "createXMLEventWriter", "(", "fileWriter", ")", ")", ";", "}" ]
Create an XMLEventWriter for this file. Make it a pretty, indenting writer.
[ "Create", "an", "XMLEventWriter", "for", "this", "file", ".", "Make", "it", "a", "pretty", "indenting", "writer", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java#L154-L159
9,120
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java
JournalOutputFile.closeIfAppropriate
public void closeIfAppropriate() throws JournalException { synchronized (JournalWriter.SYNCHRONIZER) { if (!open) { return; } // if the size limit is 0 or negative, treat it as "no limit". long currentSize = tempFile.length(); if (sizeLimit > 0 && currentSize > sizeLimit) { close(); } } }
java
public void closeIfAppropriate() throws JournalException { synchronized (JournalWriter.SYNCHRONIZER) { if (!open) { return; } // if the size limit is 0 or negative, treat it as "no limit". long currentSize = tempFile.length(); if (sizeLimit > 0 && currentSize > sizeLimit) { close(); } } }
[ "public", "void", "closeIfAppropriate", "(", ")", "throws", "JournalException", "{", "synchronized", "(", "JournalWriter", ".", "SYNCHRONIZER", ")", "{", "if", "(", "!", "open", ")", "{", "return", ";", "}", "// if the size limit is 0 or negative, treat it as \"no limit\".", "long", "currentSize", "=", "tempFile", ".", "length", "(", ")", ";", "if", "(", "sizeLimit", ">", "0", "&&", "currentSize", ">", "sizeLimit", ")", "{", "close", "(", ")", ";", "}", "}", "}" ]
Check the size limit and see whether the file is big enough to close. We could also check the age limit here, but we trust the timer to handle that.
[ "Check", "the", "size", "limit", "and", "see", "whether", "the", "file", "is", "big", "enough", "to", "close", ".", "We", "could", "also", "check", "the", "age", "limit", "here", "but", "we", "trust", "the", "timer", "to", "handle", "that", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java#L191-L203
9,121
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java
JournalOutputFile.close
public void close() throws JournalException { synchronized (JournalWriter.SYNCHRONIZER) { if (!open) { return; } try { parent.getDocumentTrailer(xmlWriter); xmlWriter.close(); fileWriter.close(); timer.cancel(); /* * java.io.File.renameTo() has a known bug when working across * file-systems, see: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So * instead of this call: tempFile.renameTo(file); We use the * following line, and check for exception... */ try { FileMovingUtil.move(tempFile, file); } catch (IOException e) { throw new JournalException("Failed to rename file from '" + tempFile.getPath() + "' to '" + file.getPath() + "'", e); } open = false; } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } } }
java
public void close() throws JournalException { synchronized (JournalWriter.SYNCHRONIZER) { if (!open) { return; } try { parent.getDocumentTrailer(xmlWriter); xmlWriter.close(); fileWriter.close(); timer.cancel(); /* * java.io.File.renameTo() has a known bug when working across * file-systems, see: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So * instead of this call: tempFile.renameTo(file); We use the * following line, and check for exception... */ try { FileMovingUtil.move(tempFile, file); } catch (IOException e) { throw new JournalException("Failed to rename file from '" + tempFile.getPath() + "' to '" + file.getPath() + "'", e); } open = false; } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } } }
[ "public", "void", "close", "(", ")", "throws", "JournalException", "{", "synchronized", "(", "JournalWriter", ".", "SYNCHRONIZER", ")", "{", "if", "(", "!", "open", ")", "{", "return", ";", "}", "try", "{", "parent", ".", "getDocumentTrailer", "(", "xmlWriter", ")", ";", "xmlWriter", ".", "close", "(", ")", ";", "fileWriter", ".", "close", "(", ")", ";", "timer", ".", "cancel", "(", ")", ";", "/*\n * java.io.File.renameTo() has a known bug when working across\n * file-systems, see:\n * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So\n * instead of this call: tempFile.renameTo(file); We use the\n * following line, and check for exception...\n */", "try", "{", "FileMovingUtil", ".", "move", "(", "tempFile", ",", "file", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "\"Failed to rename file from '\"", "+", "tempFile", ".", "getPath", "(", ")", "+", "\"' to '\"", "+", "file", ".", "getPath", "(", ")", "+", "\"'\"", ",", "e", ")", ";", "}", "open", "=", "false", ";", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}", "}" ]
Write the document trailer, clean up everything and rename the file. Set the flag saying we are closed.
[ "Write", "the", "document", "trailer", "clean", "up", "everything", "and", "rename", "the", "file", ".", "Set", "the", "flag", "saying", "we", "are", "closed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalOutputFile.java#L218-L252
9,122
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/HierarchicalLowestChildDenyOverridesPolicyAlg.java
HierarchicalLowestChildDenyOverridesPolicyAlg.combine
@Override @SuppressWarnings("unchecked") public Result combine(EvaluationCtx context, @SuppressWarnings("rawtypes") List parameters, @SuppressWarnings("rawtypes") List policyElements) { logger.info("Combining using: " + getIdentifier()); boolean atLeastOneError = false; boolean atLeastOnePermit = false; Set<Set<?>> denyObligations = new HashSet<Set<?>>(); Status firstIndeterminateStatus = null; Set<AbstractPolicy> matchedPolicies = new HashSet<AbstractPolicy>(); Iterator<?> it = policyElements.iterator(); while (it.hasNext()) { AbstractPolicy policy = ((PolicyCombinerElement) it.next()).getPolicy(); // make sure that the policy matches the context MatchResult match = policy.match(context); if (match.getResult() == MatchResult.INDETERMINATE) { atLeastOneError = true; // keep track of the first error, regardless of cause if (firstIndeterminateStatus == null) { firstIndeterminateStatus = match.getStatus(); } } else if (match.getResult() == MatchResult.MATCH) { matchedPolicies.add(policy); } } Set<AbstractPolicy> applicablePolicies = getApplicablePolicies(context, matchedPolicies); for (AbstractPolicy policy : applicablePolicies) { Result result = policy.evaluate(context); int effect = result.getDecision(); if (effect == Result.DECISION_DENY) { denyObligations.addAll(result.getObligations()); return new Result(Result.DECISION_DENY, context.getResourceId() .encode(), denyObligations); } if (effect == Result.DECISION_PERMIT) { atLeastOnePermit = true; } else if (effect == Result.DECISION_INDETERMINATE) { atLeastOneError = true; // keep track of the first error, regardless of cause if (firstIndeterminateStatus == null) { firstIndeterminateStatus = result.getStatus(); } } } // if we got a PERMIT, return it if (atLeastOnePermit) { return new Result(Result.DECISION_PERMIT, context.getResourceId() .encode()); } // if we got an INDETERMINATE, return it if (atLeastOneError) { return new Result(Result.DECISION_INDETERMINATE, firstIndeterminateStatus, context.getResourceId().encode()); } // if we got here, then nothing applied to us return new Result(Result.DECISION_NOT_APPLICABLE, context .getResourceId().encode()); }
java
@Override @SuppressWarnings("unchecked") public Result combine(EvaluationCtx context, @SuppressWarnings("rawtypes") List parameters, @SuppressWarnings("rawtypes") List policyElements) { logger.info("Combining using: " + getIdentifier()); boolean atLeastOneError = false; boolean atLeastOnePermit = false; Set<Set<?>> denyObligations = new HashSet<Set<?>>(); Status firstIndeterminateStatus = null; Set<AbstractPolicy> matchedPolicies = new HashSet<AbstractPolicy>(); Iterator<?> it = policyElements.iterator(); while (it.hasNext()) { AbstractPolicy policy = ((PolicyCombinerElement) it.next()).getPolicy(); // make sure that the policy matches the context MatchResult match = policy.match(context); if (match.getResult() == MatchResult.INDETERMINATE) { atLeastOneError = true; // keep track of the first error, regardless of cause if (firstIndeterminateStatus == null) { firstIndeterminateStatus = match.getStatus(); } } else if (match.getResult() == MatchResult.MATCH) { matchedPolicies.add(policy); } } Set<AbstractPolicy> applicablePolicies = getApplicablePolicies(context, matchedPolicies); for (AbstractPolicy policy : applicablePolicies) { Result result = policy.evaluate(context); int effect = result.getDecision(); if (effect == Result.DECISION_DENY) { denyObligations.addAll(result.getObligations()); return new Result(Result.DECISION_DENY, context.getResourceId() .encode(), denyObligations); } if (effect == Result.DECISION_PERMIT) { atLeastOnePermit = true; } else if (effect == Result.DECISION_INDETERMINATE) { atLeastOneError = true; // keep track of the first error, regardless of cause if (firstIndeterminateStatus == null) { firstIndeterminateStatus = result.getStatus(); } } } // if we got a PERMIT, return it if (atLeastOnePermit) { return new Result(Result.DECISION_PERMIT, context.getResourceId() .encode()); } // if we got an INDETERMINATE, return it if (atLeastOneError) { return new Result(Result.DECISION_INDETERMINATE, firstIndeterminateStatus, context.getResourceId().encode()); } // if we got here, then nothing applied to us return new Result(Result.DECISION_NOT_APPLICABLE, context .getResourceId().encode()); }
[ "@", "Override", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "Result", "combine", "(", "EvaluationCtx", "context", ",", "@", "SuppressWarnings", "(", "\"rawtypes\"", ")", "List", "parameters", ",", "@", "SuppressWarnings", "(", "\"rawtypes\"", ")", "List", "policyElements", ")", "{", "logger", ".", "info", "(", "\"Combining using: \"", "+", "getIdentifier", "(", ")", ")", ";", "boolean", "atLeastOneError", "=", "false", ";", "boolean", "atLeastOnePermit", "=", "false", ";", "Set", "<", "Set", "<", "?", ">", ">", "denyObligations", "=", "new", "HashSet", "<", "Set", "<", "?", ">", ">", "(", ")", ";", "Status", "firstIndeterminateStatus", "=", "null", ";", "Set", "<", "AbstractPolicy", ">", "matchedPolicies", "=", "new", "HashSet", "<", "AbstractPolicy", ">", "(", ")", ";", "Iterator", "<", "?", ">", "it", "=", "policyElements", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "AbstractPolicy", "policy", "=", "(", "(", "PolicyCombinerElement", ")", "it", ".", "next", "(", ")", ")", ".", "getPolicy", "(", ")", ";", "// make sure that the policy matches the context", "MatchResult", "match", "=", "policy", ".", "match", "(", "context", ")", ";", "if", "(", "match", ".", "getResult", "(", ")", "==", "MatchResult", ".", "INDETERMINATE", ")", "{", "atLeastOneError", "=", "true", ";", "// keep track of the first error, regardless of cause", "if", "(", "firstIndeterminateStatus", "==", "null", ")", "{", "firstIndeterminateStatus", "=", "match", ".", "getStatus", "(", ")", ";", "}", "}", "else", "if", "(", "match", ".", "getResult", "(", ")", "==", "MatchResult", ".", "MATCH", ")", "{", "matchedPolicies", ".", "add", "(", "policy", ")", ";", "}", "}", "Set", "<", "AbstractPolicy", ">", "applicablePolicies", "=", "getApplicablePolicies", "(", "context", ",", "matchedPolicies", ")", ";", "for", "(", "AbstractPolicy", "policy", ":", "applicablePolicies", ")", "{", "Result", "result", "=", "policy", ".", "evaluate", "(", "context", ")", ";", "int", "effect", "=", "result", ".", "getDecision", "(", ")", ";", "if", "(", "effect", "==", "Result", ".", "DECISION_DENY", ")", "{", "denyObligations", ".", "addAll", "(", "result", ".", "getObligations", "(", ")", ")", ";", "return", "new", "Result", "(", "Result", ".", "DECISION_DENY", ",", "context", ".", "getResourceId", "(", ")", ".", "encode", "(", ")", ",", "denyObligations", ")", ";", "}", "if", "(", "effect", "==", "Result", ".", "DECISION_PERMIT", ")", "{", "atLeastOnePermit", "=", "true", ";", "}", "else", "if", "(", "effect", "==", "Result", ".", "DECISION_INDETERMINATE", ")", "{", "atLeastOneError", "=", "true", ";", "// keep track of the first error, regardless of cause", "if", "(", "firstIndeterminateStatus", "==", "null", ")", "{", "firstIndeterminateStatus", "=", "result", ".", "getStatus", "(", ")", ";", "}", "}", "}", "// if we got a PERMIT, return it", "if", "(", "atLeastOnePermit", ")", "{", "return", "new", "Result", "(", "Result", ".", "DECISION_PERMIT", ",", "context", ".", "getResourceId", "(", ")", ".", "encode", "(", ")", ")", ";", "}", "// if we got an INDETERMINATE, return it", "if", "(", "atLeastOneError", ")", "{", "return", "new", "Result", "(", "Result", ".", "DECISION_INDETERMINATE", ",", "firstIndeterminateStatus", ",", "context", ".", "getResourceId", "(", ")", ".", "encode", "(", ")", ")", ";", "}", "// if we got here, then nothing applied to us", "return", "new", "Result", "(", "Result", ".", "DECISION_NOT_APPLICABLE", ",", "context", ".", "getResourceId", "(", ")", ".", "encode", "(", ")", ")", ";", "}" ]
Applies the combining rule to the set of policies based on the evaluation context. @param context the context from the request @param parameters a (possibly empty) non-null <code>List</code> of <code>CombinerParameter</code>s @param policyElements the policies to combine @return the result of running the combining algorithm
[ "Applies", "the", "combining", "rule", "to", "the", "set", "of", "policies", "based", "on", "the", "evaluation", "context", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/HierarchicalLowestChildDenyOverridesPolicyAlg.java#L106-L181
9,123
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyIndexInvocationHandler.java
PolicyIndexInvocationHandler.invokeTarget
private Object invokeTarget(Object target, Method method, Object[] args) throws Throwable { Object returnValue; try { returnValue = method.invoke(target, args); } catch(InvocationTargetException ite) { throw ite.getTargetException(); } return returnValue; }
java
private Object invokeTarget(Object target, Method method, Object[] args) throws Throwable { Object returnValue; try { returnValue = method.invoke(target, args); } catch(InvocationTargetException ite) { throw ite.getTargetException(); } return returnValue; }
[ "private", "Object", "invokeTarget", "(", "Object", "target", ",", "Method", "method", ",", "Object", "[", "]", "args", ")", "throws", "Throwable", "{", "Object", "returnValue", ";", "try", "{", "returnValue", "=", "method", ".", "invoke", "(", "target", ",", "args", ")", ";", "}", "catch", "(", "InvocationTargetException", "ite", ")", "{", "throw", "ite", ".", "getTargetException", "(", ")", ";", "}", "return", "returnValue", ";", "}" ]
Invoke the underlying method, catching any InvocationTargetException and rethrowing the target exception
[ "Invoke", "the", "underlying", "method", "catching", "any", "InvocationTargetException", "and", "rethrowing", "the", "target", "exception" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyIndexInvocationHandler.java#L313-L321
9,124
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyIndexInvocationHandler.java
PolicyIndexInvocationHandler.deletePolicy
private void deletePolicy(String pid) throws GeneralException { LOG.debug("Deleting policy " + pid); try { // in case the policy doesn't exist (corrupt policy index, failed to add because invalid, etc) m_policyIndex.deletePolicy(pid); } catch (PolicyIndexException e) { throw new GeneralException("Error deleting policy " + pid + " from policy index: " + e.getMessage(), e); } }
java
private void deletePolicy(String pid) throws GeneralException { LOG.debug("Deleting policy " + pid); try { // in case the policy doesn't exist (corrupt policy index, failed to add because invalid, etc) m_policyIndex.deletePolicy(pid); } catch (PolicyIndexException e) { throw new GeneralException("Error deleting policy " + pid + " from policy index: " + e.getMessage(), e); } }
[ "private", "void", "deletePolicy", "(", "String", "pid", ")", "throws", "GeneralException", "{", "LOG", ".", "debug", "(", "\"Deleting policy \"", "+", "pid", ")", ";", "try", "{", "// in case the policy doesn't exist (corrupt policy index, failed to add because invalid, etc)", "m_policyIndex", ".", "deletePolicy", "(", "pid", ")", ";", "}", "catch", "(", "PolicyIndexException", "e", ")", "{", "throw", "new", "GeneralException", "(", "\"Error deleting policy \"", "+", "pid", "+", "\" from policy index: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Remove the specified policy from the cache @param pid @throws PolicyIndexException
[ "Remove", "the", "specified", "policy", "from", "the", "cache" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pdp/src/main/java/org/fcrepo/server/security/xacml/pdp/decorator/PolicyIndexInvocationHandler.java#L366-L375
9,125
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/utilities/NormalizedURI.java
NormalizedURI.defaultPort
private final static int defaultPort(String scheme) { if (scheme == null) { return -1; } Integer port = defaultPorts.get(scheme.trim().toLowerCase()); return (port != null) ? port.intValue() : -1; }
java
private final static int defaultPort(String scheme) { if (scheme == null) { return -1; } Integer port = defaultPorts.get(scheme.trim().toLowerCase()); return (port != null) ? port.intValue() : -1; }
[ "private", "final", "static", "int", "defaultPort", "(", "String", "scheme", ")", "{", "if", "(", "scheme", "==", "null", ")", "{", "return", "-", "1", ";", "}", "Integer", "port", "=", "defaultPorts", ".", "get", "(", "scheme", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ")", ";", "return", "(", "port", "!=", "null", ")", "?", "port", ".", "intValue", "(", ")", ":", "-", "1", ";", "}" ]
Return the default port used by a given scheme. @param the scheme, e.g. http @return the port number, or -1 if unknown
[ "Return", "the", "default", "port", "used", "by", "a", "given", "scheme", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/utilities/NormalizedURI.java#L231-L237
9,126
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/types/DeploymentDSBindRule.java
DeploymentDSBindRule.describeAllowedMimeTypes
public String describeAllowedMimeTypes() { if (bindingMIMETypes == null || bindingMIMETypes.length == 0) { return ANY_MIME_TYPE; } StringBuffer out = new StringBuffer(); for (int i = 0; i < bindingMIMETypes.length; i++) { String allowed = bindingMIMETypes[i]; if (allowed == null) { return ANY_MIME_TYPE; } if (allowed.equals("*/*")) { return ANY_MIME_TYPE; } if (allowed.equals("*")) { return ANY_MIME_TYPE; } if (i > 0) { if (i < bindingMIMETypes.length - 1) { out.append(", "); } else { if (i > 1) { out.append(","); } out.append(" or "); } } out.append(allowed); } return out.toString(); }
java
public String describeAllowedMimeTypes() { if (bindingMIMETypes == null || bindingMIMETypes.length == 0) { return ANY_MIME_TYPE; } StringBuffer out = new StringBuffer(); for (int i = 0; i < bindingMIMETypes.length; i++) { String allowed = bindingMIMETypes[i]; if (allowed == null) { return ANY_MIME_TYPE; } if (allowed.equals("*/*")) { return ANY_MIME_TYPE; } if (allowed.equals("*")) { return ANY_MIME_TYPE; } if (i > 0) { if (i < bindingMIMETypes.length - 1) { out.append(", "); } else { if (i > 1) { out.append(","); } out.append(" or "); } } out.append(allowed); } return out.toString(); }
[ "public", "String", "describeAllowedMimeTypes", "(", ")", "{", "if", "(", "bindingMIMETypes", "==", "null", "||", "bindingMIMETypes", ".", "length", "==", "0", ")", "{", "return", "ANY_MIME_TYPE", ";", "}", "StringBuffer", "out", "=", "new", "StringBuffer", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "bindingMIMETypes", ".", "length", ";", "i", "++", ")", "{", "String", "allowed", "=", "bindingMIMETypes", "[", "i", "]", ";", "if", "(", "allowed", "==", "null", ")", "{", "return", "ANY_MIME_TYPE", ";", "}", "if", "(", "allowed", ".", "equals", "(", "\"*/*\"", ")", ")", "{", "return", "ANY_MIME_TYPE", ";", "}", "if", "(", "allowed", ".", "equals", "(", "\"*\"", ")", ")", "{", "return", "ANY_MIME_TYPE", ";", "}", "if", "(", "i", ">", "0", ")", "{", "if", "(", "i", "<", "bindingMIMETypes", ".", "length", "-", "1", ")", "{", "out", ".", "append", "(", "\", \"", ")", ";", "}", "else", "{", "if", "(", "i", ">", "1", ")", "{", "out", ".", "append", "(", "\",\"", ")", ";", "}", "out", ".", "append", "(", "\" or \"", ")", ";", "}", "}", "out", ".", "append", "(", "allowed", ")", ";", "}", "return", "out", ".", "toString", "(", ")", ";", "}" ]
In human readable string, describe which mime types are allowed.
[ "In", "human", "readable", "string", "describe", "which", "mime", "types", "are", "allowed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/types/DeploymentDSBindRule.java#L42-L71
9,127
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java
Journaler.postInitModule
@Override public void postInitModule() throws ModuleInitializationException { ManagementDelegate delegate = serverInterface.getManagementDelegate(); if (delegate == null) { throw new ModuleInitializationException("Can't get a ManagementDelegate from Server.getModule()", getRole()); } worker.setManagementDelegate(delegate); }
java
@Override public void postInitModule() throws ModuleInitializationException { ManagementDelegate delegate = serverInterface.getManagementDelegate(); if (delegate == null) { throw new ModuleInitializationException("Can't get a ManagementDelegate from Server.getModule()", getRole()); } worker.setManagementDelegate(delegate); }
[ "@", "Override", "public", "void", "postInitModule", "(", ")", "throws", "ModuleInitializationException", "{", "ManagementDelegate", "delegate", "=", "serverInterface", ".", "getManagementDelegate", "(", ")", ";", "if", "(", "delegate", "==", "null", ")", "{", "throw", "new", "ModuleInitializationException", "(", "\"Can't get a ManagementDelegate from Server.getModule()\"", ",", "getRole", "(", ")", ")", ";", "}", "worker", ".", "setManagementDelegate", "(", "delegate", ")", ";", "}" ]
Get the ManagementDelegate module and pass it to the worker.
[ "Get", "the", "ManagementDelegate", "module", "and", "pass", "it", "to", "the", "worker", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java#L81-L89
9,128
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java
Journaler.copyPropertiesOverParameters
private void copyPropertiesOverParameters(Map<String, String> parameters) { Properties properties = System.getProperties(); for (Object object : properties.keySet()) { String key = (String) object; if (key.startsWith(SYSTEM_PROPERTY_PREFIX)) { parameters.put(key.substring(SYSTEM_PROPERTY_PREFIX.length()), properties.getProperty(key)); } } }
java
private void copyPropertiesOverParameters(Map<String, String> parameters) { Properties properties = System.getProperties(); for (Object object : properties.keySet()) { String key = (String) object; if (key.startsWith(SYSTEM_PROPERTY_PREFIX)) { parameters.put(key.substring(SYSTEM_PROPERTY_PREFIX.length()), properties.getProperty(key)); } } }
[ "private", "void", "copyPropertiesOverParameters", "(", "Map", "<", "String", ",", "String", ">", "parameters", ")", "{", "Properties", "properties", "=", "System", ".", "getProperties", "(", ")", ";", "for", "(", "Object", "object", ":", "properties", ".", "keySet", "(", ")", ")", "{", "String", "key", "=", "(", "String", ")", "object", ";", "if", "(", "key", ".", "startsWith", "(", "SYSTEM_PROPERTY_PREFIX", ")", ")", "{", "parameters", ".", "put", "(", "key", ".", "substring", "(", "SYSTEM_PROPERTY_PREFIX", ".", "length", "(", ")", ")", ",", "properties", ".", "getProperty", "(", "key", ")", ")", ";", "}", "}", "}" ]
Augment, and perhaps override, the server parameters, using any System Property whose name begins with "fedora.journal.". So, for example, a System Property of "fedora.journal.mode" will override a server parameter of "mode".
[ "Augment", "and", "perhaps", "override", "the", "server", "parameters", "using", "any", "System", "Property", "whose", "name", "begins", "with", "fedora", ".", "journal", ".", ".", "So", "for", "example", "a", "System", "Property", "of", "fedora", ".", "journal", ".", "mode", "will", "override", "a", "server", "parameter", "of", "mode", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java#L105-L114
9,129
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java
Journaler.parseParameters
private void parseParameters(Map<String, String> parameters) throws ModuleInitializationException { logger.info("Parameters: " + parameters); String mode = parameters.get(PARAMETER_JOURNAL_MODE); if (mode == null) { inRecoveryMode = false; } else if (mode.equals(VALUE_JOURNAL_MODE_NORMAL)) { inRecoveryMode = false; } else if (mode.equals(VALUE_JOURNAL_MODE_RECOVER)) { inRecoveryMode = true; } else { throw new ModuleInitializationException("'" + PARAMETER_JOURNAL_MODE + "' parameter must be '" + VALUE_JOURNAL_MODE_NORMAL + "'(default) or '" + VALUE_JOURNAL_MODE_RECOVER + "'", getRole()); } }
java
private void parseParameters(Map<String, String> parameters) throws ModuleInitializationException { logger.info("Parameters: " + parameters); String mode = parameters.get(PARAMETER_JOURNAL_MODE); if (mode == null) { inRecoveryMode = false; } else if (mode.equals(VALUE_JOURNAL_MODE_NORMAL)) { inRecoveryMode = false; } else if (mode.equals(VALUE_JOURNAL_MODE_RECOVER)) { inRecoveryMode = true; } else { throw new ModuleInitializationException("'" + PARAMETER_JOURNAL_MODE + "' parameter must be '" + VALUE_JOURNAL_MODE_NORMAL + "'(default) or '" + VALUE_JOURNAL_MODE_RECOVER + "'", getRole()); } }
[ "private", "void", "parseParameters", "(", "Map", "<", "String", ",", "String", ">", "parameters", ")", "throws", "ModuleInitializationException", "{", "logger", ".", "info", "(", "\"Parameters: \"", "+", "parameters", ")", ";", "String", "mode", "=", "parameters", ".", "get", "(", "PARAMETER_JOURNAL_MODE", ")", ";", "if", "(", "mode", "==", "null", ")", "{", "inRecoveryMode", "=", "false", ";", "}", "else", "if", "(", "mode", ".", "equals", "(", "VALUE_JOURNAL_MODE_NORMAL", ")", ")", "{", "inRecoveryMode", "=", "false", ";", "}", "else", "if", "(", "mode", ".", "equals", "(", "VALUE_JOURNAL_MODE_RECOVER", ")", ")", "{", "inRecoveryMode", "=", "true", ";", "}", "else", "{", "throw", "new", "ModuleInitializationException", "(", "\"'\"", "+", "PARAMETER_JOURNAL_MODE", "+", "\"' parameter must be '\"", "+", "VALUE_JOURNAL_MODE_NORMAL", "+", "\"'(default) or '\"", "+", "VALUE_JOURNAL_MODE_RECOVER", "+", "\"'\"", ",", "getRole", "(", ")", ")", ";", "}", "}" ]
Check the parameters for required values and for acceptable values. At this point, the only parameter we care about is "mode".
[ "Check", "the", "parameters", "for", "required", "values", "and", "for", "acceptable", "values", ".", "At", "this", "point", "the", "only", "parameter", "we", "care", "about", "is", "mode", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/Journaler.java#L120-L137
9,130
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.getInstance
public static JournalReader getInstance(Map<String, String> parameters, String role, JournalRecoveryLog recoveryLog, ServerInterface server) throws ModuleInitializationException { try { Object journalReader = JournalHelper .createInstanceAccordingToParameter(PARAMETER_JOURNAL_READER_CLASSNAME, new Class[] { Map.class, String.class, JournalRecoveryLog.class, ServerInterface.class}, new Object[] { parameters, role, recoveryLog, server}, parameters); logger.info("JournalReader is " + journalReader.toString()); return (JournalReader) journalReader; } catch (JournalException e) { String msg = "Can't create JournalReader"; logger.error(msg, e); throw new ModuleInitializationException(msg, role, e); } }
java
public static JournalReader getInstance(Map<String, String> parameters, String role, JournalRecoveryLog recoveryLog, ServerInterface server) throws ModuleInitializationException { try { Object journalReader = JournalHelper .createInstanceAccordingToParameter(PARAMETER_JOURNAL_READER_CLASSNAME, new Class[] { Map.class, String.class, JournalRecoveryLog.class, ServerInterface.class}, new Object[] { parameters, role, recoveryLog, server}, parameters); logger.info("JournalReader is " + journalReader.toString()); return (JournalReader) journalReader; } catch (JournalException e) { String msg = "Can't create JournalReader"; logger.error(msg, e); throw new ModuleInitializationException(msg, role, e); } }
[ "public", "static", "JournalReader", "getInstance", "(", "Map", "<", "String", ",", "String", ">", "parameters", ",", "String", "role", ",", "JournalRecoveryLog", "recoveryLog", ",", "ServerInterface", "server", ")", "throws", "ModuleInitializationException", "{", "try", "{", "Object", "journalReader", "=", "JournalHelper", ".", "createInstanceAccordingToParameter", "(", "PARAMETER_JOURNAL_READER_CLASSNAME", ",", "new", "Class", "[", "]", "{", "Map", ".", "class", ",", "String", ".", "class", ",", "JournalRecoveryLog", ".", "class", ",", "ServerInterface", ".", "class", "}", ",", "new", "Object", "[", "]", "{", "parameters", ",", "role", ",", "recoveryLog", ",", "server", "}", ",", "parameters", ")", ";", "logger", ".", "info", "(", "\"JournalReader is \"", "+", "journalReader", ".", "toString", "(", ")", ")", ";", "return", "(", "JournalReader", ")", "journalReader", ";", "}", "catch", "(", "JournalException", "e", ")", "{", "String", "msg", "=", "\"Can't create JournalReader\"", ";", "logger", ".", "error", "(", "msg", ",", "e", ")", ";", "throw", "new", "ModuleInitializationException", "(", "msg", ",", "role", ",", "e", ")", ";", "}", "}" ]
Create an instance of the proper JournalReader child class, as determined by the server parameters.
[ "Create", "an", "instance", "of", "the", "proper", "JournalReader", "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/JournalReader.java#L66-L94
9,131
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.checkRepositoryHash
protected void checkRepositoryHash(String hash) throws JournalException { if (!server.hasInitialized()) { throw new IllegalStateException("The repository has is not available until " + "the server is fully initialized."); } JournalException hashException = null; if (hash == null) { hashException = new JournalException("'" + QNAME_TAG_JOURNAL + "' tag must have a '" + QNAME_ATTR_REPOSITORY_HASH + "' attribute."); } else { try { String currentHash = server.getRepositoryHash(); if (hash.equals(currentHash)) { recoveryLog.log("Validated repository hash: '" + hash + "'."); } else { hashException = new JournalException("'" + QNAME_ATTR_REPOSITORY_HASH + "' attribute in '" + QNAME_TAG_JOURNAL + "' tag does not match current repository hash: '" + hash + "' vs. '" + currentHash + "'."); } } catch (ServerException e) { hashException = new JournalException(e); } } if (hashException != null) { if (ignoreHashErrors) { recoveryLog.log("WARNING: " + hashException.getMessage()); } else { throw hashException; } } }
java
protected void checkRepositoryHash(String hash) throws JournalException { if (!server.hasInitialized()) { throw new IllegalStateException("The repository has is not available until " + "the server is fully initialized."); } JournalException hashException = null; if (hash == null) { hashException = new JournalException("'" + QNAME_TAG_JOURNAL + "' tag must have a '" + QNAME_ATTR_REPOSITORY_HASH + "' attribute."); } else { try { String currentHash = server.getRepositoryHash(); if (hash.equals(currentHash)) { recoveryLog.log("Validated repository hash: '" + hash + "'."); } else { hashException = new JournalException("'" + QNAME_ATTR_REPOSITORY_HASH + "' attribute in '" + QNAME_TAG_JOURNAL + "' tag does not match current repository hash: '" + hash + "' vs. '" + currentHash + "'."); } } catch (ServerException e) { hashException = new JournalException(e); } } if (hashException != null) { if (ignoreHashErrors) { recoveryLog.log("WARNING: " + hashException.getMessage()); } else { throw hashException; } } }
[ "protected", "void", "checkRepositoryHash", "(", "String", "hash", ")", "throws", "JournalException", "{", "if", "(", "!", "server", ".", "hasInitialized", "(", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "\"The repository has is not available until \"", "+", "\"the server is fully initialized.\"", ")", ";", "}", "JournalException", "hashException", "=", "null", ";", "if", "(", "hash", "==", "null", ")", "{", "hashException", "=", "new", "JournalException", "(", "\"'\"", "+", "QNAME_TAG_JOURNAL", "+", "\"' tag must have a '\"", "+", "QNAME_ATTR_REPOSITORY_HASH", "+", "\"' attribute.\"", ")", ";", "}", "else", "{", "try", "{", "String", "currentHash", "=", "server", ".", "getRepositoryHash", "(", ")", ";", "if", "(", "hash", ".", "equals", "(", "currentHash", ")", ")", "{", "recoveryLog", ".", "log", "(", "\"Validated repository hash: '\"", "+", "hash", "+", "\"'.\"", ")", ";", "}", "else", "{", "hashException", "=", "new", "JournalException", "(", "\"'\"", "+", "QNAME_ATTR_REPOSITORY_HASH", "+", "\"' attribute in '\"", "+", "QNAME_TAG_JOURNAL", "+", "\"' tag does not match current repository hash: '\"", "+", "hash", "+", "\"' vs. '\"", "+", "currentHash", "+", "\"'.\"", ")", ";", "}", "}", "catch", "(", "ServerException", "e", ")", "{", "hashException", "=", "new", "JournalException", "(", "e", ")", ";", "}", "}", "if", "(", "hashException", "!=", "null", ")", "{", "if", "(", "ignoreHashErrors", ")", "{", "recoveryLog", ".", "log", "(", "\"WARNING: \"", "+", "hashException", ".", "getMessage", "(", ")", ")", ";", "}", "else", "{", "throw", "hashException", ";", "}", "}", "}" ]
Compare the repository hash from the journal file with the current hash obtained from the server. If they do not match, either throw an exception or simply log it, depending on the parameters. 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.
[ "Compare", "the", "repository", "hash", "from", "the", "journal", "file", "with", "the", "current", "hash", "obtained", "from", "the", "server", ".", "If", "they", "do", "not", "match", "either", "throw", "an", "exception", "or", "simply", "log", "it", "depending", "on", "the", "parameters", ".", "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/JournalReader.java#L150-L191
9,132
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.getJournalEntryStartTag
private StartElement getJournalEntryStartTag(XMLEventReader reader) throws XMLStreamException, JournalException { XMLEvent event = reader.nextTag(); if (!isStartTagEvent(event, QNAME_TAG_JOURNAL_ENTRY)) { throw getNotStartTagException(QNAME_TAG_JOURNAL_ENTRY, event); } return event.asStartElement(); }
java
private StartElement getJournalEntryStartTag(XMLEventReader reader) throws XMLStreamException, JournalException { XMLEvent event = reader.nextTag(); if (!isStartTagEvent(event, QNAME_TAG_JOURNAL_ENTRY)) { throw getNotStartTagException(QNAME_TAG_JOURNAL_ENTRY, event); } return event.asStartElement(); }
[ "private", "StartElement", "getJournalEntryStartTag", "(", "XMLEventReader", "reader", ")", "throws", "XMLStreamException", ",", "JournalException", "{", "XMLEvent", "event", "=", "reader", ".", "nextTag", "(", ")", ";", "if", "(", "!", "isStartTagEvent", "(", "event", ",", "QNAME_TAG_JOURNAL_ENTRY", ")", ")", "{", "throw", "getNotStartTagException", "(", "QNAME_TAG_JOURNAL_ENTRY", ",", "event", ")", ";", "}", "return", "event", ".", "asStartElement", "(", ")", ";", "}" ]
Get the next event and complain if it isn't a JournalEntry start tag.
[ "Get", "the", "next", "event", "and", "complain", "if", "it", "isn", "t", "a", "JournalEntry", "start", "tag", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java#L218-L225
9,133
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.readArguments
private void readArguments(XMLEventReader reader, ConsumerJournalEntry cje) throws XMLStreamException, JournalException { while (true) { XMLEvent nextTag = reader.nextTag(); if (isStartTagEvent(nextTag, QNAME_TAG_ARGUMENT)) { readArgument(nextTag, reader, cje); } else if (isEndTagEvent(nextTag, QNAME_TAG_JOURNAL_ENTRY)) { return; } else { throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL_ENTRY, QNAME_TAG_ARGUMENT, nextTag); } } }
java
private void readArguments(XMLEventReader reader, ConsumerJournalEntry cje) throws XMLStreamException, JournalException { while (true) { XMLEvent nextTag = reader.nextTag(); if (isStartTagEvent(nextTag, QNAME_TAG_ARGUMENT)) { readArgument(nextTag, reader, cje); } else if (isEndTagEvent(nextTag, QNAME_TAG_JOURNAL_ENTRY)) { return; } else { throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL_ENTRY, QNAME_TAG_ARGUMENT, nextTag); } } }
[ "private", "void", "readArguments", "(", "XMLEventReader", "reader", ",", "ConsumerJournalEntry", "cje", ")", "throws", "XMLStreamException", ",", "JournalException", "{", "while", "(", "true", ")", "{", "XMLEvent", "nextTag", "=", "reader", ".", "nextTag", "(", ")", ";", "if", "(", "isStartTagEvent", "(", "nextTag", ",", "QNAME_TAG_ARGUMENT", ")", ")", "{", "readArgument", "(", "nextTag", ",", "reader", ",", "cje", ")", ";", "}", "else", "if", "(", "isEndTagEvent", "(", "nextTag", ",", "QNAME_TAG_JOURNAL_ENTRY", ")", ")", "{", "return", ";", "}", "else", "{", "throw", "getNotNextMemberOrEndOfGroupException", "(", "QNAME_TAG_JOURNAL_ENTRY", ",", "QNAME_TAG_ARGUMENT", ",", "nextTag", ")", ";", "}", "}", "}" ]
Read arguments and add them to the event, until we hit the end tag for the event.
[ "Read", "arguments", "and", "add", "them", "to", "the", "event", "until", "we", "hit", "the", "end", "tag", "for", "the", "event", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java#L231-L245
9,134
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.readStreamArgument
private void readStreamArgument(XMLEventReader reader, ConsumerJournalEntry journalEntry, String name) throws XMLStreamException, JournalException { try { File tempFile = JournalHelper.createTempFile(); DecodingBase64OutputStream decoder = new DecodingBase64OutputStream(new FileOutputStream(tempFile)); while (true) { XMLEvent event = reader.nextEvent(); if (event.isCharacters()) { decoder.write(event.asCharacters().getData()); } else if (isEndTagEvent(event, QNAME_TAG_ARGUMENT)) { break; } else { throw getUnexpectedEventInArgumentException(name, ARGUMENT_TYPE_STREAM, journalEntry .getMethodName(), event); } } decoder.close(); journalEntry.addArgument(name, tempFile); } catch (IOException e) { throw new JournalException("failed to write stream argument to temp file", e); } }
java
private void readStreamArgument(XMLEventReader reader, ConsumerJournalEntry journalEntry, String name) throws XMLStreamException, JournalException { try { File tempFile = JournalHelper.createTempFile(); DecodingBase64OutputStream decoder = new DecodingBase64OutputStream(new FileOutputStream(tempFile)); while (true) { XMLEvent event = reader.nextEvent(); if (event.isCharacters()) { decoder.write(event.asCharacters().getData()); } else if (isEndTagEvent(event, QNAME_TAG_ARGUMENT)) { break; } else { throw getUnexpectedEventInArgumentException(name, ARGUMENT_TYPE_STREAM, journalEntry .getMethodName(), event); } } decoder.close(); journalEntry.addArgument(name, tempFile); } catch (IOException e) { throw new JournalException("failed to write stream argument to temp file", e); } }
[ "private", "void", "readStreamArgument", "(", "XMLEventReader", "reader", ",", "ConsumerJournalEntry", "journalEntry", ",", "String", "name", ")", "throws", "XMLStreamException", ",", "JournalException", "{", "try", "{", "File", "tempFile", "=", "JournalHelper", ".", "createTempFile", "(", ")", ";", "DecodingBase64OutputStream", "decoder", "=", "new", "DecodingBase64OutputStream", "(", "new", "FileOutputStream", "(", "tempFile", ")", ")", ";", "while", "(", "true", ")", "{", "XMLEvent", "event", "=", "reader", ".", "nextEvent", "(", ")", ";", "if", "(", "event", ".", "isCharacters", "(", ")", ")", "{", "decoder", ".", "write", "(", "event", ".", "asCharacters", "(", ")", ".", "getData", "(", ")", ")", ";", "}", "else", "if", "(", "isEndTagEvent", "(", "event", ",", "QNAME_TAG_ARGUMENT", ")", ")", "{", "break", ";", "}", "else", "{", "throw", "getUnexpectedEventInArgumentException", "(", "name", ",", "ARGUMENT_TYPE_STREAM", ",", "journalEntry", ".", "getMethodName", "(", ")", ",", "event", ")", ";", "}", "}", "decoder", ".", "close", "(", ")", ";", "journalEntry", ".", "addArgument", "(", "name", ",", "tempFile", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "\"failed to write stream argument to temp file\"", ",", "e", ")", ";", "}", "}" ]
An InputStream argument appears as a Base64-encoded String. It must be decoded and written to a temp file, so it can be presented to the management method as an InputStream again.
[ "An", "InputStream", "argument", "appears", "as", "a", "Base64", "-", "encoded", "String", ".", "It", "must", "be", "decoded", "and", "written", "to", "a", "temp", "file", "so", "it", "can", "be", "presented", "to", "the", "management", "method", "as", "an", "InputStream", "again", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java#L405-L434
9,135
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java
JournalReader.getUnexpectedEventInArgumentException
private JournalException getUnexpectedEventInArgumentException(String name, String argumentType, String methodName, XMLEvent event) { return new JournalException("Unexpected event while processing '" + name + "' argument (type = '" + argumentType + "') for '" + methodName + "' method call: event is '" + event + "'"); }
java
private JournalException getUnexpectedEventInArgumentException(String name, String argumentType, String methodName, XMLEvent event) { return new JournalException("Unexpected event while processing '" + name + "' argument (type = '" + argumentType + "') for '" + methodName + "' method call: event is '" + event + "'"); }
[ "private", "JournalException", "getUnexpectedEventInArgumentException", "(", "String", "name", ",", "String", "argumentType", ",", "String", "methodName", ",", "XMLEvent", "event", ")", "{", "return", "new", "JournalException", "(", "\"Unexpected event while processing '\"", "+", "name", "+", "\"' argument (type = '\"", "+", "argumentType", "+", "\"') for '\"", "+", "methodName", "+", "\"' method call: event is '\"", "+", "event", "+", "\"'\"", ")", ";", "}" ]
If we encounter an unexpected event when reading the a method argument, create an exception with all of the pertinent information.
[ "If", "we", "encounter", "an", "unexpected", "event", "when", "reading", "the", "a", "method", "argument", "create", "an", "exception", "with", "all", "of", "the", "pertinent", "information", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalReader.java#L482-L489
9,136
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java
SimpleDOWriter.addDatastream
public void addDatastream(Datastream datastream, boolean addNewVersion) throws ServerException { assertNotInvalidated(); assertNotPendingRemoval(); // use this call to handle versionable m_obj.addDatastreamVersion(datastream, addNewVersion); }
java
public void addDatastream(Datastream datastream, boolean addNewVersion) throws ServerException { assertNotInvalidated(); assertNotPendingRemoval(); // use this call to handle versionable m_obj.addDatastreamVersion(datastream, addNewVersion); }
[ "public", "void", "addDatastream", "(", "Datastream", "datastream", ",", "boolean", "addNewVersion", ")", "throws", "ServerException", "{", "assertNotInvalidated", "(", ")", ";", "assertNotPendingRemoval", "(", ")", ";", "// use this call to handle versionable", "m_obj", ".", "addDatastreamVersion", "(", "datastream", ",", "addNewVersion", ")", ";", "}" ]
Adds a datastream to the object. @param datastream The datastream. @throws ServerException If any type of error occurred fulfilling the request.
[ "Adds", "a", "datastream", "to", "the", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java#L167-L173
9,137
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java
SimpleDOWriter.removeDatastream
public Date[] removeDatastream(String id, Date start, Date end) throws ServerException { assertNotInvalidated(); assertNotPendingRemoval(); ArrayList<Datastream> removeList = new ArrayList<Datastream>(); for (Datastream ds : m_obj.datastreams(id)) { boolean doRemove = false; if (start != null) { if (end != null) { if (ds.DSCreateDT.compareTo(start) >= 0 && ds.DSCreateDT.compareTo(end) <= 0) { doRemove = true; } } else { if (ds.DSCreateDT.compareTo(start) >= 0) { doRemove = true; } } } else { if (end != null) { if (ds.DSCreateDT.compareTo(end) <= 0) { doRemove = true; } } else { doRemove = true; } } if (doRemove) { // Note: We don't remove old audit records by design. // add this datastream to the datastream to-be-removed list. removeList.add(ds); } } /* Now that we've identified all ds versions to remove, remove 'em */ for (Datastream toRemove : removeList) { m_obj.removeDatastreamVersion(toRemove); } // finally, return the dates of each deleted item Date[] deletedDates = new Date[removeList.size()]; for (int i = 0; i < removeList.size(); i++) { deletedDates[i] = (removeList.get(i)).DSCreateDT; } return deletedDates; }
java
public Date[] removeDatastream(String id, Date start, Date end) throws ServerException { assertNotInvalidated(); assertNotPendingRemoval(); ArrayList<Datastream> removeList = new ArrayList<Datastream>(); for (Datastream ds : m_obj.datastreams(id)) { boolean doRemove = false; if (start != null) { if (end != null) { if (ds.DSCreateDT.compareTo(start) >= 0 && ds.DSCreateDT.compareTo(end) <= 0) { doRemove = true; } } else { if (ds.DSCreateDT.compareTo(start) >= 0) { doRemove = true; } } } else { if (end != null) { if (ds.DSCreateDT.compareTo(end) <= 0) { doRemove = true; } } else { doRemove = true; } } if (doRemove) { // Note: We don't remove old audit records by design. // add this datastream to the datastream to-be-removed list. removeList.add(ds); } } /* Now that we've identified all ds versions to remove, remove 'em */ for (Datastream toRemove : removeList) { m_obj.removeDatastreamVersion(toRemove); } // finally, return the dates of each deleted item Date[] deletedDates = new Date[removeList.size()]; for (int i = 0; i < removeList.size(); i++) { deletedDates[i] = (removeList.get(i)).DSCreateDT; } return deletedDates; }
[ "public", "Date", "[", "]", "removeDatastream", "(", "String", "id", ",", "Date", "start", ",", "Date", "end", ")", "throws", "ServerException", "{", "assertNotInvalidated", "(", ")", ";", "assertNotPendingRemoval", "(", ")", ";", "ArrayList", "<", "Datastream", ">", "removeList", "=", "new", "ArrayList", "<", "Datastream", ">", "(", ")", ";", "for", "(", "Datastream", "ds", ":", "m_obj", ".", "datastreams", "(", "id", ")", ")", "{", "boolean", "doRemove", "=", "false", ";", "if", "(", "start", "!=", "null", ")", "{", "if", "(", "end", "!=", "null", ")", "{", "if", "(", "ds", ".", "DSCreateDT", ".", "compareTo", "(", "start", ")", ">=", "0", "&&", "ds", ".", "DSCreateDT", ".", "compareTo", "(", "end", ")", "<=", "0", ")", "{", "doRemove", "=", "true", ";", "}", "}", "else", "{", "if", "(", "ds", ".", "DSCreateDT", ".", "compareTo", "(", "start", ")", ">=", "0", ")", "{", "doRemove", "=", "true", ";", "}", "}", "}", "else", "{", "if", "(", "end", "!=", "null", ")", "{", "if", "(", "ds", ".", "DSCreateDT", ".", "compareTo", "(", "end", ")", "<=", "0", ")", "{", "doRemove", "=", "true", ";", "}", "}", "else", "{", "doRemove", "=", "true", ";", "}", "}", "if", "(", "doRemove", ")", "{", "// Note: We don't remove old audit records by design.", "// add this datastream to the datastream to-be-removed list.", "removeList", ".", "add", "(", "ds", ")", ";", "}", "}", "/* Now that we've identified all ds versions to remove, remove 'em */", "for", "(", "Datastream", "toRemove", ":", "removeList", ")", "{", "m_obj", ".", "removeDatastreamVersion", "(", "toRemove", ")", ";", "}", "// finally, return the dates of each deleted item", "Date", "[", "]", "deletedDates", "=", "new", "Date", "[", "removeList", ".", "size", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "removeList", ".", "size", "(", ")", ";", "i", "++", ")", "{", "deletedDates", "[", "i", "]", "=", "(", "removeList", ".", "get", "(", "i", ")", ")", ".", "DSCreateDT", ";", "}", "return", "deletedDates", ";", "}" ]
Removes a datastream from the object. @param id The id of the datastream. @param start The start date (inclusive) of versions to remove. If <code>null</code>, this is taken to be the smallest possible value. @param end The end date (inclusive) of versions to remove. If <code>null</code>, this is taken to be the greatest possible value. @throws ServerException If any type of error occurred fulfilling the request.
[ "Removes", "a", "datastream", "from", "the", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java#L191-L237
9,138
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java
SimpleDOWriter.resolveSubjectToDatastream
private String resolveSubjectToDatastream(String subject) throws ServerException{ String pidURI = PID.toURI(m_obj.getPid()); if (subject.startsWith(pidURI)) { if (subject.length() == pidURI.length()) { return "RELS-EXT"; } if (subject.charAt(pidURI.length()) == '/') { return "RELS-INT"; } } throw new GeneralException("Cannot determine which relationship datastream to update for subject " + subject + ". Relationship subjects must be the URI of the object or the URI of a datastream within the object."); }
java
private String resolveSubjectToDatastream(String subject) throws ServerException{ String pidURI = PID.toURI(m_obj.getPid()); if (subject.startsWith(pidURI)) { if (subject.length() == pidURI.length()) { return "RELS-EXT"; } if (subject.charAt(pidURI.length()) == '/') { return "RELS-INT"; } } throw new GeneralException("Cannot determine which relationship datastream to update for subject " + subject + ". Relationship subjects must be the URI of the object or the URI of a datastream within the object."); }
[ "private", "String", "resolveSubjectToDatastream", "(", "String", "subject", ")", "throws", "ServerException", "{", "String", "pidURI", "=", "PID", ".", "toURI", "(", "m_obj", ".", "getPid", "(", ")", ")", ";", "if", "(", "subject", ".", "startsWith", "(", "pidURI", ")", ")", "{", "if", "(", "subject", ".", "length", "(", ")", "==", "pidURI", ".", "length", "(", ")", ")", "{", "return", "\"RELS-EXT\"", ";", "}", "if", "(", "subject", ".", "charAt", "(", "pidURI", ".", "length", "(", ")", ")", "==", "'", "'", ")", "{", "return", "\"RELS-INT\"", ";", "}", "}", "throw", "new", "GeneralException", "(", "\"Cannot determine which relationship datastream to update for subject \"", "+", "subject", "+", "\". Relationship subjects must be the URI of the object or the URI of a datastream within the object.\"", ")", ";", "}" ]
from the relationship subject, determine which datastream to modify etc
[ "from", "the", "relationship", "subject", "determine", "which", "datastream", "to", "modify", "etc" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java#L240-L251
9,139
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java
SimpleDOWriter.commit
public void commit(String logMessage) throws ServerException { assertNotInvalidated(); m_mgr.doCommit(Server.USE_DEFINITIVE_STORE, m_context, m_obj, logMessage, m_pendingRemoval); m_committed = true; invalidate(); }
java
public void commit(String logMessage) throws ServerException { assertNotInvalidated(); m_mgr.doCommit(Server.USE_DEFINITIVE_STORE, m_context, m_obj, logMessage, m_pendingRemoval); m_committed = true; invalidate(); }
[ "public", "void", "commit", "(", "String", "logMessage", ")", "throws", "ServerException", "{", "assertNotInvalidated", "(", ")", ";", "m_mgr", ".", "doCommit", "(", "Server", ".", "USE_DEFINITIVE_STORE", ",", "m_context", ",", "m_obj", ",", "logMessage", ",", "m_pendingRemoval", ")", ";", "m_committed", "=", "true", ";", "invalidate", "(", ")", ";", "}" ]
Saves the changes thus far to the permanent copy of the digital object. @param logMessage An explanation of the change(s). @throws ServerException If any type of error occurred fulfilling the request.
[ "Saves", "the", "changes", "thus", "far", "to", "the", "permanent", "copy", "of", "the", "digital", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/SimpleDOWriter.java#L510-L519
9,140
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiTransportWriter.java
RmiTransportWriter.write
@Override public void write(char[] cbuf, int off, int len) throws IOException { try { String indexedHash = RmiJournalReceiverHelper.figureIndexedHash(repositoryHash, itemIndex); receiver.writeText(indexedHash, new String(cbuf, off, len)); itemIndex++; } catch (JournalException e) { throw new IOException(e); } }
java
@Override public void write(char[] cbuf, int off, int len) throws IOException { try { String indexedHash = RmiJournalReceiverHelper.figureIndexedHash(repositoryHash, itemIndex); receiver.writeText(indexedHash, new String(cbuf, off, len)); itemIndex++; } catch (JournalException e) { throw new IOException(e); } }
[ "@", "Override", "public", "void", "write", "(", "char", "[", "]", "cbuf", ",", "int", "off", ",", "int", "len", ")", "throws", "IOException", "{", "try", "{", "String", "indexedHash", "=", "RmiJournalReceiverHelper", ".", "figureIndexedHash", "(", "repositoryHash", ",", "itemIndex", ")", ";", "receiver", ".", "writeText", "(", "indexedHash", ",", "new", "String", "(", "cbuf", ",", "off", ",", "len", ")", ")", ";", "itemIndex", "++", ";", "}", "catch", "(", "JournalException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}" ]
Each time characters are written, send them to the receiver. Keep track of how many writes, so we can create a proper item hash.
[ "Each", "time", "characters", "are", "written", "send", "them", "to", "the", "receiver", ".", "Keep", "track", "of", "how", "many", "writes", "so", "we", "can", "create", "a", "proper", "item", "hash", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiTransportWriter.java#L62-L73
9,141
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiTransportWriter.java
RmiTransportWriter.close
@Override public void close() throws IOException { try { if (!m_closed) { receiver.closeFile(); m_closed= true; } } catch (JournalException e) { throw new IOException(e); } }
java
@Override public void close() throws IOException { try { if (!m_closed) { receiver.closeFile(); m_closed= true; } } catch (JournalException e) { throw new IOException(e); } }
[ "@", "Override", "public", "void", "close", "(", ")", "throws", "IOException", "{", "try", "{", "if", "(", "!", "m_closed", ")", "{", "receiver", ".", "closeFile", "(", ")", ";", "m_closed", "=", "true", ";", "}", "}", "catch", "(", "JournalException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}" ]
Time to close the file? Tell the receiver.
[ "Time", "to", "close", "the", "file?", "Tell", "the", "receiver", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiTransportWriter.java#L78-L88
9,142
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/util/SubjectUtils.java
SubjectUtils.getAttributes
@SuppressWarnings("unchecked") public static Map<String, Set<String>> getAttributes(Subject subject) { Map<String, Set<String>> attributes = null; if (subject.getPublicCredentials() == null) { return new HashMap<String, Set<String>>(); } @SuppressWarnings("rawtypes") Iterator<HashMap> credentialObjects = subject.getPublicCredentials(HashMap.class).iterator(); while (attributes == null && credentialObjects.hasNext()) { HashMap<?,?> credentialObject = credentialObjects.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (class name): " + credentialObject.getClass().getName()); } Object key = null; Iterator<?> keys = null; keys = credentialObject.keySet().iterator(); if (!keys.hasNext()) { continue; } key = keys.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (key object name): " + key.getClass().getName()); } if (!(key instanceof String)) { continue; } keys = credentialObject.values().iterator(); if (!keys.hasNext()) { continue; } key = keys.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (value object name): " + key.getClass().getName()); } if (!(key instanceof HashSet)) { continue; } attributes = (Map<String, Set<String>>) credentialObject; } if (attributes == null) { attributes = new HashMap<String, Set<String>>(); subject.getPublicCredentials().add(attributes); } return attributes; }
java
@SuppressWarnings("unchecked") public static Map<String, Set<String>> getAttributes(Subject subject) { Map<String, Set<String>> attributes = null; if (subject.getPublicCredentials() == null) { return new HashMap<String, Set<String>>(); } @SuppressWarnings("rawtypes") Iterator<HashMap> credentialObjects = subject.getPublicCredentials(HashMap.class).iterator(); while (attributes == null && credentialObjects.hasNext()) { HashMap<?,?> credentialObject = credentialObjects.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (class name): " + credentialObject.getClass().getName()); } Object key = null; Iterator<?> keys = null; keys = credentialObject.keySet().iterator(); if (!keys.hasNext()) { continue; } key = keys.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (key object name): " + key.getClass().getName()); } if (!(key instanceof String)) { continue; } keys = credentialObject.values().iterator(); if (!keys.hasNext()) { continue; } key = keys.next(); if (logger.isDebugEnabled()) { logger.debug("checking for attributes (value object name): " + key.getClass().getName()); } if (!(key instanceof HashSet)) { continue; } attributes = (Map<String, Set<String>>) credentialObject; } if (attributes == null) { attributes = new HashMap<String, Set<String>>(); subject.getPublicCredentials().add(attributes); } return attributes; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", "getAttributes", "(", "Subject", "subject", ")", "{", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", "attributes", "=", "null", ";", "if", "(", "subject", ".", "getPublicCredentials", "(", ")", "==", "null", ")", "{", "return", "new", "HashMap", "<", "String", ",", "Set", "<", "String", ">", ">", "(", ")", ";", "}", "@", "SuppressWarnings", "(", "\"rawtypes\"", ")", "Iterator", "<", "HashMap", ">", "credentialObjects", "=", "subject", ".", "getPublicCredentials", "(", "HashMap", ".", "class", ")", ".", "iterator", "(", ")", ";", "while", "(", "attributes", "==", "null", "&&", "credentialObjects", ".", "hasNext", "(", ")", ")", "{", "HashMap", "<", "?", ",", "?", ">", "credentialObject", "=", "credentialObjects", ".", "next", "(", ")", ";", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"checking for attributes (class name): \"", "+", "credentialObject", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "}", "Object", "key", "=", "null", ";", "Iterator", "<", "?", ">", "keys", "=", "null", ";", "keys", "=", "credentialObject", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "if", "(", "!", "keys", ".", "hasNext", "(", ")", ")", "{", "continue", ";", "}", "key", "=", "keys", ".", "next", "(", ")", ";", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"checking for attributes (key object name): \"", "+", "key", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "}", "if", "(", "!", "(", "key", "instanceof", "String", ")", ")", "{", "continue", ";", "}", "keys", "=", "credentialObject", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "if", "(", "!", "keys", ".", "hasNext", "(", ")", ")", "{", "continue", ";", "}", "key", "=", "keys", ".", "next", "(", ")", ";", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"checking for attributes (value object name): \"", "+", "key", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "}", "if", "(", "!", "(", "key", "instanceof", "HashSet", ")", ")", "{", "continue", ";", "}", "attributes", "=", "(", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", ")", "credentialObject", ";", "}", "if", "(", "attributes", "==", "null", ")", "{", "attributes", "=", "new", "HashMap", "<", "String", ",", "Set", "<", "String", ">", ">", "(", ")", ";", "subject", ".", "getPublicCredentials", "(", ")", ".", "add", "(", "attributes", ")", ";", "}", "return", "attributes", ";", "}" ]
Get the attribute map of String keys to Set&lt;String&gt; values This method will not return a null @param subject @return Map&lt;String, Set&lt;String&gt;&gt;
[ "Get", "the", "attribute", "map", "of", "String", "keys", "to", "Set&lt", ";", "String&gt", ";", "values", "This", "method", "will", "not", "return", "a", "null" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/util/SubjectUtils.java#L44-L106
9,143
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalInputFile.java
JournalInputFile.closeAndRename
public void closeAndRename(File archiveDirectory) throws JournalException { try { xmlReader.close(); fileReader.close(); File archiveFile = new File(archiveDirectory, file.getName()); /* * java.io.File.renameTo() has a known bug when working across * file-systems, see: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So * instead of this call: file.renameTo(archiveFile); We use the * following line, and check for exception... */ try { FileMovingUtil.move(file, archiveFile); } catch (IOException e) { throw new JournalException("Failed to rename file from '" + file.getPath() + "' to '" + archiveFile.getPath() + "'", e); } } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }
java
public void closeAndRename(File archiveDirectory) throws JournalException { try { xmlReader.close(); fileReader.close(); File archiveFile = new File(archiveDirectory, file.getName()); /* * java.io.File.renameTo() has a known bug when working across * file-systems, see: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So * instead of this call: file.renameTo(archiveFile); We use the * following line, and check for exception... */ try { FileMovingUtil.move(file, archiveFile); } catch (IOException e) { throw new JournalException("Failed to rename file from '" + file.getPath() + "' to '" + archiveFile.getPath() + "'", e); } } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }
[ "public", "void", "closeAndRename", "(", "File", "archiveDirectory", ")", "throws", "JournalException", "{", "try", "{", "xmlReader", ".", "close", "(", ")", ";", "fileReader", ".", "close", "(", ")", ";", "File", "archiveFile", "=", "new", "File", "(", "archiveDirectory", ",", "file", ".", "getName", "(", ")", ")", ";", "/*\n * java.io.File.renameTo() has a known bug when working across\n * file-systems, see:\n * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So\n * instead of this call: file.renameTo(archiveFile); We use the\n * following line, and check for exception...\n */", "try", "{", "FileMovingUtil", ".", "move", "(", "file", ",", "archiveFile", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "\"Failed to rename file from '\"", "+", "file", ".", "getPath", "(", ")", "+", "\"' to '\"", "+", "archiveFile", ".", "getPath", "(", ")", "+", "\"'\"", ",", "e", ")", ";", "}", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
When we have processed the file, move it to the archive directory.
[ "When", "we", "have", "processed", "the", "file", "move", "it", "to", "the", "archive", "directory", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/JournalInputFile.java#L63-L88
9,144
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java
DatastreamsPane.doNew
public void doNew(String[] dropdownMimeTypes, boolean makeSelected) { int i = getTabIndex("New..."); m_tabbedPane .setComponentAt(i, new NewDatastreamPane(dropdownMimeTypes)); i = getTabIndex("New..."); m_tabbedPane.setToolTipTextAt(i, "Add a new datastream to this object"); m_tabbedPane.setIconAt(i, newIcon); m_tabbedPane.setBackgroundAt(i, Administrator.DEFAULT_COLOR); if (makeSelected) { m_tabbedPane.setSelectedIndex(i); } }
java
public void doNew(String[] dropdownMimeTypes, boolean makeSelected) { int i = getTabIndex("New..."); m_tabbedPane .setComponentAt(i, new NewDatastreamPane(dropdownMimeTypes)); i = getTabIndex("New..."); m_tabbedPane.setToolTipTextAt(i, "Add a new datastream to this object"); m_tabbedPane.setIconAt(i, newIcon); m_tabbedPane.setBackgroundAt(i, Administrator.DEFAULT_COLOR); if (makeSelected) { m_tabbedPane.setSelectedIndex(i); } }
[ "public", "void", "doNew", "(", "String", "[", "]", "dropdownMimeTypes", ",", "boolean", "makeSelected", ")", "{", "int", "i", "=", "getTabIndex", "(", "\"New...\"", ")", ";", "m_tabbedPane", ".", "setComponentAt", "(", "i", ",", "new", "NewDatastreamPane", "(", "dropdownMimeTypes", ")", ")", ";", "i", "=", "getTabIndex", "(", "\"New...\"", ")", ";", "m_tabbedPane", ".", "setToolTipTextAt", "(", "i", ",", "\"Add a new datastream to this object\"", ")", ";", "m_tabbedPane", ".", "setIconAt", "(", "i", ",", "newIcon", ")", ";", "m_tabbedPane", ".", "setBackgroundAt", "(", "i", ",", "Administrator", ".", "DEFAULT_COLOR", ")", ";", "if", "(", "makeSelected", ")", "{", "m_tabbedPane", ".", "setSelectedIndex", "(", "i", ")", ";", "}", "}" ]
Set the content of the "New..." JPanel to a fresh new datastream entry panel, and switch to it, if needed.
[ "Set", "the", "content", "of", "the", "New", "...", "JPanel", "to", "a", "fresh", "new", "datastream", "entry", "panel", "and", "switch", "to", "it", "if", "needed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java#L158-L170
9,145
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java
DatastreamsPane.updateNewRelsExt
public void updateNewRelsExt(String pid) throws Exception { if (!hasRelsExt() && getTabIndex("New RELS-EXT...") == -1) { m_tabbedPane.insertTab("New RELS-EXT...", newIcon, new NewRelsExtDatastreamPane(m_owner, pid, this), "Add a RELS-EXT datastream to this object", getTabIndex("New...")); int i = getTabIndex("New RELS-EXT..."); m_tabbedPane.setBackgroundAt(i, Administrator.DEFAULT_COLOR); } else if (hasRelsExt() && getTabIndex("New RELS-EXT...") != -1) { m_tabbedPane.remove(getTabIndex("New RELS-EXT...")); } }
java
public void updateNewRelsExt(String pid) throws Exception { if (!hasRelsExt() && getTabIndex("New RELS-EXT...") == -1) { m_tabbedPane.insertTab("New RELS-EXT...", newIcon, new NewRelsExtDatastreamPane(m_owner, pid, this), "Add a RELS-EXT datastream to this object", getTabIndex("New...")); int i = getTabIndex("New RELS-EXT..."); m_tabbedPane.setBackgroundAt(i, Administrator.DEFAULT_COLOR); } else if (hasRelsExt() && getTabIndex("New RELS-EXT...") != -1) { m_tabbedPane.remove(getTabIndex("New RELS-EXT...")); } }
[ "public", "void", "updateNewRelsExt", "(", "String", "pid", ")", "throws", "Exception", "{", "if", "(", "!", "hasRelsExt", "(", ")", "&&", "getTabIndex", "(", "\"New RELS-EXT...\"", ")", "==", "-", "1", ")", "{", "m_tabbedPane", ".", "insertTab", "(", "\"New RELS-EXT...\"", ",", "newIcon", ",", "new", "NewRelsExtDatastreamPane", "(", "m_owner", ",", "pid", ",", "this", ")", ",", "\"Add a RELS-EXT datastream to this object\"", ",", "getTabIndex", "(", "\"New...\"", ")", ")", ";", "int", "i", "=", "getTabIndex", "(", "\"New RELS-EXT...\"", ")", ";", "m_tabbedPane", ".", "setBackgroundAt", "(", "i", ",", "Administrator", ".", "DEFAULT_COLOR", ")", ";", "}", "else", "if", "(", "hasRelsExt", "(", ")", "&&", "getTabIndex", "(", "\"New RELS-EXT...\"", ")", "!=", "-", "1", ")", "{", "m_tabbedPane", ".", "remove", "(", "getTabIndex", "(", "\"New RELS-EXT...\"", ")", ")", ";", "}", "}" ]
Set the content of the "New Rels-Ext..." JPanel to a fresh new datastream entry panel, and switch to it, if needed. @throws Exception
[ "Set", "the", "content", "of", "the", "New", "Rels", "-", "Ext", "...", "JPanel", "to", "a", "fresh", "new", "datastream", "entry", "panel", "and", "switch", "to", "it", "if", "needed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java#L178-L192
9,146
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java
DatastreamsPane.getDatastreamPaneIndex
private int getDatastreamPaneIndex(String id) { int index = -1; for (int i=0; i < m_datastreamPanes.length; i++) { if(m_datastreamPanes[i].getItemId().equals(id)){ index = i; break; } } return index; }
java
private int getDatastreamPaneIndex(String id) { int index = -1; for (int i=0; i < m_datastreamPanes.length; i++) { if(m_datastreamPanes[i].getItemId().equals(id)){ index = i; break; } } return index; }
[ "private", "int", "getDatastreamPaneIndex", "(", "String", "id", ")", "{", "int", "index", "=", "-", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_datastreamPanes", ".", "length", ";", "i", "++", ")", "{", "if", "(", "m_datastreamPanes", "[", "i", "]", ".", "getItemId", "(", ")", ".", "equals", "(", "id", ")", ")", "{", "index", "=", "i", ";", "break", ";", "}", "}", "return", "index", ";", "}" ]
Gets the index of the pane containing the datastream with the given id. @return index, or -1 if index is not found
[ "Gets", "the", "index", "of", "the", "pane", "containing", "the", "datastream", "with", "the", "given", "id", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java#L207-L217
9,147
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java
DatastreamsPane.refresh
protected void refresh(String dsID) { int i = getTabIndex(dsID); try { List<Datastream> versions = Administrator.APIM.getDatastreamHistory(m_pid, dsID); m_currentVersionMap.put(dsID, versions.get(i)); logger.debug("New create date is: " + versions.get(i).getCreateDate()); DatastreamPane replacement = new DatastreamPane(m_owner, m_pid, versions, this); m_datastreamPanes[i] = replacement; m_tabbedPane.setComponentAt(i, replacement); m_tabbedPane.setToolTipTextAt(i, versions.get(i).getMIMEType() + " - " + versions.get(i).getLabel() + " (" + versions.get(i).getControlGroup().toString() + ")"); colorTabForState(dsID, versions.get(i).getState()); setDirty(dsID, false); } catch (Exception e) { Administrator .showErrorDialog(Administrator.getDesktop(), "Error while refreshing", e.getMessage() + "\nTry re-opening the object viewer.", e); } }
java
protected void refresh(String dsID) { int i = getTabIndex(dsID); try { List<Datastream> versions = Administrator.APIM.getDatastreamHistory(m_pid, dsID); m_currentVersionMap.put(dsID, versions.get(i)); logger.debug("New create date is: " + versions.get(i).getCreateDate()); DatastreamPane replacement = new DatastreamPane(m_owner, m_pid, versions, this); m_datastreamPanes[i] = replacement; m_tabbedPane.setComponentAt(i, replacement); m_tabbedPane.setToolTipTextAt(i, versions.get(i).getMIMEType() + " - " + versions.get(i).getLabel() + " (" + versions.get(i).getControlGroup().toString() + ")"); colorTabForState(dsID, versions.get(i).getState()); setDirty(dsID, false); } catch (Exception e) { Administrator .showErrorDialog(Administrator.getDesktop(), "Error while refreshing", e.getMessage() + "\nTry re-opening the object viewer.", e); } }
[ "protected", "void", "refresh", "(", "String", "dsID", ")", "{", "int", "i", "=", "getTabIndex", "(", "dsID", ")", ";", "try", "{", "List", "<", "Datastream", ">", "versions", "=", "Administrator", ".", "APIM", ".", "getDatastreamHistory", "(", "m_pid", ",", "dsID", ")", ";", "m_currentVersionMap", ".", "put", "(", "dsID", ",", "versions", ".", "get", "(", "i", ")", ")", ";", "logger", ".", "debug", "(", "\"New create date is: \"", "+", "versions", ".", "get", "(", "i", ")", ".", "getCreateDate", "(", ")", ")", ";", "DatastreamPane", "replacement", "=", "new", "DatastreamPane", "(", "m_owner", ",", "m_pid", ",", "versions", ",", "this", ")", ";", "m_datastreamPanes", "[", "i", "]", "=", "replacement", ";", "m_tabbedPane", ".", "setComponentAt", "(", "i", ",", "replacement", ")", ";", "m_tabbedPane", ".", "setToolTipTextAt", "(", "i", ",", "versions", ".", "get", "(", "i", ")", ".", "getMIMEType", "(", ")", "+", "\" - \"", "+", "versions", ".", "get", "(", "i", ")", ".", "getLabel", "(", ")", "+", "\" (\"", "+", "versions", ".", "get", "(", "i", ")", ".", "getControlGroup", "(", ")", ".", "toString", "(", ")", "+", "\")\"", ")", ";", "colorTabForState", "(", "dsID", ",", "versions", ".", "get", "(", "i", ")", ".", "getState", "(", ")", ")", ";", "setDirty", "(", "dsID", ",", "false", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "Administrator", ".", "showErrorDialog", "(", "Administrator", ".", "getDesktop", "(", ")", ",", "\"Error while refreshing\"", ",", "e", ".", "getMessage", "(", ")", "+", "\"\\nTry re-opening the object viewer.\"", ",", "e", ")", ";", "}", "}" ]
Refresh the content of the tab for the indicated datastream with the latest information from the server.
[ "Refresh", "the", "content", "of", "the", "tab", "for", "the", "indicated", "datastream", "with", "the", "latest", "information", "from", "the", "server", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java#L233-L257
9,148
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java
DatastreamsPane.addDatastreamTab
protected void addDatastreamTab(String dsID, boolean reInitNewPanel) throws Exception { DatastreamPane[] newArray = new DatastreamPane[m_datastreamPanes.length + 1]; for (int i = 0; i < m_datastreamPanes.length; i++) { newArray[i] = m_datastreamPanes[i]; } List<Datastream> versions = Administrator.APIM.getDatastreamHistory(m_pid, dsID); m_currentVersionMap.put(dsID, versions.get(0)); newArray[m_datastreamPanes.length] = new DatastreamPane(m_owner, m_pid, versions, this); // swap the arrays m_datastreamPanes = newArray; int newIndex = getTabIndex("New..."); m_tabbedPane.add(m_datastreamPanes[m_datastreamPanes.length - 1], newIndex); m_tabbedPane.setTitleAt(newIndex, dsID); m_tabbedPane.setToolTipTextAt(newIndex, versions.get(0).getMIMEType() + " - " + versions.get(0).getLabel() + " (" + versions.get(0).getControlGroup().toString() + ")"); colorTabForState(dsID, versions.get(0).getState()); if (reInitNewPanel) { doNew(XML_MIMETYPE, false); } updateNewRelsExt(m_pid); m_tabbedPane.setSelectedIndex(getTabIndex(dsID)); }
java
protected void addDatastreamTab(String dsID, boolean reInitNewPanel) throws Exception { DatastreamPane[] newArray = new DatastreamPane[m_datastreamPanes.length + 1]; for (int i = 0; i < m_datastreamPanes.length; i++) { newArray[i] = m_datastreamPanes[i]; } List<Datastream> versions = Administrator.APIM.getDatastreamHistory(m_pid, dsID); m_currentVersionMap.put(dsID, versions.get(0)); newArray[m_datastreamPanes.length] = new DatastreamPane(m_owner, m_pid, versions, this); // swap the arrays m_datastreamPanes = newArray; int newIndex = getTabIndex("New..."); m_tabbedPane.add(m_datastreamPanes[m_datastreamPanes.length - 1], newIndex); m_tabbedPane.setTitleAt(newIndex, dsID); m_tabbedPane.setToolTipTextAt(newIndex, versions.get(0).getMIMEType() + " - " + versions.get(0).getLabel() + " (" + versions.get(0).getControlGroup().toString() + ")"); colorTabForState(dsID, versions.get(0).getState()); if (reInitNewPanel) { doNew(XML_MIMETYPE, false); } updateNewRelsExt(m_pid); m_tabbedPane.setSelectedIndex(getTabIndex(dsID)); }
[ "protected", "void", "addDatastreamTab", "(", "String", "dsID", ",", "boolean", "reInitNewPanel", ")", "throws", "Exception", "{", "DatastreamPane", "[", "]", "newArray", "=", "new", "DatastreamPane", "[", "m_datastreamPanes", ".", "length", "+", "1", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_datastreamPanes", ".", "length", ";", "i", "++", ")", "{", "newArray", "[", "i", "]", "=", "m_datastreamPanes", "[", "i", "]", ";", "}", "List", "<", "Datastream", ">", "versions", "=", "Administrator", ".", "APIM", ".", "getDatastreamHistory", "(", "m_pid", ",", "dsID", ")", ";", "m_currentVersionMap", ".", "put", "(", "dsID", ",", "versions", ".", "get", "(", "0", ")", ")", ";", "newArray", "[", "m_datastreamPanes", ".", "length", "]", "=", "new", "DatastreamPane", "(", "m_owner", ",", "m_pid", ",", "versions", ",", "this", ")", ";", "// swap the arrays", "m_datastreamPanes", "=", "newArray", ";", "int", "newIndex", "=", "getTabIndex", "(", "\"New...\"", ")", ";", "m_tabbedPane", ".", "add", "(", "m_datastreamPanes", "[", "m_datastreamPanes", ".", "length", "-", "1", "]", ",", "newIndex", ")", ";", "m_tabbedPane", ".", "setTitleAt", "(", "newIndex", ",", "dsID", ")", ";", "m_tabbedPane", ".", "setToolTipTextAt", "(", "newIndex", ",", "versions", ".", "get", "(", "0", ")", ".", "getMIMEType", "(", ")", "+", "\" - \"", "+", "versions", ".", "get", "(", "0", ")", ".", "getLabel", "(", ")", "+", "\" (\"", "+", "versions", ".", "get", "(", "0", ")", ".", "getControlGroup", "(", ")", ".", "toString", "(", ")", "+", "\")\"", ")", ";", "colorTabForState", "(", "dsID", ",", "versions", ".", "get", "(", "0", ")", ".", "getState", "(", ")", ")", ";", "if", "(", "reInitNewPanel", ")", "{", "doNew", "(", "XML_MIMETYPE", ",", "false", ")", ";", "}", "updateNewRelsExt", "(", "m_pid", ")", ";", "m_tabbedPane", ".", "setSelectedIndex", "(", "getTabIndex", "(", "dsID", ")", ")", ";", "}" ]
Add a new tab with a new datastream.
[ "Add", "a", "new", "tab", "with", "a", "new", "datastream", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/objecteditor/DatastreamsPane.java#L262-L290
9,149
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.loginForm
private void loginForm(HttpServletResponse response) throws IOException { response.reset(); response.addHeader("WWW-Authenticate", "Basic realm=\"!!Fedora Repository Server\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); OutputStream out = response.getOutputStream(); out.write("Fedora: 401 ".getBytes()); out.flush(); out.close(); }
java
private void loginForm(HttpServletResponse response) throws IOException { response.reset(); response.addHeader("WWW-Authenticate", "Basic realm=\"!!Fedora Repository Server\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); OutputStream out = response.getOutputStream(); out.write("Fedora: 401 ".getBytes()); out.flush(); out.close(); }
[ "private", "void", "loginForm", "(", "HttpServletResponse", "response", ")", "throws", "IOException", "{", "response", ".", "reset", "(", ")", ";", "response", ".", "addHeader", "(", "\"WWW-Authenticate\"", ",", "\"Basic realm=\\\"!!Fedora Repository Server\\\"\"", ")", ";", "response", ".", "setStatus", "(", "HttpServletResponse", ".", "SC_UNAUTHORIZED", ")", ";", "OutputStream", "out", "=", "response", ".", "getOutputStream", "(", ")", ";", "out", ".", "write", "(", "\"Fedora: 401 \"", ".", "getBytes", "(", ")", ")", ";", "out", ".", "flush", "(", ")", ";", "out", ".", "close", "(", ")", ";", "}" ]
Sends a 401 error to the browser. This forces a login box to be displayed allowing the user to login. @param response the response to set the headers and status
[ "Sends", "a", "401", "error", "to", "the", "browser", ".", "This", "forces", "a", "login", "box", "to", "be", "displayed", "allowing", "the", "user", "to", "login", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L349-L358
9,150
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.authenticate
private Subject authenticate(HttpServletRequest req) { String authorization = req.getHeader("authorization"); if (authorization == null || authorization.trim().isEmpty()) { return null; } // subject from session instead of re-authenticating // can't change username/password for this session. Subject subject = (Subject) req.getSession().getAttribute(authorization); if (subject != null) { return subject; } String auth = null; try { byte[] data = Base64.decode(authorization.substring(6)); auth = new String(data); } catch (IOException e) { logger.error(e.toString()); return null; } String username = auth.substring(0, auth.indexOf(':')); String password = auth.substring(auth.indexOf(':') + 1); if (logger.isDebugEnabled()) { logger.debug("auth username: " + username); } LoginContext loginContext = null; try { CallbackHandler handler = new UsernamePasswordCallbackHandler(username, password); loginContext = new LoginContext(jaasConfigName, handler); loginContext.login(); } catch (LoginException le) { logger.error(le.toString()); return null; } // successfully logged in subject = loginContext.getSubject(); // object accessable by a fixed key for usage req.getSession().setAttribute(SESSION_SUBJECT_KEY, subject); // object accessable only by base64 encoded username:password that was // initially used - prevents some dodgy stuff req.getSession().setAttribute(authorization, subject); return subject; }
java
private Subject authenticate(HttpServletRequest req) { String authorization = req.getHeader("authorization"); if (authorization == null || authorization.trim().isEmpty()) { return null; } // subject from session instead of re-authenticating // can't change username/password for this session. Subject subject = (Subject) req.getSession().getAttribute(authorization); if (subject != null) { return subject; } String auth = null; try { byte[] data = Base64.decode(authorization.substring(6)); auth = new String(data); } catch (IOException e) { logger.error(e.toString()); return null; } String username = auth.substring(0, auth.indexOf(':')); String password = auth.substring(auth.indexOf(':') + 1); if (logger.isDebugEnabled()) { logger.debug("auth username: " + username); } LoginContext loginContext = null; try { CallbackHandler handler = new UsernamePasswordCallbackHandler(username, password); loginContext = new LoginContext(jaasConfigName, handler); loginContext.login(); } catch (LoginException le) { logger.error(le.toString()); return null; } // successfully logged in subject = loginContext.getSubject(); // object accessable by a fixed key for usage req.getSession().setAttribute(SESSION_SUBJECT_KEY, subject); // object accessable only by base64 encoded username:password that was // initially used - prevents some dodgy stuff req.getSession().setAttribute(authorization, subject); return subject; }
[ "private", "Subject", "authenticate", "(", "HttpServletRequest", "req", ")", "{", "String", "authorization", "=", "req", ".", "getHeader", "(", "\"authorization\"", ")", ";", "if", "(", "authorization", "==", "null", "||", "authorization", ".", "trim", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "// subject from session instead of re-authenticating", "// can't change username/password for this session.", "Subject", "subject", "=", "(", "Subject", ")", "req", ".", "getSession", "(", ")", ".", "getAttribute", "(", "authorization", ")", ";", "if", "(", "subject", "!=", "null", ")", "{", "return", "subject", ";", "}", "String", "auth", "=", "null", ";", "try", "{", "byte", "[", "]", "data", "=", "Base64", ".", "decode", "(", "authorization", ".", "substring", "(", "6", ")", ")", ";", "auth", "=", "new", "String", "(", "data", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "error", "(", "e", ".", "toString", "(", ")", ")", ";", "return", "null", ";", "}", "String", "username", "=", "auth", ".", "substring", "(", "0", ",", "auth", ".", "indexOf", "(", "'", "'", ")", ")", ";", "String", "password", "=", "auth", ".", "substring", "(", "auth", ".", "indexOf", "(", "'", "'", ")", "+", "1", ")", ";", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"auth username: \"", "+", "username", ")", ";", "}", "LoginContext", "loginContext", "=", "null", ";", "try", "{", "CallbackHandler", "handler", "=", "new", "UsernamePasswordCallbackHandler", "(", "username", ",", "password", ")", ";", "loginContext", "=", "new", "LoginContext", "(", "jaasConfigName", ",", "handler", ")", ";", "loginContext", ".", "login", "(", ")", ";", "}", "catch", "(", "LoginException", "le", ")", "{", "logger", ".", "error", "(", "le", ".", "toString", "(", ")", ")", ";", "return", "null", ";", "}", "// successfully logged in", "subject", "=", "loginContext", ".", "getSubject", "(", ")", ";", "// object accessable by a fixed key for usage", "req", ".", "getSession", "(", ")", ".", "setAttribute", "(", "SESSION_SUBJECT_KEY", ",", "subject", ")", ";", "// object accessable only by base64 encoded username:password that was", "// initially used - prevents some dodgy stuff", "req", ".", "getSession", "(", ")", ".", "setAttribute", "(", "authorization", ",", "subject", ")", ";", "return", "subject", ";", "}" ]
Performs the authentication. Once a Subject is obtained, it is stored in the users session. Subsequent requests check for the existence of this object before performing the authentication again. @param req the servlet request. @return a user principal that was extracted from the login context.
[ "Performs", "the", "authentication", ".", "Once", "a", "Subject", "is", "obtained", "it", "is", "stored", "in", "the", "users", "session", ".", "Subsequent", "requests", "check", "for", "the", "existence", "of", "this", "object", "before", "performing", "the", "authentication", "again", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L369-L421
9,151
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.getUserPrincipal
private Principal getUserPrincipal(Subject subject) { Principal userPrincipal = null; Set<Principal> principals = subject.getPrincipals(); // try and get userPrincipal based on userClassNames if (userClassNames != null && userClassNames.size() > 0) { for (Principal p : principals) { if (userPrincipal == null && userClassNames.contains(p.getClass().getName())) { userPrincipal = p; } } } // no userPrincipal found using userClassNames, just grab first principal if (userPrincipal == null) { Iterator<Principal> i = principals.iterator(); // should always have 1 at least and 1st should be user principal if (i.hasNext()) { userPrincipal = i.next(); } } if (logger.isDebugEnabled()) { logger.debug("found userPrincipal [{}]: {}", userPrincipal.getClass().getName(), userPrincipal.getName()); } return userPrincipal; }
java
private Principal getUserPrincipal(Subject subject) { Principal userPrincipal = null; Set<Principal> principals = subject.getPrincipals(); // try and get userPrincipal based on userClassNames if (userClassNames != null && userClassNames.size() > 0) { for (Principal p : principals) { if (userPrincipal == null && userClassNames.contains(p.getClass().getName())) { userPrincipal = p; } } } // no userPrincipal found using userClassNames, just grab first principal if (userPrincipal == null) { Iterator<Principal> i = principals.iterator(); // should always have 1 at least and 1st should be user principal if (i.hasNext()) { userPrincipal = i.next(); } } if (logger.isDebugEnabled()) { logger.debug("found userPrincipal [{}]: {}", userPrincipal.getClass().getName(), userPrincipal.getName()); } return userPrincipal; }
[ "private", "Principal", "getUserPrincipal", "(", "Subject", "subject", ")", "{", "Principal", "userPrincipal", "=", "null", ";", "Set", "<", "Principal", ">", "principals", "=", "subject", ".", "getPrincipals", "(", ")", ";", "// try and get userPrincipal based on userClassNames", "if", "(", "userClassNames", "!=", "null", "&&", "userClassNames", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "Principal", "p", ":", "principals", ")", "{", "if", "(", "userPrincipal", "==", "null", "&&", "userClassNames", ".", "contains", "(", "p", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ")", "{", "userPrincipal", "=", "p", ";", "}", "}", "}", "// no userPrincipal found using userClassNames, just grab first principal", "if", "(", "userPrincipal", "==", "null", ")", "{", "Iterator", "<", "Principal", ">", "i", "=", "principals", ".", "iterator", "(", ")", ";", "// should always have 1 at least and 1st should be user principal", "if", "(", "i", ".", "hasNext", "(", ")", ")", "{", "userPrincipal", "=", "i", ".", "next", "(", ")", ";", "}", "}", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"found userPrincipal [{}]: {}\"", ",", "userPrincipal", ".", "getClass", "(", ")", ".", "getName", "(", ")", ",", "userPrincipal", ".", "getName", "(", ")", ")", ";", "}", "return", "userPrincipal", ";", "}" ]
Given a subject, obtain the userPrincipal from it. The user principal is defined by a Principal class that can be defined in the web.xml file. If this is undefined, the first principal found is assumed to be the userPrincipal. @param subject the subject returned from authentication. @return the userPrincipal associated with the given subject.
[ "Given", "a", "subject", "obtain", "the", "userPrincipal", "from", "it", ".", "The", "user", "principal", "is", "defined", "by", "a", "Principal", "class", "that", "can", "be", "defined", "in", "the", "web", ".", "xml", "file", ".", "If", "this", "is", "undefined", "the", "first", "principal", "found", "is", "assumed", "to", "be", "the", "userPrincipal", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L433-L464
9,152
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.getUserRoles
private Set<String> getUserRoles(Subject subject) { Set<String> userRoles = null; // get roles from specified classes Set<Principal> principals = subject.getPrincipals(); if (roleClassNames != null && roleClassNames.size() > 0) { for (Principal p : principals) { if (roleClassNames.contains(p.getClass().getName())) { if (userRoles == null) userRoles = new HashSet<String>(); userRoles.add(p.getName()); } } } // get roles from specified attributes Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); for (String key : attributes.keySet()) { if (roleAttributeNames.contains(key)) { if (userRoles == null) userRoles = new HashSet<String>(); userRoles.addAll(attributes.get(key)); } } if (userRoles == null) userRoles = Collections.emptySet(); if (logger.isDebugEnabled()) { for (String r : userRoles) { logger.debug("found role: {}", r); } } return userRoles; }
java
private Set<String> getUserRoles(Subject subject) { Set<String> userRoles = null; // get roles from specified classes Set<Principal> principals = subject.getPrincipals(); if (roleClassNames != null && roleClassNames.size() > 0) { for (Principal p : principals) { if (roleClassNames.contains(p.getClass().getName())) { if (userRoles == null) userRoles = new HashSet<String>(); userRoles.add(p.getName()); } } } // get roles from specified attributes Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); for (String key : attributes.keySet()) { if (roleAttributeNames.contains(key)) { if (userRoles == null) userRoles = new HashSet<String>(); userRoles.addAll(attributes.get(key)); } } if (userRoles == null) userRoles = Collections.emptySet(); if (logger.isDebugEnabled()) { for (String r : userRoles) { logger.debug("found role: {}", r); } } return userRoles; }
[ "private", "Set", "<", "String", ">", "getUserRoles", "(", "Subject", "subject", ")", "{", "Set", "<", "String", ">", "userRoles", "=", "null", ";", "// get roles from specified classes", "Set", "<", "Principal", ">", "principals", "=", "subject", ".", "getPrincipals", "(", ")", ";", "if", "(", "roleClassNames", "!=", "null", "&&", "roleClassNames", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "Principal", "p", ":", "principals", ")", "{", "if", "(", "roleClassNames", ".", "contains", "(", "p", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ")", "{", "if", "(", "userRoles", "==", "null", ")", "userRoles", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "userRoles", ".", "add", "(", "p", ".", "getName", "(", ")", ")", ";", "}", "}", "}", "// get roles from specified attributes", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", "attributes", "=", "SubjectUtils", ".", "getAttributes", "(", "subject", ")", ";", "for", "(", "String", "key", ":", "attributes", ".", "keySet", "(", ")", ")", "{", "if", "(", "roleAttributeNames", ".", "contains", "(", "key", ")", ")", "{", "if", "(", "userRoles", "==", "null", ")", "userRoles", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "userRoles", ".", "addAll", "(", "attributes", ".", "get", "(", "key", ")", ")", ";", "}", "}", "if", "(", "userRoles", "==", "null", ")", "userRoles", "=", "Collections", ".", "emptySet", "(", ")", ";", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "for", "(", "String", "r", ":", "userRoles", ")", "{", "logger", ".", "debug", "(", "\"found role: {}\"", ",", "r", ")", ";", "}", "}", "return", "userRoles", ";", "}" ]
Obtains the roles for the user based on the class names and attribute names provided in the web.xml file. @param subject the subject returned from authentication. @return a set of strings that represent the users roles.
[ "Obtains", "the", "roles", "for", "the", "user", "based", "on", "the", "class", "names", "and", "attribute", "names", "provided", "in", "the", "web", ".", "xml", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L474-L506
9,153
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.addRolesToSubject
private void addRolesToSubject(Subject subject, Set<String> userRoles) { if (userRoles == null) { userRoles = Collections.emptySet(); } Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); Set<String> roles = attributes.get(ROLE_KEY); if (roles == null) { roles = new HashSet<String>(userRoles); attributes.put(ROLE_KEY, roles); } else { roles.addAll(userRoles); } if (logger.isDebugEnabled()) { for (String role : userRoles) { logger.debug("added role: {}", role); } } }
java
private void addRolesToSubject(Subject subject, Set<String> userRoles) { if (userRoles == null) { userRoles = Collections.emptySet(); } Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); Set<String> roles = attributes.get(ROLE_KEY); if (roles == null) { roles = new HashSet<String>(userRoles); attributes.put(ROLE_KEY, roles); } else { roles.addAll(userRoles); } if (logger.isDebugEnabled()) { for (String role : userRoles) { logger.debug("added role: {}", role); } } }
[ "private", "void", "addRolesToSubject", "(", "Subject", "subject", ",", "Set", "<", "String", ">", "userRoles", ")", "{", "if", "(", "userRoles", "==", "null", ")", "{", "userRoles", "=", "Collections", ".", "emptySet", "(", ")", ";", "}", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", "attributes", "=", "SubjectUtils", ".", "getAttributes", "(", "subject", ")", ";", "Set", "<", "String", ">", "roles", "=", "attributes", ".", "get", "(", "ROLE_KEY", ")", ";", "if", "(", "roles", "==", "null", ")", "{", "roles", "=", "new", "HashSet", "<", "String", ">", "(", "userRoles", ")", ";", "attributes", ".", "put", "(", "ROLE_KEY", ",", "roles", ")", ";", "}", "else", "{", "roles", ".", "addAll", "(", "userRoles", ")", ";", "}", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "for", "(", "String", "role", ":", "userRoles", ")", "{", "logger", ".", "debug", "(", "\"added role: {}\"", ",", "role", ")", ";", "}", "}", "}" ]
Adds roles to the Subject object. @param subject the subject that was returned from authentication. @param userRoles the set of user roles that were found.
[ "Adds", "roles", "to", "the", "Subject", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L516-L536
9,154
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java
AuthFilterJAAS.populateFedoraAttributes
private void populateFedoraAttributes(Subject subject, Set<String> userRoles, HttpServletRequest request) { Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); // get the fedoraRole attribute or create it. Set<String> roles = attributes.get(FEDORA_ROLE_KEY); if (roles == null) { roles = new HashSet<String>(userRoles); attributes.put(FEDORA_ROLE_KEY, roles); } else { roles.addAll(userRoles); } request.setAttribute(FEDORA_ATTRIBUTES_KEY, attributes); }
java
private void populateFedoraAttributes(Subject subject, Set<String> userRoles, HttpServletRequest request) { Map<String, Set<String>> attributes = SubjectUtils.getAttributes(subject); // get the fedoraRole attribute or create it. Set<String> roles = attributes.get(FEDORA_ROLE_KEY); if (roles == null) { roles = new HashSet<String>(userRoles); attributes.put(FEDORA_ROLE_KEY, roles); } else { roles.addAll(userRoles); } request.setAttribute(FEDORA_ATTRIBUTES_KEY, attributes); }
[ "private", "void", "populateFedoraAttributes", "(", "Subject", "subject", ",", "Set", "<", "String", ">", "userRoles", ",", "HttpServletRequest", "request", ")", "{", "Map", "<", "String", ",", "Set", "<", "String", ">", ">", "attributes", "=", "SubjectUtils", ".", "getAttributes", "(", "subject", ")", ";", "// get the fedoraRole attribute or create it.", "Set", "<", "String", ">", "roles", "=", "attributes", ".", "get", "(", "FEDORA_ROLE_KEY", ")", ";", "if", "(", "roles", "==", "null", ")", "{", "roles", "=", "new", "HashSet", "<", "String", ">", "(", "userRoles", ")", ";", "attributes", ".", "put", "(", "FEDORA_ROLE_KEY", ",", "roles", ")", ";", "}", "else", "{", "roles", ".", "addAll", "(", "userRoles", ")", ";", "}", "request", ".", "setAttribute", "(", "FEDORA_ATTRIBUTES_KEY", ",", "attributes", ")", ";", "}" ]
Add roles and other subject attributes where Fedora expects them - a Map called FEDORA_AUX_SUBJECT_ATTRIBUTES. Roles will be put in "fedoraRole" and others will be named as-is. @param subject the subject from authentication. @param userRoles the set of user roles. @param request the request in which to place the attributes.
[ "Add", "roles", "and", "other", "subject", "attributes", "where", "Fedora", "expects", "them", "-", "a", "Map", "called", "FEDORA_AUX_SUBJECT_ATTRIBUTES", ".", "Roles", "will", "be", "put", "in", "fedoraRole", "and", "others", "will", "be", "named", "as", "-", "is", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-jaas/src/main/java/org/fcrepo/server/security/jaas/AuthFilterJAAS.java#L550-L567
9,155
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/PEP.java
PEP.denyAccess
private void denyAccess(HttpServletResponse response, String message) throws IOException { StringBuilder sb = new StringBuilder(); sb.append("Fedora: 403 ").append(message.toUpperCase()); response.reset(); response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setContentType("text/plain"); response.setContentLength(sb.length()); ServletOutputStream out = response.getOutputStream(); out.write(sb.toString().getBytes()); out.flush(); out.close(); }
java
private void denyAccess(HttpServletResponse response, String message) throws IOException { StringBuilder sb = new StringBuilder(); sb.append("Fedora: 403 ").append(message.toUpperCase()); response.reset(); response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setContentType("text/plain"); response.setContentLength(sb.length()); ServletOutputStream out = response.getOutputStream(); out.write(sb.toString().getBytes()); out.flush(); out.close(); }
[ "private", "void", "denyAccess", "(", "HttpServletResponse", "response", ",", "String", "message", ")", "throws", "IOException", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"Fedora: 403 \"", ")", ".", "append", "(", "message", ".", "toUpperCase", "(", ")", ")", ";", "response", ".", "reset", "(", ")", ";", "response", ".", "setStatus", "(", "HttpServletResponse", ".", "SC_FORBIDDEN", ")", ";", "response", ".", "setContentType", "(", "\"text/plain\"", ")", ";", "response", ".", "setContentLength", "(", "sb", ".", "length", "(", ")", ")", ";", "ServletOutputStream", "out", "=", "response", ".", "getOutputStream", "(", ")", ";", "out", ".", "write", "(", "sb", ".", "toString", "(", ")", ".", "getBytes", "(", ")", ")", ";", "out", ".", "flush", "(", ")", ";", "out", ".", "close", "(", ")", ";", "}" ]
Outputs an access denied message. @param out the output stream to send the message to @param message the message to send
[ "Outputs", "an", "access", "denied", "message", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/PEP.java#L266-L279
9,156
fcrepo3/fcrepo
fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/PEP.java
PEP.loginForm
private void loginForm(HttpServletResponse response) { response.reset(); response.addHeader("WWW-Authenticate", "Basic realm=\"!!Fedora Repository Server\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); }
java
private void loginForm(HttpServletResponse response) { response.reset(); response.addHeader("WWW-Authenticate", "Basic realm=\"!!Fedora Repository Server\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); }
[ "private", "void", "loginForm", "(", "HttpServletResponse", "response", ")", "{", "response", ".", "reset", "(", ")", ";", "response", ".", "addHeader", "(", "\"WWW-Authenticate\"", ",", "\"Basic realm=\\\"!!Fedora Repository Server\\\"\"", ")", ";", "response", ".", "setStatus", "(", "HttpServletResponse", ".", "SC_UNAUTHORIZED", ")", ";", "}" ]
Sends a 401 error to the browser. This forces a login screen to be displayed allowing the user to login. @param response the response to set the headers and status
[ "Sends", "a", "401", "error", "to", "the", "browser", ".", "This", "forces", "a", "login", "screen", "to", "be", "displayed", "allowing", "the", "user", "to", "login", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-security/fcrepo-security-pep/src/main/java/org/fcrepo/server/security/xacml/pep/rest/PEP.java#L288-L293
9,157
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumer.java
JournalConsumer.shutdown
public void shutdown() throws ModuleShutdownException { try { consumerThread.shutdown(); reader.shutdown(); recoveryLog.shutdown("Server is shutting down."); } catch (JournalException e) { throw new ModuleShutdownException("Error closing journal reader.", role, e); } }
java
public void shutdown() throws ModuleShutdownException { try { consumerThread.shutdown(); reader.shutdown(); recoveryLog.shutdown("Server is shutting down."); } catch (JournalException e) { throw new ModuleShutdownException("Error closing journal reader.", role, e); } }
[ "public", "void", "shutdown", "(", ")", "throws", "ModuleShutdownException", "{", "try", "{", "consumerThread", ".", "shutdown", "(", ")", ";", "reader", ".", "shutdown", "(", ")", ";", "recoveryLog", ".", "shutdown", "(", "\"Server is shutting down.\"", ")", ";", "}", "catch", "(", "JournalException", "e", ")", "{", "throw", "new", "ModuleShutdownException", "(", "\"Error closing journal reader.\"", ",", "role", ",", "e", ")", ";", "}", "}" ]
Tell the thread, the reader and the log to shut down.
[ "Tell", "the", "thread", "the", "reader", "and", "the", "log", "to", "shut", "down", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumer.java#L82-L92
9,158
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/PID.java
PID.getInstance
public static PID getInstance(String pidString) { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new FaultException("Malformed PID: " + e.getMessage(), e); } }
java
public static PID getInstance(String pidString) { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new FaultException("Malformed PID: " + e.getMessage(), e); } }
[ "public", "static", "PID", "getInstance", "(", "String", "pidString", ")", "{", "try", "{", "return", "new", "PID", "(", "pidString", ")", ";", "}", "catch", "(", "MalformedPIDException", "e", ")", "{", "throw", "new", "FaultException", "(", "\"Malformed PID: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Factory method that throws an unchecked exception if it's not well-formed. @param pidString the String value of the PID @return PID
[ "Factory", "method", "that", "throws", "an", "unchecked", "exception", "if", "it", "s", "not", "well", "-", "formed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/PID.java#L82-L88
9,159
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/PID.java
PID.normalize
public static String normalize(String pidString) throws MalformedPIDException { if (pidString == null) { throw new MalformedPIDException("PID is null."); } return normalize(pidString, 0, pidString.length()); }
java
public static String normalize(String pidString) throws MalformedPIDException { if (pidString == null) { throw new MalformedPIDException("PID is null."); } return normalize(pidString, 0, pidString.length()); }
[ "public", "static", "String", "normalize", "(", "String", "pidString", ")", "throws", "MalformedPIDException", "{", "if", "(", "pidString", "==", "null", ")", "{", "throw", "new", "MalformedPIDException", "(", "\"PID is null.\"", ")", ";", "}", "return", "normalize", "(", "pidString", ",", "0", ",", "pidString", ".", "length", "(", ")", ")", ";", "}" ]
Return the normalized form of the given pid string, or throw a MalformedPIDException. @param pidString @return String normalized version of the pid @throws MalformedPIDException
[ "Return", "the", "normalized", "form", "of", "the", "given", "pid", "string", "or", "throw", "a", "MalformedPIDException", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/PID.java#L113-L120
9,160
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/PID.java
PID.toURIReference
public static SimpleURIReference toURIReference(String pidString) { SimpleURIReference ref = null; try { ref = new SimpleURIReference(new URI(toURI(pidString))); } catch (URISyntaxException e) { // assumes pid is well-formed throw new Error(e); } return ref; }
java
public static SimpleURIReference toURIReference(String pidString) { SimpleURIReference ref = null; try { ref = new SimpleURIReference(new URI(toURI(pidString))); } catch (URISyntaxException e) { // assumes pid is well-formed throw new Error(e); } return ref; }
[ "public", "static", "SimpleURIReference", "toURIReference", "(", "String", "pidString", ")", "{", "SimpleURIReference", "ref", "=", "null", ";", "try", "{", "ref", "=", "new", "SimpleURIReference", "(", "new", "URI", "(", "toURI", "(", "pidString", ")", ")", ")", ";", "}", "catch", "(", "URISyntaxException", "e", ")", "{", "// assumes pid is well-formed", "throw", "new", "Error", "(", "e", ")", ";", "}", "return", "ref", ";", "}" ]
Return a URIReference of some PID string, assuming it is well-formed.
[ "Return", "a", "URIReference", "of", "some", "PID", "string", "assuming", "it", "is", "well", "-", "formed", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/PID.java#L245-L254
9,161
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/PID.java
PID.main
public static void main(String[] args) throws Exception { if (args.length > 0) { PID p = new PID(args[0]); System.out.println("Normalized : " + p.toString()); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } else { System.out.println("--------------------------------------"); System.out.println("PID Syntax Checker - Interactive mode"); System.out.println("--------------------------------------"); boolean done = false; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!done) { try { System.out.print("Enter a PID (ENTER to exit): "); String line = reader.readLine(); if (line.isEmpty()) { done = true; } else { PID p = new PID(line); System.out.println("Normalized : " + p.toString()); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } } catch (MalformedPIDException e) { System.out.println("ERROR: " + e.getMessage()); } } } }
java
public static void main(String[] args) throws Exception { if (args.length > 0) { PID p = new PID(args[0]); System.out.println("Normalized : " + p.toString()); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } else { System.out.println("--------------------------------------"); System.out.println("PID Syntax Checker - Interactive mode"); System.out.println("--------------------------------------"); boolean done = false; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!done) { try { System.out.print("Enter a PID (ENTER to exit): "); String line = reader.readLine(); if (line.isEmpty()) { done = true; } else { PID p = new PID(line); System.out.println("Normalized : " + p.toString()); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } } catch (MalformedPIDException e) { System.out.println("ERROR: " + e.getMessage()); } } } }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "args", ".", "length", ">", "0", ")", "{", "PID", "p", "=", "new", "PID", "(", "args", "[", "0", "]", ")", ";", "System", ".", "out", ".", "println", "(", "\"Normalized : \"", "+", "p", ".", "toString", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"To filename : \"", "+", "p", ".", "toFilename", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"From filename : \"", "+", "PID", ".", "fromFilename", "(", "p", ".", "toFilename", "(", ")", ")", ".", "toString", "(", ")", ")", ";", "}", "else", "{", "System", ".", "out", ".", "println", "(", "\"--------------------------------------\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"PID Syntax Checker - Interactive mode\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"--------------------------------------\"", ")", ";", "boolean", "done", "=", "false", ";", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "System", ".", "in", ")", ")", ";", "while", "(", "!", "done", ")", "{", "try", "{", "System", ".", "out", ".", "print", "(", "\"Enter a PID (ENTER to exit): \"", ")", ";", "String", "line", "=", "reader", ".", "readLine", "(", ")", ";", "if", "(", "line", ".", "isEmpty", "(", ")", ")", "{", "done", "=", "true", ";", "}", "else", "{", "PID", "p", "=", "new", "PID", "(", "line", ")", ";", "System", ".", "out", ".", "println", "(", "\"Normalized : \"", "+", "p", ".", "toString", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"To filename : \"", "+", "p", ".", "toFilename", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"From filename : \"", "+", "PID", ".", "fromFilename", "(", "p", ".", "toFilename", "(", ")", ")", ".", "toString", "(", ")", ")", ";", "}", "}", "catch", "(", "MalformedPIDException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"ERROR: \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}", "}", "}" ]
Command-line interactive tester. If one arg given, prints normalized form of that PID and exits. If no args, enters interactive mode.
[ "Command", "-", "line", "interactive", "tester", ".", "If", "one", "arg", "given", "prints", "normalized", "form", "of", "that", "PID", "and", "exits", ".", "If", "no", "args", "enters", "interactive", "mode", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/PID.java#L303-L335
9,162
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchResultSQLImpl.java
FieldSearchResultSQLImpl.getObjectFields
private ObjectFields getObjectFields(String pid) throws UnrecognizedFieldException, ObjectIntegrityException, RepositoryConfigurationException, StreamIOException, ServerException { DOReader r = m_repoReader.getReader(Server.USE_DEFINITIVE_STORE, ReadOnlyContext.EMPTY, pid); ObjectFields f; // If there's a DC record available, use SAX to parse the most // recent version of it into f. Datastream dcmd = null; try { dcmd = r.GetDatastream("DC", null); } catch (ClassCastException cce) { throw new ObjectIntegrityException("Object " + r.GetObjectPID() + " has a DC datastream, but it's not inline XML."); } if (dcmd != null) { f = new ObjectFields(m_resultFields, dcmd.getContentStream()); // add dcmDate if wanted for (String element : m_resultFields) { if (element.equals("dcmDate")) { f.setDCMDate(dcmd.DSCreateDT); } } } else { f = new ObjectFields(); } // add non-dc values from doReader for the others in m_resultFields[] // Disseminator[] disses=null; for (String n : m_resultFields) { if (n.equals("pid")) { f.setPid(pid); } if (n.equals("label")) { f.setLabel(r.GetObjectLabel()); } if (n.equals("state")) { f.setState(r.GetObjectState()); } if (n.equals("ownerId")) { f.setOwnerId(r.getOwnerId()); } if (n.equals("cDate")) { f.setCDate(r.getCreateDate()); } if (n.equals("mDate")) { f.setMDate(r.getLastModDate()); } } return f; }
java
private ObjectFields getObjectFields(String pid) throws UnrecognizedFieldException, ObjectIntegrityException, RepositoryConfigurationException, StreamIOException, ServerException { DOReader r = m_repoReader.getReader(Server.USE_DEFINITIVE_STORE, ReadOnlyContext.EMPTY, pid); ObjectFields f; // If there's a DC record available, use SAX to parse the most // recent version of it into f. Datastream dcmd = null; try { dcmd = r.GetDatastream("DC", null); } catch (ClassCastException cce) { throw new ObjectIntegrityException("Object " + r.GetObjectPID() + " has a DC datastream, but it's not inline XML."); } if (dcmd != null) { f = new ObjectFields(m_resultFields, dcmd.getContentStream()); // add dcmDate if wanted for (String element : m_resultFields) { if (element.equals("dcmDate")) { f.setDCMDate(dcmd.DSCreateDT); } } } else { f = new ObjectFields(); } // add non-dc values from doReader for the others in m_resultFields[] // Disseminator[] disses=null; for (String n : m_resultFields) { if (n.equals("pid")) { f.setPid(pid); } if (n.equals("label")) { f.setLabel(r.GetObjectLabel()); } if (n.equals("state")) { f.setState(r.GetObjectState()); } if (n.equals("ownerId")) { f.setOwnerId(r.getOwnerId()); } if (n.equals("cDate")) { f.setCDate(r.getCreateDate()); } if (n.equals("mDate")) { f.setMDate(r.getLastModDate()); } } return f; }
[ "private", "ObjectFields", "getObjectFields", "(", "String", "pid", ")", "throws", "UnrecognizedFieldException", ",", "ObjectIntegrityException", ",", "RepositoryConfigurationException", ",", "StreamIOException", ",", "ServerException", "{", "DOReader", "r", "=", "m_repoReader", ".", "getReader", "(", "Server", ".", "USE_DEFINITIVE_STORE", ",", "ReadOnlyContext", ".", "EMPTY", ",", "pid", ")", ";", "ObjectFields", "f", ";", "// If there's a DC record available, use SAX to parse the most", "// recent version of it into f.", "Datastream", "dcmd", "=", "null", ";", "try", "{", "dcmd", "=", "r", ".", "GetDatastream", "(", "\"DC\"", ",", "null", ")", ";", "}", "catch", "(", "ClassCastException", "cce", ")", "{", "throw", "new", "ObjectIntegrityException", "(", "\"Object \"", "+", "r", ".", "GetObjectPID", "(", ")", "+", "\" has a DC datastream, but it's not inline XML.\"", ")", ";", "}", "if", "(", "dcmd", "!=", "null", ")", "{", "f", "=", "new", "ObjectFields", "(", "m_resultFields", ",", "dcmd", ".", "getContentStream", "(", ")", ")", ";", "// add dcmDate if wanted", "for", "(", "String", "element", ":", "m_resultFields", ")", "{", "if", "(", "element", ".", "equals", "(", "\"dcmDate\"", ")", ")", "{", "f", ".", "setDCMDate", "(", "dcmd", ".", "DSCreateDT", ")", ";", "}", "}", "}", "else", "{", "f", "=", "new", "ObjectFields", "(", ")", ";", "}", "// add non-dc values from doReader for the others in m_resultFields[]", "// Disseminator[] disses=null;", "for", "(", "String", "n", ":", "m_resultFields", ")", "{", "if", "(", "n", ".", "equals", "(", "\"pid\"", ")", ")", "{", "f", ".", "setPid", "(", "pid", ")", ";", "}", "if", "(", "n", ".", "equals", "(", "\"label\"", ")", ")", "{", "f", ".", "setLabel", "(", "r", ".", "GetObjectLabel", "(", ")", ")", ";", "}", "if", "(", "n", ".", "equals", "(", "\"state\"", ")", ")", "{", "f", ".", "setState", "(", "r", ".", "GetObjectState", "(", ")", ")", ";", "}", "if", "(", "n", ".", "equals", "(", "\"ownerId\"", ")", ")", "{", "f", ".", "setOwnerId", "(", "r", ".", "getOwnerId", "(", ")", ")", ";", "}", "if", "(", "n", ".", "equals", "(", "\"cDate\"", ")", ")", "{", "f", ".", "setCDate", "(", "r", ".", "getCreateDate", "(", ")", ")", ";", "}", "if", "(", "n", ".", "equals", "(", "\"mDate\"", ")", ")", "{", "f", ".", "setMDate", "(", "r", ".", "getLastModDate", "(", ")", ")", ";", "}", "}", "return", "f", ";", "}" ]
For the given pid, get a reader on the object from the repository and return an ObjectFields object with resultFields fields populated. @param pid the unique identifier of the object for which the information is requested. @return ObjectFields populated with the requested fields @throws UnrecognizedFieldException if a resultFields value isn't valid @throws ObjectIntegrityException if the underlying digital object can't be parsed @throws RepositoryConfigurationException if the sax parser can't be constructed @throws StreamIOException if an error occurs while reading the serialized digital object stream @throws ServerException if any other kind of error occurs while reading the underlying object
[ "For", "the", "given", "pid", "get", "a", "reader", "on", "the", "object", "from", "the", "repository", "and", "return", "an", "ObjectFields", "object", "with", "resultFields", "fields", "populated", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchResultSQLImpl.java#L481-L533
9,163
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchResultSQLImpl.java
FieldSearchResultSQLImpl.isDCProp
private static final boolean isDCProp(String in) {//2004.05.18 wdn5e wasn't static final if (in.equals("mDate") || in.equals("dcmDate")) { return false; } for (String n : FieldSearchSQLImpl.DB_COLUMN_NAMES) { if (n.startsWith("dc") && n.toLowerCase().indexOf(in.toLowerCase()) == 2) { //2004.05.18 wdn5e (was -1) return true; } } return false; }
java
private static final boolean isDCProp(String in) {//2004.05.18 wdn5e wasn't static final if (in.equals("mDate") || in.equals("dcmDate")) { return false; } for (String n : FieldSearchSQLImpl.DB_COLUMN_NAMES) { if (n.startsWith("dc") && n.toLowerCase().indexOf(in.toLowerCase()) == 2) { //2004.05.18 wdn5e (was -1) return true; } } return false; }
[ "private", "static", "final", "boolean", "isDCProp", "(", "String", "in", ")", "{", "//2004.05.18 wdn5e wasn't static final", "if", "(", "in", ".", "equals", "(", "\"mDate\"", ")", "||", "in", ".", "equals", "(", "\"dcmDate\"", ")", ")", "{", "return", "false", ";", "}", "for", "(", "String", "n", ":", "FieldSearchSQLImpl", ".", "DB_COLUMN_NAMES", ")", "{", "if", "(", "n", ".", "startsWith", "(", "\"dc\"", ")", "&&", "n", ".", "toLowerCase", "(", ")", ".", "indexOf", "(", "in", ".", "toLowerCase", "(", ")", ")", "==", "2", ")", "{", "//2004.05.18 wdn5e (was -1)", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Tell whether a field name, as given in the search request, is a dublin core field. @param the field @return whether it's a dublin core field
[ "Tell", "whether", "a", "field", "name", "as", "given", "in", "the", "search", "request", "is", "a", "dublin", "core", "field", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/search/FieldSearchResultSQLImpl.java#L712-L723
9,164
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ModelBasedTripleGenerator.java
ModelBasedTripleGenerator.getTriplesForObject
public Set<Triple> getTriplesForObject(DOReader reader) throws ResourceIndexException { Set<Triple> objectTriples = new HashSet<Triple>(); try { for (String modelRelobject:reader.getContentModels()){ if (m_generators.containsKey(modelRelobject)) { objectTriples.addAll(m_generators.get(modelRelobject) .getTriplesForObject(reader)); } } } catch (ServerException e) { throw new ResourceIndexException("Could not read object's content model", e); } return objectTriples; }
java
public Set<Triple> getTriplesForObject(DOReader reader) throws ResourceIndexException { Set<Triple> objectTriples = new HashSet<Triple>(); try { for (String modelRelobject:reader.getContentModels()){ if (m_generators.containsKey(modelRelobject)) { objectTriples.addAll(m_generators.get(modelRelobject) .getTriplesForObject(reader)); } } } catch (ServerException e) { throw new ResourceIndexException("Could not read object's content model", e); } return objectTriples; }
[ "public", "Set", "<", "Triple", ">", "getTriplesForObject", "(", "DOReader", "reader", ")", "throws", "ResourceIndexException", "{", "Set", "<", "Triple", ">", "objectTriples", "=", "new", "HashSet", "<", "Triple", ">", "(", ")", ";", "try", "{", "for", "(", "String", "modelRelobject", ":", "reader", ".", "getContentModels", "(", ")", ")", "{", "if", "(", "m_generators", ".", "containsKey", "(", "modelRelobject", ")", ")", "{", "objectTriples", ".", "addAll", "(", "m_generators", ".", "get", "(", "modelRelobject", ")", ".", "getTriplesForObject", "(", "reader", ")", ")", ";", "}", "}", "}", "catch", "(", "ServerException", "e", ")", "{", "throw", "new", "ResourceIndexException", "(", "\"Could not read object's content model\"", ",", "e", ")", ";", "}", "return", "objectTriples", ";", "}" ]
Gets all triples implied by the object's models. @param reader Reads the current object @return Set of all triples implied by the object's models.
[ "Gets", "all", "triples", "implied", "by", "the", "object", "s", "models", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ModelBasedTripleGenerator.java#L90-L109
9,165
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java
DOValidatorSchematron.validate
public void validate(StreamSource objectSource) throws ServerException { DOValidatorSchematronResult result = null; try { // Create a transformer that uses the validating stylesheet. // Run the Schematron validation of the Fedora object and // output results in DOM format. Transformer vtransformer = validatingStyleSheet.newTransformer(); DOMResult validationResult = new DOMResult(); vtransformer.transform(objectSource, validationResult); result = new DOValidatorSchematronResult(validationResult); } catch (Exception e) { Validation validation = new Validation("unknown"); String problem = "Schematron validation failed:".concat(e.getMessage()); validation.setObjectProblems(Collections.singletonList(problem)); logger.error("Schematron validation failed", e); throw new ObjectValidityException(e.getMessage(), validation); } if (!result.isValid()) { String msg = null; try { msg = result.getXMLResult(); } catch (Exception e) { logger.warn("Error getting XML result of schematron validation failure", e); } Validation validation = new Validation("unknown"); if (msg == null) { msg = "Unknown schematron error. Error getting XML results of schematron validation"; } validation.setObjectProblems(Collections.singletonList(msg)); throw new ObjectValidityException(msg, validation); } }
java
public void validate(StreamSource objectSource) throws ServerException { DOValidatorSchematronResult result = null; try { // Create a transformer that uses the validating stylesheet. // Run the Schematron validation of the Fedora object and // output results in DOM format. Transformer vtransformer = validatingStyleSheet.newTransformer(); DOMResult validationResult = new DOMResult(); vtransformer.transform(objectSource, validationResult); result = new DOValidatorSchematronResult(validationResult); } catch (Exception e) { Validation validation = new Validation("unknown"); String problem = "Schematron validation failed:".concat(e.getMessage()); validation.setObjectProblems(Collections.singletonList(problem)); logger.error("Schematron validation failed", e); throw new ObjectValidityException(e.getMessage(), validation); } if (!result.isValid()) { String msg = null; try { msg = result.getXMLResult(); } catch (Exception e) { logger.warn("Error getting XML result of schematron validation failure", e); } Validation validation = new Validation("unknown"); if (msg == null) { msg = "Unknown schematron error. Error getting XML results of schematron validation"; } validation.setObjectProblems(Collections.singletonList(msg)); throw new ObjectValidityException(msg, validation); } }
[ "public", "void", "validate", "(", "StreamSource", "objectSource", ")", "throws", "ServerException", "{", "DOValidatorSchematronResult", "result", "=", "null", ";", "try", "{", "// Create a transformer that uses the validating stylesheet.", "// Run the Schematron validation of the Fedora object and", "// output results in DOM format.", "Transformer", "vtransformer", "=", "validatingStyleSheet", ".", "newTransformer", "(", ")", ";", "DOMResult", "validationResult", "=", "new", "DOMResult", "(", ")", ";", "vtransformer", ".", "transform", "(", "objectSource", ",", "validationResult", ")", ";", "result", "=", "new", "DOValidatorSchematronResult", "(", "validationResult", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "Validation", "validation", "=", "new", "Validation", "(", "\"unknown\"", ")", ";", "String", "problem", "=", "\"Schematron validation failed:\"", ".", "concat", "(", "e", ".", "getMessage", "(", ")", ")", ";", "validation", ".", "setObjectProblems", "(", "Collections", ".", "singletonList", "(", "problem", ")", ")", ";", "logger", ".", "error", "(", "\"Schematron validation failed\"", ",", "e", ")", ";", "throw", "new", "ObjectValidityException", "(", "e", ".", "getMessage", "(", ")", ",", "validation", ")", ";", "}", "if", "(", "!", "result", ".", "isValid", "(", ")", ")", "{", "String", "msg", "=", "null", ";", "try", "{", "msg", "=", "result", ".", "getXMLResult", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "\"Error getting XML result of schematron validation failure\"", ",", "e", ")", ";", "}", "Validation", "validation", "=", "new", "Validation", "(", "\"unknown\"", ")", ";", "if", "(", "msg", "==", "null", ")", "{", "msg", "=", "\"Unknown schematron error. Error getting XML results of schematron validation\"", ";", "}", "validation", ".", "setObjectProblems", "(", "Collections", ".", "singletonList", "(", "msg", ")", ")", ";", "throw", "new", "ObjectValidityException", "(", "msg", ",", "validation", ")", ";", "}", "}" ]
Run the Schematron validation on a Fedora object. @param objectSource the Fedora object as an StreamSource @throws ServerException
[ "Run", "the", "Schematron", "validation", "on", "a", "Fedora", "object", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java#L107-L140
9,166
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java
DOValidatorSchematron.setUp
private Templates setUp(String preprocessorPath, String fedoraschemaPath, String phase) throws ObjectValidityException, TransformerException { String key = fedoraschemaPath + "#" + phase; Templates templates = generatedStyleSheets.get(key); if (templates == null) { rulesSource = fileToStreamSource(fedoraschemaPath); preprocessorSource = fileToStreamSource(preprocessorPath); templates = createValidatingStyleSheet(rulesSource, preprocessorSource, phase); generatedStyleSheets.put(key, templates); } return templates; }
java
private Templates setUp(String preprocessorPath, String fedoraschemaPath, String phase) throws ObjectValidityException, TransformerException { String key = fedoraschemaPath + "#" + phase; Templates templates = generatedStyleSheets.get(key); if (templates == null) { rulesSource = fileToStreamSource(fedoraschemaPath); preprocessorSource = fileToStreamSource(preprocessorPath); templates = createValidatingStyleSheet(rulesSource, preprocessorSource, phase); generatedStyleSheets.put(key, templates); } return templates; }
[ "private", "Templates", "setUp", "(", "String", "preprocessorPath", ",", "String", "fedoraschemaPath", ",", "String", "phase", ")", "throws", "ObjectValidityException", ",", "TransformerException", "{", "String", "key", "=", "fedoraschemaPath", "+", "\"#\"", "+", "phase", ";", "Templates", "templates", "=", "generatedStyleSheets", ".", "get", "(", "key", ")", ";", "if", "(", "templates", "==", "null", ")", "{", "rulesSource", "=", "fileToStreamSource", "(", "fedoraschemaPath", ")", ";", "preprocessorSource", "=", "fileToStreamSource", "(", "preprocessorPath", ")", ";", "templates", "=", "createValidatingStyleSheet", "(", "rulesSource", ",", "preprocessorSource", ",", "phase", ")", ";", "generatedStyleSheets", ".", "put", "(", "key", ",", "templates", ")", ";", "}", "return", "templates", ";", "}" ]
Run setup to prepare for Schematron validation. This entails dynamically creating the validating stylesheet using the preprocessor and the schema. @param preprocessorPath the location of the Schematron preprocessor @param fedoraschemaPath the URL of the Schematron schema @param phase the phase in the fedora object lifecycle to which validation should pertain. (Currently options are "ingest" and "store") @return StreamSource @throws ObjectValidityException
[ "Run", "setup", "to", "prepare", "for", "Schematron", "validation", ".", "This", "entails", "dynamically", "creating", "the", "validating", "stylesheet", "using", "the", "preprocessor", "and", "the", "schema", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java#L156-L171
9,167
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java
DOValidatorSchematron.createValidatingStyleSheet
private Templates createValidatingStyleSheet(StreamSource rulesSource, StreamSource preprocessorSource, String phase) throws ObjectValidityException, TransformerException { ReadableCharArrayWriter out = new ReadableCharArrayWriter(4096); try { // Create a transformer for that uses the Schematron preprocessor stylesheet. // Transform the Schematron schema (rules) into a validating stylesheet. Transformer ptransformer = XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out)); out.close(); } catch (Exception e) { logger.error("Schematron validation failed", e); throw new ObjectValidityException(e.getMessage()); } return XmlTransformUtility.getTemplates( new StreamSource(out.toReader())); }
java
private Templates createValidatingStyleSheet(StreamSource rulesSource, StreamSource preprocessorSource, String phase) throws ObjectValidityException, TransformerException { ReadableCharArrayWriter out = new ReadableCharArrayWriter(4096); try { // Create a transformer for that uses the Schematron preprocessor stylesheet. // Transform the Schematron schema (rules) into a validating stylesheet. Transformer ptransformer = XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out)); out.close(); } catch (Exception e) { logger.error("Schematron validation failed", e); throw new ObjectValidityException(e.getMessage()); } return XmlTransformUtility.getTemplates( new StreamSource(out.toReader())); }
[ "private", "Templates", "createValidatingStyleSheet", "(", "StreamSource", "rulesSource", ",", "StreamSource", "preprocessorSource", ",", "String", "phase", ")", "throws", "ObjectValidityException", ",", "TransformerException", "{", "ReadableCharArrayWriter", "out", "=", "new", "ReadableCharArrayWriter", "(", "4096", ")", ";", "try", "{", "// Create a transformer for that uses the Schematron preprocessor stylesheet.", "// Transform the Schematron schema (rules) into a validating stylesheet.", "Transformer", "ptransformer", "=", "XmlTransformUtility", ".", "getTransformer", "(", "preprocessorSource", ")", ";", "ptransformer", ".", "setParameter", "(", "\"phase\"", ",", "phase", ")", ";", "ptransformer", ".", "transform", "(", "rulesSource", ",", "new", "StreamResult", "(", "out", ")", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "error", "(", "\"Schematron validation failed\"", ",", "e", ")", ";", "throw", "new", "ObjectValidityException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "return", "XmlTransformUtility", ".", "getTemplates", "(", "new", "StreamSource", "(", "out", ".", "toReader", "(", ")", ")", ")", ";", "}" ]
Create the validating stylesheet which will be used to perform the actual Schematron validation. The validating stylesheet is created dynamically using the preprocessor stylesheet and the Schematron schema for Fedora. The phase is key. The stylesheet is created for the appropriate phase as specified in the Schematron rules schema. Valid work flow phases are currently "ingest" and "store." Different schematron rules apply to different phases of the object lifecycle. Some rules are applied when an object is first being ingested into the repository. Other rules apply before the object is put into permanent storage. @param rulesSource the location of the rules @param preprocessorSource the location of the Schematron preprocessor @param phase the phase in the fedora object lifecycle to which validation should pertain. (Currently options are "ingest" and "store" @return A ByteArrayOutputStream containing the stylesheet @throws ObjectValidityException @throws TransformerException
[ "Create", "the", "validating", "stylesheet", "which", "will", "be", "used", "to", "perform", "the", "actual", "Schematron", "validation", ".", "The", "validating", "stylesheet", "is", "created", "dynamically", "using", "the", "preprocessor", "stylesheet", "and", "the", "Schematron", "schema", "for", "Fedora", ".", "The", "phase", "is", "key", ".", "The", "stylesheet", "is", "created", "for", "the", "appropriate", "phase", "as", "specified", "in", "the", "Schematron", "rules", "schema", ".", "Valid", "work", "flow", "phases", "are", "currently", "ingest", "and", "store", ".", "Different", "schematron", "rules", "apply", "to", "different", "phases", "of", "the", "object", "lifecycle", ".", "Some", "rules", "are", "applied", "when", "an", "object", "is", "first", "being", "ingested", "into", "the", "repository", ".", "Other", "rules", "apply", "before", "the", "object", "is", "put", "into", "permanent", "storage", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/validation/DOValidatorSchematron.java#L195-L215
9,168
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/DBPathRegistry.java
DBPathRegistry.exists
@Override public boolean exists(String pid) throws LowlevelStorageException { Connection connection = null; PreparedStatement statement = null; ResultSet rs = null; try { connection = connectionPool.getReadOnlyConnection(); statement = connection.prepareStatement(selectByIdQuery); statement.setString(1,pid); rs = statement.executeQuery(); return rs.next(); } catch (SQLException e1) { throw new LowlevelStorageException(true, "sql failure (get)", e1); } finally { try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connectionPool.free(connection); } } catch (Exception e2) { // purposely general to include uninstantiated statement, connection throw new LowlevelStorageException(true, "sql failure closing statement, connection, pool (get)", e2); } finally { rs = null; statement = null; connection = null; } } }
java
@Override public boolean exists(String pid) throws LowlevelStorageException { Connection connection = null; PreparedStatement statement = null; ResultSet rs = null; try { connection = connectionPool.getReadOnlyConnection(); statement = connection.prepareStatement(selectByIdQuery); statement.setString(1,pid); rs = statement.executeQuery(); return rs.next(); } catch (SQLException e1) { throw new LowlevelStorageException(true, "sql failure (get)", e1); } finally { try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connectionPool.free(connection); } } catch (Exception e2) { // purposely general to include uninstantiated statement, connection throw new LowlevelStorageException(true, "sql failure closing statement, connection, pool (get)", e2); } finally { rs = null; statement = null; connection = null; } } }
[ "@", "Override", "public", "boolean", "exists", "(", "String", "pid", ")", "throws", "LowlevelStorageException", "{", "Connection", "connection", "=", "null", ";", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "rs", "=", "null", ";", "try", "{", "connection", "=", "connectionPool", ".", "getReadOnlyConnection", "(", ")", ";", "statement", "=", "connection", ".", "prepareStatement", "(", "selectByIdQuery", ")", ";", "statement", ".", "setString", "(", "1", ",", "pid", ")", ";", "rs", "=", "statement", ".", "executeQuery", "(", ")", ";", "return", "rs", ".", "next", "(", ")", ";", "}", "catch", "(", "SQLException", "e1", ")", "{", "throw", "new", "LowlevelStorageException", "(", "true", ",", "\"sql failure (get)\"", ",", "e1", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "rs", "!=", "null", ")", "{", "rs", ".", "close", "(", ")", ";", "}", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "if", "(", "connection", "!=", "null", ")", "{", "connectionPool", ".", "free", "(", "connection", ")", ";", "}", "}", "catch", "(", "Exception", "e2", ")", "{", "// purposely general to include uninstantiated statement, connection", "throw", "new", "LowlevelStorageException", "(", "true", ",", "\"sql failure closing statement, connection, pool (get)\"", ",", "e2", ")", ";", "}", "finally", "{", "rs", "=", "null", ";", "statement", "=", "null", ";", "connection", "=", "null", ";", "}", "}", "}" ]
Checks to see whether a pid exists in the registry. Makes no audits of the number of registrations or the paths registered.
[ "Checks", "to", "see", "whether", "a", "pid", "exists", "in", "the", "registry", ".", "Makes", "no", "audits", "of", "the", "number", "of", "registrations", "or", "the", "paths", "registered", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/lowlevel/DBPathRegistry.java#L91-L127
9,169
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/ConvertObjectSerialization.java
ConvertObjectSerialization.setObjectDefaults
private void setObjectDefaults(DigitalObject obj) { if (obj.getCreateDate() == null) obj.setCreateDate(m_now); if (obj.getLastModDate() == null) obj.setLastModDate(m_now); Iterator<String> dsIds = obj.datastreamIdIterator(); while (dsIds.hasNext()) { String dsid = dsIds.next(); for (Datastream ds : obj.datastreams(dsid)) { ds.DSSize = 0; if (ds.DSCreateDT == null) { ds.DSCreateDT = m_now; } } } }
java
private void setObjectDefaults(DigitalObject obj) { if (obj.getCreateDate() == null) obj.setCreateDate(m_now); if (obj.getLastModDate() == null) obj.setLastModDate(m_now); Iterator<String> dsIds = obj.datastreamIdIterator(); while (dsIds.hasNext()) { String dsid = dsIds.next(); for (Datastream ds : obj.datastreams(dsid)) { ds.DSSize = 0; if (ds.DSCreateDT == null) { ds.DSCreateDT = m_now; } } } }
[ "private", "void", "setObjectDefaults", "(", "DigitalObject", "obj", ")", "{", "if", "(", "obj", ".", "getCreateDate", "(", ")", "==", "null", ")", "obj", ".", "setCreateDate", "(", "m_now", ")", ";", "if", "(", "obj", ".", "getLastModDate", "(", ")", "==", "null", ")", "obj", ".", "setLastModDate", "(", "m_now", ")", ";", "Iterator", "<", "String", ">", "dsIds", "=", "obj", ".", "datastreamIdIterator", "(", ")", ";", "while", "(", "dsIds", ".", "hasNext", "(", ")", ")", "{", "String", "dsid", "=", "dsIds", ".", "next", "(", ")", ";", "for", "(", "Datastream", "ds", ":", "obj", ".", "datastreams", "(", "dsid", ")", ")", "{", "ds", ".", "DSSize", "=", "0", ";", "if", "(", "ds", ".", "DSCreateDT", "==", "null", ")", "{", "ds", ".", "DSCreateDT", "=", "m_now", ";", "}", "}", "}", "}" ]
- Sets datastream sizes to 0
[ "-", "Sets", "datastream", "sizes", "to", "0" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/ConvertObjectSerialization.java#L175-L189
9,170
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/ConvertObjectSerialization.java
ConvertObjectSerialization.main
public static void main(String[] args) throws ClassNotFoundException { LogConfig.initMinimal(); if (args.length < 4 || args.length > 7) { die("Expected 4 to 7 arguments", true); } File sourceDir = new File(args[0]); if (!sourceDir.isDirectory()) { die("Not a directory: " + sourceDir.getPath(), false); } File destDir = new File(args[1]); @SuppressWarnings("unchecked") Class<DODeserializer> deserializer = (Class<DODeserializer>) Class.forName(args[2]); @SuppressWarnings("unchecked") Class<DOSerializer> serializer = (Class<DOSerializer>) Class.forName(args[3]); // So DOTranslationUtility works... System.setProperty("fedora.hostname", "localhost"); System.setProperty("fedora.port", "8080"); System.setProperty("fedora.appServerContext", Constants.FEDORA_DEFAULT_APP_CONTEXT); boolean pretty = args.length > 4 && args[4].equals("true"); String inExt = "xml"; if (args.length > 5) inExt = args[5]; String outExt = "xml"; if (args.length > 6) outExt = args[6]; ConvertObjectSerialization converter = new ConvertObjectSerialization(deserializer, serializer, pretty, inExt, outExt); converter.convert(sourceDir, destDir); TripleIteratorFactory.defaultInstance().shutdown(); }
java
public static void main(String[] args) throws ClassNotFoundException { LogConfig.initMinimal(); if (args.length < 4 || args.length > 7) { die("Expected 4 to 7 arguments", true); } File sourceDir = new File(args[0]); if (!sourceDir.isDirectory()) { die("Not a directory: " + sourceDir.getPath(), false); } File destDir = new File(args[1]); @SuppressWarnings("unchecked") Class<DODeserializer> deserializer = (Class<DODeserializer>) Class.forName(args[2]); @SuppressWarnings("unchecked") Class<DOSerializer> serializer = (Class<DOSerializer>) Class.forName(args[3]); // So DOTranslationUtility works... System.setProperty("fedora.hostname", "localhost"); System.setProperty("fedora.port", "8080"); System.setProperty("fedora.appServerContext", Constants.FEDORA_DEFAULT_APP_CONTEXT); boolean pretty = args.length > 4 && args[4].equals("true"); String inExt = "xml"; if (args.length > 5) inExt = args[5]; String outExt = "xml"; if (args.length > 6) outExt = args[6]; ConvertObjectSerialization converter = new ConvertObjectSerialization(deserializer, serializer, pretty, inExt, outExt); converter.convert(sourceDir, destDir); TripleIteratorFactory.defaultInstance().shutdown(); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "ClassNotFoundException", "{", "LogConfig", ".", "initMinimal", "(", ")", ";", "if", "(", "args", ".", "length", "<", "4", "||", "args", ".", "length", ">", "7", ")", "{", "die", "(", "\"Expected 4 to 7 arguments\"", ",", "true", ")", ";", "}", "File", "sourceDir", "=", "new", "File", "(", "args", "[", "0", "]", ")", ";", "if", "(", "!", "sourceDir", ".", "isDirectory", "(", ")", ")", "{", "die", "(", "\"Not a directory: \"", "+", "sourceDir", ".", "getPath", "(", ")", ",", "false", ")", ";", "}", "File", "destDir", "=", "new", "File", "(", "args", "[", "1", "]", ")", ";", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "Class", "<", "DODeserializer", ">", "deserializer", "=", "(", "Class", "<", "DODeserializer", ">", ")", "Class", ".", "forName", "(", "args", "[", "2", "]", ")", ";", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "Class", "<", "DOSerializer", ">", "serializer", "=", "(", "Class", "<", "DOSerializer", ">", ")", "Class", ".", "forName", "(", "args", "[", "3", "]", ")", ";", "// So DOTranslationUtility works...", "System", ".", "setProperty", "(", "\"fedora.hostname\"", ",", "\"localhost\"", ")", ";", "System", ".", "setProperty", "(", "\"fedora.port\"", ",", "\"8080\"", ")", ";", "System", ".", "setProperty", "(", "\"fedora.appServerContext\"", ",", "Constants", ".", "FEDORA_DEFAULT_APP_CONTEXT", ")", ";", "boolean", "pretty", "=", "args", ".", "length", ">", "4", "&&", "args", "[", "4", "]", ".", "equals", "(", "\"true\"", ")", ";", "String", "inExt", "=", "\"xml\"", ";", "if", "(", "args", ".", "length", ">", "5", ")", "inExt", "=", "args", "[", "5", "]", ";", "String", "outExt", "=", "\"xml\"", ";", "if", "(", "args", ".", "length", ">", "6", ")", "outExt", "=", "args", "[", "6", "]", ";", "ConvertObjectSerialization", "converter", "=", "new", "ConvertObjectSerialization", "(", "deserializer", ",", "serializer", ",", "pretty", ",", "inExt", ",", "outExt", ")", ";", "converter", ".", "convert", "(", "sourceDir", ",", "destDir", ")", ";", "TripleIteratorFactory", ".", "defaultInstance", "(", ")", ".", "shutdown", "(", ")", ";", "}" ]
Command-line utility to convert objects from one format to another. @param args command-line args.
[ "Command", "-", "line", "utility", "to", "convert", "objects", "from", "one", "format", "to", "another", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/storage/translation/ConvertObjectSerialization.java#L196-L234
9,171
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/messaging/AtomAPIMMessage.java
AtomAPIMMessage.objectToString
private String objectToString(Object obj, String xsdType) { if (obj == null) { return "null"; } String javaType = obj.getClass().getCanonicalName(); String term; if (javaType != null && javaType.equals("java.util.Date")) { // several circumstances yield null canonical names term = DateUtility.convertDateToXSDString((Date) obj); } else if (xsdType.equals("fedora-types:ArrayOfString")) { term = array2string(obj); } else if (xsdType.equals("xsd:boolean")) { term = obj.toString(); } else if (xsdType.equals("xsd:nonNegativeInteger")) { term = obj.toString(); } else if (xsdType.equals("fedora-types:RelationshipTuple")) { RelationshipTuple[] tuples = (RelationshipTuple[]) obj; TupleArrayTripleIterator iter = new TupleArrayTripleIterator(new ArrayList<RelationshipTuple>(Arrays .asList(tuples))); ReadableByteArrayOutputStream os = new ReadableByteArrayOutputStream(); try { iter.toStream(os, RDFFormat.NOTATION_3, false); } catch (TrippiException e) { e.printStackTrace(); } term = os.getString(Charset.forName("UTF-8")); } else if (javaType != null && javaType.equals("java.lang.String")) { term = (String) obj; term = term.replaceAll("\"", "'"); } else { term = "[OMITTED]"; } return term; }
java
private String objectToString(Object obj, String xsdType) { if (obj == null) { return "null"; } String javaType = obj.getClass().getCanonicalName(); String term; if (javaType != null && javaType.equals("java.util.Date")) { // several circumstances yield null canonical names term = DateUtility.convertDateToXSDString((Date) obj); } else if (xsdType.equals("fedora-types:ArrayOfString")) { term = array2string(obj); } else if (xsdType.equals("xsd:boolean")) { term = obj.toString(); } else if (xsdType.equals("xsd:nonNegativeInteger")) { term = obj.toString(); } else if (xsdType.equals("fedora-types:RelationshipTuple")) { RelationshipTuple[] tuples = (RelationshipTuple[]) obj; TupleArrayTripleIterator iter = new TupleArrayTripleIterator(new ArrayList<RelationshipTuple>(Arrays .asList(tuples))); ReadableByteArrayOutputStream os = new ReadableByteArrayOutputStream(); try { iter.toStream(os, RDFFormat.NOTATION_3, false); } catch (TrippiException e) { e.printStackTrace(); } term = os.getString(Charset.forName("UTF-8")); } else if (javaType != null && javaType.equals("java.lang.String")) { term = (String) obj; term = term.replaceAll("\"", "'"); } else { term = "[OMITTED]"; } return term; }
[ "private", "String", "objectToString", "(", "Object", "obj", ",", "String", "xsdType", ")", "{", "if", "(", "obj", "==", "null", ")", "{", "return", "\"null\"", ";", "}", "String", "javaType", "=", "obj", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", ";", "String", "term", ";", "if", "(", "javaType", "!=", "null", "&&", "javaType", ".", "equals", "(", "\"java.util.Date\"", ")", ")", "{", "// several circumstances yield null canonical names", "term", "=", "DateUtility", ".", "convertDateToXSDString", "(", "(", "Date", ")", "obj", ")", ";", "}", "else", "if", "(", "xsdType", ".", "equals", "(", "\"fedora-types:ArrayOfString\"", ")", ")", "{", "term", "=", "array2string", "(", "obj", ")", ";", "}", "else", "if", "(", "xsdType", ".", "equals", "(", "\"xsd:boolean\"", ")", ")", "{", "term", "=", "obj", ".", "toString", "(", ")", ";", "}", "else", "if", "(", "xsdType", ".", "equals", "(", "\"xsd:nonNegativeInteger\"", ")", ")", "{", "term", "=", "obj", ".", "toString", "(", ")", ";", "}", "else", "if", "(", "xsdType", ".", "equals", "(", "\"fedora-types:RelationshipTuple\"", ")", ")", "{", "RelationshipTuple", "[", "]", "tuples", "=", "(", "RelationshipTuple", "[", "]", ")", "obj", ";", "TupleArrayTripleIterator", "iter", "=", "new", "TupleArrayTripleIterator", "(", "new", "ArrayList", "<", "RelationshipTuple", ">", "(", "Arrays", ".", "asList", "(", "tuples", ")", ")", ")", ";", "ReadableByteArrayOutputStream", "os", "=", "new", "ReadableByteArrayOutputStream", "(", ")", ";", "try", "{", "iter", ".", "toStream", "(", "os", ",", "RDFFormat", ".", "NOTATION_3", ",", "false", ")", ";", "}", "catch", "(", "TrippiException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "term", "=", "os", ".", "getString", "(", "Charset", ".", "forName", "(", "\"UTF-8\"", ")", ")", ";", "}", "else", "if", "(", "javaType", "!=", "null", "&&", "javaType", ".", "equals", "(", "\"java.lang.String\"", ")", ")", "{", "term", "=", "(", "String", ")", "obj", ";", "term", "=", "term", ".", "replaceAll", "(", "\"\\\"\"", ",", "\"'\"", ")", ";", "}", "else", "{", "term", "=", "\"[OMITTED]\"", ";", "}", "return", "term", ";", "}" ]
Get the String value of an object based on its class or XML Schema Datatype. @param obj @param xsdType @return
[ "Get", "the", "String", "value", "of", "an", "object", "based", "on", "its", "class", "or", "XML", "Schema", "Datatype", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/messaging/AtomAPIMMessage.java#L253-L286
9,172
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/impl/BasicRequestCtx.java
BasicRequestCtx.encodeAttributes
private void encodeAttributes(List attributes, PrintStream out, Indenter indenter) { Iterator it = attributes.iterator(); while (it.hasNext()) { Attribute attr = (Attribute)(it.next()); attr.encode(out, indenter); } }
java
private void encodeAttributes(List attributes, PrintStream out, Indenter indenter) { Iterator it = attributes.iterator(); while (it.hasNext()) { Attribute attr = (Attribute)(it.next()); attr.encode(out, indenter); } }
[ "private", "void", "encodeAttributes", "(", "List", "attributes", ",", "PrintStream", "out", ",", "Indenter", "indenter", ")", "{", "Iterator", "it", "=", "attributes", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "Attribute", "attr", "=", "(", "Attribute", ")", "(", "it", ".", "next", "(", ")", ")", ";", "attr", ".", "encode", "(", "out", ",", "indenter", ")", ";", "}", "}" ]
Private helper function to encode the attribute sets
[ "Private", "helper", "function", "to", "encode", "the", "attribute", "sets" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/impl/BasicRequestCtx.java#L496-L503
9,173
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/impl/BasicRequestCtx.java
BasicRequestCtx.encodeSubject
private void encodeSubject(Subject subject, PrintStream out, Indenter indenter) { char [] indent = indenter.makeString().toCharArray(); out.print(indent); out.append("<Subject SubjectCategory=\"") .append(subject.getCategory().toString()).append('"'); List subjectAttrs = subject.getAttributesAsList(); if (subjectAttrs.size() == 0) { // there's nothing in this Subject, so just close the tag out.println("/>"); } else { // there's content, so fill it in out.println('>'); encodeAttributes(subjectAttrs, out, indenter); out.print(indent); out.println("</Subject>"); } }
java
private void encodeSubject(Subject subject, PrintStream out, Indenter indenter) { char [] indent = indenter.makeString().toCharArray(); out.print(indent); out.append("<Subject SubjectCategory=\"") .append(subject.getCategory().toString()).append('"'); List subjectAttrs = subject.getAttributesAsList(); if (subjectAttrs.size() == 0) { // there's nothing in this Subject, so just close the tag out.println("/>"); } else { // there's content, so fill it in out.println('>'); encodeAttributes(subjectAttrs, out, indenter); out.print(indent); out.println("</Subject>"); } }
[ "private", "void", "encodeSubject", "(", "Subject", "subject", ",", "PrintStream", "out", ",", "Indenter", "indenter", ")", "{", "char", "[", "]", "indent", "=", "indenter", ".", "makeString", "(", ")", ".", "toCharArray", "(", ")", ";", "out", ".", "print", "(", "indent", ")", ";", "out", ".", "append", "(", "\"<Subject SubjectCategory=\\\"\"", ")", ".", "append", "(", "subject", ".", "getCategory", "(", ")", ".", "toString", "(", ")", ")", ".", "append", "(", "'", "'", ")", ";", "List", "subjectAttrs", "=", "subject", ".", "getAttributesAsList", "(", ")", ";", "if", "(", "subjectAttrs", ".", "size", "(", ")", "==", "0", ")", "{", "// there's nothing in this Subject, so just close the tag", "out", ".", "println", "(", "\"/>\"", ")", ";", "}", "else", "{", "// there's content, so fill it in", "out", ".", "println", "(", "'", "'", ")", ";", "encodeAttributes", "(", "subjectAttrs", ",", "out", ",", "indenter", ")", ";", "out", ".", "print", "(", "indent", ")", ";", "out", ".", "println", "(", "\"</Subject>\"", ")", ";", "}", "}" ]
Private helper function to encode the subjects
[ "Private", "helper", "function", "to", "encode", "the", "subjects" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/impl/BasicRequestCtx.java#L508-L529
9,174
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/servletfilters/ldap/FilterLdap.java
FilterLdap.init
@Override public void init(FilterConfig filterConfig) { String m = "L init() "; try { logger.debug(m + ">"); super.init(filterConfig); m = FilterSetup.getFilterNameAbbrev(FILTER_NAME) + " init() "; inited = false; if (!initErrors) { Set<String> temp = new HashSet<String>(); if (ATTRIBUTES2RETURN == null) { ATTRIBUTES2RETURN = EMPTY_STRING_ARRAY; } else { for (String element : ATTRIBUTES2RETURN) { temp.add(element); } } if (AUTHENTICATE && PASSWORD != null && !PASSWORD.isEmpty()) { temp.add(PASSWORD); } DIRECTORY_ATTRIBUTES_NEEDED = (String[]) temp.toArray(StringArrayPrototype); boolean haveBindMethod = false; if (SECURITY_AUTHENTICATION != null && !SECURITY_AUTHENTICATION.isEmpty()) { haveBindMethod = true; } boolean haveSuperUser = false; if (SECURITY_PRINCIPAL != null && !SECURITY_PRINCIPAL.isEmpty()) { haveSuperUser = true; } boolean haveSuperUserPassword = false; if (SECURITY_CREDENTIALS != null && !SECURITY_CREDENTIALS.isEmpty()) { haveSuperUserPassword = true; } if (haveBindMethod && haveSuperUserPassword) { initErrors = !haveSuperUser; } } if (initErrors) { logger.error(m + "not initialized; see previous error"); } inited = true; } finally { logger.debug("{}<", m); } }
java
@Override public void init(FilterConfig filterConfig) { String m = "L init() "; try { logger.debug(m + ">"); super.init(filterConfig); m = FilterSetup.getFilterNameAbbrev(FILTER_NAME) + " init() "; inited = false; if (!initErrors) { Set<String> temp = new HashSet<String>(); if (ATTRIBUTES2RETURN == null) { ATTRIBUTES2RETURN = EMPTY_STRING_ARRAY; } else { for (String element : ATTRIBUTES2RETURN) { temp.add(element); } } if (AUTHENTICATE && PASSWORD != null && !PASSWORD.isEmpty()) { temp.add(PASSWORD); } DIRECTORY_ATTRIBUTES_NEEDED = (String[]) temp.toArray(StringArrayPrototype); boolean haveBindMethod = false; if (SECURITY_AUTHENTICATION != null && !SECURITY_AUTHENTICATION.isEmpty()) { haveBindMethod = true; } boolean haveSuperUser = false; if (SECURITY_PRINCIPAL != null && !SECURITY_PRINCIPAL.isEmpty()) { haveSuperUser = true; } boolean haveSuperUserPassword = false; if (SECURITY_CREDENTIALS != null && !SECURITY_CREDENTIALS.isEmpty()) { haveSuperUserPassword = true; } if (haveBindMethod && haveSuperUserPassword) { initErrors = !haveSuperUser; } } if (initErrors) { logger.error(m + "not initialized; see previous error"); } inited = true; } finally { logger.debug("{}<", m); } }
[ "@", "Override", "public", "void", "init", "(", "FilterConfig", "filterConfig", ")", "{", "String", "m", "=", "\"L init() \"", ";", "try", "{", "logger", ".", "debug", "(", "m", "+", "\">\"", ")", ";", "super", ".", "init", "(", "filterConfig", ")", ";", "m", "=", "FilterSetup", ".", "getFilterNameAbbrev", "(", "FILTER_NAME", ")", "+", "\" init() \"", ";", "inited", "=", "false", ";", "if", "(", "!", "initErrors", ")", "{", "Set", "<", "String", ">", "temp", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "if", "(", "ATTRIBUTES2RETURN", "==", "null", ")", "{", "ATTRIBUTES2RETURN", "=", "EMPTY_STRING_ARRAY", ";", "}", "else", "{", "for", "(", "String", "element", ":", "ATTRIBUTES2RETURN", ")", "{", "temp", ".", "add", "(", "element", ")", ";", "}", "}", "if", "(", "AUTHENTICATE", "&&", "PASSWORD", "!=", "null", "&&", "!", "PASSWORD", ".", "isEmpty", "(", ")", ")", "{", "temp", ".", "add", "(", "PASSWORD", ")", ";", "}", "DIRECTORY_ATTRIBUTES_NEEDED", "=", "(", "String", "[", "]", ")", "temp", ".", "toArray", "(", "StringArrayPrototype", ")", ";", "boolean", "haveBindMethod", "=", "false", ";", "if", "(", "SECURITY_AUTHENTICATION", "!=", "null", "&&", "!", "SECURITY_AUTHENTICATION", ".", "isEmpty", "(", ")", ")", "{", "haveBindMethod", "=", "true", ";", "}", "boolean", "haveSuperUser", "=", "false", ";", "if", "(", "SECURITY_PRINCIPAL", "!=", "null", "&&", "!", "SECURITY_PRINCIPAL", ".", "isEmpty", "(", ")", ")", "{", "haveSuperUser", "=", "true", ";", "}", "boolean", "haveSuperUserPassword", "=", "false", ";", "if", "(", "SECURITY_CREDENTIALS", "!=", "null", "&&", "!", "SECURITY_CREDENTIALS", ".", "isEmpty", "(", ")", ")", "{", "haveSuperUserPassword", "=", "true", ";", "}", "if", "(", "haveBindMethod", "&&", "haveSuperUserPassword", ")", "{", "initErrors", "=", "!", "haveSuperUser", ";", "}", "}", "if", "(", "initErrors", ")", "{", "logger", ".", "error", "(", "m", "+", "\"not initialized; see previous error\"", ")", ";", "}", "inited", "=", "true", ";", "}", "finally", "{", "logger", ".", "debug", "(", "\"{}<\"", ",", "m", ")", ";", "}", "}" ]
public Boolean REQUIRE_RETURNED_ATTRS = Boolean.FALSE;
[ "public", "Boolean", "REQUIRE_RETURNED_ATTRS", "=", "Boolean", ".", "FALSE", ";" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/servletfilters/ldap/FilterLdap.java#L99-L152
9,175
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Uploader.java
Uploader.upload
public String upload(final File file) throws IOException { if (Administrator.INSTANCE == null) { return fc.uploadFile(file); } else { // paint initial status to the progress bar String msg = "Uploading " + file.length() + " bytes to " + fc.getUploadURL(); Dimension d = Administrator.PROGRESS.getSize(); Administrator.PROGRESS.setString(msg); Administrator.PROGRESS.setValue(100); Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1); // then start the thread, passing parms in SwingWorker<String> worker = new SwingWorker<String>() { @Override public String construct() { try { return fc.uploadFile(file); } catch (IOException e) { thrownException = e; return ""; } } }; worker.start(); // keep updating status till the worker's finished int ms = 200; while (!worker.done) { try { Administrator.PROGRESS.setValue(ms); Administrator.PROGRESS.paintImmediately(0, 0, (int) d .getWidth() - 1, (int) d.getHeight() - 1); Thread.sleep(100); ms = ms + 100; if (ms >= 2000) { ms = 200; } } catch (InterruptedException ie) { } } // reset the status bar to normal Administrator.PROGRESS.setValue(2000); Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1); try { Thread.sleep(100); } catch (InterruptedException ie) { } // report if there was an error; otherwise return the response if (worker.thrownException != null) { throw (IOException) worker.thrownException; } else { return (String) worker.getValue(); } } }
java
public String upload(final File file) throws IOException { if (Administrator.INSTANCE == null) { return fc.uploadFile(file); } else { // paint initial status to the progress bar String msg = "Uploading " + file.length() + " bytes to " + fc.getUploadURL(); Dimension d = Administrator.PROGRESS.getSize(); Administrator.PROGRESS.setString(msg); Administrator.PROGRESS.setValue(100); Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1); // then start the thread, passing parms in SwingWorker<String> worker = new SwingWorker<String>() { @Override public String construct() { try { return fc.uploadFile(file); } catch (IOException e) { thrownException = e; return ""; } } }; worker.start(); // keep updating status till the worker's finished int ms = 200; while (!worker.done) { try { Administrator.PROGRESS.setValue(ms); Administrator.PROGRESS.paintImmediately(0, 0, (int) d .getWidth() - 1, (int) d.getHeight() - 1); Thread.sleep(100); ms = ms + 100; if (ms >= 2000) { ms = 200; } } catch (InterruptedException ie) { } } // reset the status bar to normal Administrator.PROGRESS.setValue(2000); Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1); try { Thread.sleep(100); } catch (InterruptedException ie) { } // report if there was an error; otherwise return the response if (worker.thrownException != null) { throw (IOException) worker.thrownException; } else { return (String) worker.getValue(); } } }
[ "public", "String", "upload", "(", "final", "File", "file", ")", "throws", "IOException", "{", "if", "(", "Administrator", ".", "INSTANCE", "==", "null", ")", "{", "return", "fc", ".", "uploadFile", "(", "file", ")", ";", "}", "else", "{", "// paint initial status to the progress bar", "String", "msg", "=", "\"Uploading \"", "+", "file", ".", "length", "(", ")", "+", "\" bytes to \"", "+", "fc", ".", "getUploadURL", "(", ")", ";", "Dimension", "d", "=", "Administrator", ".", "PROGRESS", ".", "getSize", "(", ")", ";", "Administrator", ".", "PROGRESS", ".", "setString", "(", "msg", ")", ";", "Administrator", ".", "PROGRESS", ".", "setValue", "(", "100", ")", ";", "Administrator", ".", "PROGRESS", ".", "paintImmediately", "(", "0", ",", "0", ",", "(", "int", ")", "d", ".", "getWidth", "(", ")", "-", "1", ",", "(", "int", ")", "d", ".", "getHeight", "(", ")", "-", "1", ")", ";", "// then start the thread, passing parms in", "SwingWorker", "<", "String", ">", "worker", "=", "new", "SwingWorker", "<", "String", ">", "(", ")", "{", "@", "Override", "public", "String", "construct", "(", ")", "{", "try", "{", "return", "fc", ".", "uploadFile", "(", "file", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "thrownException", "=", "e", ";", "return", "\"\"", ";", "}", "}", "}", ";", "worker", ".", "start", "(", ")", ";", "// keep updating status till the worker's finished", "int", "ms", "=", "200", ";", "while", "(", "!", "worker", ".", "done", ")", "{", "try", "{", "Administrator", ".", "PROGRESS", ".", "setValue", "(", "ms", ")", ";", "Administrator", ".", "PROGRESS", ".", "paintImmediately", "(", "0", ",", "0", ",", "(", "int", ")", "d", ".", "getWidth", "(", ")", "-", "1", ",", "(", "int", ")", "d", ".", "getHeight", "(", ")", "-", "1", ")", ";", "Thread", ".", "sleep", "(", "100", ")", ";", "ms", "=", "ms", "+", "100", ";", "if", "(", "ms", ">=", "2000", ")", "{", "ms", "=", "200", ";", "}", "}", "catch", "(", "InterruptedException", "ie", ")", "{", "}", "}", "// reset the status bar to normal", "Administrator", ".", "PROGRESS", ".", "setValue", "(", "2000", ")", ";", "Administrator", ".", "PROGRESS", ".", "paintImmediately", "(", "0", ",", "0", ",", "(", "int", ")", "d", ".", "getWidth", "(", ")", "-", "1", ",", "(", "int", ")", "d", ".", "getHeight", "(", ")", "-", "1", ")", ";", "try", "{", "Thread", ".", "sleep", "(", "100", ")", ";", "}", "catch", "(", "InterruptedException", "ie", ")", "{", "}", "// report if there was an error; otherwise return the response", "if", "(", "worker", ".", "thrownException", "!=", "null", ")", "{", "throw", "(", "IOException", ")", "worker", ".", "thrownException", ";", "}", "else", "{", "return", "(", "String", ")", "worker", ".", "getValue", "(", ")", ";", "}", "}", "}" ]
Send a file to the server, getting back the identifier.
[ "Send", "a", "file", "to", "the", "server", "getting", "back", "the", "identifier", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Uploader.java#L86-L152
9,176
fcrepo3/fcrepo
fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Uploader.java
Uploader.main
public static void main(String[] args) { try { if (args.length == 5 || args.length == 6) { String protocol = args[0]; int port = Integer.parseInt(args[1]); String user = args[2]; String password = args[3]; String fileName = args[4]; String context = Constants.FEDORA_DEFAULT_APP_CONTEXT; if (args.length == 6 && !args[5].isEmpty()) { context = args[5]; } Uploader uploader = new Uploader(protocol, port, context, user, password); File f = new File(fileName); System.out.println(uploader.upload(new FileInputStream(f))); System.out.println(uploader.upload(f)); uploader = new Uploader(protocol, port, context, user + "test", password); System.out.println(uploader.upload(f)); } else { System.err .println("Usage: Uploader host port user password file [context]"); } } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); } }
java
public static void main(String[] args) { try { if (args.length == 5 || args.length == 6) { String protocol = args[0]; int port = Integer.parseInt(args[1]); String user = args[2]; String password = args[3]; String fileName = args[4]; String context = Constants.FEDORA_DEFAULT_APP_CONTEXT; if (args.length == 6 && !args[5].isEmpty()) { context = args[5]; } Uploader uploader = new Uploader(protocol, port, context, user, password); File f = new File(fileName); System.out.println(uploader.upload(new FileInputStream(f))); System.out.println(uploader.upload(f)); uploader = new Uploader(protocol, port, context, user + "test", password); System.out.println(uploader.upload(f)); } else { System.err .println("Usage: Uploader host port user password file [context]"); } } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); } }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "try", "{", "if", "(", "args", ".", "length", "==", "5", "||", "args", ".", "length", "==", "6", ")", "{", "String", "protocol", "=", "args", "[", "0", "]", ";", "int", "port", "=", "Integer", ".", "parseInt", "(", "args", "[", "1", "]", ")", ";", "String", "user", "=", "args", "[", "2", "]", ";", "String", "password", "=", "args", "[", "3", "]", ";", "String", "fileName", "=", "args", "[", "4", "]", ";", "String", "context", "=", "Constants", ".", "FEDORA_DEFAULT_APP_CONTEXT", ";", "if", "(", "args", ".", "length", "==", "6", "&&", "!", "args", "[", "5", "]", ".", "isEmpty", "(", ")", ")", "{", "context", "=", "args", "[", "5", "]", ";", "}", "Uploader", "uploader", "=", "new", "Uploader", "(", "protocol", ",", "port", ",", "context", ",", "user", ",", "password", ")", ";", "File", "f", "=", "new", "File", "(", "fileName", ")", ";", "System", ".", "out", ".", "println", "(", "uploader", ".", "upload", "(", "new", "FileInputStream", "(", "f", ")", ")", ")", ";", "System", ".", "out", ".", "println", "(", "uploader", ".", "upload", "(", "f", ")", ")", ";", "uploader", "=", "new", "Uploader", "(", "protocol", ",", "port", ",", "context", ",", "user", "+", "\"test\"", ",", "password", ")", ";", "System", ".", "out", ".", "println", "(", "uploader", ".", "upload", "(", "f", ")", ")", ";", "}", "else", "{", "System", ".", "err", ".", "println", "(", "\"Usage: Uploader host port user password file [context]\"", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"ERROR: \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Test this class by uploading the given file three times. First, with the provided credentials, as an InputStream. Second, with the provided credentials, as a File. Third, with bogus credentials, as a File.
[ "Test", "this", "class", "by", "uploading", "the", "given", "file", "three", "times", ".", "First", "with", "the", "provided", "credentials", "as", "an", "InputStream", ".", "Second", "with", "the", "provided", "credentials", "as", "a", "File", ".", "Third", "with", "bogus", "credentials", "as", "a", "File", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-client/fcrepo-client-admin/src/main/java/org/fcrepo/client/Uploader.java#L159-L193
9,177
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/SpringServlet.java
SpringServlet.getFedoraHomeDir
private File getFedoraHomeDir() throws ServletException { String fedoraHome = Constants.FEDORA_HOME; if (fedoraHome == null) { failStartup("FEDORA_HOME was not configured properly. It must be " + "set via the fedora.home servlet init-param (preferred), " + "the fedora.home system property, or the FEDORA_HOME " + "environment variable.", null); } File fedoraHomeDir = new File(fedoraHome); if (!fedoraHomeDir.isDirectory()) { failStartup("The FEDORA_HOME directory, " + fedoraHomeDir.getPath() + " does not exist", null); } File writeTest = new File(fedoraHomeDir, "writeTest.tmp"); String writeErrorMessage = "The FEDORA_HOME directory, " + fedoraHomeDir.getPath() + " is not writable by " + "the current user, " + System.getProperty("user.name"); try { writeTest.createNewFile(); if (!writeTest.exists()) { throw new IOException(""); } writeTest.delete(); } catch (IOException e) { failStartup(writeErrorMessage, null); } return fedoraHomeDir; }
java
private File getFedoraHomeDir() throws ServletException { String fedoraHome = Constants.FEDORA_HOME; if (fedoraHome == null) { failStartup("FEDORA_HOME was not configured properly. It must be " + "set via the fedora.home servlet init-param (preferred), " + "the fedora.home system property, or the FEDORA_HOME " + "environment variable.", null); } File fedoraHomeDir = new File(fedoraHome); if (!fedoraHomeDir.isDirectory()) { failStartup("The FEDORA_HOME directory, " + fedoraHomeDir.getPath() + " does not exist", null); } File writeTest = new File(fedoraHomeDir, "writeTest.tmp"); String writeErrorMessage = "The FEDORA_HOME directory, " + fedoraHomeDir.getPath() + " is not writable by " + "the current user, " + System.getProperty("user.name"); try { writeTest.createNewFile(); if (!writeTest.exists()) { throw new IOException(""); } writeTest.delete(); } catch (IOException e) { failStartup(writeErrorMessage, null); } return fedoraHomeDir; }
[ "private", "File", "getFedoraHomeDir", "(", ")", "throws", "ServletException", "{", "String", "fedoraHome", "=", "Constants", ".", "FEDORA_HOME", ";", "if", "(", "fedoraHome", "==", "null", ")", "{", "failStartup", "(", "\"FEDORA_HOME was not configured properly. It must be \"", "+", "\"set via the fedora.home servlet init-param (preferred), \"", "+", "\"the fedora.home system property, or the FEDORA_HOME \"", "+", "\"environment variable.\"", ",", "null", ")", ";", "}", "File", "fedoraHomeDir", "=", "new", "File", "(", "fedoraHome", ")", ";", "if", "(", "!", "fedoraHomeDir", ".", "isDirectory", "(", ")", ")", "{", "failStartup", "(", "\"The FEDORA_HOME directory, \"", "+", "fedoraHomeDir", ".", "getPath", "(", ")", "+", "\" does not exist\"", ",", "null", ")", ";", "}", "File", "writeTest", "=", "new", "File", "(", "fedoraHomeDir", ",", "\"writeTest.tmp\"", ")", ";", "String", "writeErrorMessage", "=", "\"The FEDORA_HOME directory, \"", "+", "fedoraHomeDir", ".", "getPath", "(", ")", "+", "\" is not writable by \"", "+", "\"the current user, \"", "+", "System", ".", "getProperty", "(", "\"user.name\"", ")", ";", "try", "{", "writeTest", ".", "createNewFile", "(", ")", ";", "if", "(", "!", "writeTest", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"\"", ")", ";", "}", "writeTest", ".", "delete", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "failStartup", "(", "writeErrorMessage", ",", "null", ")", ";", "}", "return", "fedoraHomeDir", ";", "}" ]
Validates and returns the value of FEDORA_HOME. @return the FEDORA_HOME directory. @throws ServletException if FEDORA_HOME (or fedora.home) was not set, does not denote an existing directory, or is not writable by the current user.
[ "Validates", "and", "returns", "the", "value", "of", "FEDORA_HOME", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/SpringServlet.java#L85-L115
9,178
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java
DefaultManagement.validate
@Override public Validation validate(Context context, String pid, Date asOfDateTime) throws ServerException { try { logger.debug("Entered validate"); m_authz.enforceValidate(context, pid, asOfDateTime); return ecmValidator.validate(context, pid, asOfDateTime); } finally { // Logger completion if (logger.isInfoEnabled()) { StringBuilder logMsg = new StringBuilder("Completed validate("); logMsg.append("pid: ").append(pid); logMsg.append(", asOfDateTime: ").append(asOfDateTime); logMsg.append(")"); logger.info(logMsg.toString()); } logger.debug("Exiting validate"); } }
java
@Override public Validation validate(Context context, String pid, Date asOfDateTime) throws ServerException { try { logger.debug("Entered validate"); m_authz.enforceValidate(context, pid, asOfDateTime); return ecmValidator.validate(context, pid, asOfDateTime); } finally { // Logger completion if (logger.isInfoEnabled()) { StringBuilder logMsg = new StringBuilder("Completed validate("); logMsg.append("pid: ").append(pid); logMsg.append(", asOfDateTime: ").append(asOfDateTime); logMsg.append(")"); logger.info(logMsg.toString()); } logger.debug("Exiting validate"); } }
[ "@", "Override", "public", "Validation", "validate", "(", "Context", "context", ",", "String", "pid", ",", "Date", "asOfDateTime", ")", "throws", "ServerException", "{", "try", "{", "logger", ".", "debug", "(", "\"Entered validate\"", ")", ";", "m_authz", ".", "enforceValidate", "(", "context", ",", "pid", ",", "asOfDateTime", ")", ";", "return", "ecmValidator", ".", "validate", "(", "context", ",", "pid", ",", "asOfDateTime", ")", ";", "}", "finally", "{", "// Logger completion", "if", "(", "logger", ".", "isInfoEnabled", "(", ")", ")", "{", "StringBuilder", "logMsg", "=", "new", "StringBuilder", "(", "\"Completed validate(\"", ")", ";", "logMsg", ".", "append", "(", "\"pid: \"", ")", ".", "append", "(", "pid", ")", ";", "logMsg", ".", "append", "(", "\", asOfDateTime: \"", ")", ".", "append", "(", "asOfDateTime", ")", ";", "logMsg", ".", "append", "(", "\")\"", ")", ";", "logger", ".", "info", "(", "logMsg", ".", "toString", "(", ")", ")", ";", "}", "logger", ".", "debug", "(", "\"Exiting validate\"", ")", ";", "}", "}" ]
Validate the object against the datacontracts from the objects content model. This method just delegates the validation to EcmValidator @param context the call context @param pid the pid of the object to validate @param asOfDateTime the datetime to get to object as @return The result of the validation @see org.fcrepo.server.validation.ecm.EcmValidator
[ "Validate", "the", "object", "against", "the", "datacontracts", "from", "the", "objects", "content", "model", ".", "This", "method", "just", "delegates", "the", "validation", "to", "EcmValidator" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java#L1834-L1862
9,179
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java
DefaultManagement.addAuditRecord
private void addAuditRecord(Context context, DOWriter w, String action, String componentID, String justification, Date nowUTC) throws ServerException { AuditRecord audit = new AuditRecord(); audit.id = w.newAuditRecordID(); audit.processType = "Fedora API-M"; audit.action = action; audit.componentID = componentID; audit.responsibility = context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri); audit.date = nowUTC; audit.justification = justification; w.getAuditRecords().add(audit); }
java
private void addAuditRecord(Context context, DOWriter w, String action, String componentID, String justification, Date nowUTC) throws ServerException { AuditRecord audit = new AuditRecord(); audit.id = w.newAuditRecordID(); audit.processType = "Fedora API-M"; audit.action = action; audit.componentID = componentID; audit.responsibility = context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri); audit.date = nowUTC; audit.justification = justification; w.getAuditRecords().add(audit); }
[ "private", "void", "addAuditRecord", "(", "Context", "context", ",", "DOWriter", "w", ",", "String", "action", ",", "String", "componentID", ",", "String", "justification", ",", "Date", "nowUTC", ")", "throws", "ServerException", "{", "AuditRecord", "audit", "=", "new", "AuditRecord", "(", ")", ";", "audit", ".", "id", "=", "w", ".", "newAuditRecordID", "(", ")", ";", "audit", ".", "processType", "=", "\"Fedora API-M\"", ";", "audit", ".", "action", "=", "action", ";", "audit", ".", "componentID", "=", "componentID", ";", "audit", ".", "responsibility", "=", "context", ".", "getSubjectValue", "(", "Constants", ".", "SUBJECT", ".", "LOGIN_ID", ".", "uri", ")", ";", "audit", ".", "date", "=", "nowUTC", ";", "audit", ".", "justification", "=", "justification", ";", "w", ".", "getAuditRecords", "(", ")", ".", "add", "(", "audit", ")", ";", "}" ]
Creates a new audit record and adds it to the digital object audit trail.
[ "Creates", "a", "new", "audit", "record", "and", "adds", "it", "to", "the", "digital", "object", "audit", "trail", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java#L1868-L1884
9,180
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java
DefaultManagement.appendAltIDs
private static void appendAltIDs(StringBuilder logMsg, String[] altIDs) { logMsg.append(", altIDs: "); if (altIDs == null) { logMsg.append("null"); } else { for (String altID : altIDs) { logMsg.append("'").append(altID).append("'"); } } }
java
private static void appendAltIDs(StringBuilder logMsg, String[] altIDs) { logMsg.append(", altIDs: "); if (altIDs == null) { logMsg.append("null"); } else { for (String altID : altIDs) { logMsg.append("'").append(altID).append("'"); } } }
[ "private", "static", "void", "appendAltIDs", "(", "StringBuilder", "logMsg", ",", "String", "[", "]", "altIDs", ")", "{", "logMsg", ".", "append", "(", "\", altIDs: \"", ")", ";", "if", "(", "altIDs", "==", "null", ")", "{", "logMsg", ".", "append", "(", "\"null\"", ")", ";", "}", "else", "{", "for", "(", "String", "altID", ":", "altIDs", ")", "{", "logMsg", ".", "append", "(", "\"'\"", ")", ".", "append", "(", "altID", ")", ".", "append", "(", "\"'\"", ")", ";", "}", "}", "}" ]
Appends alt IDs to the log message.
[ "Appends", "alt", "IDs", "to", "the", "log", "message", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/management/DefaultManagement.java#L1889-L1898
9,181
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/validation/DOObjectValidatorModule.java
DOObjectValidatorModule.setValidators
public void setValidators(Map<String,? extends DOObjectValidator> validators){ logger.info("Adding {} object validators", validators.size()); m_validators.putAll(validators); if (m_validators.size() > 0) { m_enabled = true; } }
java
public void setValidators(Map<String,? extends DOObjectValidator> validators){ logger.info("Adding {} object validators", validators.size()); m_validators.putAll(validators); if (m_validators.size() > 0) { m_enabled = true; } }
[ "public", "void", "setValidators", "(", "Map", "<", "String", ",", "?", "extends", "DOObjectValidator", ">", "validators", ")", "{", "logger", ".", "info", "(", "\"Adding {} object validators\"", ",", "validators", ".", "size", "(", ")", ")", ";", "m_validators", ".", "putAll", "(", "validators", ")", ";", "if", "(", "m_validators", ".", "size", "(", ")", ">", "0", ")", "{", "m_enabled", "=", "true", ";", "}", "}" ]
spring config of the validators
[ "spring", "config", "of", "the", "validators" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/validation/DOObjectValidatorModule.java#L74-L80
9,182
fcrepo3/fcrepo
fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java
Installer.install
public void install() throws InstallationFailedException { installDir.mkdirs(); // Write out the install options used to a properties file in the install directory try { OutputStream out = new FileOutputStream(new File(installDir, "install.properties")); _opts.dump(out); out.close(); } catch (Exception e) { throw new InstallationFailedException(e.getMessage(), e); } new FedoraHome(_dist, _opts).install(); if (!_opts.getValue(InstallOptions.INSTALL_TYPE) .equals(InstallOptions.INSTALL_CLIENT)) { Container container = ContainerFactory.getContainer(_dist, _opts); container.install(); container.deploy(buildWAR()); if (_opts.getBooleanValue(InstallOptions.DEPLOY_LOCAL_SERVICES, true)) { deployLocalService(container, Distribution.FOP_WAR); deployLocalService(container, Distribution.IMAGEMANIP_WAR); deployLocalService(container, Distribution.SAXON_WAR); deployLocalService(container, Distribution.DEMO_WAR); } Database database = new Database(_dist, _opts); database.install(); } System.out.println("Installation complete."); if (!_opts.getValue(InstallOptions.INSTALL_TYPE) .equals(InstallOptions.INSTALL_CLIENT) && _opts.getValue(InstallOptions.SERVLET_ENGINE) .equals(InstallOptions.OTHER)) { System.out .println("\n" + "----------------------------------------------------------------------\n" + "The Fedora Installer cannot automatically deploy the Web ARchives to \n" + "the selected servlet container. You must deploy the WAR files \n" + "manually. You can find fedora.war plus several sample back-end \n" + "services and a demonstration object package in: \n" + "\t" + fedoraHome.getAbsolutePath() + File.separator + "install"); } System.out .println("\n" + "----------------------------------------------------------------------\n" + "Before starting Fedora, please ensure that any required environment\n" + "variables are correctly defined\n" + "\t(e.g. FEDORA_HOME, JAVA_HOME, JAVA_OPTS, CATALINA_HOME).\n" + "For more information, please consult the Installation & Configuration\n" + "Guide in the online documentation.\n" + "----------------------------------------------------------------------\n"); }
java
public void install() throws InstallationFailedException { installDir.mkdirs(); // Write out the install options used to a properties file in the install directory try { OutputStream out = new FileOutputStream(new File(installDir, "install.properties")); _opts.dump(out); out.close(); } catch (Exception e) { throw new InstallationFailedException(e.getMessage(), e); } new FedoraHome(_dist, _opts).install(); if (!_opts.getValue(InstallOptions.INSTALL_TYPE) .equals(InstallOptions.INSTALL_CLIENT)) { Container container = ContainerFactory.getContainer(_dist, _opts); container.install(); container.deploy(buildWAR()); if (_opts.getBooleanValue(InstallOptions.DEPLOY_LOCAL_SERVICES, true)) { deployLocalService(container, Distribution.FOP_WAR); deployLocalService(container, Distribution.IMAGEMANIP_WAR); deployLocalService(container, Distribution.SAXON_WAR); deployLocalService(container, Distribution.DEMO_WAR); } Database database = new Database(_dist, _opts); database.install(); } System.out.println("Installation complete."); if (!_opts.getValue(InstallOptions.INSTALL_TYPE) .equals(InstallOptions.INSTALL_CLIENT) && _opts.getValue(InstallOptions.SERVLET_ENGINE) .equals(InstallOptions.OTHER)) { System.out .println("\n" + "----------------------------------------------------------------------\n" + "The Fedora Installer cannot automatically deploy the Web ARchives to \n" + "the selected servlet container. You must deploy the WAR files \n" + "manually. You can find fedora.war plus several sample back-end \n" + "services and a demonstration object package in: \n" + "\t" + fedoraHome.getAbsolutePath() + File.separator + "install"); } System.out .println("\n" + "----------------------------------------------------------------------\n" + "Before starting Fedora, please ensure that any required environment\n" + "variables are correctly defined\n" + "\t(e.g. FEDORA_HOME, JAVA_HOME, JAVA_OPTS, CATALINA_HOME).\n" + "For more information, please consult the Installation & Configuration\n" + "Guide in the online documentation.\n" + "----------------------------------------------------------------------\n"); }
[ "public", "void", "install", "(", ")", "throws", "InstallationFailedException", "{", "installDir", ".", "mkdirs", "(", ")", ";", "// Write out the install options used to a properties file in the install directory", "try", "{", "OutputStream", "out", "=", "new", "FileOutputStream", "(", "new", "File", "(", "installDir", ",", "\"install.properties\"", ")", ")", ";", "_opts", ".", "dump", "(", "out", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "InstallationFailedException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "new", "FedoraHome", "(", "_dist", ",", "_opts", ")", ".", "install", "(", ")", ";", "if", "(", "!", "_opts", ".", "getValue", "(", "InstallOptions", ".", "INSTALL_TYPE", ")", ".", "equals", "(", "InstallOptions", ".", "INSTALL_CLIENT", ")", ")", "{", "Container", "container", "=", "ContainerFactory", ".", "getContainer", "(", "_dist", ",", "_opts", ")", ";", "container", ".", "install", "(", ")", ";", "container", ".", "deploy", "(", "buildWAR", "(", ")", ")", ";", "if", "(", "_opts", ".", "getBooleanValue", "(", "InstallOptions", ".", "DEPLOY_LOCAL_SERVICES", ",", "true", ")", ")", "{", "deployLocalService", "(", "container", ",", "Distribution", ".", "FOP_WAR", ")", ";", "deployLocalService", "(", "container", ",", "Distribution", ".", "IMAGEMANIP_WAR", ")", ";", "deployLocalService", "(", "container", ",", "Distribution", ".", "SAXON_WAR", ")", ";", "deployLocalService", "(", "container", ",", "Distribution", ".", "DEMO_WAR", ")", ";", "}", "Database", "database", "=", "new", "Database", "(", "_dist", ",", "_opts", ")", ";", "database", ".", "install", "(", ")", ";", "}", "System", ".", "out", ".", "println", "(", "\"Installation complete.\"", ")", ";", "if", "(", "!", "_opts", ".", "getValue", "(", "InstallOptions", ".", "INSTALL_TYPE", ")", ".", "equals", "(", "InstallOptions", ".", "INSTALL_CLIENT", ")", "&&", "_opts", ".", "getValue", "(", "InstallOptions", ".", "SERVLET_ENGINE", ")", ".", "equals", "(", "InstallOptions", ".", "OTHER", ")", ")", "{", "System", ".", "out", ".", "println", "(", "\"\\n\"", "+", "\"----------------------------------------------------------------------\\n\"", "+", "\"The Fedora Installer cannot automatically deploy the Web ARchives to \\n\"", "+", "\"the selected servlet container. You must deploy the WAR files \\n\"", "+", "\"manually. You can find fedora.war plus several sample back-end \\n\"", "+", "\"services and a demonstration object package in: \\n\"", "+", "\"\\t\"", "+", "fedoraHome", ".", "getAbsolutePath", "(", ")", "+", "File", ".", "separator", "+", "\"install\"", ")", ";", "}", "System", ".", "out", ".", "println", "(", "\"\\n\"", "+", "\"----------------------------------------------------------------------\\n\"", "+", "\"Before starting Fedora, please ensure that any required environment\\n\"", "+", "\"variables are correctly defined\\n\"", "+", "\"\\t(e.g. FEDORA_HOME, JAVA_HOME, JAVA_OPTS, CATALINA_HOME).\\n\"", "+", "\"For more information, please consult the Installation & Configuration\\n\"", "+", "\"Guide in the online documentation.\\n\"", "+", "\"----------------------------------------------------------------------\\n\"", ")", ";", "}" ]
Install the distribution based on the options.
[ "Install", "the", "distribution", "based", "on", "the", "options", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java#L44-L100
9,183
fcrepo3/fcrepo
fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java
Installer.main
public static void main(String[] args) { LogConfig.initMinimal(); try { Distribution dist = new ClassLoaderDistribution(); InstallOptions opts = null; if (args.length == 0) { opts = new InstallOptions(dist); } else { Map<String, String> props = new HashMap<String, String>(); for (String file : args) { props.putAll(FileUtils.loadMap(new File(file))); } opts = new InstallOptions(dist, props); } // set fedora.home System.setProperty("fedora.home", opts .getValue(InstallOptions.FEDORA_HOME)); new Installer(dist, opts).install(); } catch (Exception e) { printException(e); System.exit(1); } }
java
public static void main(String[] args) { LogConfig.initMinimal(); try { Distribution dist = new ClassLoaderDistribution(); InstallOptions opts = null; if (args.length == 0) { opts = new InstallOptions(dist); } else { Map<String, String> props = new HashMap<String, String>(); for (String file : args) { props.putAll(FileUtils.loadMap(new File(file))); } opts = new InstallOptions(dist, props); } // set fedora.home System.setProperty("fedora.home", opts .getValue(InstallOptions.FEDORA_HOME)); new Installer(dist, opts).install(); } catch (Exception e) { printException(e); System.exit(1); } }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "LogConfig", ".", "initMinimal", "(", ")", ";", "try", "{", "Distribution", "dist", "=", "new", "ClassLoaderDistribution", "(", ")", ";", "InstallOptions", "opts", "=", "null", ";", "if", "(", "args", ".", "length", "==", "0", ")", "{", "opts", "=", "new", "InstallOptions", "(", "dist", ")", ";", "}", "else", "{", "Map", "<", "String", ",", "String", ">", "props", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "for", "(", "String", "file", ":", "args", ")", "{", "props", ".", "putAll", "(", "FileUtils", ".", "loadMap", "(", "new", "File", "(", "file", ")", ")", ")", ";", "}", "opts", "=", "new", "InstallOptions", "(", "dist", ",", "props", ")", ";", "}", "// set fedora.home", "System", ".", "setProperty", "(", "\"fedora.home\"", ",", "opts", ".", "getValue", "(", "InstallOptions", ".", "FEDORA_HOME", ")", ")", ";", "new", "Installer", "(", "dist", ",", "opts", ")", ".", "install", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "printException", "(", "e", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "}" ]
Command-line entry point.
[ "Command", "-", "line", "entry", "point", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java#L170-L195
9,184
fcrepo3/fcrepo
fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java
Installer.printException
private static void printException(Exception e) { if (e instanceof InstallationCancelledException) { System.out.println("Installation cancelled."); return; } boolean recognized = false; String msg = "ERROR: "; if (e instanceof InstallationFailedException) { msg += "Installation failed: " + e.getMessage(); recognized = true; } else if (e instanceof OptionValidationException) { OptionValidationException ove = (OptionValidationException) e; msg += "Bad value for '" + ove.getOptionId() + "': " + e.getMessage(); recognized = true; } if (recognized) { System.err.println(msg); if (e.getCause() != null) { System.err.println("Caused by: "); e.getCause().printStackTrace(System.err); } } else { System.err.println(msg + "Unexpected error; installation aborted."); e.printStackTrace(); } }
java
private static void printException(Exception e) { if (e instanceof InstallationCancelledException) { System.out.println("Installation cancelled."); return; } boolean recognized = false; String msg = "ERROR: "; if (e instanceof InstallationFailedException) { msg += "Installation failed: " + e.getMessage(); recognized = true; } else if (e instanceof OptionValidationException) { OptionValidationException ove = (OptionValidationException) e; msg += "Bad value for '" + ove.getOptionId() + "': " + e.getMessage(); recognized = true; } if (recognized) { System.err.println(msg); if (e.getCause() != null) { System.err.println("Caused by: "); e.getCause().printStackTrace(System.err); } } else { System.err.println(msg + "Unexpected error; installation aborted."); e.printStackTrace(); } }
[ "private", "static", "void", "printException", "(", "Exception", "e", ")", "{", "if", "(", "e", "instanceof", "InstallationCancelledException", ")", "{", "System", ".", "out", ".", "println", "(", "\"Installation cancelled.\"", ")", ";", "return", ";", "}", "boolean", "recognized", "=", "false", ";", "String", "msg", "=", "\"ERROR: \"", ";", "if", "(", "e", "instanceof", "InstallationFailedException", ")", "{", "msg", "+=", "\"Installation failed: \"", "+", "e", ".", "getMessage", "(", ")", ";", "recognized", "=", "true", ";", "}", "else", "if", "(", "e", "instanceof", "OptionValidationException", ")", "{", "OptionValidationException", "ove", "=", "(", "OptionValidationException", ")", "e", ";", "msg", "+=", "\"Bad value for '\"", "+", "ove", ".", "getOptionId", "(", ")", "+", "\"': \"", "+", "e", ".", "getMessage", "(", ")", ";", "recognized", "=", "true", ";", "}", "if", "(", "recognized", ")", "{", "System", ".", "err", ".", "println", "(", "msg", ")", ";", "if", "(", "e", ".", "getCause", "(", ")", "!=", "null", ")", "{", "System", ".", "err", ".", "println", "(", "\"Caused by: \"", ")", ";", "e", ".", "getCause", "(", ")", ".", "printStackTrace", "(", "System", ".", "err", ")", ";", "}", "}", "else", "{", "System", ".", "err", ".", "println", "(", "msg", "+", "\"Unexpected error; installation aborted.\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Print a message appropriate for the given exception in as human-readable way as possible.
[ "Print", "a", "message", "appropriate", "for", "the", "given", "exception", "in", "as", "human", "-", "readable", "way", "as", "possible", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-installer/src/main/java/org/fcrepo/utilities/install/Installer.java#L201-L231
9,185
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumerThread.java
JournalConsumerThread.run
@Override public void run() { try { waitUntilServerIsInitialized(); recoveryLog.log("Start recovery."); while (true) { if (shutdown) { break; } ConsumerJournalEntry cje = reader.readJournalEntry(); if (cje == null) { break; } cje.invokeMethod(delegate, recoveryLog); cje.close(); } reader.shutdown(); recoveryLog.log("Recovery complete."); } catch (Throwable e) { /* * It makes sense to catch Exception here, because any uncaught * exception will not be reported - there is no console to print the * stack trace! It might not be appropriate to catch Throwable, but * it's the only way we can know about missing class files and such. * Of course, if we catch an OutOfMemoryError or a * VirtualMachineError, all bets are off. */ logger.error("Error during Journal recovery", e); String stackTrace = JournalHelper.captureStackTrace(e); recoveryLog.log("PROBLEM: " + stackTrace); recoveryLog.log("Recovery terminated prematurely."); } finally { recoveryLog.shutdown(); } }
java
@Override public void run() { try { waitUntilServerIsInitialized(); recoveryLog.log("Start recovery."); while (true) { if (shutdown) { break; } ConsumerJournalEntry cje = reader.readJournalEntry(); if (cje == null) { break; } cje.invokeMethod(delegate, recoveryLog); cje.close(); } reader.shutdown(); recoveryLog.log("Recovery complete."); } catch (Throwable e) { /* * It makes sense to catch Exception here, because any uncaught * exception will not be reported - there is no console to print the * stack trace! It might not be appropriate to catch Throwable, but * it's the only way we can know about missing class files and such. * Of course, if we catch an OutOfMemoryError or a * VirtualMachineError, all bets are off. */ logger.error("Error during Journal recovery", e); String stackTrace = JournalHelper.captureStackTrace(e); recoveryLog.log("PROBLEM: " + stackTrace); recoveryLog.log("Recovery terminated prematurely."); } finally { recoveryLog.shutdown(); } }
[ "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "waitUntilServerIsInitialized", "(", ")", ";", "recoveryLog", ".", "log", "(", "\"Start recovery.\"", ")", ";", "while", "(", "true", ")", "{", "if", "(", "shutdown", ")", "{", "break", ";", "}", "ConsumerJournalEntry", "cje", "=", "reader", ".", "readJournalEntry", "(", ")", ";", "if", "(", "cje", "==", "null", ")", "{", "break", ";", "}", "cje", ".", "invokeMethod", "(", "delegate", ",", "recoveryLog", ")", ";", "cje", ".", "close", "(", ")", ";", "}", "reader", ".", "shutdown", "(", ")", ";", "recoveryLog", ".", "log", "(", "\"Recovery complete.\"", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "/*\n * It makes sense to catch Exception here, because any uncaught\n * exception will not be reported - there is no console to print the\n * stack trace! It might not be appropriate to catch Throwable, but\n * it's the only way we can know about missing class files and such.\n * Of course, if we catch an OutOfMemoryError or a\n * VirtualMachineError, all bets are off.\n */", "logger", ".", "error", "(", "\"Error during Journal recovery\"", ",", "e", ")", ";", "String", "stackTrace", "=", "JournalHelper", ".", "captureStackTrace", "(", "e", ")", ";", "recoveryLog", ".", "log", "(", "\"PROBLEM: \"", "+", "stackTrace", ")", ";", "recoveryLog", ".", "log", "(", "\"Recovery terminated prematurely.\"", ")", ";", "}", "finally", "{", "recoveryLog", ".", "shutdown", "(", ")", ";", "}", "}" ]
Wait until the server completes its initialization, then process journal entries until the reader says there are no more, or until a shutdown is requested.
[ "Wait", "until", "the", "server", "completes", "its", "initialization", "then", "process", "journal", "entries", "until", "the", "reader", "says", "there", "are", "no", "more", "or", "until", "a", "shutdown", "is", "requested", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumerThread.java#L68-L105
9,186
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumerThread.java
JournalConsumerThread.waitUntilServerIsInitialized
private void waitUntilServerIsInitialized() { int i = 0; for (; i < 60; i++) { if (server.hasInitialized() || shutdown) { return; } try { Thread.sleep(1000); } catch (InterruptedException e) { logger.warn("Thread was interrupted"); } } logger.error("Can't recover from the Journal - " + "the server hasn't initialized after " + i + " seconds."); shutdown = true; }
java
private void waitUntilServerIsInitialized() { int i = 0; for (; i < 60; i++) { if (server.hasInitialized() || shutdown) { return; } try { Thread.sleep(1000); } catch (InterruptedException e) { logger.warn("Thread was interrupted"); } } logger.error("Can't recover from the Journal - " + "the server hasn't initialized after " + i + " seconds."); shutdown = true; }
[ "private", "void", "waitUntilServerIsInitialized", "(", ")", "{", "int", "i", "=", "0", ";", "for", "(", ";", "i", "<", "60", ";", "i", "++", ")", "{", "if", "(", "server", ".", "hasInitialized", "(", ")", "||", "shutdown", ")", "{", "return", ";", "}", "try", "{", "Thread", ".", "sleep", "(", "1000", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "logger", ".", "warn", "(", "\"Thread was interrupted\"", ")", ";", "}", "}", "logger", ".", "error", "(", "\"Can't recover from the Journal - \"", "+", "\"the server hasn't initialized after \"", "+", "i", "+", "\" seconds.\"", ")", ";", "shutdown", "=", "true", ";", "}" ]
Wait for the server to initialize. If we wait too long, give up and shut down the thread.
[ "Wait", "for", "the", "server", "to", "initialize", ".", "If", "we", "wait", "too", "long", "give", "up", "and", "shut", "down", "the", "thread", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/JournalConsumerThread.java#L111-L126
9,187
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyParser.java
PolicyParser.getSchema
private static Schema getSchema(InputStream schemaStream) throws SAXException { Schema result; synchronized(SCHEMA_FACTORY){ result = SCHEMA_FACTORY.newSchema(new StreamSource(schemaStream)); } return result; }
java
private static Schema getSchema(InputStream schemaStream) throws SAXException { Schema result; synchronized(SCHEMA_FACTORY){ result = SCHEMA_FACTORY.newSchema(new StreamSource(schemaStream)); } return result; }
[ "private", "static", "Schema", "getSchema", "(", "InputStream", "schemaStream", ")", "throws", "SAXException", "{", "Schema", "result", ";", "synchronized", "(", "SCHEMA_FACTORY", ")", "{", "result", "=", "SCHEMA_FACTORY", ".", "newSchema", "(", "new", "StreamSource", "(", "schemaStream", ")", ")", ";", "}", "return", "result", ";", "}" ]
Schema Factory is not thread safe @return
[ "Schema", "Factory", "is", "not", "thread", "safe" ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyParser.java#L80-L86
9,188
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyParser.java
PolicyParser.parse
public AbstractPolicy parse(InputStream policyStream, boolean schemaValidate) throws ValidationException { // Parse; die if not well-formed Document doc = null; DocumentBuilder domParser = null; try { domParser = XmlTransformUtility.borrowDocumentBuilder(); domParser.setErrorHandler(THROW_ALL); doc = domParser.parse(policyStream); } catch (Exception e) { throw new ValidationException("Policy invalid; malformed XML", e); } finally { if (domParser != null) { XmlTransformUtility.returnDocumentBuilder(domParser); } } if (schemaValidate) { // XSD-validate; die if not schema-valid Validator validator = null; try { validator = m_validators.borrowObject(); validator.validate(new DOMSource(doc)); } catch (Exception e) { throw new ValidationException("Policy invalid; schema" + " validation failed", e); } finally { if (validator != null) try { m_validators.returnObject(validator); } catch (Exception e) { logger.warn(e.getMessage(), e); } } } // Construct AbstractPolicy from doc; die if root isn't "Policy[Set]" Element root = doc.getDocumentElement(); String rootName = root.getTagName(); try { if (rootName.equals("Policy")) { return Policy.getInstance(root); } else if (rootName.equals("PolicySet")) { return PolicySet.getInstance(root); } else { throw new ValidationException("Policy invalid; root element is " + rootName + ", but should be " + "Policy or PolicySet"); } } catch (ParsingException e) { throw new ValidationException("Policy invalid; failed parsing by " + "Sun XACML implementation", e); } }
java
public AbstractPolicy parse(InputStream policyStream, boolean schemaValidate) throws ValidationException { // Parse; die if not well-formed Document doc = null; DocumentBuilder domParser = null; try { domParser = XmlTransformUtility.borrowDocumentBuilder(); domParser.setErrorHandler(THROW_ALL); doc = domParser.parse(policyStream); } catch (Exception e) { throw new ValidationException("Policy invalid; malformed XML", e); } finally { if (domParser != null) { XmlTransformUtility.returnDocumentBuilder(domParser); } } if (schemaValidate) { // XSD-validate; die if not schema-valid Validator validator = null; try { validator = m_validators.borrowObject(); validator.validate(new DOMSource(doc)); } catch (Exception e) { throw new ValidationException("Policy invalid; schema" + " validation failed", e); } finally { if (validator != null) try { m_validators.returnObject(validator); } catch (Exception e) { logger.warn(e.getMessage(), e); } } } // Construct AbstractPolicy from doc; die if root isn't "Policy[Set]" Element root = doc.getDocumentElement(); String rootName = root.getTagName(); try { if (rootName.equals("Policy")) { return Policy.getInstance(root); } else if (rootName.equals("PolicySet")) { return PolicySet.getInstance(root); } else { throw new ValidationException("Policy invalid; root element is " + rootName + ", but should be " + "Policy or PolicySet"); } } catch (ParsingException e) { throw new ValidationException("Policy invalid; failed parsing by " + "Sun XACML implementation", e); } }
[ "public", "AbstractPolicy", "parse", "(", "InputStream", "policyStream", ",", "boolean", "schemaValidate", ")", "throws", "ValidationException", "{", "// Parse; die if not well-formed", "Document", "doc", "=", "null", ";", "DocumentBuilder", "domParser", "=", "null", ";", "try", "{", "domParser", "=", "XmlTransformUtility", ".", "borrowDocumentBuilder", "(", ")", ";", "domParser", ".", "setErrorHandler", "(", "THROW_ALL", ")", ";", "doc", "=", "domParser", ".", "parse", "(", "policyStream", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ValidationException", "(", "\"Policy invalid; malformed XML\"", ",", "e", ")", ";", "}", "finally", "{", "if", "(", "domParser", "!=", "null", ")", "{", "XmlTransformUtility", ".", "returnDocumentBuilder", "(", "domParser", ")", ";", "}", "}", "if", "(", "schemaValidate", ")", "{", "// XSD-validate; die if not schema-valid", "Validator", "validator", "=", "null", ";", "try", "{", "validator", "=", "m_validators", ".", "borrowObject", "(", ")", ";", "validator", ".", "validate", "(", "new", "DOMSource", "(", "doc", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ValidationException", "(", "\"Policy invalid; schema\"", "+", "\" validation failed\"", ",", "e", ")", ";", "}", "finally", "{", "if", "(", "validator", "!=", "null", ")", "try", "{", "m_validators", ".", "returnObject", "(", "validator", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "warn", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}", "}", "// Construct AbstractPolicy from doc; die if root isn't \"Policy[Set]\"", "Element", "root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "String", "rootName", "=", "root", ".", "getTagName", "(", ")", ";", "try", "{", "if", "(", "rootName", ".", "equals", "(", "\"Policy\"", ")", ")", "{", "return", "Policy", ".", "getInstance", "(", "root", ")", ";", "}", "else", "if", "(", "rootName", ".", "equals", "(", "\"PolicySet\"", ")", ")", "{", "return", "PolicySet", ".", "getInstance", "(", "root", ")", ";", "}", "else", "{", "throw", "new", "ValidationException", "(", "\"Policy invalid; root element is \"", "+", "rootName", "+", "\", but should be \"", "+", "\"Policy or PolicySet\"", ")", ";", "}", "}", "catch", "(", "ParsingException", "e", ")", "{", "throw", "new", "ValidationException", "(", "\"Policy invalid; failed parsing by \"", "+", "\"Sun XACML implementation\"", ",", "e", ")", ";", "}", "}" ]
Parses the given policy and optionally schema validates it. @param policyStream the serialized XACML policy @param schemaValidate whether to schema validate @return the parsed policy. @throws ValidationException if the given xml is not a valid policy. This will occur if it is not well-formed XML, its root element is not named <code>Policy</code> or <code>PolicySet</code>, it triggers a parse exception in the Sun libraries when constructing an <code>AbstractPolicy</code> from the DOM, or (if validation is true) it is not schema-valid.
[ "Parses", "the", "given", "policy", "and", "optionally", "schema", "validates", "it", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/security/PolicyParser.java#L113-L167
9,189
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiJournalReceiver.java
RmiJournalReceiver.exportAndBind
public void exportAndBind() throws RemoteException, AlreadyBoundException, InterruptedException { Registry registry = LocateRegistry .createRegistry(arguments.getRegistryPortNumber()); registry.rebind(RMI_BINDING_NAME, this); Thread.sleep(2000); logger.info("RmiJournalReceiver is ready - journal directory is '" + arguments.getDirectoryPath().getAbsolutePath() + "'"); }
java
public void exportAndBind() throws RemoteException, AlreadyBoundException, InterruptedException { Registry registry = LocateRegistry .createRegistry(arguments.getRegistryPortNumber()); registry.rebind(RMI_BINDING_NAME, this); Thread.sleep(2000); logger.info("RmiJournalReceiver is ready - journal directory is '" + arguments.getDirectoryPath().getAbsolutePath() + "'"); }
[ "public", "void", "exportAndBind", "(", ")", "throws", "RemoteException", ",", "AlreadyBoundException", ",", "InterruptedException", "{", "Registry", "registry", "=", "LocateRegistry", ".", "createRegistry", "(", "arguments", ".", "getRegistryPortNumber", "(", ")", ")", ";", "registry", ".", "rebind", "(", "RMI_BINDING_NAME", ",", "this", ")", ";", "Thread", ".", "sleep", "(", "2000", ")", ";", "logger", ".", "info", "(", "\"RmiJournalReceiver is ready - journal directory is '\"", "+", "arguments", ".", "getDirectoryPath", "(", ")", ".", "getAbsolutePath", "(", ")", "+", "\"'\"", ")", ";", "}" ]
Create an RMI registry, and bind this object to the expected name.
[ "Create", "an", "RMI", "registry", "and", "bind", "this", "object", "to", "the", "expected", "name", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multicast/rmi/RmiJournalReceiver.java#L78-L87
9,190
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.updateTriples
private void updateTriples(Set<Triple> set, boolean delete) throws ResourceIndexException { try { if (delete) { _writer.delete(getTripleIterator(set), _syncUpdates); } else { _writer.add(getTripleIterator(set), _syncUpdates); } } catch (Exception e) { throw new ResourceIndexException("Error updating triples", e); } }
java
private void updateTriples(Set<Triple> set, boolean delete) throws ResourceIndexException { try { if (delete) { _writer.delete(getTripleIterator(set), _syncUpdates); } else { _writer.add(getTripleIterator(set), _syncUpdates); } } catch (Exception e) { throw new ResourceIndexException("Error updating triples", e); } }
[ "private", "void", "updateTriples", "(", "Set", "<", "Triple", ">", "set", ",", "boolean", "delete", ")", "throws", "ResourceIndexException", "{", "try", "{", "if", "(", "delete", ")", "{", "_writer", ".", "delete", "(", "getTripleIterator", "(", "set", ")", ",", "_syncUpdates", ")", ";", "}", "else", "{", "_writer", ".", "add", "(", "getTripleIterator", "(", "set", ")", ",", "_syncUpdates", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ResourceIndexException", "(", "\"Error updating triples\"", ",", "e", ")", ";", "}", "}" ]
Applies the given adds or deletes to the triplestore. If _syncUpdates is true, changes will be flushed before returning.
[ "Applies", "the", "given", "adds", "or", "deletes", "to", "the", "triplestore", ".", "If", "_syncUpdates", "is", "true", "changes", "will", "be", "flushed", "before", "returning", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L159-L170
9,191
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.updateTripleDiffs
private void updateTripleDiffs(Set<Triple> existing, Set<Triple> desired) throws ResourceIndexException { // Delete any existing triples that are no longer desired, // leaving the ones we want in place HashSet<Triple> obsoleteTriples = new HashSet<Triple>(existing); obsoleteTriples.removeAll(desired); updateTriples(obsoleteTriples, true); // Add only new desired triples HashSet<Triple> newTriples = new HashSet<Triple>(desired); newTriples.removeAll(existing); updateTriples(newTriples, false); }
java
private void updateTripleDiffs(Set<Triple> existing, Set<Triple> desired) throws ResourceIndexException { // Delete any existing triples that are no longer desired, // leaving the ones we want in place HashSet<Triple> obsoleteTriples = new HashSet<Triple>(existing); obsoleteTriples.removeAll(desired); updateTriples(obsoleteTriples, true); // Add only new desired triples HashSet<Triple> newTriples = new HashSet<Triple>(desired); newTriples.removeAll(existing); updateTriples(newTriples, false); }
[ "private", "void", "updateTripleDiffs", "(", "Set", "<", "Triple", ">", "existing", ",", "Set", "<", "Triple", ">", "desired", ")", "throws", "ResourceIndexException", "{", "// Delete any existing triples that are no longer desired,", "// leaving the ones we want in place", "HashSet", "<", "Triple", ">", "obsoleteTriples", "=", "new", "HashSet", "<", "Triple", ">", "(", "existing", ")", ";", "obsoleteTriples", ".", "removeAll", "(", "desired", ")", ";", "updateTriples", "(", "obsoleteTriples", ",", "true", ")", ";", "// Add only new desired triples", "HashSet", "<", "Triple", ">", "newTriples", "=", "new", "HashSet", "<", "Triple", ">", "(", "desired", ")", ";", "newTriples", ".", "removeAll", "(", "existing", ")", ";", "updateTriples", "(", "newTriples", ",", "false", ")", ";", "}" ]
Computes the difference between the given sets and applies the appropriate deletes and adds to the triplestore. If _syncUpdates is true, changes will be flushed before returning.
[ "Computes", "the", "difference", "between", "the", "given", "sets", "and", "applies", "the", "appropriate", "deletes", "and", "adds", "to", "the", "triplestore", ".", "If", "_syncUpdates", "is", "true", "changes", "will", "be", "flushed", "before", "returning", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L177-L191
9,192
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.getTripleIterator
private TripleIterator getTripleIterator(final Set<Triple> set) { return new TripleIterator() { private final Iterator<Triple> _iter = set.iterator(); @Override public boolean hasNext() { return _iter.hasNext(); } @Override public Triple next() { return getLocalizedTriple(_iter.next()); } @Override public void close() { } }; }
java
private TripleIterator getTripleIterator(final Set<Triple> set) { return new TripleIterator() { private final Iterator<Triple> _iter = set.iterator(); @Override public boolean hasNext() { return _iter.hasNext(); } @Override public Triple next() { return getLocalizedTriple(_iter.next()); } @Override public void close() { } }; }
[ "private", "TripleIterator", "getTripleIterator", "(", "final", "Set", "<", "Triple", ">", "set", ")", "{", "return", "new", "TripleIterator", "(", ")", "{", "private", "final", "Iterator", "<", "Triple", ">", "_iter", "=", "set", ".", "iterator", "(", ")", ";", "@", "Override", "public", "boolean", "hasNext", "(", ")", "{", "return", "_iter", ".", "hasNext", "(", ")", ";", "}", "@", "Override", "public", "Triple", "next", "(", ")", "{", "return", "getLocalizedTriple", "(", "_iter", ".", "next", "(", ")", ")", ";", "}", "@", "Override", "public", "void", "close", "(", ")", "{", "}", "}", ";", "}" ]
Gets a Trippi TripleIterator for the given set.
[ "Gets", "a", "Trippi", "TripleIterator", "for", "the", "given", "set", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L196-L215
9,193
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.getLocalizedTriple
private Triple getLocalizedTriple(Triple triple) { try { return _connector.getElementFactory().createTriple( getLocalizedResource(triple.getSubject()), getLocalizedResource(triple.getPredicate()), getLocalizedObject(triple.getObject())); } catch (GraphElementFactoryException e) { throw new RuntimeException("Error localizing triple", e); } }
java
private Triple getLocalizedTriple(Triple triple) { try { return _connector.getElementFactory().createTriple( getLocalizedResource(triple.getSubject()), getLocalizedResource(triple.getPredicate()), getLocalizedObject(triple.getObject())); } catch (GraphElementFactoryException e) { throw new RuntimeException("Error localizing triple", e); } }
[ "private", "Triple", "getLocalizedTriple", "(", "Triple", "triple", ")", "{", "try", "{", "return", "_connector", ".", "getElementFactory", "(", ")", ".", "createTriple", "(", "getLocalizedResource", "(", "triple", ".", "getSubject", "(", ")", ")", ",", "getLocalizedResource", "(", "triple", ".", "getPredicate", "(", ")", ")", ",", "getLocalizedObject", "(", "triple", ".", "getObject", "(", ")", ")", ")", ";", "}", "catch", "(", "GraphElementFactoryException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Error localizing triple\"", ",", "e", ")", ";", "}", "}" ]
Gets a Triple appropriate for writing to the store.
[ "Gets", "a", "Triple", "appropriate", "for", "writing", "to", "the", "store", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L220-L229
9,194
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.getLocalizedResource
private URIReference getLocalizedResource(Node n) throws GraphElementFactoryException { if (n instanceof URIReference) { URIReference u = (URIReference) n; return _connector.getElementFactory().createResource(u.getURI()); } else { throw new RuntimeException("Error localizing triple; " + n.getClass().getName() + " is not a URIReference"); } }
java
private URIReference getLocalizedResource(Node n) throws GraphElementFactoryException { if (n instanceof URIReference) { URIReference u = (URIReference) n; return _connector.getElementFactory().createResource(u.getURI()); } else { throw new RuntimeException("Error localizing triple; " + n.getClass().getName() + " is not a URIReference"); } }
[ "private", "URIReference", "getLocalizedResource", "(", "Node", "n", ")", "throws", "GraphElementFactoryException", "{", "if", "(", "n", "instanceof", "URIReference", ")", "{", "URIReference", "u", "=", "(", "URIReference", ")", "n", ";", "return", "_connector", ".", "getElementFactory", "(", ")", ".", "createResource", "(", "u", ".", "getURI", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"Error localizing triple; \"", "+", "n", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\" is not a URIReference\"", ")", ";", "}", "}" ]
Gets a localized URIReference based on the given Node.
[ "Gets", "a", "localized", "URIReference", "based", "on", "the", "given", "Node", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L234-L243
9,195
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java
ResourceIndexImpl.getLocalizedObject
private ObjectNode getLocalizedObject(Node n) throws GraphElementFactoryException { if (n instanceof URIReference) { return getLocalizedResource(n); } else if (n instanceof Literal) { Literal l = (Literal) n; GraphElementFactory elementFactory = _connector.getElementFactory(); if (l.getDatatypeURI() != null) { return elementFactory.createLiteral(l.getLexicalForm(), l.getDatatypeURI()); } else if (l.getLanguage() != null) { return elementFactory.createLiteral(l.getLexicalForm(), l.getLanguage()); } else { return elementFactory.createLiteral(l.getLexicalForm()); } } else { throw new RuntimeException("Error localizing triple; " + n.getClass().getName() + " is not a URIReference " + "or a Literal"); } }
java
private ObjectNode getLocalizedObject(Node n) throws GraphElementFactoryException { if (n instanceof URIReference) { return getLocalizedResource(n); } else if (n instanceof Literal) { Literal l = (Literal) n; GraphElementFactory elementFactory = _connector.getElementFactory(); if (l.getDatatypeURI() != null) { return elementFactory.createLiteral(l.getLexicalForm(), l.getDatatypeURI()); } else if (l.getLanguage() != null) { return elementFactory.createLiteral(l.getLexicalForm(), l.getLanguage()); } else { return elementFactory.createLiteral(l.getLexicalForm()); } } else { throw new RuntimeException("Error localizing triple; " + n.getClass().getName() + " is not a URIReference " + "or a Literal"); } }
[ "private", "ObjectNode", "getLocalizedObject", "(", "Node", "n", ")", "throws", "GraphElementFactoryException", "{", "if", "(", "n", "instanceof", "URIReference", ")", "{", "return", "getLocalizedResource", "(", "n", ")", ";", "}", "else", "if", "(", "n", "instanceof", "Literal", ")", "{", "Literal", "l", "=", "(", "Literal", ")", "n", ";", "GraphElementFactory", "elementFactory", "=", "_connector", ".", "getElementFactory", "(", ")", ";", "if", "(", "l", ".", "getDatatypeURI", "(", ")", "!=", "null", ")", "{", "return", "elementFactory", ".", "createLiteral", "(", "l", ".", "getLexicalForm", "(", ")", ",", "l", ".", "getDatatypeURI", "(", ")", ")", ";", "}", "else", "if", "(", "l", ".", "getLanguage", "(", ")", "!=", "null", ")", "{", "return", "elementFactory", ".", "createLiteral", "(", "l", ".", "getLexicalForm", "(", ")", ",", "l", ".", "getLanguage", "(", ")", ")", ";", "}", "else", "{", "return", "elementFactory", ".", "createLiteral", "(", "l", ".", "getLexicalForm", "(", ")", ")", ";", "}", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"Error localizing triple; \"", "+", "n", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\" is not a URIReference \"", "+", "\"or a Literal\"", ")", ";", "}", "}" ]
Gets a localized URIReference or Literal based on the given Node.
[ "Gets", "a", "localized", "URIReference", "or", "Literal", "based", "on", "the", "given", "Node", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/resourceIndex/ResourceIndexImpl.java#L248-L269
9,196
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileJournalReader.java
MultiFileJournalReader.scanThroughFilesForNextJournalEntry
private void scanThroughFilesForNextJournalEntry() throws JournalException { try { while (true) { if (currentFile != null) { // Check to see whether the current file contains any more // entries. advancePastWhitespace(currentFile.getReader()); XMLEvent next = currentFile.getReader().peek(); if (isStartTagEvent(next, QNAME_TAG_JOURNAL_ENTRY)) { // found it return; } else if (isEndTagEvent(next, QNAME_TAG_JOURNAL)) { // need to get the next file closeCurrentFile(); } else { // problems throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL, QNAME_TAG_JOURNAL_ENTRY, next); } } // If we don't have a file open, try to open one. if (currentFile == null) { currentFile = openNextFile(); } // If we still don't have a file open, we're finished. if (currentFile == null) { // if there was no next file, we're done. return; } // A new file needs to be advanced before using. advanceIntoFile(currentFile.getReader()); } } catch (XMLStreamException e) { throw new JournalException(e); } }
java
private void scanThroughFilesForNextJournalEntry() throws JournalException { try { while (true) { if (currentFile != null) { // Check to see whether the current file contains any more // entries. advancePastWhitespace(currentFile.getReader()); XMLEvent next = currentFile.getReader().peek(); if (isStartTagEvent(next, QNAME_TAG_JOURNAL_ENTRY)) { // found it return; } else if (isEndTagEvent(next, QNAME_TAG_JOURNAL)) { // need to get the next file closeCurrentFile(); } else { // problems throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL, QNAME_TAG_JOURNAL_ENTRY, next); } } // If we don't have a file open, try to open one. if (currentFile == null) { currentFile = openNextFile(); } // If we still don't have a file open, we're finished. if (currentFile == null) { // if there was no next file, we're done. return; } // A new file needs to be advanced before using. advanceIntoFile(currentFile.getReader()); } } catch (XMLStreamException e) { throw new JournalException(e); } }
[ "private", "void", "scanThroughFilesForNextJournalEntry", "(", ")", "throws", "JournalException", "{", "try", "{", "while", "(", "true", ")", "{", "if", "(", "currentFile", "!=", "null", ")", "{", "// Check to see whether the current file contains any more", "// entries. ", "advancePastWhitespace", "(", "currentFile", ".", "getReader", "(", ")", ")", ";", "XMLEvent", "next", "=", "currentFile", ".", "getReader", "(", ")", ".", "peek", "(", ")", ";", "if", "(", "isStartTagEvent", "(", "next", ",", "QNAME_TAG_JOURNAL_ENTRY", ")", ")", "{", "// found it", "return", ";", "}", "else", "if", "(", "isEndTagEvent", "(", "next", ",", "QNAME_TAG_JOURNAL", ")", ")", "{", "// need to get the next file", "closeCurrentFile", "(", ")", ";", "}", "else", "{", "// problems", "throw", "getNotNextMemberOrEndOfGroupException", "(", "QNAME_TAG_JOURNAL", ",", "QNAME_TAG_JOURNAL_ENTRY", ",", "next", ")", ";", "}", "}", "// If we don't have a file open, try to open one.", "if", "(", "currentFile", "==", "null", ")", "{", "currentFile", "=", "openNextFile", "(", ")", ";", "}", "// If we still don't have a file open, we're finished.", "if", "(", "currentFile", "==", "null", ")", "{", "// if there was no next file, we're done.", "return", ";", "}", "// A new file needs to be advanced before using.", "advanceIntoFile", "(", "currentFile", ".", "getReader", "(", ")", ")", ";", "}", "}", "catch", "(", "XMLStreamException", "e", ")", "{", "throw", "new", "JournalException", "(", "e", ")", ";", "}", "}" ]
Advance to the next journal entry if there is one. If we find one, the current file will be pointing to it. If we don't find one, there will be no current file.
[ "Advance", "to", "the", "next", "journal", "entry", "if", "there", "is", "one", ".", "If", "we", "find", "one", "the", "current", "file", "will", "be", "pointing", "to", "it", ".", "If", "we", "don", "t", "find", "one", "there", "will", "be", "no", "current", "file", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileJournalReader.java#L144-L184
9,197
fcrepo3/fcrepo
fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileJournalReader.java
MultiFileJournalReader.openNextFile
protected JournalInputFile openNextFile() throws JournalException { File[] journalFiles = MultiFileJournalHelper .getSortedArrayOfJournalFiles(journalDirectory, filenamePrefix); if (journalFiles.length == 0) { return null; } JournalInputFile nextFile = new JournalInputFile(journalFiles[0]); recoveryLog.log("Opening journal file: '" + nextFile.getFilename() + "'"); return nextFile; }
java
protected JournalInputFile openNextFile() throws JournalException { File[] journalFiles = MultiFileJournalHelper .getSortedArrayOfJournalFiles(journalDirectory, filenamePrefix); if (journalFiles.length == 0) { return null; } JournalInputFile nextFile = new JournalInputFile(journalFiles[0]); recoveryLog.log("Opening journal file: '" + nextFile.getFilename() + "'"); return nextFile; }
[ "protected", "JournalInputFile", "openNextFile", "(", ")", "throws", "JournalException", "{", "File", "[", "]", "journalFiles", "=", "MultiFileJournalHelper", ".", "getSortedArrayOfJournalFiles", "(", "journalDirectory", ",", "filenamePrefix", ")", ";", "if", "(", "journalFiles", ".", "length", "==", "0", ")", "{", "return", "null", ";", "}", "JournalInputFile", "nextFile", "=", "new", "JournalInputFile", "(", "journalFiles", "[", "0", "]", ")", ";", "recoveryLog", ".", "log", "(", "\"Opening journal file: '\"", "+", "nextFile", ".", "getFilename", "(", ")", "+", "\"'\"", ")", ";", "return", "nextFile", ";", "}" ]
Look in the directory for files that match the prefix. If there are none, leave with currentFile still null. If we find one, advance into it.
[ "Look", "in", "the", "directory", "for", "files", "that", "match", "the", "prefix", ".", "If", "there", "are", "none", "leave", "with", "currentFile", "still", "null", ".", "If", "we", "find", "one", "advance", "into", "it", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-server/src/main/java/org/fcrepo/server/journal/readerwriter/multifile/MultiFileJournalReader.java#L190-L204
9,198
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/rdf/JRDF.java
JRDF.sameResource
public static boolean sameResource(URIReference u1, String u2) { return u1.getURI().toString().equals(u2); }
java
public static boolean sameResource(URIReference u1, String u2) { return u1.getURI().toString().equals(u2); }
[ "public", "static", "boolean", "sameResource", "(", "URIReference", "u1", ",", "String", "u2", ")", "{", "return", "u1", ".", "getURI", "(", ")", ".", "toString", "(", ")", ".", "equals", "(", "u2", ")", ";", "}" ]
Tells whether the given resources are equivalent, with one given as a URI string. @param u1 first resource. @param u2 second resource, given as a URI string. @return true if equivalent, false otherwise.
[ "Tells", "whether", "the", "given", "resources", "are", "equivalent", "with", "one", "given", "as", "a", "URI", "string", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/rdf/JRDF.java#L70-L72
9,199
fcrepo3/fcrepo
fcrepo-common/src/main/java/org/fcrepo/common/rdf/JRDF.java
JRDF.sameLiteral
public static boolean sameLiteral(Literal l1, String l2, URI type, String lang) { if (l1.getLexicalForm().equals(l2) && eq(l1.getLanguage(), lang)) { if (l1.getDatatypeURI() == null) { return type == null; } else { return type != null && type.equals(l1.getDatatypeURI()); } } else { return false; } }
java
public static boolean sameLiteral(Literal l1, String l2, URI type, String lang) { if (l1.getLexicalForm().equals(l2) && eq(l1.getLanguage(), lang)) { if (l1.getDatatypeURI() == null) { return type == null; } else { return type != null && type.equals(l1.getDatatypeURI()); } } else { return false; } }
[ "public", "static", "boolean", "sameLiteral", "(", "Literal", "l1", ",", "String", "l2", ",", "URI", "type", ",", "String", "lang", ")", "{", "if", "(", "l1", ".", "getLexicalForm", "(", ")", ".", "equals", "(", "l2", ")", "&&", "eq", "(", "l1", ".", "getLanguage", "(", ")", ",", "lang", ")", ")", "{", "if", "(", "l1", ".", "getDatatypeURI", "(", ")", "==", "null", ")", "{", "return", "type", "==", "null", ";", "}", "else", "{", "return", "type", "!=", "null", "&&", "type", ".", "equals", "(", "l1", ".", "getDatatypeURI", "(", ")", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}" ]
Tells whether the given literals are equivalent, with one given as a set of simple values. @param l1 first literal. @param l2 second literal's lexical value. @param type second literal's datatype URI string, if applicable. @param lang second literal's language tag string, if applicable. @return true if equivalent, false otherwise.
[ "Tells", "whether", "the", "given", "literals", "are", "equivalent", "with", "one", "given", "as", "a", "set", "of", "simple", "values", "." ]
37df51b9b857fd12c6ab8269820d406c3c4ad774
https://github.com/fcrepo3/fcrepo/blob/37df51b9b857fd12c6ab8269820d406c3c4ad774/fcrepo-common/src/main/java/org/fcrepo/common/rdf/JRDF.java#L105-L119