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
Show line numbers
/* Groovy Class #* */ import java.net.URI; import java.net.URL; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; class urlReader { def xwiki; def context; String index; String type; int height; int width; void setObjects(xwiki, context) { setXWiki(xwiki); setContext(context); } void setXWiki(xwiki) { this.xwiki = xwiki; } void setContext(context) { this.context = context; } String readUrl(URLtoRead) { index = ""; type = "none"; height = 0; width = 0; try { String url = URLtoRead; java.net.URI refuri = new java.net.URI(url); String query = refuri.getQuery(); String host = refuri.getHost(); String path = refuri.getPath(); if(host.endsWith("youtube.com")) { if(query.startsWith("v=")) { if(query.indexOf("&") > -1) { query = query.substring(2,query.indexOf("&")); } else { query = query.substring(2); } type = "youtube"; index = query; /* type = "video"; index = query; */ } } /* else if (host.endsWith("video.google.com")) { type = "video"; index = query; } else if (host.endsWith("dailymotion.com")) { type = "video"; index = query; } */ else if (host.endsWith("flickr.com") && url.indexOf(".jpg") == -1) { String page_source = xwiki.getURLContent(url); String imgSourceString = "<link rel=\"image_src\" href=\""; String imgEndString = ".jpg"; int startIndex = page_source.indexOf(imgSourceString) + imgSourceString.length(); int endIndex = page_source.indexOf(imgEndString, startIndex) + imgEndString.length(); index = page_source.substring(startIndex, endIndex); if(index.endsWith("_m.jpg")) { index = index.replaceAll("_m.jpg", ".jpg"); } type = "flickr"; //error check if(!index.endsWith(".jpg")) { index = ""; type = "error"; } else { java.awt.image.BufferedImage imageFile = javax.imageio.ImageIO.read(new java.net.URL(index)); height = imageFile.getHeight(); width = imageFile.getWidth(); } } else if(path.endsWith(".jpg") || path.endsWith(".bmp") || path.endsWith(".gif") || path.endsWith(".png")) { type = "image"; index = url; java.awt.image.BufferedImage imageFile = javax.imageio.ImageIO.read(new java.net.URL(url)); height = imageFile.getHeight(); width = imageFile.getWidth(); } } catch(Exception e) { index = ""; type = "error"; } return type; } String getIndex() { return index; } int getImageHeight() { return height; } int getImageWidth() { return width; } } /* *# */
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey