



body { -webkit-text-size-adjust: 100%; }
1 2 3 4 5 6 7 8 | <div class="row"> <div class="form-group col-sm-3"> <!- ignore --> <label for="url" class="control-label label-width-5">URL</label> <input type="text" id="url" name="url" class="form-control" data-ng-model="model.url" data-ng-keyup="keyInUrl()" data-ng-style="{'width':urlWidth}"> </div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // set the initial value for url width $scope.urlWidth = 200; // calculate width at runtime $scope.keyInUrl = function() { var url = $scope.model.url; if (!isEmptyOrUndefined($scope.model.url)){ var width = ((url.length + 1) * 9); console.log('width = ' + width); if(width > 200) { $scope.urlWidth = width; } else { $scope.urlWidth = 200; } } } |
SELECT DRAWING_ID, NVL(TARGET_INSFEE, 0) FROM CAM_DRAWING
SELECT DRAWING_ID, ISNULL(TARGET_INSFEE, 0) FROM CAM_DRAWING
CREATE TABLE "CAM_CAMPAIGN_IMGS" ( CAMPAIGN_ID nvarchar(10) NOT NULL, CID nvarchar(100) NOT NULL, IMAGE varbinary(MAX) NOT NULL, CONTENT_TYPE nvarchar(100) NOT NULL, CONSTRAINT PK_CAM_CAMPAIGN_IMGS PRIMARY KEY (CAMPAIGN_ID, CID) ) GO
package com.xxx.ecp.commons.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Lob; import javax.persistence.Table; @Entity @Table(name="CAM_CAMPAIGN_IMGS") public class CamCampaignImg implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId private CamCampaignImgPK id; @Column(name="CONTENT_TYPE") private String contentType; @Lob @Column(name="IMAGE") private byte[] image; public CamCampaignImg() { } public CamCampaignImgPK getId() { return this.id; } public void setId(CamCampaignImgPK id) { this.id = id; } public String getContentType() { return this.contentType; } public void setContentType(String contentType) { this.contentType = contentType; } public byte[] getImage() { return this.image; } public void setImage(byte[] image) { this.image = image; } }
CamCampaignImgPK imgPK = new CamCampaignImgPK(); imgPK.setCampaignId(camCampaign.getCampaignId()); imgPK.setCid(form.getImgFileName()); CamCampaignImg camCampaignImg = new CamCampaignImg(); camCampaignImg.setId(imgPK); camCampaignImg.setContentType(form.getContentType()); // convert to bytes from input stream camCampaignImg.setImage(form.getImgFile().getBytes()); camCampaiganImgRep.create(camCampaignImg);
List<CamCampaignImg> imgs = camCampaignImgRepCust.findByCampaignId(campaign.getCampaignId()); for(CamCampaignImg img : imgs) { // get image's content type String contentType = img.getContentType(); // get image file's input stream InputStream imgInputStream = new ByteArrayInputStream(img.getImage()); }
<dependency> <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId> <version>1.14</version> <scope>compile</scope> </dependency>
package albert.practice.file; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.tika.Tika; import lombok.extern.slf4j.Slf4j; @Slf4j public class FileContentTypeUtils { private static List<String> imageMediaTypes = new ArrayList<>(); private static void setImageMediaTypes() { // http://www.fileformat.info/info/mimetype/image/index.htm imageMediaTypes = Arrays.asList("image/cgm", "image/fits", "image/g3fax", "image/gif", "image/ief", "image/jp2", "image/jpeg", "image/jpm", "image/jpx", "image/naplps", "image/png", "image/prs.btif", "image/prs.pti", "image/t38", "image/tiff", "image/tiff-fx", "image/vnd.adobe.photoshop", "image/vnd.cns.inf2", "image/vnd.djvu", "image/vnd.dwg", "image/vnd.dxf", "image/vnd.fastbidsheet", "image/vnd.fpx", "image/vnd.fst", "image/vnd.fujixerox.edmics-mmr", "image/vnd.fujixerox.edmics-rlc", "image/vnd.globalgraphics.pgb", "image/vnd.microsoft.icon", "image/vnd.mix", "image/vnd.ms-modi", "image/vnd.net-fpx", "image/vnd.sealed.png", "image/vnd.sealedmedia.softseal.gif", "image/vnd.sealedmedia.softseal.jpg", "image/vnd.svf", "image/vnd.wap.wbmp", "image/vnd.xiff"); } public static Boolean isImage(String sourceFile) throws IOException { setImageMediaTypes(); Boolean isImage = Boolean.FALSE; File file = FileUtils.getFile(sourceFile); Tika tika = new Tika(); try { String mediaType = tika.detect(file); isImage = imageMediaTypes.contains(mediaType); } catch (IOException e) { throw e; } return isImage; } }
package albert.practice.file; import java.io.IOException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class FileContentTypeUtilsTest extends FileContentTypeUtils { private String imageFile; private String pdfFile; @Before public void setup() { imageFile = "/Users/albert/Dropbox/picture/panda.png"; pdfFile = "/Users/albert/Dropbox/test_測試.pdf"; } @Test public void testImageFile() throws IOException { Assert.assertTrue(isImage(imageFile)); } @Test public void testPdfFile() throws IOException { Assert.assertFalse(isImage(pdfFile)); } }
package albert.practice.designPattern.factory; public enum ShapeEnum { CIRCLE, RECTANGLE, SQUARE, TRIANGLE, OVAL; }
package albert.practice.designPattern.factory; import static org.junit.Assert.assertEquals; import java.util.function.Supplier; import org.junit.Test; public class ShapeFactoryTest { @Test public void testDifferentShape() { Supplier<ShapeFactory> shapeFactory = ShapeFactory::new; shapeFactory.get().getShape(ShapeEnum.CIRCLE).draw(); shapeFactory.get().getShape(ShapeEnum.RECTANGLE).draw(); shapeFactory.get().getShape(ShapeEnum.OVAL).draw(); shapeFactory.get().getShape(ShapeEnum.SQUARE).draw(); shapeFactory.get().getShape(ShapeEnum.TRIANGLE).draw(); } @Test // https://stackoverflow.com/questions/4512358/emma-coverage-on-enum-types/4548912#4548912 public void testShapeEnum() { ShapeEnum[] shapeEnums = ShapeEnum.values(); assertEquals(5, shapeEnums.length); } }