use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class FacesConfigDescriptor method readFacesConfigDocument.
private void readFacesConfigDocument(WebBundleDescriptor webd) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// TODO: Why are we turning off validation here?
factory.setValidating(false);
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder builder = factory.newDocumentBuilder();
ModuleDescriptor moduleDesc = webd.getModuleDescriptor();
String archBase = context.getAbstractArchive().getURI().toString();
String uri = null;
if (moduleDesc.isStandalone()) {
uri = archBase;
} else {
uri = archBase + File.separator + FileUtils.makeFriendlyFilename(moduleDesc.getArchiveUri());
}
FileArchive arch = new FileArchive();
arch.open(URI.create(uri));
InputStream is = arch.getEntry(facesConfigFileName);
InputSource source = new InputSource(is);
try {
facesConfigDocument = builder.parse(source);
} finally {
try {
if (is != null)
is.close();
} catch (Exception e) {
}
}
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class TagLibFactory method createDocument.
/**
* Helper method to create the document object from the tld files specified
* by the location in web.xml of the war archive.
*
* @param location location of jsp tlds
* @param webd has all the information about the web.xml of the war archive
* @return document object created from tlds specified at the given location
* @throws IOException
* @throws SAXException
*/
private Document createDocument(String location, WebBundleDescriptor webd) throws IOException, SAXException {
Document document = null;
InputSource source = null;
if (// NOI18N
location.startsWith("/"))
location = location.substring(1);
else
// NOI18N
location = "WEB-INF/" + location;
ModuleDescriptor moduleDesc = webd.getModuleDescriptor();
String archBase = context.getAbstractArchive().getURI().getPath();
String uri = null;
if (moduleDesc.isStandalone()) {
uri = archBase;
} else {
uri = archBase + File.separator + FileUtils.makeFriendlyFilename(moduleDesc.getArchiveUri());
}
FileArchive arch = new FileArchive();
arch.open(uri);
InputStream is = arch.getEntry(location);
try {
// is can be null if wrong location of tld is specified in web.xml
if (is == null)
throw new IOException(smh.getLocalString(// NOI18N
getClass().getName() + ".exception1", // NOI18N
"Wrong tld [ {0} ] specified in the web.xml of [ {1} ]", new Object[] { location, moduleDesc.getArchiveUri() }));
source = new InputSource(is);
document = builder.parse(source);
} finally {
try {
if (is != null)
is.close();
} catch (Exception e) {
}
}
return document;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class FormLoginPage method check.
/**
* The Web form-login-page value defines the location in the web application
* where the page can be used for login page can be found within web application
* test
*
* @param descriptor the Web deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(WebBundleDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor.getLoginConfiguration() != null) {
boolean foundIt = false;
// ZipEntry ze = null;
// JarFile jar =null;
FileArchive arch = null;
String formLoginPage = descriptor.getLoginConfiguration().getFormLoginPage();
if (formLoginPage.length() > 0) {
try {
// File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
// if(f==null){
String uri = getAbstractArchiveUri(descriptor);
try {
arch = new FileArchive();
arch.open(uri);
} catch (IOException e) {
throw e;
}
// }
if (formLoginPage.startsWith("/"))
formLoginPage = formLoginPage.substring(1);
// if (f!=null){
// ze = jar.getEntry(formLoginPage);
// foundIt = (ze != null);
// }
// else{
File flp = new File(new File(arch.getURI()), formLoginPage);
if (flp.exists())
foundIt = true;
flp = null;
// }
// if (jar!=null)
// jar.close();
} catch (Exception ex) {
// should be aldready set?
foundIt = false;
}
if (foundIt) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The form-login-page [ {0} ] value does define the location in the web application [ {1} ] where the page can be used for login page can be found.", new Object[] { formLoginPage, descriptor.getName() }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: The form-login-page [ {0} ] value does not define the location in the web application [ {1} ] where the page to be used for the login page can be found.", new Object[] { formLoginPage, descriptor.getName() }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no form-login-page name elements within this web archive [ {0} ]", new Object[] { descriptor.getName() }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no form-login-page name elements within this web archive [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class JspFile method check.
/**
* Jsp file element contains the full path to Jsp file within web application
* test.
*
* @param descriptor the Web deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(WebBundleDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!descriptor.getJspDescriptors().isEmpty()) {
boolean oneFailed = false;
boolean foundIt = false;
// ZipEntry ze=null;
// JarFile jar=null;
FileArchive arch = null;
// get the jsps in this .war
Set jsps = descriptor.getJspDescriptors();
Iterator itr = jsps.iterator();
// test the jsps in this .war
while (itr.hasNext()) {
foundIt = false;
WebComponentDescriptor jsp = (WebComponentDescriptor) itr.next();
String jspFilename = jsp.getWebComponentImplementation();
String uri = null;
try {
// File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
// if(f==null){
uri = getAbstractArchiveUri(descriptor);
try {
arch = new FileArchive();
arch.open(uri);
} catch (IOException e) {
throw e;
}
if (jspFilename.startsWith("/"))
jspFilename = jspFilename.substring(1);
// if(f!=null){
// ze = jar.getEntry(jspFilename);
// foundIt=(ze !=null);
// }else{
File jspf = new File(new File(arch.getURI()), jspFilename);
if (jspf.exists())
foundIt = true;
jspf = null;
// }
// if (jar!=null)
// jar.close();
} catch (Exception e) {
if (!oneFailed) {
oneFailed = true;
}
}
if (foundIt) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Jsp file [ {0} ] contains the full path to Jsp file within web application [ {1} ]", new Object[] { jspFilename, descriptor.getName() }));
} else {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Jsp file [ {0} ] is not found within [ {1} ] or does not contain the full path to Jsp file within web application [ {2} ]", new Object[] { jspFilename, uri, descriptor.getName() }));
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no Jsp components within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class Location method check.
/**
* Location element contains the location of the resource in the web
* application
*
* @param descriptor the Web deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(WebBundleDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
boolean oneFailed = false;
boolean foundIt = false;
// ZipEntry ze = null;
// JarFile jar =null;
FileArchive arch = null;
// get the errorpage's in this .war
for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
foundIt = false;
ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
String location = errorpage.getLocation();
String uri = null;
try {
// File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
// if(f==null){
uri = getAbstractArchiveUri(descriptor);
try {
arch = new FileArchive();
arch.open(uri);
} catch (IOException ioe) {
throw ioe;
}
// }
if (location.startsWith("/"))
location = location.substring(1);
// if (f!=null){
// ze = jar.getEntry(location);
// foundIt = (ze != null);
// }
// else{
File loc = new File(new File(arch.getURI()), location);
if (loc.exists())
foundIt = true;
loc = null;
// }
// if (jar!=null)
// jar.close();
} catch (Exception ex) {
if (!oneFailed) {
oneFailed = true;
}
}
if (foundIt) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Location [ {0} ] contains the location of the resource within web application [ {1} ]", new Object[] { location, descriptor.getName() }));
} else {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Location [ {0} ] is not found within [ {1} ] or does not contain the location of the resource within web application [ {2} ]", new Object[] { location, uri, descriptor.getName() }));
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no location elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
Aggregations