}
InputSource source = new InputSource(stream);
Unmarshaller unmarshaller;
try {
unmarshaller = new Unmarshaller(portletXmlMapping);
unmarshaller.setEntityResolver(new EntityResolver(Constants.RES_PORTLET_DTDS, Constants.RES_PORTLET_DTD_NAMES));
} catch (MappingException e) {
throw (UnavailableException) new UnavailableException("Unable to construct unmarshaller for portlet.xml at context " + contextName).initCause(e);
}
unmarshaller.setIgnoreExtraElements(true);
PortletApplicationDefinitionImpl portletApp;
try {
portletApp = (PortletApplicationDefinitionImpl) unmarshaller.unmarshal(source);
} catch (MarshalException e) {
throw (UnavailableException) new UnavailableException("Unable to unmarshal portlet.xml from context " + contextName).initCause(e);
} catch (ValidationException e) {
throw (UnavailableException) new UnavailableException("Unable to validate portlet.xml from context " + contextName).initCause(e);
}
// load its web.xml
stream = appContext.getResourceAsStream("/WEB-INF/web.xml");
if (stream == null) {
throw new UnavailableException("No web.xml found in context " + contextName);
}
source = new InputSource(stream);
try {
unmarshaller = new Unmarshaller(webXmlMapping);
unmarshaller.setEntityResolver(new EntityResolver(Constants.RES_WEB_PUBLIC_ID,
Constants.RES_WEB_DTD,
Constants.RES_WEB_DTD_NAME));
} catch (MappingException e) {
throw (UnavailableException) new UnavailableException("Unable to construct unmarshaller for web.xml from context " + contextName + ". Error message: " + e.getMessage()).initCause(e);
}