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

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


        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

    }
    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

  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() ) ) {
View Full Code Here

        RepositoryFile destFile = toFile( destFileDto );

        // add the existing acls and file data
        RepositoryFileAcl acl = getRepository().getAcl( sourceFile.getId() );
        if ( !file.isFolder() ) {
          IRepositoryFileData data = getData( sourceFile );

          getRepository().updateFile( destFile, data, null );
          getRepository().updateAcl( acl );
        } else {
          getRepository().updateFolder( destFile, null );
View Full Code Here

   * @param pathId  (colon separated path for the repository file)
   * @param newName (New name of the file)
   * @return
   */
  public boolean doRename( String pathId, String newName ) throws Exception {
    IUnifiedRepository repository = getRepository();
    RepositoryFile fileToBeRenamed = repository.getFile( FileUtils.idToPath( pathId ) );
    StringBuilder buf = new StringBuilder( fileToBeRenamed.getPath().length() );
    buf.append( getParentPath( fileToBeRenamed.getPath() ) );
    buf.append( RepositoryFile.SEPARATOR );
    buf.append( newName );
    if ( !fileToBeRenamed.isFolder() ) {
      String extension = getExtension( fileToBeRenamed.getName() );
      if ( extension != null ) {
        buf.append( extension );
      }
    }
    repository.moveFile( fileToBeRenamed.getId(), buf.toString(), "Renaming the file" );
    RepositoryFile movedFile = repository.getFileById( fileToBeRenamed.getId() );
    if ( movedFile != null ) {
      if ( !movedFile.isFolder() ) {
        Map<String, Properties> localePropertiesMap = movedFile.getLocalePropertiesMap();
        if ( localePropertiesMap == null ) {
          localePropertiesMap = new HashMap<String, Properties>();
          Properties properties = new Properties();
          properties.setProperty( "file.title", newName );
          properties.setProperty( "title", newName );
          localePropertiesMap.put( "default", properties );
        } else {
          for ( Map.Entry<String, Properties> entry : localePropertiesMap.entrySet() ) {
            Properties properties = entry.getValue();
            if ( properties.containsKey( "file.title" ) ) {
              properties.setProperty( "file.title", newName );
            }
            if ( properties.containsKey( "title" ) ) {
              properties.setProperty( "title", newName );
            }
          }
        }
        RepositoryFile updatedFile =
          new RepositoryFile.Builder( movedFile ).localePropertiesMap( localePropertiesMap ).name( newName ).title(
            newName ).build();
        repository.updateFile( updatedFile, getData( movedFile ), "Updating the file" );
      }
      return true;
    } else {
      return false;
      //return Response.ok( "File to be renamed does not exist" ).build();
View Full Code Here

      }
      throw new MondrianCatalogServiceException( Messages.getInstance().getErrorString(
        "MondrianCatalogHelper.ERROR_0003_INSUFFICIENT_PERMISSION" ), Reason.ACCESS_DENIED ); //$NON-NLS-1$
    }

    IUnifiedRepository solutionRepository = PentahoSystem.get( IUnifiedRepository.class );
    RepositoryFile deletingFile = solutionRepository.getFile( RepositoryFile.SEPARATOR + "etc" //$NON-NLS-1$
      + RepositoryFile.SEPARATOR + "mondrian" + RepositoryFile.SEPARATOR + catalog.getName() ); //$NON-NLS-1$
    solutionRepository.deleteFile( deletingFile.getId(), true, "" ); //$NON-NLS-1$
    reInit( pentahoSession );
  }
View Full Code Here

TOP

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

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.