use of org.structr.web.entity.Folder in project structr by structr.
the class JavaParserModule method handlePomFile.
private void handlePomFile(final File file, final Folder folder, final Folder parentFolder) {
final XPath xpath = XPathFactory.newInstance().newXPath();
QName returnType = XPathConstants.STRING;
final String content = file.getFavoriteContent();
final String projectName;
try {
projectName = (String) xpath.evaluate("/project/name", parseXml(content), returnType);
final Module newMod = createModule(projectName, folder);
logger.info("Created module '" + projectName + "' in folder " + folder.getPath());
// Check if we are child of a parent module
// Find the closest ancestor folder which has a module
Module mod = null;
Folder possibleModuleParentFolder = parentFolder;
// Continue until root folder or a module was found
while (possibleModuleParentFolder != null && mod == null) {
try {
mod = app.nodeQuery(Module.class).and(Module.folder, possibleModuleParentFolder).getFirst();
} catch (FrameworkException ignore) {
}
if (mod != null) {
newMod.setProperty(Module.parent, mod);
break;
}
// Continue while loop
possibleModuleParentFolder = possibleModuleParentFolder.getParent();
}
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException | FrameworkException ex) {
logger.warn("Exception exception occured", ex);
}
}
use of org.structr.web.entity.Folder in project structr by structr.
the class JavaParserModule method handlePackage.
private org.structr.javaparser.entity.Package handlePackage(final PackageDeclaration pkg) {
final PropertyMap packageIdentifyingProperties = new PropertyMap();
packageIdentifyingProperties.put(org.structr.javaparser.entity.Package.name, pkg.getNameAsString());
org.structr.javaparser.entity.Package clsPackage = (org.structr.javaparser.entity.Package) getOrCreate(Package.class, packageIdentifyingProperties, packageIdentifyingProperties);
if (clsPackage != null) {
try {
// Find corresponding folder
final Folder packageFolder = app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), StringUtils.replaceAll(clsPackage.getName(), ".", "/")).getFirst();
if (packageFolder != null) {
clsPackage.setProperty(Package.folder, packageFolder);
}
} catch (final FrameworkException ex) {
}
;
}
return clsPackage;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class JavaParserModule method addJarsToIndex.
/**
* Add compilation units of all jar files found in the given folder to the index.
*
* @param folderPath
*/
public void addJarsToIndex(final String folderPath) {
logger.info("Starting adding jar files in " + folderPath);
final CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
final AtomicLong count = new AtomicLong(0);
try {
Files.newDirectoryStream(Paths.get(folderPath), path -> path.toString().endsWith(".jar")).forEach((file) -> {
try {
typeSolver.add(new JarTypeSolver(new FileInputStream(file.toFile())));
count.addAndGet(1L);
} catch (IOException ex) {
}
});
} catch (IOException ex) {
}
logger.info("Added " + count.toString() + " jar files to the type solver");
typeSolver.add(structrTypeSolver);
facade = JavaParserFacade.get(typeSolver);
logger.info("Done with adding jar files in " + folderPath);
}
use of org.structr.web.entity.Folder in project structr by structr.
the class Importer method createFileNode.
private File createFileNode(final String path, final String contentType, final long size, final long checksum, final Class fileClass) throws FrameworkException {
final PropertyKey<Integer> versionKey = StructrApp.key(File.class, "version");
final PropertyKey<Folder> parentKey = StructrApp.key(File.class, "parent");
final PropertyKey<String> contentTypeKey = StructrApp.key(File.class, "contentType");
final PropertyKey<String> pathKey = StructrApp.key(File.class, "path");
final PropertyKey<Long> checksumKey = StructrApp.key(File.class, "checksum");
final PropertyKey<Long> sizeKey = StructrApp.key(File.class, "size");
return app.create(fileClass != null ? fileClass : File.class, new NodeAttribute(AbstractNode.name, PathHelper.getName(path)), new NodeAttribute(parentKey, FileHelper.createFolderPath(securityContext, PathHelper.getFolderPath(path))), new NodeAttribute(contentTypeKey, contentType), new NodeAttribute(sizeKey, size), new NodeAttribute(checksumKey, checksum), new NodeAttribute(versionKey, 1), new NodeAttribute(AbstractNode.visibleToPublicUsers, publicVisible), new NodeAttribute(AbstractNode.visibleToAuthenticatedUsers, authVisible));
}
use of org.structr.web.entity.Folder in project structr by structr.
the class DeployCommand method exportFiles.
private void exportFiles(final Path target, final Path configTarget) throws FrameworkException {
logger.info("Exporting files (unchanged files will be skipped)");
final PropertyKey<Boolean> inclKey = StructrApp.key(File.class, "includeInFrontendExport");
final PropertyKey<Boolean> jsKey = StructrApp.key(File.class, "useAsJavascriptLibrary");
final PropertyKey<Folder> parentKey = StructrApp.key(File.class, "parent");
final Map<String, Object> config = new TreeMap<>();
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
// fetch toplevel folders and recurse
for (final Folder folder : app.nodeQuery(Folder.class).and(parentKey, null).sort(Folder.name).and(inclKey, true).getAsList()) {
exportFilesAndFolders(target, folder, config);
}
// fetch toplevel files that are marked for export or for use as a javascript library
for (final File file : app.nodeQuery(File.class).and(parentKey, null).sort(File.name).and().or(inclKey, true).or(jsKey, true).getAsList()) {
exportFile(target, file, config);
}
tx.success();
} catch (IOException ioex) {
logger.warn("", ioex);
}
try (final Writer fos = new OutputStreamWriter(new FileOutputStream(configTarget.toFile()))) {
getGson().toJson(config, fos);
} catch (IOException ioex) {
logger.warn("", ioex);
}
}
Aggregations