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;
019:
020: import java.io.Reader;
021: import java.util.ArrayList;
022: import java.util.List;
023: import javax.servlet.http.HttpServletRequest;
024:
025: import org.apache.roller.webservices.adminapi.sdk.Entry;
026: import org.apache.roller.webservices.adminapi.sdk.EntrySet;
027: import org.apache.roller.webservices.adminapi.sdk.Service;
028: import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
029: import org.jdom.Document;
030:
031: /**
032: * This class handles requests for the AAPP introspection document.
033: * It only processes HTTP GET requests.
034: *
035: * @author jtb
036: */
037: class IntrospectionHandler extends Handler {
038: public IntrospectionHandler(HttpServletRequest request)
039: throws HandlerException {
040: super (request);
041: }
042:
043: protected EntrySet getEntrySet(Document d)
044: throws UnexpectedRootElementException {
045: throw new UnsupportedOperationException();
046: }
047:
048: public EntrySet processGet() throws HandlerException {
049: if (getUri().isIntrospection()) {
050: return getIntrospection(getRequest());
051: } else {
052: throw new BadRequestException("ERROR: Unknown GET URI type");
053: }
054: }
055:
056: public EntrySet processPost(Reader r) {
057: throw new UnsupportedOperationException(
058: "ERROR: POST not supported in this handler");
059: }
060:
061: public EntrySet processPut(Reader r) {
062: throw new UnsupportedOperationException(
063: "ERROR: PUT not supported in this handler");
064: }
065:
066: public EntrySet processDelete() {
067: throw new UnsupportedOperationException(
068: "ERROR: DELETE not supported in this handler");
069: }
070:
071: private Service getIntrospection(HttpServletRequest req) {
072: String href = getUrlPrefix();
073: Service service = new Service(href);
074:
075: Service.Workspace workspace = new Service.Workspace();
076: workspace.setTitle("Workspace: Collections for administration");
077: workspace.setHref(service.getHref());
078: service.setEntries(new Entry[] { workspace });
079:
080: List workspaceCollections = new ArrayList();
081:
082: Service.Workspace.Collection weblogCol = new Service.Workspace.Collection();
083: weblogCol.setTitle("Collection: Weblog administration entries");
084: weblogCol
085: .setMemberType(org.apache.roller.webservices.adminapi.sdk.Entry.Types.WEBLOG);
086: weblogCol
087: .setHref(service.getHref()
088: + "/"
089: + org.apache.roller.webservices.adminapi.sdk.EntrySet.Types.WEBLOGS);
090: workspaceCollections.add(weblogCol);
091:
092: Service.Workspace.Collection userCol = new Service.Workspace.Collection();
093: userCol.setTitle("Collection: User administration entries");
094: userCol.setMemberType("user");
095: userCol
096: .setHref(service.getHref()
097: + "/"
098: + org.apache.roller.webservices.adminapi.sdk.EntrySet.Types.USERS);
099: workspaceCollections.add(userCol);
100:
101: Service.Workspace.Collection memberCol = new Service.Workspace.Collection();
102: memberCol.setTitle("Collection: Member administration entries");
103: memberCol.setMemberType("member");
104: memberCol
105: .setHref(service.getHref()
106: + "/"
107: + org.apache.roller.webservices.adminapi.sdk.EntrySet.Types.MEMBERS);
108: workspaceCollections.add(memberCol);
109:
110: workspace.setEntries((Entry[]) workspaceCollections
111: .toArray(new Entry[0]));
112:
113: return service;
114: }
115: }
|