001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.webservices.adminapi.sdk;
019:
020: import java.io.IOException;
021: import java.io.StringWriter;
022: import java.io.Writer;
023: import java.util.Arrays;
024: import org.jdom.Document;
025: import org.jdom.Namespace;
026: import org.jdom.output.Format;
027: import org.jdom.output.XMLOutputter;
028:
029: /**
030: * This class is the abstract notion of an entry.
031: * Weblog resources are represented by sets of entries.
032: */
033: public abstract class Entry {
034: protected static final Namespace NAMESPACE = Namespace
035: .getNamespace("http://purl.org/apache/roller/aapp#");
036:
037: /** Entry types. */
038: public static interface Types {
039: /**
040: * User entry.
041: * A user entry is contained within a user entry set.
042: */
043: public static final String USER = "user";
044: /**
045: * Weblog entry.
046: * A weblog entry is contained within a weblog entry set.
047: */
048: public static final String WEBLOG = "weblog";
049: /**
050: * Member entry.
051: * A member entry is contained within a member entry set.
052: */
053: public static final String MEMBER = "member";
054: /**
055: * Collection entry.
056: * A collection entry is contained within a workspace, which is
057: * contained within a service.
058: */
059: public static final String COLLECTION = "collection";
060: }
061:
062: /** XML attributes common to all entry types. */
063: protected static interface Attributes {
064: public static final String HREF = "href";
065: }
066:
067: private String href = null;
068:
069: /** Get the HREF that identifies this entry. */
070: public String getHref() {
071: return href;
072: }
073:
074: /** Set the HREF that identifies this entry. */
075: public void setHref(String href) {
076: this .href = href;
077: }
078:
079: /** This entry, as a JDOM Document object. */
080: public abstract Document toDocument();
081:
082: /**
083: * This entry, as a String (XML).
084: */
085: public String toString() {
086: Writer writer = new StringWriter();
087: XMLOutputter outputter = new XMLOutputter();
088: outputter.setFormat(Format.getPrettyFormat());
089: try {
090: outputter.output(toDocument(), writer);
091: writer.close();
092: } catch (IOException ioe) {
093: throw new IllegalStateException(ioe.getMessage());
094: }
095:
096: return writer.toString();
097: }
098:
099: public abstract String getType();
100:
101: public boolean equals(Object o) {
102: if (o == null || o.getClass() != this .getClass()) {
103: return false;
104: }
105:
106: Entry other = (Entry) o;
107:
108: if (!areEqual(getHref(), other.getHref())) {
109: return false;
110: }
111: if (!areEqual(getType(), other.getType())) {
112: return false;
113: }
114:
115: return true;
116: }
117:
118: protected static boolean areEqual(Object o1, Object o2) {
119: return o1 == null ? o2 == null : o1.equals(o2);
120: }
121:
122: protected static boolean areEqual(Object[] oa1, Object[] oa2) {
123: return oa1 == null ? oa2 == null : Arrays.equals(oa1, oa2);
124: }
125: }
|