Search in sources :

Example 1 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.

the class TextFileInputDialog method getCSV.

// Get the data layout
private void getCSV() {
    TextFileInputMeta meta = new TextFileInputMeta();
    getInfo(meta, true);
    // CSV without separator defined
    if (meta.content.fileType.equalsIgnoreCase("CSV") && (meta.content.separator == null || meta.content.separator.isEmpty())) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "TextFileInput.Exception.NoSeparator"));
        mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.DialogTitle"));
        mb.open();
        return;
    }
    TextFileInputMeta previousMeta = (TextFileInputMeta) meta.clone();
    FileInputList textFileList = meta.getFileInputList(transMeta);
    InputStream fileInputStream;
    CompressionInputStream inputStream = null;
    StringBuilder lineStringBuilder = new StringBuilder(256);
    int fileFormatType = meta.getFileFormatTypeNr();
    String delimiter = transMeta.environmentSubstitute(meta.content.separator);
    String enclosure = transMeta.environmentSubstitute(meta.content.enclosure);
    String escapeCharacter = transMeta.environmentSubstitute(meta.content.escapeCharacter);
    if (textFileList.nrOfFiles() > 0) {
        int clearFields = meta.content.header ? SWT.YES : SWT.NO;
        int nrInputFields = meta.inputFields.length;
        if (nrInputFields > 0) {
            MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.ClearFieldList.DialogMessage"));
            mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.ClearFieldList.DialogTitle"));
            clearFields = mb.open();
            if (clearFields == SWT.CANCEL) {
                return;
            }
        }
        try {
            wFields.table.removeAll();
            FileObject fileObject = textFileList.getFile(0);
            fileInputStream = KettleVFS.getInputStream(fileObject);
            Table table = wFields.table;
            CompressionProvider provider = CompressionProviderFactory.getInstance().createCompressionProviderInstance(meta.content.fileCompression);
            inputStream = provider.createInputStream(fileInputStream);
            InputStreamReader reader;
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                reader = new InputStreamReader(inputStream, meta.getEncoding());
            } else {
                reader = new InputStreamReader(inputStream);
            }
            EncodingType encodingType = EncodingType.guessEncodingType(reader.getEncoding());
            // Scan the header-line, determine fields...
            String line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
            if (line != null) {
                // Estimate the number of input fields...
                // Chop up the line using the delimiter
                String[] fields = TextFileInputUtils.guessStringsFromLine(transMeta, log, line, meta, delimiter, enclosure, escapeCharacter);
                for (int i = 0; i < fields.length; i++) {
                    String field = fields[i];
                    if (field == null || field.length() == 0 || !meta.content.header) {
                        field = "Field" + (i + 1);
                    } else {
                        // Trim the field
                        field = Const.trim(field);
                        // Replace all spaces & - with underscore _
                        field = Const.replace(field, " ", "_");
                        field = Const.replace(field, "-", "_");
                    }
                    TableItem item = new TableItem(table, SWT.NONE);
                    item.setText(1, field);
                    // The default type is String...
                    item.setText(2, "String");
                }
                wFields.setRowNums();
                wFields.optWidth(true);
                // Copy it...
                getInfo(meta, true);
                // Sample a few lines to determine the correct type of the fields...
                String shellText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToSample.DialogTitle");
                String lineText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToSample.DialogMessage");
                EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
                int samples = end.open();
                if (samples >= 0) {
                    getInfo(meta, true);
                    TextFileCSVImportProgressDialog pd = new TextFileCSVImportProgressDialog(shell, meta, transMeta, reader, samples, clearFields == SWT.YES);
                    String message = pd.open();
                    if (message != null) {
                        wFields.removeAll();
                        // OK, what's the result of our search?
                        getData(meta);
                        // 
                        if (clearFields == SWT.NO) {
                            getFieldsData(previousMeta, true);
                            wFields.table.setSelection(previousMeta.inputFields.length, wFields.table.getItemCount() - 1);
                        }
                        wFields.removeEmptyRows();
                        wFields.setRowNums();
                        wFields.optWidth(true);
                        EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ScanResults.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ScanResults.DialogMessage"), message, true);
                        etd.setReadOnly();
                        etd.open();
                    }
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.UnableToReadHeaderLine.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
                mb.open();
            }
        } catch (IOException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.IOError.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.IOError.DialogMessage"), e);
        } catch (KettleException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorGettingFileDesc.DialogMessage"), e);
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
            // Ignore errors
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.NoValidFileFound.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Table(org.eclipse.swt.widgets.Table) InputStreamReader(java.io.InputStreamReader) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) InputStream(java.io.InputStream) TableItem(org.eclipse.swt.widgets.TableItem) EncodingType(org.pentaho.di.trans.steps.fileinput.text.EncodingType) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IOException(java.io.IOException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) CompressionProvider(org.pentaho.di.core.compress.CompressionProvider) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) FileObject(org.apache.commons.vfs2.FileObject) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 2 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project accumulo by apache.

