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: package org.apache.pluto.descriptors.services.castor;
018:
019: import org.apache.pluto.descriptors.portlet.PortletAppDD;
020: import org.apache.pluto.descriptors.services.Constants;
021: import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
022: import org.exolab.castor.mapping.Mapping;
023: import org.exolab.castor.mapping.MappingException;
024:
025: import java.io.IOException;
026: import java.io.InputStream;
027: import java.io.OutputStream;
028: import java.net.URL;
029:
030: /**
031: * Abstract Implementation of the Web Application Deployment
032: * Descriptor service. Provides default implementation of
033: * the service; requiring only that subclasses provide the
034: * input streams to/from the actual descriptor.
035: *
036: * @version $Id: PortletAppDescriptorServiceImpl.java 156743 2005-03-10 05:50:30Z ddewolf $
037: * @since Mar 5, 2005
038: */
039: public class PortletAppDescriptorServiceImpl extends
040: AbstractCastorDescriptorService implements
041: PortletAppDescriptorService {
042:
043: public static final String PORTLET_XML_MAPPING = "castor-portlet-xml-mapping.xml";
044:
045: /**
046: * Read the Web Application Deployment Descriptor.
047: *
048: * @return WebAppDD instance representing the descriptor.
049: * @throws java.io.IOException
050: */
051: public PortletAppDD read(InputStream in) throws IOException {
052: PortletAppDD portlet = (PortletAppDD) readInternal(in);
053: return portlet;
054: }
055:
056: /**
057: * Write the deployment descriptor.
058: * @param portlet
059: * @throws java.io.IOException
060: */
061: public void write(PortletAppDD portlet, OutputStream out)
062: throws IOException {
063: writeInternal(portlet, out);
064: }
065:
066: /**
067: * Retrieve the Web Application Deployment
068: * descriptor's public Id.
069: * @return
070: */
071: protected String getPublicId() {
072: return Constants.PORLTET_XML_PUBLIC_ID;
073: }
074:
075: /**
076: * Retrieve the Web Application Deployment
077: * descriptor's DTD uri.
078: * @return
079: */
080: protected String getDTDUri() {
081: return Constants.PORTLET_XML_DTD;
082: }
083:
084: /**
085: * Read and Retrieve the Web Application's Castor Mapping
086: * resource.
087: *
088: * @return
089: * @throws java.io.IOException
090: * @throws org.exolab.castor.mapping.MappingException
091: */
092: protected Mapping getCastorMapping() throws IOException,
093: MappingException {
094: URL url = getClass().getResource(PORTLET_XML_MAPPING);
095: if (url == null) {
096: throw new NullPointerException(
097: "Configuration Error. Resource: "
098: + PORTLET_XML_MAPPING + " not found.");
099: }
100: Mapping mapping = new Mapping();
101: mapping.loadMapping(url);
102: return mapping;
103: }
104:
105: protected boolean getIgnoreExtraElements() {
106: return true;
107: }
108: }
|