001: /*
002: * Copyright 2007 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not 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.
015: */
016: package org.outerj.daisy.publisher.serverimpl.httphandlers;
017:
018: import org.outerj.daisy.httpconnector.spi.HttpUtil;
019: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
020: import org.outerj.daisy.repository.Repository;
021: import org.outerj.daisy.xmlutil.XmlSerializer;
022: import org.outerj.daisy.publisher.Publisher;
023: import org.outerj.daisy.util.HttpConstants;
024: import org.outerx.daisy.x10Publisher.*;
025: import org.xml.sax.ContentHandler;
026:
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029: import java.util.Map;
030:
031: /**
032: * Upon special request:
033: * This URL offers a built-in publisher request that can be performed using GET, and is
034: * equivalent to the /publisher/documentPage request available in Daisy 1.2
035: *
036: */
037: public class PubDocumentHandler extends AbstractPublisherRequestHandler {
038: public void handleRequest(Map matchMap, HttpServletRequest request,
039: HttpServletResponse response, Repository repository,
040: RequestHandlerSupport support) throws Exception {
041: if (request.getMethod().equals(HttpConstants.GET)) {
042: String documentId = HttpUtil.getStringParam(request,
043: "documentId");
044: String locale = HttpUtil.getStringParam(request, "locale");
045: String version = HttpUtil
046: .getStringParam(request, "version");
047: boolean includeNavigation = HttpUtil.getBooleanParam(
048: request, "includeNavigation");
049: String navigationDocId = null;
050: String activePath = null;
051: boolean contextualized = true;
052: if (includeNavigation) {
053: navigationDocId = HttpUtil.getStringParam(request,
054: "navigationDocId");
055: activePath = request.getParameter("activePath"); // this is allowed to be null
056: contextualized = HttpUtil.getBooleanParam(request,
057: "contextualized");
058: }
059:
060: String branch = String.valueOf(HttpUtil.getBranchId(
061: request, repository));
062: String language = String.valueOf(HttpUtil.getLanguageId(
063: request, repository));
064:
065: PublisherRequestDocument publisherRequestDocument = PublisherRequestDocument.Factory
066: .newInstance();
067: PublisherRequestDocument.PublisherRequest publisherRequest = publisherRequestDocument
068: .addNewPublisherRequest();
069: publisherRequest.setLocale(locale);
070: DocumentDocument.Document pubDocReq = publisherRequest
071: .addNewDocument();
072: pubDocReq.setId(documentId);
073: pubDocReq.setBranch(branch);
074: pubDocReq.setLanguage(language);
075: pubDocReq.setVersion(version);
076: pubDocReq.addNewAclInfo();
077: pubDocReq.addNewSubscriptionInfo();
078: pubDocReq.addNewShallowAnnotatedVersion();
079: pubDocReq.addNewAnnotatedDocument();
080: PreparedDocumentsDocument.PreparedDocuments prepDocReq = pubDocReq
081: .addNewPreparedDocuments();
082: PreparedDocumentsDocument.PreparedDocuments.Context prepDocReqContext = prepDocReq
083: .addNewContext();
084: prepDocReqContext.setBranch(branch);
085: prepDocReqContext.setLanguage(language);
086: if (includeNavigation) {
087: VariantKeyType prepDocNav = prepDocReq
088: .addNewNavigationDocument();
089: prepDocNav.setId(navigationDocId);
090: prepDocNav.setBranch(branch);
091: prepDocNav.setLanguage(language);
092: }
093: pubDocReq.addNewComments();
094: if (includeNavigation) {
095: NavigationTreeDocument.NavigationTree navigationTreeReq = publisherRequest
096: .addNewNavigationTree();
097: VariantKeyType navDoc = navigationTreeReq
098: .addNewNavigationDocument();
099: navDoc.setId(navigationDocId);
100: navDoc.setBranch(branch);
101: navDoc.setLanguage(language);
102: VariantKeyType activeDoc = navigationTreeReq
103: .addNewActiveDocument();
104: activeDoc.setId(documentId);
105: activeDoc.setBranch(branch);
106: activeDoc.setLanguage(language);
107: if (activePath != null) {
108: navigationTreeReq.setActivePath(activePath);
109: }
110: navigationTreeReq.setContextualized(contextualized);
111: }
112:
113: ContentHandler serializer = new XmlSerializer(response
114: .getOutputStream());
115:
116: Publisher publisher = (Publisher) repository
117: .getExtension("Publisher");
118: publisher.processRequest(publisherRequestDocument,
119: serializer);
120:
121: } else {
122: response.sendError(HttpConstants._405_Method_Not_Allowed);
123: }
124: }
125:
126: public String getPathPattern() {
127: return "/document";
128: }
129: }
|