001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.publication;
019:
020: /**
021: * Value object to identify documents.
022: */
023: public class DocumentIdentifier {
024:
025: private String publicationId;
026: private String area;
027: private String language;
028: private String uuid;
029:
030: /**
031: * Ctor.
032: * @param pubId The publication ID.
033: * @param area The area.
034: * @param uuid The document UUID.
035: * @param language The language.
036: */
037: public DocumentIdentifier(String pubId, String area, String uuid,
038: String language) {
039:
040: if (uuid.startsWith("/") && uuid.split("-").length == 4) {
041: throw new IllegalArgumentException("The UUID [" + uuid
042: + "] must not begin with a '/'!");
043: }
044: if (uuid.indexOf("/") > 0) {
045: throw new IllegalArgumentException(
046: "The UUID ["
047: + uuid
048: + "] must not contain a '/' after the first position!");
049: }
050:
051: this .publicationId = pubId;
052: this .area = area;
053: this .language = language;
054: this .uuid = uuid;
055: }
056:
057: /**
058: * @return The UUID.
059: */
060: public String getUUID() {
061: return this .uuid;
062: }
063:
064: /**
065: * @return The area.
066: */
067: public String getArea() {
068: return area;
069: }
070:
071: /**
072: * @return The language.
073: */
074: public String getLanguage() {
075: return language;
076: }
077:
078: /**
079: * @return The publication ID.
080: */
081: public String getPublicationId() {
082: return publicationId;
083: }
084:
085: public boolean equals(Object obj) {
086: return (obj instanceof DocumentIdentifier)
087: && obj.hashCode() == hashCode();
088: }
089:
090: public int hashCode() {
091: return getKey().hashCode();
092: }
093:
094: protected String getKey() {
095: return this .publicationId + ":" + this .area + ":" + this .uuid
096: + ":" + this .language;
097: }
098:
099: public String toString() {
100: return getKey();
101: }
102:
103: }
|