[8164] | 1 | /**
|
---|
| 2 | *############################################################################
|
---|
| 3 | * A component of the Greenstone Librarian Interface, part of the Greenstone
|
---|
| 4 | * digital library suite from the New Zealand Digital Library Project at the
|
---|
| 5 | * University of Waikato, New Zealand.
|
---|
| 6 | *
|
---|
| 7 | * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
|
---|
| 8 | *
|
---|
| 9 | * Copyright (C) 2004 New Zealand Digital Library Project
|
---|
| 10 | *
|
---|
| 11 | * This program is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | *############################################################################
|
---|
| 25 | */
|
---|
| 26 |
|
---|
[7822] | 27 | package org.greenstone.gatherer.metadata;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | import java.io.*;
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | /** This class represents one metadata (element, value) pair */
|
---|
| 34 | public class MetadataValue
|
---|
[7978] | 35 | implements Comparable
|
---|
[7822] | 36 | {
|
---|
[7978] | 37 | /** The folder that this piece of metadata was inherited from, if applicable */
|
---|
| 38 | private File folder_metadata_inherited_from = null;
|
---|
| 39 | private MetadataElement metadata_element = null;
|
---|
| 40 | private MetadataValueTreeNode metadata_value_tree_node = null;
|
---|
[23394] | 41 | // this will be set to true if the metadata element definition says accumulating = false.
|
---|
| 42 | private boolean must_not_accumulate = false;
|
---|
[7978] | 43 | private boolean is_accumulating_metadata = false;
|
---|
[11301] | 44 | /** Whether this metadata applies to only one file (ie. there are no wildcards in the FileSet value) */
|
---|
| 45 | private boolean is_one_file_only_metadata = true;
|
---|
[7822] | 46 |
|
---|
| 47 |
|
---|
[7978] | 48 | public MetadataValue(MetadataElement metadata_element, MetadataValueTreeNode metadata_value_tree_node)
|
---|
| 49 | {
|
---|
| 50 | this.metadata_element = metadata_element;
|
---|
| 51 | this.metadata_value_tree_node = metadata_value_tree_node;
|
---|
[23394] | 52 | if (metadata_element != null) {
|
---|
| 53 | if (!metadata_element.isAccumulating()) {
|
---|
| 54 | must_not_accumulate = true;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
[7978] | 57 | }
|
---|
[7822] | 58 |
|
---|
| 59 |
|
---|
[7978] | 60 | public int compareTo(Object metadata_value_object)
|
---|
| 61 | {
|
---|
| 62 | MetadataValue metadata_value = (MetadataValue) metadata_value_object;
|
---|
[7822] | 63 |
|
---|
[7978] | 64 | // First compare the metadata elements
|
---|
| 65 | int c = MetadataSetManager.compareMetadataElements(this.getMetadataElement(), metadata_value.getMetadataElement());
|
---|
| 66 | if (c != 0) {
|
---|
| 67 | return c;
|
---|
| 68 | }
|
---|
[7822] | 69 |
|
---|
[7978] | 70 | // Then use the metadata values
|
---|
| 71 | return this.getFullValue().compareTo(metadata_value.getFullValue());
|
---|
| 72 | }
|
---|
[7822] | 73 |
|
---|
| 74 |
|
---|
[7978] | 75 | public File getFolderMetadataInheritedFrom()
|
---|
| 76 | {
|
---|
| 77 | return folder_metadata_inherited_from;
|
---|
| 78 | }
|
---|
[7822] | 79 |
|
---|
| 80 |
|
---|
[7978] | 81 | public MetadataElement getMetadataElement()
|
---|
| 82 | {
|
---|
| 83 | return metadata_element;
|
---|
| 84 | }
|
---|
[7822] | 85 |
|
---|
| 86 |
|
---|
[7978] | 87 | public String getFullValue()
|
---|
| 88 | {
|
---|
| 89 | return metadata_value_tree_node.getFullValue();
|
---|
| 90 | }
|
---|
[7822] | 91 |
|
---|
| 92 |
|
---|
[7978] | 93 | public String getValue()
|
---|
| 94 | {
|
---|
| 95 | return metadata_value_tree_node.getValue();
|
---|
| 96 | }
|
---|
[7822] | 97 |
|
---|
| 98 |
|
---|
[7978] | 99 | public MetadataValueTreeNode getMetadataValueTreeNode()
|
---|
| 100 | {
|
---|
| 101 | return metadata_value_tree_node;
|
---|
| 102 | }
|
---|
[7822] | 103 |
|
---|
| 104 |
|
---|
[7978] | 105 | public void inheritsMetadataFromFolder(File folder_metadata_inherited_from)
|
---|
| 106 | {
|
---|
| 107 | this.folder_metadata_inherited_from = folder_metadata_inherited_from;
|
---|
| 108 | }
|
---|
[7822] | 109 |
|
---|
| 110 |
|
---|
[7978] | 111 | public boolean isAccumulatingMetadata()
|
---|
| 112 | {
|
---|
| 113 | return is_accumulating_metadata;
|
---|
| 114 | }
|
---|
[7827] | 115 |
|
---|
| 116 |
|
---|
[7978] | 117 | public boolean isInheritedMetadata()
|
---|
| 118 | {
|
---|
| 119 | return (folder_metadata_inherited_from != null);
|
---|
| 120 | }
|
---|
[7827] | 121 |
|
---|
| 122 |
|
---|
[11301] | 123 | public boolean isOneFileOnlyMetadata()
|
---|
| 124 | {
|
---|
| 125 | return is_one_file_only_metadata;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|
[7978] | 129 | public void setIsAccumulatingMetadata(boolean is_accumulating_metadata)
|
---|
| 130 | {
|
---|
[23394] | 131 | if (!must_not_accumulate) {
|
---|
[7978] | 132 | this.is_accumulating_metadata = is_accumulating_metadata;
|
---|
[23394] | 133 | }
|
---|
[7978] | 134 | }
|
---|
[11301] | 135 |
|
---|
| 136 |
|
---|
| 137 | public void setIsOneFileOnlyMetadata(boolean is_one_file_only_metadata)
|
---|
| 138 | {
|
---|
| 139 | this.is_one_file_only_metadata = is_one_file_only_metadata;
|
---|
| 140 | }
|
---|
[7822] | 141 | }
|
---|