Search in sources :

Example 1 with JspConfigMetaData

use of org.jboss.metadata.web.spec.JspConfigMetaData in project wildfly by wildfly.

the class UndertowDeploymentInfoService method createJspConfig.

private static HashMap<String, JspPropertyGroup> createJspConfig(JBossWebMetaData metaData) {
    final HashMap<String, JspPropertyGroup> result = new HashMap<>();
    // Jakarta Server Pages Config
    JspConfigMetaData config = metaData.getJspConfig();
    if (config != null) {
        // Jakarta Server Pages Property groups
        List<JspPropertyGroupMetaData> groups = config.getPropertyGroups();
        if (groups != null) {
            for (JspPropertyGroupMetaData group : groups) {
                org.apache.jasper.deploy.JspPropertyGroup jspPropertyGroup = new org.apache.jasper.deploy.JspPropertyGroup();
                for (String pattern : group.getUrlPatterns()) {
                    jspPropertyGroup.addUrlPattern(pattern);
                }
                jspPropertyGroup.setElIgnored(group.getElIgnored());
                jspPropertyGroup.setPageEncoding(group.getPageEncoding());
                jspPropertyGroup.setScriptingInvalid(group.getScriptingInvalid());
                jspPropertyGroup.setIsXml(group.getIsXml());
                if (group.getIncludePreludes() != null) {
                    for (String includePrelude : group.getIncludePreludes()) {
                        jspPropertyGroup.addIncludePrelude(includePrelude);
                    }
                }
                if (group.getIncludeCodas() != null) {
                    for (String includeCoda : group.getIncludeCodas()) {
                        jspPropertyGroup.addIncludeCoda(includeCoda);
                    }
                }
                jspPropertyGroup.setDeferredSyntaxAllowedAsLiteral(group.getDeferredSyntaxAllowedAsLiteral());
                jspPropertyGroup.setTrimDirectiveWhitespaces(group.getTrimDirectiveWhitespaces());
                jspPropertyGroup.setDefaultContentType(group.getDefaultContentType());
                jspPropertyGroup.setBuffer(group.getBuffer());
                jspPropertyGroup.setErrorOnUndeclaredNamespace(group.getErrorOnUndeclaredNamespace());
                for (String pattern : jspPropertyGroup.getUrlPatterns()) {
                    // Split off the groups to individual mappings
                    result.put(pattern, jspPropertyGroup);
                }
            }
        }
    }
    // it looks like jasper needs these in order of least specified to most specific
    final LinkedHashMap<String, JspPropertyGroup> ret = new LinkedHashMap<>();
    final ArrayList<String> paths = new ArrayList<>(result.keySet());
    Collections.sort(paths, new Comparator<String>() {

        @Override
        public int compare(final String o1, final String o2) {
            return o1.length() - o2.length();
        }
    });
    for (String path : paths) {
        ret.put(path, result.get(path));
    }
    return ret;
}
Also used : JspPropertyGroup(org.apache.jasper.deploy.JspPropertyGroup) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JspConfigMetaData(org.jboss.metadata.web.spec.JspConfigMetaData) ArrayList(java.util.ArrayList) JspPropertyGroupMetaData(org.jboss.metadata.web.spec.JspPropertyGroupMetaData) JspPropertyGroup(org.apache.jasper.deploy.JspPropertyGroup) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with JspConfigMetaData

use of org.jboss.metadata.web.spec.JspConfigMetaData in project wildfly by wildfly.

the class TldParsingDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
        return;
    }
    TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    if (tldsMetaData == null) {
        tldsMetaData = new TldsMetaData();
        deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
    }
    Map<String, TldMetaData> tlds = new HashMap<String, TldMetaData>();
    tldsMetaData.setTlds(tlds);
    final List<TldMetaData> uniqueTlds = new ArrayList<>();
    final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final List<VirtualFile> testRoots = new ArrayList<VirtualFile>();
    testRoots.add(deploymentRoot);
    testRoots.add(deploymentRoot.getChild(WEB_INF));
    testRoots.add(deploymentRoot.getChild(META_INF));
    for (ResourceRoot root : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
        testRoots.add(root.getRoot());
        testRoots.add(root.getRoot().getChild(META_INF));
        testRoots.add(root.getRoot().getChild(META_INF).getChild(RESOURCES));
    }
    JspConfigMetaData merged = warMetaData.getMergedJBossWebMetaData().getJspConfig();
    if (merged != null && merged.getTaglibs() != null) {
        for (final TaglibMetaData tld : merged.getTaglibs()) {
            boolean found = false;
            for (final VirtualFile root : testRoots) {
                VirtualFile child = root.getChild(tld.getTaglibLocation());
                if (child.exists()) {
                    if (isTldFile(child)) {
                        TldMetaData value = processTld(deploymentRoot, child, tlds, uniqueTlds);
                        if (!tlds.containsKey(tld.getTaglibUri())) {
                            tlds.put(tld.getTaglibUri(), value);
                        }
                    }
                    found = true;
                    break;
                }
            }
            if (!found) {
                UndertowLogger.ROOT_LOGGER.tldNotFound(tld.getTaglibLocation());
            }
        }
    }
    // TLDs are located in WEB-INF or any subdir (except the top level "classes" and "lib")
    // and in JARs from WEB-INF/lib, in META-INF or any subdir
    List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            VirtualFile webFragment = resourceRoot.getRoot().getChild(META_INF);
            if (webFragment.exists() && webFragment.isDirectory()) {
                processTlds(deploymentRoot, webFragment.getChildren(), tlds, uniqueTlds);
            }
        }
    }
    VirtualFile webInf = deploymentRoot.getChild(WEB_INF);
    if (webInf.exists() && webInf.isDirectory()) {
        for (VirtualFile file : webInf.getChildren()) {
            if (isTldFile(file)) {
                processTld(deploymentRoot, file, tlds, uniqueTlds);
            } else if (file.isDirectory() && !CLASSES.equals(file.getName()) && !LIB.equals(file.getName())) {
                processTlds(deploymentRoot, file.getChildren(), tlds, uniqueTlds);
            }
        }
    }
    JBossWebMetaData mergedMd = warMetaData.getMergedJBossWebMetaData();
    if (mergedMd.getListeners() == null) {
        mergedMd.setListeners(new ArrayList<ListenerMetaData>());
    }
    final ArrayList<TldMetaData> allTlds = new ArrayList<>(uniqueTlds);
    allTlds.addAll(tldsMetaData.getSharedTlds(deploymentUnit));
    for (final TldMetaData tld : allTlds) {
        if (tld.getListeners() != null) {
            for (ListenerMetaData l : tld.getListeners()) {
                mergedMd.getListeners().add(l);
            }
        }
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) VirtualFile(org.jboss.vfs.VirtualFile) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) ArrayList(java.util.ArrayList) JspConfigMetaData(org.jboss.metadata.web.spec.JspConfigMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) TaglibMetaData(org.jboss.metadata.web.spec.TaglibMetaData) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JspConfigMetaData (org.jboss.metadata.web.spec.JspConfigMetaData)2 LinkedHashMap (java.util.LinkedHashMap)1 JspPropertyGroup (org.apache.jasper.deploy.JspPropertyGroup)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 WarMetaData (org.jboss.as.web.common.WarMetaData)1 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)1 JspPropertyGroupMetaData (org.jboss.metadata.web.spec.JspPropertyGroupMetaData)1 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)1 TaglibMetaData (org.jboss.metadata.web.spec.TaglibMetaData)1 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)1 VirtualFile (org.jboss.vfs.VirtualFile)1