the class MiniAccumuloClusterImpl method getClasspath.

private String getClasspath() throws IOException {
    try {
        ArrayList<ClassLoader> classloaders = new ArrayList<>();
        ClassLoader cl = this.getClass().getClassLoader();
        while (cl != null) {
            classloaders.add(cl);
            cl = cl.getParent();
        }
        Collections.reverse(classloaders);
        StringBuilder classpathBuilder = new StringBuilder();
        classpathBuilder.append(config.getConfDir().getAbsolutePath());
        if (config.getHadoopConfDir() != null)
            classpathBuilder.append(File.pathSeparator).append(config.getHadoopConfDir().getAbsolutePath());
        if (config.getClasspathItems() == null) {
            // assume 0 is the system classloader and skip it
            for (int i = 1; i < classloaders.size(); i++) {
                ClassLoader classLoader = classloaders.get(i);
                if (classLoader instanceof URLClassLoader) {
                    for (URL u : ((URLClassLoader) classLoader).getURLs()) {
                        append(classpathBuilder, u);
                    }
                } else if (classLoader instanceof VFSClassLoader) {
                    VFSClassLoader vcl = (VFSClassLoader) classLoader;
                    for (FileObject f : vcl.getFileObjects()) {
                        append(classpathBuilder, f.getURL());
                    }
                } else {
                    throw new IllegalArgumentException("Unknown classloader type : " + classLoader.getClass().getName());
                }
            }
        } else {
            for (String s : config.getClasspathItems()) classpathBuilder.append(File.pathSeparator).append(s);
        }
        return classpathBuilder.toString();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project scheduling by ow2-proactive.

the class SchedulerStateRest method deleteFile.

@Override
public boolean deleteFile(String sessionId, String spaceName, String filePath) throws IOException, NotConnectedRestException, PermissionRestException {
    checkAccess(sessionId, "deleteFile");
    Session session = dataspaceRestApi.checkSessionValidity(sessionId);
    filePath = normalizeFilePath(filePath, null);
    FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
    if (!sourcefo.exists() || !sourcefo.isWriteable()) {
        RuntimeException ex = new IllegalArgumentException("File or Folder " + filePath + " does not exist or is not writable in space " + spaceName);
        logger.error(ex);
        throw ex;
    }
    if (sourcefo.getType().equals(FileType.FILE)) {
        logger.info("[deleteFile] deleting file " + sourcefo.getURL());
        sourcefo.delete();
    } else if (sourcefo.getType().equals(FileType.FOLDER)) {
        logger.info("[deleteFile] deleting folder (and all its descendants) " + sourcefo.getURL());
        sourcefo.delete(Selectors.SELECT_ALL);
    } else {
        RuntimeException ex = new IllegalArgumentException("File " + filePath + " has an unsupported type " + sourcefo.getType());
        logger.error(ex);
        throw ex;
    }
    return true;
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 4 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project spoofax by metaborg.

the class LanguageIdentifierService method identifyToResource.

@Override
@Nullable
public IdentifiedResource identifyToResource(FileObject resource, Iterable<? extends ILanguageImpl> impls) {
    // Ignore directories.
    try {
        if (resource.getType() == FileType.FOLDER) {
            return null;
        }
    } catch (FileSystemException e) {
        logger.error("Cannot identify {}, cannot determine its file type", e, resource);
        return null;
    }
    // Try to identify using the dialect identifier first.
    try {
        final IdentifiedDialect dialect = dialectIdentifier.identify(resource);
        if (dialect != null) {
            return new IdentifiedResource(resource, dialect);
        }
    } catch (MetaborgException e) {
        logger.error("Cannot identify dialect of {}", e, resource);
        return null;
    } catch (MetaborgRuntimeException e) {
    // Ignore
    }
    // Identify using identification facet.
    final Set<ILanguage> identifiedLanguages = Sets.newLinkedHashSet();
    ILanguageImpl identifiedImpl = null;
    for (ILanguageImpl impl : impls) {
        if (identify(resource, impl)) {
            identifiedLanguages.add(impl.belongsTo());
            identifiedImpl = impl;
        }
    }
    if (identifiedLanguages.size() > 1) {
        throw new IllegalStateException("Resource " + resource + " identifies to multiple languages: " + Joiner.on(", ").join(identifiedLanguages));
    }
    if (identifiedImpl == null) {
        return null;
    }
    return new IdentifiedResource(resource, null, identifiedImpl);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaborgException(org.metaborg.core.MetaborgException) IdentifiedDialect(org.metaborg.core.language.dialect.IdentifiedDialect) Nullable(javax.annotation.Nullable)

Example 5 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project spoofax by metaborg.

the class LanguageComponentFactory method createConfig.

@Override
public ComponentCreationConfig createConfig(IComponentCreationConfigRequest configRequest) throws MetaborgException {
    final ComponentFactoryRequest request = (ComponentFactoryRequest) configRequest;
    final FileObject location = request.location();
    if (!request.valid()) {
        throw new MetaborgException(request.toString());
    }
    final ILanguageComponentConfig componentConfig = request.config();
    logger.debug("Creating language component for {}", location);
    final LanguageIdentifier identifier = componentConfig.identifier();
    final Collection<LanguageContributionIdentifier> langContribs = request.config().langContribs();
    if (langContribs.isEmpty()) {
        langContribs.add(new LanguageContributionIdentifier(identifier, componentConfig.name()));
    }
    final ComponentCreationConfig config = new ComponentCreationConfig(identifier, location, langContribs, componentConfig);
    final SyntaxFacet syntaxFacet;
    if (componentConfig.sdfEnabled()) {
        syntaxFacet = request.syntaxFacet();
        if (syntaxFacet != null) {
            config.addFacet(syntaxFacet);
        }
    } else {
        syntaxFacet = null;
    }
    final DynamicClassLoadingFacet dynamicClassLoadingFacet = request.dynamicClassLoadingFacet();
    if (dynamicClassLoadingFacet != null) {
        config.addFacet(dynamicClassLoadingFacet);
    }
    final StrategoRuntimeFacet strategoRuntimeFacet = request.strategoRuntimeFacet();
    if (strategoRuntimeFacet != null) {
        config.addFacet(strategoRuntimeFacet);
    }
    final IStrategoAppl esvTerm = request.esvTerm();
    if (esvTerm != null) {
        final String[] extensions = extensions(esvTerm);
        if (extensions.length != 0) {
            final Iterable<String> extensionsIterable = Iterables2.from(extensions);
            final IdentificationFacet identificationFacet = new IdentificationFacet(new ResourceExtensionsIdentifier(extensionsIterable));
            config.addFacet(identificationFacet);
            final ResourceExtensionFacet resourceExtensionsFacet = new ResourceExtensionFacet(extensionsIterable);
            config.addFacet(resourceExtensionsFacet);
        }
        if (ParseFacetFromESV.hasParser(esvTerm)) {
            @Nullable final ParseFacet parseFacet = ParseFacetFromESV.create(esvTerm);
            if (parseFacet != null) {
                config.addFacet(parseFacet);
            }
        // If parser is set to 'none' in ESV, ParseFacetFromESV.create returns `null` and we create no
        // ParserFacet, which is used to in language extension to select which language component contributes
        // the parser, since multiple language components contributing a parser is not supported.
        } else if (syntaxFacet != null) {
            // Default to JSGLR when there is a syntax facet, but no parser was explicitly set in ESV.
            config.addFacet(new ParseFacet("jsglr"));
        }
        final boolean hasContext = ContextFacetFromESV.hasContext(esvTerm);
        final boolean hasAnalysis = AnalysisFacetFromESV.hasAnalysis(esvTerm);
        final IContextFactory contextFactory;
        final ISpoofaxAnalyzer analyzer;
        final AnalysisFacet analysisFacet;
        if (hasAnalysis) {
            final String analysisType = AnalysisFacetFromESV.type(esvTerm);
            assert analysisType != null : "Analyzer type cannot be null because hasAnalysis is true, no null check is needed.";
            analyzer = analyzers.get(analysisType);
            analysisFacet = AnalysisFacetFromESV.create(esvTerm);
            final String contextType = hasContext ? ContextFacetFromESV.type(esvTerm) : null;
            if (hasContext && contextType == null) {
                contextFactory = null;
            } else {
                final String analysisContextType;
                switch(analysisType) {
                    default:
                    case StrategoAnalyzer.name:
                        analysisContextType = contextType == null ? LegacyContextFactory.name : contextType;
                        break;
                    case TaskEngineAnalyzer.name:
                        analysisContextType = IndexTaskContextFactory.name;
                        break;
                    case SingleFileConstraintAnalyzer.name:
                    case MultiFileConstraintAnalyzer.name:
                        analysisContextType = ConstraintContextFactory.name;
                        break;
                }
                if (hasContext && !analysisType.equals(StrategoAnalyzer.name) && !analysisContextType.equals(contextType)) {
                    logger.warn("Ignoring explicit context type {}, because it is incompatible with analysis {}.", contextType, analysisType);
                }
                contextFactory = contextFactory(analysisContextType);
            }
        } else if (hasContext) {
            final String type = ContextFacetFromESV.type(esvTerm);
            contextFactory = contextFactory(type);
            analyzer = null;
            analysisFacet = null;
        } else {
            contextFactory = contextFactory(LegacyContextFactory.name);
            analyzer = null;
            analysisFacet = null;
        }
        if (contextFactory != null) {
            final IContextStrategy contextStrategy = contextStrategy(ProjectContextStrategy.name);
            config.addFacet(new ContextFacet(contextFactory, contextStrategy));
        }
        if (analyzer != null) {
            config.addFacet(new AnalyzerFacet<>(analyzer));
        }
        if (analysisFacet != null) {
            config.addFacet(analysisFacet);
        }
        final ActionFacet menusFacet = ActionFacetFromESV.create(esvTerm);
        if (menusFacet != null) {
            config.addFacet(menusFacet);
        }
        final StylerFacet stylerFacet = StylerFacetFromESV.create(esvTerm);
        if (stylerFacet != null) {
            config.addFacet(stylerFacet);
        }
        final IFacet resolverFacet = ResolverFacetFromESV.createResolver(esvTerm);
        if (resolverFacet != null) {
            config.addFacet(resolverFacet);
        }
        final IFacet hoverFacet = ResolverFacetFromESV.createHover(esvTerm);
        if (hoverFacet != null) {
            config.addFacet(hoverFacet);
        }
        final OutlineFacet outlineFacet = OutlineFacetFromESV.create(esvTerm);
        if (outlineFacet != null) {
            config.addFacet(outlineFacet);
        }
        final ShellFacet shellFacet = ShellFacetFromESV.create(esvTerm);
        if (shellFacet != null) {
            config.addFacet(shellFacet);
        }
    }
    return config;
}
Also used : ResourceExtensionsIdentifier(org.metaborg.core.language.ResourceExtensionsIdentifier) MetaborgException(org.metaborg.core.MetaborgException) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) LanguageContributionIdentifier(org.metaborg.core.language.LanguageContributionIdentifier) ParseFacet(org.metaborg.core.syntax.ParseFacet) ISpoofaxAnalyzer(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzer) IContextFactory(org.metaborg.core.context.IContextFactory) FileObject(org.apache.commons.vfs2.FileObject) StylerFacet(org.metaborg.spoofax.core.style.StylerFacet) ContextFacet(org.metaborg.core.context.ContextFacet) OutlineFacet(org.metaborg.spoofax.core.outline.OutlineFacet) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) StrategoRuntimeFacet(org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet) ShellFacet(org.metaborg.spoofax.core.shell.ShellFacet) SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) IdentificationFacet(org.metaborg.core.language.IdentificationFacet) ActionFacet(org.metaborg.spoofax.core.action.ActionFacet) AnalysisFacet(org.metaborg.spoofax.core.analysis.AnalysisFacet) DynamicClassLoadingFacet(org.metaborg.spoofax.core.dynamicclassloading.DynamicClassLoadingFacet) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IContextStrategy(org.metaborg.core.context.IContextStrategy) ResourceExtensionFacet(org.metaborg.core.language.ResourceExtensionFacet) IFacet(org.metaborg.core.language.IFacet) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) Nullable(javax.annotation.Nullable)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)38 KettleException (org.pentaho.di.core.exception.KettleException)22 IOException (java.io.IOException)20 FileSystemException (org.apache.commons.vfs2.FileSystemException)12 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 InputStream (java.io.InputStream)7 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 File (java.io.File)5 InputStreamReader (java.io.InputStreamReader)5 ArrayList (java.util.ArrayList)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 RowMeta (org.pentaho.di.core.row.RowMeta)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TableItem (org.eclipse.swt.widgets.TableItem)3 MetaborgException (org.metaborg.core.MetaborgException)3