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.plugin.column; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.db.AbstractRenderer; 020import org.opengion.hayabusa.db.CellRenderer; 021import org.opengion.hayabusa.db.DBColumn; 022import org.opengion.fukurou.util.StringUtil; 023 024/** 025 * QRCODE レンデラーは、カラムのデータからQRコードを表示する場合に使用するクラスです。 026 * div 要素に、QRコードに変換する文字列を設定して、それを qrcode.js を使用して QRコードに 027 * 変換します。一旦、画像ファイルを生成してから表示する方式とは異なり、canvas に直接描画しています。 028 * その後、img に変換することで、Webの印刷が出来るようにしています。 029 * パラメータは、img タグに適用されます。 030 * 031 * 基本的な構造は、データ設定用の div 要素と、QR表示用のcanvas、起動用のscript です。 032 * 033 * <div id='div≪カラム名≫' class='QRDATA' >≪値≫</div> 034 * <canvas id='can≪カラム名≫' class='QRCANVAS' style='display:none;'> </canvas> 035 * <img src='' id='img≪カラム名≫' class='QRIMG' ≪パラメータ≫ '></canvas> 036 * <script>qrView('≪カラム名≫');</script> 037 * 038 * script に CDNサービス を使うと、無線環境(iPad等)ではものすごく遅くなったため、ローカルに配置することにします。 039 * <script src="https://cdn.jsdelivr.net/npm/qrcode@latest/build/qrcode.min.js"><!-- --></script> 040 * 041 * これらは、使用する画面に、組み込んでください。 042 * <script src="{@SYS.JSP}/option/qrcode.min.js"><!-- --></script> 043 * <script src="{@SYS.JSP}/option/videocamera.js"><!-- --></script> 044 * 045 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 046 * @og.group データ表示 047 * 048 * @version 7.4 049 * @author Kazuhiko Hasegawa 050 * @since JDK11.0, 051 */ 052public class Renderer_QRCODE extends AbstractRenderer { 053 /** このプログラムのVERSION文字列を設定します。 {@value} */ 054 private static final String VERSION = "7.4.2.1 (2021/05/21)" ; 055 056 private static final String BASE_HTML = "<div id='div≪カラム名≫' class='QRDATA'>≪値≫</div>" 057 + CR + "<canvas id='can≪カラム名≫' class='QRCANVAS' style='display:none;'> </canvas>" 058 + CR + "<img src='' id='img≪カラム名≫' class='QRIMG' ≪パラメータ≫ >" 059 + CR + "<script>qrView('≪カラム名≫');</script>" ; 060 061 private String name; 062 private String param; 063 064 /** 065 * デフォルトコンストラクター 066 * 067 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 068 */ 069 public Renderer_QRCODE() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 070 071 /** 072 * DBColumnオブジェクトを指定したprivateコンストラクター。 073 * 074 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 075 * 076 * @param clm DBColumnオブジェクト 077 */ 078 private Renderer_QRCODE( final DBColumn clm ) { 079 super(); 080 081 name = clm.getName(); 082 param = StringUtil.nvalAdd( clm.getRendererParam() , 083 clm.getRendererAttributes().get( "optionAttributes" ) ); 084 } 085 086 /** 087 * 各オブジェクトから自分のインスタンスを返します。 088 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 089 * まかされます。 090 * 091 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 092 * 093 * @param clm DBColumnオブジェクト 094 * 095 * @return CellEditorオブジェクト 096 * @og.rtnNotNull 097 */ 098 public CellRenderer newInstance( final DBColumn clm ) { 099 return new Renderer_QRCODE( clm ); 100 } 101 102 /** 103 * データの表示用文字列を返します。 104 * 105 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 106 * 107 * @param value 入力値 108 * 109 * @return データの表示用文字列 110 * @og.rtnNotNull 111 */ 112 @Override 113 public String getValue( final String value ) { 114 return makeCanvas( name, value ); 115 } 116 117 /** 118 * データの表示用文字列を返します。 119 * 120 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 121 * 122 * @param row 行番号 123 * @param value 入力値 124 * 125 * @return データ表示用の文字列 126 * @og.rtnNotNull 127 */ 128 @Override 129 public String getValue( final int row,final String value ) { 130 final String newName = name + HybsSystem.JOINT_STRING + row; 131 return makeCanvas( newName, value ); 132 } 133 134 /** 135 * データ出力用の文字列を作成します。 136 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 137 * データを返します。 138 * 基本は、#getValue( String ) をそのまま返します。 139 * 140 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 141 * 142 * @param value 入力値 143 * 144 * @return データ出力用の文字列 145 * @og.rtnNotNull 146 * @see #getValue( String ) 147 */ 148 @Override 149 public String getWriteValue( final String value ) { 150 return value == null ? "" : value; 151 } 152 153 /** 154 * データの表示用文字列を返します。 155 * 156 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 157 * 158 * @param name カラム名 159 * @param value 入力値 表示するファイルのアドレス 160 * 161 * @return データ表示用の文字列 162 * @og.rtnNotNull 163 */ 164 private String makeCanvas( final String name,final String value ) { 165 return BASE_HTML.replaceAll( "≪カラム名≫" , name ).replaceAll( "≪パラメータ≫" , param ).replaceAll( "≪値≫" , value ); 166 } 167}