Search in sources :

Example 1 with FacesLibraryFragment

use of com.ibm.xsp.registry.FacesLibraryFragment in project org.openntf.nsfodp by OpenNTF.

the class XspTranspiler method defineCustomControls.

private void defineCustomControls(Path ccSourceRoot) throws IOException {
    if (ccSourceRoot != null) {
        subTask("Initializing Custom Control definitions");
        // Generate a classpath, which the CC library needs to find classes for property types
        Set<Path> cleanup = new HashSet<>();
        try {
            Collection<String> dependencies = buildDependenciesCollection(cleanup);
            String[] classPath = dependencies.toArray(new String[dependencies.size()]);
            ConfigParser configParser = ConfigParserFactory.getParserInstance();
            try (JavaSourceClassLoader classLoader = new JavaSourceClassLoader(Thread.currentThread().getContextClassLoader(), Collections.emptyList(), classPath)) {
                FacesClassLoader facesClassLoader = new DynamicFacesClassLoader(dynamicXPageBean, classLoader);
                try (Stream<Path> ccConfigs = Files.find(ccSourceRoot, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile() && path.toString().toLowerCase().endsWith(".xsp-config"), FileVisitOption.FOLLOW_LINKS)) {
                    // $NON-NLS-1$
                    ccConfigs.forEach(ccConfig -> {
                        Document xspConfig = ODPUtil.readXml(ccConfig);
                        // $NON-NLS-1$
                        String namespace = StringUtil.trim(NSFODPDomUtil.node(xspConfig, "/faces-config/faces-config-extension/namespace-uri/text()").get().getTextContent());
                        Path fileName = ccSourceRoot.relativize(ccConfig);
                        FacesLibraryFragment fragment = configParser.createFacesLibraryFragment(facesProject, facesClassLoader, fileName.toString(), xspConfig.getDocumentElement(), resourceBundleSource, iconUrlSource, namespace);
                        facesProject.register(fragment);
                        facesProject.getRegistry().refreshReferences();
                    });
                }
            }
        } finally {
            NSFODPUtil.deltree(cleanup);
        }
    }
}
Also used : Path(java.nio.file.Path) FacesLibraryFragment(com.ibm.xsp.registry.FacesLibraryFragment) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) Document(org.w3c.dom.Document) HashSet(java.util.HashSet)

Aggregations

DynamicFacesClassLoader (com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader)1 JavaSourceClassLoader (com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader)1 FacesClassLoader (com.ibm.xsp.library.FacesClassLoader)1 FacesLibraryFragment (com.ibm.xsp.registry.FacesLibraryFragment)1 ConfigParser (com.ibm.xsp.registry.parse.ConfigParser)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Document (org.w3c.dom.Document)1