results.add(new ScanResult(acceptedFile));
logger.debug("Starting file loading into model, file: " + scanResult.getFile()); fileContent = ioService.readAllString(scanResult.getFile()); if (fileContent == null || "".equals(fileContent)) { logger.debug("file: " + scanResult.getFile() + " is empty."); result.addError(new DriverError("File has no content", Paths.convert(scanResult.getFile()))); continue; scanResult.getFile(), javaType.getSyntaxErrors()); } else if (javaType.isEnum()) { loadFromJavaEnum((JavaEnumSource) javaType, scanResult.getFile(), dataModel, result); } else { loadFromJavaClass((JavaClassSource) javaType, scanResult.getFile(), dataModel, result); logger.debug("The class, {}, in the file, {}, was vetoed and will be skipped.", javaType.getQualifiedName(), scanResult.getFile()); } else { logger.debug("File: " + scanResult.getFile() + " do not contain a managed java type, it will be skipped."); Paths.convert(scanResult.getFile()))); } catch (Exception e) {
@Override public Form getFormById( String ctxUID, long formId ) { FormEditorContext editorContext = formEditorContextManager.getRootEditorContext( ctxUID ); if ( editorContext != null ) { try { if ( editorContext.getForm().getId().equals( new Long( formId ) ) ) { return editorContext.getForm(); } Path currentForm = Paths.convert( ioService.get( new URI( editorContext.getPath() ) ) ); Project project = projectService.resolveProject( currentForm ); FileUtils utils = FileUtils.getInstance(); List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<org.uberfire.java.nio.file.Path>(); nioPaths.add( Paths.convert( project.getRootPath() ) ); Collection<FileUtils.ScanResult> forms = utils.scan( ioService, nioPaths, "form", true ); String header = formSerializationManager.generateHeaderFormFormId( formId ); for ( FileUtils.ScanResult form : forms ) { org.uberfire.java.nio.file.Path formPath = form.getFile(); org.uberfire.java.nio.file.Path path = Paths.convert( project.getRootPath() ).resolve( MAIN_RESOURCES_PATH ).resolve( formPath ); String xml = ioService.readAllString( path ).trim(); if ( xml.startsWith( header ) ) { return formSerializationManager.loadFormFromXML( xml ); } } } catch ( Exception e ) { log.warn( "Error getting form {} from context {}: {}", formId, ctxUID, e ); } } return null; }
String formName; for ( FileUtils.ScanResult form : forms ) { formPath = Paths.convert( form.getFile() ); formDirUri = getFormDirUri( formPath ); formName = formPath.getFileName();
private List<FormDefinition> findForms(final Path path, final FormSearchConstraint constraint) { List<FormDefinition> result = new ArrayList<>(); Module module = moduleService.resolveModule(path); FileUtils utils = FileUtils.getInstance(); List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>(); nioPaths.add(Paths.convert(module.getRootPath())); Collection<FileUtils.ScanResult> forms = utils.scan(ioService, nioPaths, FormResourceTypeDefinition.EXTENSION, true); for (FileUtils.ScanResult form : forms) { org.uberfire.java.nio.file.Path formPath = form.getFile(); try { FormDefinition formDefinition = serializer.deserialize(ioService.readAllString(formPath).trim()); if (constraint == null || constraint.accepts(formDefinition)) { result.add(formDefinition); } } catch (Exception ex) { logger.warn("Unable to generate FormDefinition for {}", path, ex); } } return result; }
public Collection<ScanResult> scanDirectories(IOService ioService, Path rootPath, final boolean includeRoot, final boolean recursiveScan/*, final Map<Path, Path> scannedCache*/) throws IOException { final Collection<ScanResult> results = new ArrayList<ScanResult>(); final List<Path> childDirectories = new ArrayList<Path>(); if (rootPath != null) { if (Files.isDirectory(rootPath) /* && !scannedCache.containsKey(rootPath)*/) { //scannedCache.put(rootPath, rootPath); if (includeRoot) results.add(new ScanResult(rootPath)); final DirectoryStream<Path> children = ioService.newDirectoryStream(rootPath); //finally if (recursiveScan) { for (Path child : children) { results.addAll( scanDirectories(ioService, child, true, recursiveScan/*, scannedCache*/) ); } } } } return results; }
public Collection<ScanResult> scan(IOService ioService, Collection<Path> rootPaths, Collection<String> fileTypes, boolean recursiveScan) throws IOException { List<ScanResult> results = new ArrayList<ScanResult>(); final Map<Path, Path> scannedCache = new HashMap<Path, Path>(); if (rootPaths != null) { for (Path root : rootPaths) { if (Files.isDirectory(root) && !scannedCache.containsKey(root)) { results.addAll(scan(ioService, root, fileTypes, recursiveScan, scannedCache)); } else if ( (fileTypes == null || isFromType( root, fileTypes )) && !scannedCache.containsKey( root ) ) { results.add( new ScanResult( root ) ); scannedCache.put( root, root ); } } } return results; }