Search in sources :

Example 1 with TldMetaData

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

the class JSFSharedTldsProcessor method init.

private void init() {
    JSFModuleIdFactory moduleFactory = JSFModuleIdFactory.getInstance();
    List<String> jsfSlotNames = moduleFactory.getActiveJSFVersions();
    for (String slot : jsfSlotNames) {
        final List<TldMetaData> jsfTlds = new ArrayList<TldMetaData>();
        try {
            ModuleClassLoader jsf = Module.getModuleFromCallerModuleLoader(moduleFactory.getImplModId(slot)).getClassLoader();
            for (String tld : JSF_TAGLIBS) {
                InputStream is = jsf.getResourceAsStream("META-INF/" + tld);
                if (is != null) {
                    TldMetaData tldMetaData = parseTLD(is);
                    jsfTlds.add(tldMetaData);
                }
            }
        } catch (ModuleLoadException e) {
        // Ignore
        } catch (Exception e) {
        // Ignore
        }
        jsfTldMap.put(slot, jsfTlds);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 2 with TldMetaData

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

the class TldParsingDeploymentProcessor method processTlds.

private void processTlds(VirtualFile root, List<VirtualFile> files, Map<String, TldMetaData> tlds, final List<TldMetaData> uniqueTlds) throws DeploymentUnitProcessingException {
    for (VirtualFile file : files) {
        if (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
            String pathNameRelativeToRoot;
            try {
                pathNameRelativeToRoot = file.getPathNameRelativeTo(root);
            } catch (IllegalArgumentException e) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), root.getPathName()), e);
            }
            final TldMetaData value = parseTLD(file);
            String key = "/" + pathNameRelativeToRoot;
            uniqueTlds.add(value);
            if (!tlds.containsKey(key)) {
                tlds.put(key, value);
            }
        } else if (file.isDirectory()) {
            processTlds(root, file.getChildren(), tlds, uniqueTlds);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) TldMetaData(org.jboss.metadata.web.spec.TldMetaData)

Example 3 with TldMetaData

use of org.jboss.metadata.web.spec.TldMetaData 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));
    }
    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()) {
                    String pathNameRelativeToRoot;
                    try {
                        pathNameRelativeToRoot = child.getPathNameRelativeTo(deploymentRoot);
                    } catch (IllegalArgumentException e) {
                        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(child.getPathName(), deploymentRoot.getPathName()), e);
                    }
                    final TldMetaData value = parseTLD(child);
                    value.setUri(tld.getTaglibUri());
                    uniqueTlds.add(value);
                    String key = "/" + pathNameRelativeToRoot;
                    if (!tlds.containsKey(key)) {
                        tlds.put(key, value);
                    }
                    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 (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
                String pathNameRelativeToRoot;
                try {
                    pathNameRelativeToRoot = file.getPathNameRelativeTo(deploymentRoot);
                } catch (IllegalArgumentException e) {
                    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), deploymentRoot.getPathName()), e);
                }
                final TldMetaData value = parseTLD(file);
                uniqueTlds.add(value);
                String key = "/" + pathNameRelativeToRoot;
                if (!tlds.containsKey(key)) {
                    tlds.put(key, value);
                }
            } 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) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) 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)

Example 4 with TldMetaData

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

the class JSFSharedTldsProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit topLevelDeployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
    String jsfVersion = JsfVersionMarker.getVersion(topLevelDeployment);
    if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) {
        return;
    }
    // Add the shared TLDs metadata
    List<TldMetaData> tldsMetaData = deploymentUnit.getAttachment(SharedTldsMetaDataBuilder.ATTACHMENT_KEY);
    if (tldsMetaData == null)
        tldsMetaData = new ArrayList<TldMetaData>();
    String slot = jsfVersion;
    if (!JSFModuleIdFactory.getInstance().isValidJSFSlot(slot)) {
        slot = JSFModuleIdFactory.getInstance().getDefaultSlot();
    }
    slot = JSFModuleIdFactory.getInstance().computeSlot(slot);
    List<TldMetaData> jsfTlds = this.jsfTldMap.get(slot);
    if (jsfTlds != null)
        tldsMetaData.addAll(jsfTlds);
    deploymentUnit.putAttachment(SharedTldsMetaDataBuilder.ATTACHMENT_KEY, tldsMetaData);
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 5 with TldMetaData

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

the class UndertowDeploymentInfoService method createTldsInfo.

private static HashMap<String, TagLibraryInfo> createTldsInfo(final TldsMetaData tldsMetaData, List<TldMetaData> sharedTlds) throws ClassNotFoundException {
    final HashMap<String, TagLibraryInfo> ret = new HashMap<>();
    if (tldsMetaData != null) {
        if (tldsMetaData.getTlds() != null) {
            for (Map.Entry<String, TldMetaData> tld : tldsMetaData.getTlds().entrySet()) {
                createTldInfo(tld.getKey(), tld.getValue(), ret);
            }
        }
        if (sharedTlds != null) {
            for (TldMetaData metaData : sharedTlds) {
                createTldInfo(null, metaData, ret);
            }
        }
    }
    //we also register them under the new namespaces
    for (String k : new HashSet<>(ret.keySet())) {
        if (k != null) {
            if (k.startsWith(OLD_URI_PREFIX)) {
                String newUri = k.replace(OLD_URI_PREFIX, NEW_URI_PREFIX);
                ret.put(newUri, ret.get(k));
            }
        }
    }
    return ret;
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TagLibraryInfo(org.apache.jasper.deploy.TagLibraryInfo) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

TldMetaData (org.jboss.metadata.web.spec.TldMetaData)9 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ModuleLoadException (org.jboss.modules.ModuleLoadException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 WarMetaData (org.jboss.as.web.common.WarMetaData)2 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)2 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)2 VirtualFile (org.jboss.vfs.VirtualFile)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TagLibraryInfo (org.apache.jasper.deploy.TagLibraryInfo)1