Package org.pentaho.platform.api.repository2.unified

Examples of org.pentaho.platform.api.repository2.unified.Converter


        return null;
      }

      converters = converterHandler.getConverters();

      final Converter converter = converters.get( ext );
      if ( converter == null ) {
        return null;
      }

      // Check the mime type
      mimeResolver = PentahoSystem.get( NameBaseMimeResolver.class );

      // fail if we have no mime resolver
      if ( mimeResolver == null ) {
        return null;
      }

      final String mimeType = mimeResolver.resolveMimeTypeForFileName( repositoryFile.getName() ).getName();
      if ( ( mimeType == null ) || ( mimeType.isEmpty() ) ) {
        return null;
      }

      // Get the input stream
      InputStream inputStream = converter.convert( repositoryFile.getId() );
      if ( inputStream == null ) {
        return null;
      }

      // Get the file data
      repositoryFileData = converter.convert( inputStream, "UTF-8", mimeType );
      if ( repositoryFileData == null ) {
        return null;
      }
    }
View Full Code Here


        String extension = FilenameUtils.getExtension( filePath );
        try {
          // Try to get the converter for the extension. If there is not converter available then we will
          //assume simple type and will get the data that way
          if(converterHandler != null) {
            Converter converter = converterHandler.getConverter( extension );
            if(converter != null) {
              inputStream = converter.convert( repositoryFile.getId() );
            }
          }
          if(inputStream == null) {
            inputStream =
              getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
          }
        } catch ( UnifiedRepositoryException ure ) {
          //ignored
        }
      } else {
        String extension = FilenameUtils.getExtension( filePath );
        String baseName = FilenameUtils.removeExtension( filePath );
        if ( extension.length() > 0 ) {
          extension = "." + extension; //$NON-NLS-1$
        }
        String language = locale.getLanguage();
        String country = locale.getCountry();
        String variant = locale.getVariant();
        if ( !variant.equals( "" ) ) { //$NON-NLS-1$
          repositoryFile =
              getRepository().getFile( baseName + "_" + language + "_" + country + "_" + variant + extension ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }
            }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( baseName + "_" + language + "_" + country + extension ); //$NON-NLS-1$//$NON-NLS-2$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }             }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( baseName + "_" + language + extension ); //$NON-NLS-1$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }
            }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( filePath );
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
View Full Code Here

    if ( exists() ) {
      String extension = FilenameUtils.getExtension( repositoryFile.getPath() );
      // Try to get the converter for the extension. If there is not converter available then we will
      //assume simple type and will get the data that way
      if(getConverterHandler() != null) {
        Converter converter = getConverterHandler().getConverter( extension );
        if(converter != null) {
          inputStream = converter.convert( repositoryFile.getId() );
        }
      }
      if(inputStream == null) {
        inputStream = REPOSITORY.getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
      }
View Full Code Here

        for ( MimeTypeDefinitionDto mimeTypeDef : importHandler.getMimeTypeDefinitions().getMimeTypeDefinition() ) {
          MimeType mimeType = new MimeType( mimeTypeDef.getMimeType(), mimeTypeDef.getExtension() );
          mimeType.setHidden( mimeTypeDef.isHidden() );
          mimeType.setLocale( mimeTypeDef.isLocale() );

          Converter converter = null;
          String converterBeanName = mimeTypeDef.getConverter() != null && !mimeTypeDef.getConverter().isEmpty()
              ? mimeTypeDef.getConverter() : "streamConverter";
          converter = PentahoSystem.get( Converter.class, /*session*/ null, Collections.singletonMap( "name", converterBeanName ) );
          if ( converter == null ) {
            log.error( "Could not find converter class \"" + converterBeanName + "\" for mimeType \""
View Full Code Here

    // Find the converter - defined in spring xml by import handlers
    if ( converters == null ) {
      IRepositoryContentConverterHandler converterHandler = PentahoSystem.get( IRepositoryContentConverterHandler.class );
      converters = converterHandler.getConverters();
    }
    final Converter converter = converters.get( ext );
    if ( converter == null ) {
      log.debug( "Skipping file without converter: " + name );
      return null;
    }

    // just send the converter the file id and let it decide which type to get
    // since it is already based on the file extension
    return converter.convert( repositoryFile.getId() );
  }
View Full Code Here

      getLogger().trace( "copying file to repository: " + name );

      if ( getMimeTypeMap().get( mimeType ) == null ) {
        getLogger().debug( "Skipping file - mime type of " + mimeType + " is not registered :" + name );
      }
      Converter converter = getMimeTypeMap().get( mimeType ).getConverter();
      if ( converter == null ) {
        getLogger().debug( "Skipping file without converter: " + name );
        return false;
      }

      RepositoryFile repositoryFile;

      IRepositoryFileData data = converter.convert( bundle.getInputStream(), bundle.getCharset(), mimeType );
      if ( null == file ) {
        repositoryFile = createFile( bundle, repositoryPath, data );
        if ( repositoryFile != null ) {
          updateAclFromBundle( true, bundle, repositoryFile );
        }
View Full Code Here

    }
    try {
      boolean searching = true;
      while ( searching ) {

        RepositoryFile[] propertyFiles = listFiles( searchDir, new IFileFilter() {
          public boolean accept( RepositoryFile file ) {
            return file.getName().toLowerCase().endsWith( PROPERTIES_SUFFIX );
          }
        } );
        RepositoryFile blcv = null;
View Full Code Here

    return wrapper;
  }

  public IRepositoryFileData getData( RepositoryFile repositoryFile ) {
    IRepositoryContentConverterHandler converterHandler;
    Map<String, Converter> converters;
    NameBaseMimeResolver mimeResolver;

    IRepositoryFileData repositoryFileData = null;

    if ( !repositoryFile.isFolder() ) {
      // Get the extension
      final String ext = RepositoryFilenameUtils.getExtension( repositoryFile.getName() );
      if ( ( ext == null ) || ( ext.isEmpty() ) ) {
        return null;
      }

      // Find the converter

      // If we have not been given a handler, try PentahoSystem
      converterHandler = PentahoSystem.get( IRepositoryContentConverterHandler.class );

      // fail if we have no converter handler
      if ( converterHandler == null ) {
        return null;
      }

      converters = converterHandler.getConverters();

      final Converter converter = converters.get( ext );
      if ( converter == null ) {
        return null;
      }
View Full Code Here

        }
      }
    } else {
      // This is not a file from the system folder. User is trying to access a resource in the repository.
      // Get the RepositoryContentConverterHandler
      IRepositoryContentConverterHandler converterHandler = PentahoSystem.get( IRepositoryContentConverterHandler.class);
      RepositoryFile repositoryFile = null;
      if ( locale == null ) {
        repositoryFile = getRepository().getFile( filePath );
        String extension = FilenameUtils.getExtension( filePath );
        try {
          // Try to get the converter for the extension. If there is not converter available then we will
          //assume simple type and will get the data that way
          if(converterHandler != null) {
            Converter converter = converterHandler.getConverter( extension );
            if(converter != null) {
              inputStream = converter.convert( repositoryFile.getId() );
            }
          }
          if(inputStream == null) {
            inputStream =
              getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
          }
        } catch ( UnifiedRepositoryException ure ) {
          //ignored
        }
      } else {
        String extension = FilenameUtils.getExtension( filePath );
        String baseName = FilenameUtils.removeExtension( filePath );
        if ( extension.length() > 0 ) {
          extension = "." + extension; //$NON-NLS-1$
        }
        String language = locale.getLanguage();
        String country = locale.getCountry();
        String variant = locale.getVariant();
        if ( !variant.equals( "" ) ) { //$NON-NLS-1$
          repositoryFile =
              getRepository().getFile( baseName + "_" + language + "_" + country + "_" + variant + extension ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }
            }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( baseName + "_" + language + "_" + country + extension ); //$NON-NLS-1$//$NON-NLS-2$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }             }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( baseName + "_" + language + extension ); //$NON-NLS-1$
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
                inputStream =
                  getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class ).getStream();
              }
            }
          } catch ( UnifiedRepositoryException ure ) {
            //ignored
          }
        }
        if ( inputStream == null ) {
          repositoryFile = getRepository().getFile( filePath );
          try {
            if ( repositoryFile != null ) {
              // Try to get the converter for the extension. If there is not converter available then we will
              //assume simple type and will get the data that way
              if(converterHandler != null) {
                Converter converter = converterHandler.getConverter( FilenameUtils.getExtension( filePath ) );
                if(converter != null) {
                  inputStream = converter.convert( repositoryFile.getId() );
                }
              }
              if(inputStream == null) {
View Full Code Here

          String
              sourcePath =
              sourceFile.getPath().substring( 0, sourceFile.getPath().lastIndexOf( FileUtils.PATH_SEPARATOR ) );
          if ( !sourcePath.equals( destDir.getPath() ) ) { // We're saving to a different folder than we're copying
            // from
            IRepositoryFileData data = getData( sourceFile );
            RepositoryFileAcl acl = getRepository().getAcl( sourceFileId );
            RepositoryFile
                destFile =
                getRepository().getFile( destDir.getPath() + FileUtils.PATH_SEPARATOR + fileName );
            if ( destFile == null ) { // destFile doesn't exist so we'll create it.
              RepositoryFile duplicateFile =
                  new RepositoryFile.Builder( fileName ).hidden( sourceFile.isHidden() ).versioned(
                      sourceFile.isVersioned() ).build();
              final RepositoryFile repositoryFile =
                  getRepository().createFile( destDir.getId(), duplicateFile, data, acl, null );
              getRepository()
                  .setFileMetadata( repositoryFile.getId(), getRepository().getFileMetadata( sourceFileId ) );
            } else if ( mode == MODE_OVERWRITE ) { // destFile exists so check to see if we want to overwrite it.
              RepositoryFileDto destFileDto = toFileDto( destFile, null, false );
              destFileDto.setHidden( sourceFile.isHidden() );
              destFile = toFile( destFileDto );
              final RepositoryFile repositoryFile = getRepository().updateFile( destFile, data, null );
              getRepository().updateAcl( acl );
              getRepository()
                  .setFileMetadata( repositoryFile.getId(), getRepository().getFileMetadata( sourceFileId ) );
            }
          }
        }
      }
    } else {
      for ( String sourceFileId : sourceFileIds ) {
        RepositoryFile sourceFile = getRepository().getFileById( sourceFileId );
        if ( destDir != null && destDir.isFolder() && sourceFile != null && !sourceFile.isFolder() ) {

          // First try to see if regular name is available
          String fileName = sourceFile.getName();
          String copyText = "";
          String rootCopyText = "";
          String nameNoExtension = fileName;
          String extension = "";
          int indexOfDot = fileName.lastIndexOf( '.' );
          if ( !( indexOfDot == -1 ) ) {
            nameNoExtension = fileName.substring( 0, indexOfDot );
            extension = fileName.substring( indexOfDot );
          }

          RepositoryFileDto
              testFile =
              getRepoWs().getFile( path + FileUtils.PATH_SEPARATOR + nameNoExtension + extension ); //$NON-NLS-1$
          if ( testFile != null ) {
            // Second try COPY_PREFIX, If the name already ends with a COPY_PREFIX don't append twice
            if ( !nameNoExtension
                .endsWith( Messages.getInstance().getString( "FileResource.COPY_PREFIX" ) ) ) { //$NON-NLS-1$
              copyText = rootCopyText = Messages.getInstance().getString( "FileResource.COPY_PREFIX" );
              fileName = nameNoExtension + copyText + extension;
              testFile = getRepoWs().getFile( path + FileUtils.PATH_SEPARATOR + fileName );
            }
          }

          // Third try COPY_PREFIX + DUPLICATE_INDICATOR
          Integer nameCount = 1;
          while ( testFile != null ) {
            nameCount++;
            copyText =
                rootCopyText + Messages.getInstance().getString( "FileResource.DUPLICATE_INDICATOR", nameCount );
            fileName = nameNoExtension + copyText + extension;
            testFile = getRepoWs().getFile( path + FileUtils.PATH_SEPARATOR + fileName );
          }
          IRepositoryFileData data = getData( sourceFile );
          RepositoryFileAcl acl = getRepository().getAcl( sourceFileId );
          RepositoryFile duplicateFile = null;

          // If the title is different than the source file, copy it separately
          if ( !sourceFile.getName().equals( sourceFile.getTitle() ) ) {
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.repository2.unified.Converter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.