001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.hayabusa.io;
017
018import java.io.File;
019
020import org.opengion.fukurou.model.FileOperation;
021import org.opengion.fukurou.model.FileOperationFactory;
022import org.opengion.fukurou.util.StringUtil;
023import org.opengion.hayabusa.common.HybsSystem;
024import org.opengion.fukurou.system.HybsConst;                                           // 5.10.9.0 (2019/03/01)
025
026/**
027 * クラウドを含むファイル操作クラスの生成
028 *
029 * 直接fukurouをCallしてもよいのですが、hayabusaからの呼び出しではシステムリソースを参照する必要があるため
030 * ラッパー的にこのクラスを経由してCallする事でシステムリソースが使われるようにしておきます。
031 * (タグ以外からも呼び出されるため、commonTagSupportではなく専用クラスをioパッケージに作成しています)
032 *
033 * ローカルのファイルを扱いたい場合は、pluginにDEFAULTを指定してください。
034 *
035 * @og.rev 5.10.8.0 (2019/02/01) 新規作成
036 * @og.group
037 *
038 * @version 5.0
039 * @author Takahashi Masakazu
040 * @since JDK7.0
041 */
042public final class HybsFileOperationFactory {
043        private static String defPlugin=HybsSystem.sys("CLOUD_TARGET");
044        private static String defBucket=HybsSystem.sys("CLOUD_BUCKET");
045
046        /**
047         * コンストラクタはprivate化しておきます。
048         */
049        private HybsFileOperationFactory(){
050                // コンストラクタ
051        }
052
053        /**
054         * fukurouのFileOperationFactoryを呼び出してFOInterfaceを取得します。
055         * plugin,buketを指定しない場合はシステムリソースを利用します。
056         *
057         * @param plugin プラグイン名
058         * @param bucket バケット名
059         * @param path ファイルパス
060         * @return FileOperationインスタンス
061         */
062        public static FileOperation create(final String plugin, final String bucket, final String path) {
063                return FileOperationFactory.newStorageOperation( StringUtil.nval(plugin, defPlugin), StringUtil.nval(bucket, defBucket), path );
064        }
065
066        /**
067         * ディレクトリとファイル名を指定用です。
068         *
069         * @param plugin プラグイン名
070         * @param bucket バケット名
071         * @param dir ディレクトリパス
072         * @param file ファイル名
073         * @return FileOperationインスタンス
074         */
075        public static FileOperation create(final String plugin, final String bucket, final String dir, final String file) {
076                final StringBuilder sb = new StringBuilder(HybsConst.BUFFER_SMALL)
077                                                                .append(dir).append(HybsConst.FS).append(file);
078                return create(plugin, bucket, sb.toString());
079        }
080
081        /**
082         * FileOperation(ディレクトリ)とファイル名を指定用です。
083         *
084         * @param plugin プラグイン名
085         * @param bucket バケット名
086         * @param dir ファイル(ディレクトリパス取得)
087         * @param file ファイル名
088         * @return FileOperationインスタンス
089         */
090        public static FileOperation create(final String plugin, final String bucket, final File dir, final String file) {
091                final StringBuilder sb = new StringBuilder(HybsConst.BUFFER_SMALL)
092                                                                .append(dir.getPath()).append(HybsConst.FS).append(file);
093                return create(plugin, bucket, sb.toString());
094        }
095
096}