General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
CreativityAndCogntion
▼
:
Document Index
»
Page:
BibliographyClassGroovy
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
BibliographyClassGroovy
Wiki source code of
BibliographyClassGroovy
Last modified by
Kenneth Latimer
on 2009/09/29 12:55
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: 2: /* Groovy Class #* */ 3: 4: import java.net.URI; 5: import java.net.URL; 6: import java.awt.image.BufferedImage; 7: import javax.imageio.ImageIO; 8: 9: class urlReader { 10: def xwiki; 11: def context; 12: String index; 13: String type; 14: int height; 15: int width; 16: 17: void setObjects(xwiki, context) { 18: setXWiki(xwiki); 19: setContext(context); 20: } 21: 22: void setXWiki(xwiki) { 23: this.xwiki = xwiki; 24: } 25: 26: void setContext(context) { 27: this.context = context; 28: } 29: 30: String readUrl(URLtoRead) { 31: index = ""; 32: type = "none"; 33: height = 0; 34: width = 0; 35: 36: try { 37: String url = URLtoRead; 38: java.net.URI refuri = new java.net.URI(url); 39: String query = refuri.getQuery(); 40: String host = refuri.getHost(); 41: String path = refuri.getPath(); 42: if(host.endsWith("youtube.com")) { 43: if(query.startsWith("v=")) { 44: if(query.indexOf("&") > -1) { 45: query = query.substring(2,query.indexOf("&")); 46: } 47: else { 48: query = query.substring(2); 49: } 50: type = "youtube"; 51: index = query; 52: 53: /* type = "video"; 54: index = query; */ 55: } 56: } 57: /* else if (host.endsWith("video.google.com")) { 58: type = "video"; 59: index = query; 60: } 61: else if (host.endsWith("dailymotion.com")) { 62: type = "video"; 63: index = query; 64: } */ 65: else if (host.endsWith("flickr.com") && url.indexOf(".jpg") == -1) { 66: 67: String page_source = xwiki.getURLContent(url); 68: String imgSourceString = "<link rel=\"image_src\" href=\""; 69: String imgEndString = ".jpg"; 70: int startIndex = page_source.indexOf(imgSourceString) + imgSourceString.length(); 71: int endIndex = page_source.indexOf(imgEndString, startIndex) + imgEndString.length(); 72: index = page_source.substring(startIndex, endIndex); 73: if(index.endsWith("_m.jpg")) { 74: index = index.replaceAll("_m.jpg", ".jpg"); 75: } 76: type = "flickr"; 77: 78: //error check 79: if(!index.endsWith(".jpg")) { 80: index = ""; 81: type = "error"; 82: } 83: 84: else { 85: java.awt.image.BufferedImage imageFile = javax.imageio.ImageIO.read(new java.net.URL(index)); 86: height = imageFile.getHeight(); 87: width = imageFile.getWidth(); 88: } 89: } 90: else if(path.endsWith(".jpg") || path.endsWith(".bmp") || path.endsWith(".gif") || path.endsWith(".png")) { 91: type = "image"; 92: index = url; 93: 94: java.awt.image.BufferedImage imageFile = javax.imageio.ImageIO.read(new java.net.URL(url)); 95: height = imageFile.getHeight(); 96: width = imageFile.getWidth(); 97: } 98: } 99: catch(Exception e) { 100: index = ""; 101: type = "error"; 102: } 103: 104: return type; 105: } 106: 107: String getIndex() { 108: return index; 109: } 110: int getImageHeight() { 111: return height; 112: } 113: int getImageWidth() { 114: return width; 115: } 116: } 117: /* *# */
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey