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");
}
}
}
}
Aggregations