📄 item.java
字号:
{ Collection myCollection = null; // get the collection ID int cid = itemRow.getIntColumn("owning_collection"); myCollection = Collection.find(ourContext, cid); return myCollection; } /** * Get Dublin Core metadata for the item. * Passing in a <code>null</code> value for <code>qualifier</code> * or <code>lang</code> only matches Dublin Core fields where that * qualifier or languages is actually <code>null</code>. * Passing in <code>Item.ANY</code> * retrieves all metadata fields with any value for the qualifier or * language, including <code>null</code> * <P> * Examples: * <P> * Return values of the unqualified "title" field, in any language. * Qualified title fields (e.g. "title.uniform") are NOT returned: * <P> * <code>item.getDC( "title", null, Item.ANY );</code> * <P> * Return all US English values of the "title" element, with any qualifier * (including unqualified): * <P> * <code>item.getDC( "title", Item.ANY, "en_US" );</code> * <P> * The ordering of values of a particular element/qualifier/language * combination is significant. When retrieving with wildcards, values of a * particular element/qualifier/language combinations will be adjacent, but * the overall ordering of the combinations is indeterminate. * * @param element * the Dublin Core element. <code>Item.ANY</code> matches any * element. <code>null</code> doesn't really make sense as all * DC must have an element. * @param qualifier * the qualifier. <code>null</code> means unqualified, and * <code>Item.ANY</code> means any qualifier (including * unqualified.) * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means only * values with no language are returned, and * <code>Item.ANY</code> means values with any country code or * no country code are returned. * @return Dublin Core fields that match the parameters */ public DCValue[] getDC(String element, String qualifier, String lang) { return getMetadata(MetadataSchema.DC_SCHEMA, element, qualifier, lang); } /** * Get metadata for the item in a chosen schema. * See <code>MetadataSchema</code> for more information about schemas. * Passing in a <code>null</code> value for <code>qualifier</code> * or <code>lang</code> only matches metadata fields where that * qualifier or languages is actually <code>null</code>. * Passing in <code>Item.ANY</code> * retrieves all metadata fields with any value for the qualifier or * language, including <code>null</code> * <P> * Examples: * <P> * Return values of the unqualified "title" field, in any language. * Qualified title fields (e.g. "title.uniform") are NOT returned: * <P> * <code>item.getMetadata("dc", "title", null, Item.ANY );</code> * <P> * Return all US English values of the "title" element, with any qualifier * (including unqualified): * <P> * <code>item.getMetadata("dc, "title", Item.ANY, "en_US" );</code> * <P> * The ordering of values of a particular element/qualifier/language * combination is significant. When retrieving with wildcards, values of a * particular element/qualifier/language combinations will be adjacent, but * the overall ordering of the combinations is indeterminate. * * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the element name. <code>Item.ANY</code> matches any * element. <code>null</code> doesn't really make sense as all * metadata must have an element. * @param qualifier * the qualifier. <code>null</code> means unqualified, and * <code>Item.ANY</code> means any qualifier (including * unqualified.) * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means only * values with no language are returned, and * <code>Item.ANY</code> means values with any country code or * no country code are returned. * @return metadata fields that match the parameters */ public DCValue[] getMetadata(String schema, String element, String qualifier, String lang) { // Build up list of matching values List values = new ArrayList(); Iterator i = dublinCore.iterator(); while (i.hasNext()) { DCValue dcv = (DCValue) i.next(); if (match(schema, element, qualifier, lang, dcv)) { // We will return a copy of the object in case it is altered DCValue copy = new DCValue(); copy.element = dcv.element; copy.qualifier = dcv.qualifier; copy.value = dcv.value; copy.language = dcv.language; copy.schema = dcv.schema; values.add(copy); } } // Create an array of matching values DCValue[] valueArray = new DCValue[values.size()]; valueArray = (DCValue[]) values.toArray(valueArray); return valueArray; } /** * Add Dublin Core metadata fields. These are appended to existing values. * Use <code>clearDC</code> to remove values. The ordering of values * passed in is maintained. * * @param element * the Dublin Core element * @param qualifier * the Dublin Core qualifer, or <code>null</code> for * unqualified * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means the * value has no language (for example, a date). * @param values * the values to add. */ public void addDC(String element, String qualifier, String lang, String[] values) { addMetadata(MetadataSchema.DC_SCHEMA, element, qualifier, lang, values); } /** * Add a single Dublin Core metadata field. This is appended to existing * values. Use <code>clearDC</code> to remove values. * * @param element * the Dublin Core element * @param qualifier * the Dublin Core qualifer, or <code>null</code> for * unqualified * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means the * value has no language (for example, a date). * @param value * the value to add. */ public void addDC(String element, String qualifier, String lang, String value) { addMetadata(MetadataSchema.DC_SCHEMA, element, qualifier, lang, value); } /** * Add metadata fields. These are appended to existing values. * Use <code>clearDC</code> to remove values. The ordering of values * passed in is maintained. * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the metadata element name * @param qualifier * the metadata qualifer name, or <code>null</code> for * unqualified * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means the * value has no language (for example, a date). * @param values * the values to add. */ public void addMetadata(String schema, String element, String qualifier, String lang, String[] values) { // We will not verify that they are valid entries in the registry // until update() is called. for (int i = 0; i < values.length; i++) { DCValue dcv = new DCValue(); dcv.schema = schema; dcv.element = element; dcv.qualifier = qualifier; dcv.language = lang; dcv.value = (values[i] == null ? null : values[i].trim()); dublinCore.add(dcv); } if (values.length > 0) { dublinCoreChanged = true; } } /** * Add a single metadata field. This is appended to existing * values. Use <code>clearDC</code> to remove values. * * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the metadata element name * @param qualifier * the metadata qualifer, or <code>null</code> for * unqualified * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means the * value has no language (for example, a date). * @param value * the value to add. */ public void addMetadata(String schema, String element, String qualifier, String lang, String value) { String[] valArray = new String[1]; valArray[0] = value; addMetadata(schema, element, qualifier, lang, valArray); } /** * Clear Dublin Core metadata values. As with <code>getDC</code> above, * passing in <code>null</code> only matches fields where the qualifier or * language is actually <code>null</code>.<code>Item.ANY</code> will * match any element, qualifier or language, including <code>null</code>. * Thus, <code>item.clearDC(Item.ANY, Item.ANY, Item.ANY)</code> will * remove all Dublin Core metadata associated with an item. * * @param element * the Dublin Core element to remove, or <code>Item.ANY</code> * @param qualifier * the qualifier. <code>null</code> means unqualified, and * <code>Item.ANY</code> means any qualifier (including * unqualified.) * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means only * values with no language are removed, and <code>Item.ANY</code> * means values with any country code or no country code are * removed. */ public void clearDC(String element, String qualifier, String lang) { clearMetadata(MetadataSchema.DC_SCHEMA, element, qualifier, lang); } /** * Clear metadata values. As with <code>getDC</code> above, * passing in <code>null</code> only matches fields where the qualifier or * language is actually <code>null</code>.<code>Item.ANY</code> will * match any element, qualifier or language, including <code>null</code>. * Thus, <code>item.clearDC(Item.ANY, Item.ANY, Item.ANY)</code> will * remove all Dublin Core metadata associated with an item. * * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the Dublin Core element to remove, or <code>Item.ANY</code> * @param qualifier * the qualifier. <code>null</code> means unqualified, and * <code>Item.ANY</code> means any qualifier (including * unqualified.) * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means only * values with no language are removed, and <code>Item.ANY</code> * means values with any country code or no country code are * removed. */ public void clearMetadata(String schema, String element, String qualifier, String lang) { // We will build a list of values NOT matching the values to clear List values = new ArrayList(); Iterator i = dublinCore.iterator(); while (i.hasNext()) { DCValue dcv = (DCValue) i.next(); if (!match(schema, element, qualifier, lang, dcv)) { values.add(dcv); } } // Now swap the old list of values for the new, unremoved values dublinCore = values; dublinCoreChanged = true; } /** * Utility method for pattern-matching metadata elements. This * method will return <code>true</code> if the given schema, * element, qualifier and language match the schema, element, * qualifier and language of the <code>DCValue</code> object passed * in. Any or all of the elemenent, qualifier and language passed * in can be the <code>Item.ANY</code> wildcard. * * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the element to match, or <code>Item.ANY</code> * @param qualifier * the qualifier to match, or <code>Item.ANY</code> * @param language * the language to match, or <code>Item.ANY</code> * @param dcv * the Dublin Core value * @return <code>true</code> if there is a match */ private boolean match(String schema, String element, String qualifier, String language, DCValue dcv) { // We will attempt to disprove a match - if we can't we have a match if (!element.equals(Item.ANY) && !element.equals(dcv.element)) { // Elements do not match, no wildcard return false; } if (qualifier == null) { // Value must be unqualified if (dcv.qualifier != null) { // Value is qualified, so no match return false; } } else if (!qualifier.equals(Item.ANY)) { // Not a wildcard, so qualifier must match exactly if (!qualifier.equals(dcv.qualifier)) { return false; } } if (language == null) { // Value must be null language to match if (dcv.language != null) { // Value is qualified, so no match return false; } } else if (!language.equals(Item.ANY)) { // Not a wildcard, so language must match exactly if (!language.equals(dcv.language)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -