001/* 002 * Copyright 2012 Anyware Services 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 */ 016package org.ametys.odf.oai; 017 018import java.io.IOException; 019import java.util.Arrays; 020import java.util.Collection; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025import org.apache.cocoon.ProcessingException; 026import org.apache.cocoon.xml.XMLUtils; 027import org.xml.sax.SAXException; 028 029import org.ametys.odf.orgunit.OrgUnit; 030import org.ametys.odf.orgunit.RootOrgUnitProvider; 031import org.ametys.runtime.config.Config; 032 033/** 034 * Generator for the "Identify" OAI request. 035 */ 036public class IdentifyGenerator extends AbstractOAIVerbGenerator implements Serviceable 037{ 038 private RootOrgUnitProvider _rootOrgUnitProvider; 039 040 @Override 041 public void service(ServiceManager serviceManager) throws ServiceException 042 { 043 _rootOrgUnitProvider = (RootOrgUnitProvider) serviceManager.lookup(RootOrgUnitProvider.ROLE); 044 } 045 046 @Override 047 protected void generateVerb() throws IOException, SAXException, ProcessingException 048 { 049 XMLUtils.startElement(contentHandler, "Identify"); 050 051 OrgUnit rootOrgUnit = _rootOrgUnitProvider.getRoot(); 052 XMLUtils.createElement(contentHandler, "repositoryName", "Catalogue des formations \"" + rootOrgUnit.getTitle() + "\" (" + rootOrgUnit.getUAICode() + ")"); 053 XMLUtils.createElement(contentHandler, "baseURL", getURL()); 054 XMLUtils.createElement(contentHandler, "protocolVersion", "2.0"); 055 XMLUtils.createElement(contentHandler, "adminEmail", Config.getInstance().getValueAsString("smtp.mail.sysadminto")); 056 XMLUtils.createElement(contentHandler, "earliestDatestamp", "1970-01-01T00:00:00Z"); 057 XMLUtils.createElement(contentHandler, "deletedRecord", "no"); 058 XMLUtils.createElement(contentHandler, "granularity", "YYYY-MM-DDThh:mm:ssZ"); 059 060 XMLUtils.endElement(contentHandler, "Identify"); 061 } 062 063 @Override 064 protected Collection<String> getAllowedParameters() 065 { 066 return Arrays.asList("verb"); 067 } 068 069 @Override 070 protected Collection<String> getRequiredParameters() 071 { 072 return Arrays.asList("verb"); 073 } 074}