Search in sources :

Example 6 with TldMetaData

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

the class ExternalTldParsingDeploymentProcessor method parseTLD.

private TldMetaData parseTLD(Resource tld) throws DeploymentUnitProcessingException {
    if (IMPLICIT_TLD.equals(tld.getName())) {
        // Implicit TLDs are different from regular TLDs
        return new TldMetaData();
    }
    InputStream is = null;
    try {
        is = tld.openStream();
        final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setXMLResolver(NoopXMLResolver.create());
        XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
        return TldMetaDataParser.parse(xmlReader);
    } catch (XMLStreamException e) {
        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.getName(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.getName()), e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
        // Ignore
        }
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 7 with TldMetaData

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

the class ExternalTldParsingDeploymentProcessor 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);
    Map<String, TldMetaData> tlds = tldsMetaData.getTlds();
    Set<String> sharedTldUris = new HashSet<>();
    for (TldMetaData shared : tldsMetaData.getSharedTlds(deploymentUnit)) {
        sharedTldUris.add(shared.getUri());
    }
    Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    try {
        Iterator<Resource> resources = module.globResources("META-INF/**.tld");
        while (resources.hasNext()) {
            final Resource resource = resources.next();
            //waste time re-parsing them
            if (resource.getURL().toString().contains("com/sun/jsf-impl/main")) {
                continue;
            }
            if (resource.getName().startsWith("META-INF/")) {
                if (tlds.containsKey(resource.getName())) {
                    continue;
                }
                if (resource.getURL().getProtocol().equals("vfs")) {
                    continue;
                }
                final TldMetaData value = parseTLD(resource);
                if (sharedTldUris.contains(value.getUri())) {
                    //don't re-include shared TLD's
                    continue;
                }
                String key = "/" + resource.getName();
                if (!tlds.containsKey(key)) {
                    tlds.put(key, value);
                }
                if (!tlds.containsKey(value.getUri())) {
                    tlds.put(value.getUri(), value);
                }
                if (value.getListeners() != null) {
                    for (ListenerMetaData l : value.getListeners()) {
                        List<ListenerMetaData> listeners = warMetaData.getMergedJBossWebMetaData().getListeners();
                        if (listeners == null) {
                            warMetaData.getMergedJBossWebMetaData().setListeners(listeners = new ArrayList<ListenerMetaData>());
                        }
                        listeners.add(l);
                    }
                }
            }
        }
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WarMetaData(org.jboss.as.web.common.WarMetaData) Resource(org.jboss.modules.Resource) ArrayList(java.util.ArrayList) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Example 8 with TldMetaData

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

the class TldParsingDeploymentProcessor method parseTLD.

private TldMetaData parseTLD(VirtualFile tld) throws DeploymentUnitProcessingException {
    if (IMPLICIT_TLD.equals(tld.getName())) {
        // Implicit TLDs are different from regular TLDs
        return new TldMetaData();
    }
    InputStream is = null;
    try {
        is = tld.openStream();
        final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setXMLResolver(NoopXMLResolver.create());
        XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
        return TldMetaDataParser.parse(xmlReader);
    } catch (XMLStreamException e) {
        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString()), e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
        // Ignore
        }
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 9 with TldMetaData

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

the class SharedTldsMetaDataBuilder method init.

private void init() {
    try {
        ModuleClassLoader jstl = Module.getModuleFromCallerModuleLoader(ModuleIdentifier.create("javax.servlet.jstl.api")).getClassLoader();
        for (String tld : JSTL_TAGLIBS) {
            InputStream is = jstl.getResourceAsStream("META-INF/" + tld);
            if (is != null) {
                TldMetaData tldMetaData = parseTLD(tld, is);
                jstlTlds.add(tldMetaData);
            }
        }
    } catch (ModuleLoadException e) {
    // Ignore
    } catch (Exception e) {
    // Ignore
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InputStream(java.io.InputStream) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

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