Search in sources :

Example 1 with AbstractSplitDesignElement

use of org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method importFileResources.

private void importFileResources(NDXLImporter importer, NDatabase database) throws Exception {
    subTask(Messages.ODPCompiler_importingFileResources);
    Map<AbstractSplitDesignElement, Document> elements = odp.getFileResources().stream().filter(res -> {
        Path filePath = odp.getBaseDirectory().relativize(res.getDataFile());
        String normalizedPath = filePath.toString().replace('\\', '/');
        switch(normalizedPath) {
            case "META-INF/MANIFEST.MF":
                {
                    // Special handling of MANIFEST.MF, which can cause trouble in FP10 when blank
                    try {
                        if (Files.size(res.getDataFile()) == 0) {
                            return false;
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                break;
            case "WebContent/WEB-INF/xsp.properties":
                {
                    // Special handling of xsp.properties to set production options
                    if (this.isSetProductionXspOptions()) {
                        try (InputStream is = NSFODPUtil.newInputStream(res.getDataFile())) {
                            Properties props = new Properties();
                            props.load(is);
                            // $NON-NLS-1$ //$NON-NLS-2$
                            props.put("xsp.resources.aggregate", "true");
                            // $NON-NLS-1$ //$NON-NLS-2$
                            props.put("xsp.client.resources.uncompressed", "false");
                            try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
                                props.store(baos, null);
                                baos.flush();
                                res.setOverrideData(baos.toByteArray());
                            }
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
        }
        return true;
    }).collect(Collectors.toMap(Function.identity(), res -> {
        try {
            return res.getDxl();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }));
    for (Map.Entry<AbstractSplitDesignElement, Document> entry : elements.entrySet()) {
        AbstractSplitDesignElement res = entry.getKey();
        Document dxlDoc = entry.getValue();
        Path filePath = odp.getBaseDirectory().relativize(res.getDataFile());
        // $NON-NLS-1$
        importDxl(importer, NSFODPDomUtil.getXmlString(dxlDoc, null), database, res.getClass().getSimpleName() + " " + filePath);
        if (res instanceof FileResource) {
            FileResource fileRes = (FileResource) res;
            if (fileRes.isCopyToClasses()) {
                // Also create a copy beneath WEB-INF/classes
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Files.copy(fileRes.getDataFile(), baos);
                // Use expanded syntax due to the presence of the xmlns
                // $NON-NLS-1$
                String title = NSFODPDomUtil.node(dxlDoc, "/*[name()='note']/*[name()='item'][@name='$TITLE']/*[name()='text']/text()").get().getTextContent();
                if (StringUtil.isEmpty(title)) {
                    throw new IllegalStateException(MessageFormat.format(Messages.ODPCompiler_couldNotIdentifyTitle, filePath));
                }
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                CompilerUtil.importFileResource(importer, baos.toByteArray(), database, "WEB-INF/classes/" + title, "~C4g", "w");
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) FileResource(org.openntf.nsfodp.commons.odp.FileResource) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StringUtil (com.ibm.commons.util.StringUtil)1 StreamUtil (com.ibm.commons.util.io.StreamUtil)1 NException (com.ibm.domino.napi.NException)1 Os (com.ibm.domino.napi.c.Os)1 DynamicFacesClassLoader (com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader)1 JavaCompilerException (com.ibm.xsp.extlib.javacompiler.JavaCompilerException)1 JavaSourceClassLoader (com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader)1 FacesClassLoader (com.ibm.xsp.library.FacesClassLoader)1 CompositeComponentDefinitionImpl (com.ibm.xsp.registry.CompositeComponentDefinitionImpl)1 FacesSharableRegistry (com.ibm.xsp.registry.FacesSharableRegistry)1 LibraryFragmentImpl (com.ibm.xsp.registry.LibraryFragmentImpl)1 UpdatableLibrary (com.ibm.xsp.registry.UpdatableLibrary)1 ConfigParser (com.ibm.xsp.registry.parse.ConfigParser)1 ConfigParserFactory (com.ibm.xsp.registry.parse.ConfigParserFactory)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1