Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/IterativeHTMLCrawler.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/IterativeHTMLCrawler.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/IterativeHTMLCrawler.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/IterativeHTMLCrawler.java Wed Jan 30 23:44:03 2008
@@ -14,550 +14,458 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.search.crawler;
-
import java.io.File;
import java.io.FileOutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.StringTokenizer;
-
+import org.apache.log4j.Logger;
import websphinx.RobotExclusion;
-
-import org.apache.log4j.Category;
-
-
/**
* Crawl iteratively
*/
public class IterativeHTMLCrawler {
- static Category log = Category.getInstance(IterativeHTMLCrawler.class);
-
- java.util.Vector urlsToCrawl;
- java.util.TreeSet urlsToCrawlLowerCase;
- String url_list_file = "url_file.txt";
- String html_dump_directory = "html_dump";
- private String rootURL;
- private String[] scopeURL;
- private RobotExclusion robot;
-
- /**
- * Command line interface
- *
- * @param args Configuration file crawler.xconf
- */
- public static void main(String[] args) {
- if (args.length == 0) {
+ private static Logger log = Logger.getLogger(IterativeHTMLCrawler.class);
+ java.util.Vector urlsToCrawl;
+ java.util.TreeSet urlsToCrawlLowerCase;
+ String url_list_file = "url_file.txt";
+ String html_dump_directory = "html_dump";
+ private String rootURL;
+ private String[] scopeURL;
+ private RobotExclusion robot;
+ /**
+ * Command line interface
+ *
+ * @param args
+ * Configuration file crawler.xconf
+ */
+ public static void main(String[] args) {
+ if(args.length == 0){
+ System.err.println("Usage: IterativeHTMLCrawler crawler.xconf");
+ return;
+ }
+ try{
+ if(args.length == 1){
+ CrawlerConfiguration ce = new CrawlerConfiguration(args[0]);
+ new IterativeHTMLCrawler(new File(args[0])).crawl(new URL(ce.getBaseURL()), ce.getScopeURL());
+ }else{
System.err.println("Usage: IterativeHTMLCrawler crawler.xconf");
-
- return;
- }
-
- try {
- if (args.length == 1) {
- CrawlerConfiguration ce = new CrawlerConfiguration(args[0]);
- new IterativeHTMLCrawler(new File(args[0])).crawl(new URL(ce.getBaseURL()), ce.getScopeURL());
- } else {
- System.err.println("Usage: IterativeHTMLCrawler crawler.xconf");
- }
- } catch (MalformedURLException e) {
- log.error("" + e);
- }
- }
-
- /**
- * Creates a new IterativeHTMLCrawler object.
- *
- * @param url_list_file File where all dumped files will be listed
- * @param html_dump_directory Directory where htdocs should be dumped
- * @param userAgent User-agent for robots.txt
- */
- public IterativeHTMLCrawler(String url_list_file, String html_dump_directory, String userAgent) {
- this.url_list_file = url_list_file;
- this.html_dump_directory = html_dump_directory;
-
- robot = new RobotExclusion(userAgent);
- }
-
- /**
- * Creates a new IterativeHTMLCrawler object.
- * @param config Configuration File
- */
- public IterativeHTMLCrawler(File config) {
- CrawlerConfiguration ce = new CrawlerConfiguration(config.getAbsolutePath());
-
-
- this.url_list_file = ce.getURIListResolved();
- log.debug("URI list file: " + this.url_list_file);
-
- this.html_dump_directory = ce.getHTDocsDumpDirResolved();
- log.debug("HTDocs Dump Dir: " + this.html_dump_directory);
-
- robot = new RobotExclusion(ce.getUserAgent());
-
- String robots_file = ce.getRobotsFileResolved();
- log.debug("Robots File: " + robots_file);
- String robots_domain = ce.getRobotsDomain();
- if (robots_file != null && robots_domain != null) {
- log.debug(robots_file + " " + robots_domain);
- robot.addLocalEntries(robots_domain, new File(robots_file));
- }
- }
-
- /**
- * Crawl
- *
- * @param start Start crawling at this URL
- * @param scope Limit crawling to this scope
- */
- public void crawl(URL start, String scope) {
- scopeURL = new String[1];
- scopeURL[0] = scope;
-
- String seedURL = start.toString();
- this.rootURL = seedURL.substring(0, seedURL.indexOf("/", 8));
-
- urlsToCrawl = new java.util.Vector();
- urlsToCrawlLowerCase = new java.util.TreeSet();
-
- String currentURLPath = start.toString().substring(0, start.toString().lastIndexOf("/"));
-
- try {
- log.info("Start crawling at: " + start);
-
- if (addURL(start.getFile(), currentURLPath) != null) {
- dumpHTDoc(start);
- } else {
- log.warn("Start URL has not been dumped: " + start);
- }
- } catch (MalformedURLException e) {
- log.error("" + e);
- }
-
- int currentPosition = 0;
-
- while (currentPosition < urlsToCrawl.size()) {
- URL currentURL = (URL) urlsToCrawl.elementAt(currentPosition);
- currentURLPath = currentURL.toString().substring(0, currentURL.toString().lastIndexOf("/"));
-
- log.info("INFO: Current Array Size: " + urlsToCrawl.size() + ", Current Position: " + currentPosition + ", Current URL: " + currentURL.toString());
-
-
- java.util.List urlsWithinPage = parsePage(currentURL.toString());
-
- if (urlsWithinPage != null) {
- java.util.Iterator iterator = urlsWithinPage.iterator();
-
- while (iterator.hasNext()) {
- String urlCandidate = (String) iterator.next();
-
- try {
- URL urlToCrawl = null;
-
- if ((urlToCrawl = addURL(urlCandidate, currentURLPath)) != null) {
- dumpHTDoc(urlToCrawl);
- }
- } catch (MalformedURLException e) {
- log.warn("" + e + " " + urlCandidate);
- }
- }
- }
-
- currentPosition = currentPosition + 1;
- }
-
- log.info("Stop crawling at: " + urlsToCrawl.elementAt(urlsToCrawl.size()-1));
-
-
-
- // Write all crawled URLs into file
- try {
- File parent = new File(new File(url_list_file).getParent());
- if (!parent.isDirectory()) {
- parent.mkdirs();
- log.warn("Directory has been created: " + parent);
- }
- java.io.PrintWriter out = new java.io.PrintWriter(new FileOutputStream(url_list_file));
-
- for (int i = 0; i < urlsToCrawl.size(); i++) {
- out.println("" + urlsToCrawl.elementAt(i));
- }
-
- out.close();
- } catch (java.io.FileNotFoundException e) {
- log.error("" + e);
- }
- }
-
- /**
- * Add URLs to crawl
- *
- * @param urlCandidate DOCUMENT ME!
- * @param currentURLPath DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws MalformedURLException DOCUMENT ME!
- */
- public URL addURL(String urlCandidate, String currentURLPath)
- throws MalformedURLException {
- URL url = new URL(parseHREF(urlCandidate, urlCandidate.toLowerCase(), currentURLPath));
- //completeURL(currentURL,urlCandidate) new URL(currentURLPath+"/"+urlCandidate);
-
- if (filterURL(urlCandidate, currentURLPath, urlsToCrawlLowerCase)) {
- if (!robot.disallowed(url)) {
- if (url.getQuery() == null) {
- urlsToCrawl.add(url);
- urlsToCrawlLowerCase.add(url.toString().toLowerCase());
- log.debug("URL added: " + url);
- } else {
- log.info("Don't crawl URLs with query string: " + url);
- }
-
- return url;
- } else {
- log.info("Disallowed by robots.txt: " + urlCandidate);
- }
- }
-
- return null;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param urlString DOCUMENT ME!
- *
- * @return ok, 404
- */
- public java.util.List parsePage(String urlString) {
- String status = "ok";
-
- try {
- URL currentURL = new java.net.URL(urlString);
- String currentURLPath = urlString.substring(0, urlString.lastIndexOf("/"));
- HttpURLConnection httpCon = (HttpURLConnection) currentURL.openConnection();
-
- httpCon.setRequestProperty("User-Agent", "Lenya Lucene Crawler");
-
- httpCon.connect();
-
- long lastModified = httpCon.getLastModified();
-
- if (httpCon.getResponseCode() == HttpURLConnection.HTTP_OK) {
- String contentType = httpCon.getContentType();
-
- if (contentType.indexOf("text/html") != -1) {
- return handleHTML(httpCon);
- } else if (contentType.indexOf("application/pdf") != -1) {
- handlePDF(httpCon);
- } else {
- status = "Not an excepted content type : " + contentType;
- }
- } else {
- status = "bad";
- }
-
- httpCon.disconnect();
- } catch (java.net.MalformedURLException mue) {
- status = mue.toString();
- } catch (java.net.UnknownHostException uh) {
- status = uh.toString(); // Mark as a bad URL
- } catch (java.io.IOException ioe) {
- status = ioe.toString(); // Mark as a bad URL
- } catch (Exception e) {
- status = e.toString(); // Mark as a bad URL
- }
-
- //return status;
- return null;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param httpCon DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.io.IOException DOCUMENT ME!
- */
- public static java.util.List handleHTML(HttpURLConnection httpCon)
- throws java.io.IOException {
- ContentHandler handler = new HTMLHandler();
- handler.parse(httpCon.getInputStream());
-
- if (handler.getRobotFollow()) {
- java.util.List links = handler.getLinks();
-
- return links;
- }
-
- return null;
- }
-
- /**
- * Parse PDF for links
- *
- * @param httpCon DOCUMENT ME!
- */
- public void handlePDF(HttpURLConnection httpCon) {
- log.debug(".handlePDF(): Not handled yet!");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param url DOCUMENT ME!
- * @param currentURLPath DOCUMENT ME!
- * @param links DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean filterURL(String url, String currentURLPath, java.util.TreeSet links) {
- String urlLowCase = url.toLowerCase();
-
- if (!(urlLowCase.startsWith("http://") || urlLowCase.startsWith("https://"))) {
- url = parseHREF(url, urlLowCase, currentURLPath);
-
- if (url != null) {
- urlLowCase = url.toLowerCase();
- }
- }
-
- if ((url != null) && inScope(url)) {
- if (!links.contains(urlLowCase)) {
- return true;
+ }
+ }catch(MalformedURLException e){
+ log.error("" + e);
+ }
+ }
+ /**
+ * Creates a new IterativeHTMLCrawler object.
+ *
+ * @param url_list_file
+ * File where all dumped files will be listed
+ * @param html_dump_directory
+ * Directory where htdocs should be dumped
+ * @param userAgent
+ * User-agent for robots.txt
+ */
+ public IterativeHTMLCrawler(String url_list_file, String html_dump_directory, String userAgent) {
+ this.url_list_file = url_list_file;
+ this.html_dump_directory = html_dump_directory;
+ robot = new RobotExclusion(userAgent);
+ }
+ /**
+ * Creates a new IterativeHTMLCrawler object.
+ *
+ * @param config
+ * Configuration File
+ */
+ public IterativeHTMLCrawler(File config) {
+ CrawlerConfiguration ce = new CrawlerConfiguration(config.getAbsolutePath());
+ this.url_list_file = ce.getURIListResolved();
+ log.debug("URI list file: " + this.url_list_file);
+ this.html_dump_directory = ce.getHTDocsDumpDirResolved();
+ log.debug("HTDocs Dump Dir: " + this.html_dump_directory);
+ robot = new RobotExclusion(ce.getUserAgent());
+ String robots_file = ce.getRobotsFileResolved();
+ log.debug("Robots File: " + robots_file);
+ String robots_domain = ce.getRobotsDomain();
+ if(robots_file != null && robots_domain != null){
+ log.debug(robots_file + " " + robots_domain);
+ robot.addLocalEntries(robots_domain, new File(robots_file));
+ }
+ }
+ /**
+ * Crawl
+ *
+ * @param start
+ * Start crawling at this URL
+ * @param scope
+ * Limit crawling to this scope
+ */
+ public void crawl(URL start, String scope) {
+ scopeURL = new String[1];
+ scopeURL[0] = scope;
+ String seedURL = start.toString();
+ this.rootURL = seedURL.substring(0, seedURL.indexOf("/", 8));
+ urlsToCrawl = new java.util.Vector();
+ urlsToCrawlLowerCase = new java.util.TreeSet();
+ String currentURLPath = start.toString().substring(0, start.toString().lastIndexOf("/"));
+ try{
+ log.info("Start crawling at: " + start);
+ if(addURL(start.getFile(), currentURLPath) != null){
+ dumpHTDoc(start);
+ }else{
+ log.warn("Start URL has not been dumped: " + start);
+ }
+ }catch(MalformedURLException e){
+ log.error("" + e);
+ }
+ int currentPosition = 0;
+ while(currentPosition < urlsToCrawl.size()){
+ URL currentURL = (URL) urlsToCrawl.elementAt(currentPosition);
+ currentURLPath = currentURL.toString().substring(0, currentURL.toString().lastIndexOf("/"));
+ log.info("INFO: Current Array Size: " + urlsToCrawl.size() + ", Current Position: " + currentPosition + ", Current URL: " + currentURL.toString());
+ java.util.List urlsWithinPage = parsePage(currentURL.toString());
+ if(urlsWithinPage != null){
+ java.util.Iterator iterator = urlsWithinPage.iterator();
+ while(iterator.hasNext()){
+ String urlCandidate = (String) iterator.next();
+ try{
+ URL urlToCrawl = null;
+ if((urlToCrawl = addURL(urlCandidate, currentURLPath)) != null){
+ dumpHTDoc(urlToCrawl);
+ }
+ }catch(MalformedURLException e){
+ log.warn("" + e + " " + urlCandidate);
+ }
+ }
+ }
+ currentPosition = currentPosition + 1;
+ }
+ log.info("Stop crawling at: " + urlsToCrawl.elementAt(urlsToCrawl.size() - 1));
+ // Write all crawled URLs into file
+ try{
+ File parent = new File(new File(url_list_file).getParent());
+ if(!parent.isDirectory()){
+ parent.mkdirs();
+ log.warn("Directory has been created: " + parent);
+ }
+ java.io.PrintWriter out = new java.io.PrintWriter(new FileOutputStream(url_list_file));
+ for(int i = 0; i < urlsToCrawl.size(); i++){
+ out.println("" + urlsToCrawl.elementAt(i));
+ }
+ out.close();
+ }catch(java.io.FileNotFoundException e){
+ log.error("" + e);
+ }
+ }
+ /**
+ * Add URLs to crawl
+ *
+ * @param urlCandidate
+ * DOCUMENT ME!
+ * @param currentURLPath
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws MalformedURLException
+ * DOCUMENT ME!
+ */
+ public URL addURL(String urlCandidate, String currentURLPath) throws MalformedURLException {
+ URL url = new URL(parseHREF(urlCandidate, urlCandidate.toLowerCase(), currentURLPath));
+ // completeURL(currentURL,urlCandidate) new URL(currentURLPath+"/"+urlCandidate);
+ if(filterURL(urlCandidate, currentURLPath, urlsToCrawlLowerCase)){
+ if(!robot.disallowed(url)){
+ if(url.getQuery() == null){
+ urlsToCrawl.add(url);
+ urlsToCrawlLowerCase.add(url.toString().toLowerCase());
+ log.debug("URL added: " + url);
+ }else{
+ log.info("Don't crawl URLs with query string: " + url);
}
- } else {
- log.debug("Not in scope: " + url);
- }
-
- return false;
- }
-
- /**
- * Parse URL and complete if necessary
- *
- * @param url URL from href
- * @param urlLowCase url is lower case
- * @param currentURLPath URL of current page
- *
- * @return Completed URL
- */
- public String parseHREF(String url, String urlLowCase, String currentURLPath) {
- if (urlLowCase.startsWith("http://") || urlLowCase.startsWith("https://")) {
return url;
- }
-
- // Looks for incomplete URL and completes them
- if (urlLowCase.startsWith("/")) {
- url = rootURL + url;
- } else if (urlLowCase.startsWith("./")) {
- url = currentURLPath + url.substring(1, url.length());
- } else if (urlLowCase.startsWith("../")) {
- int back = 1;
-
- // Count number of "../"s
- while (urlLowCase.indexOf("../", back * 3) != -1)
- back++;
-
- int pos = currentURLPath.length();
- int count = back;
-
- while (count-- > 0) {
- pos = currentURLPath.lastIndexOf("/", pos) - 1;
- }
-
- String dotsRemoved = url.substring(3 * back, url.length());
- if (dotsRemoved.length() > 0 && dotsRemoved.charAt(0) == '.') {
- log.error("Parsing failed: " + url + " (" + currentURLPath + ")");
- url = null;
- } else {
- url = currentURLPath.substring(0, pos + 2) + dotsRemoved;
- }
- } else if (urlLowCase.startsWith("javascript:")) {
- // handle javascript:...
- log.debug("\"javascript:\" is not implemented yet!");
- url = null;
- } else if (urlLowCase.startsWith("#")) {
- log.debug("\"#\" (anchor) will be ignored!");
-
- // internal anchor... ignore.
- url = null;
- } else if (urlLowCase.startsWith("mailto:")) {
- log.debug("\"mailto:\" is not a URL to be followed!");
-
- // handle mailto:...
+ }else{
+ log.info("Disallowed by robots.txt: " + urlCandidate);
+ }
+ }
+ return null;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param urlString
+ * DOCUMENT ME!
+ *
+ * @return ok, 404
+ */
+ public java.util.List parsePage(String urlString) {
+ // String status = "ok";
+ String status = "";
+ try{
+ URL currentURL = new java.net.URL(urlString);
+ // String currentURLPath = urlString.substring(0, urlString.lastIndexOf("/"));
+ HttpURLConnection httpCon = (HttpURLConnection) currentURL.openConnection();
+ httpCon.setRequestProperty("User-Agent", "Lenya Lucene Crawler");
+ httpCon.connect();
+ // long lastModified = httpCon.getLastModified();
+ if(httpCon.getResponseCode() == HttpURLConnection.HTTP_OK){
+ String contentType = httpCon.getContentType();
+ if(contentType.indexOf("text/html") != -1){
+ return handleHTML(httpCon);
+ }else if(contentType.indexOf("application/pdf") != -1){
+ handlePDF(httpCon);
+ }else{
+ status = "Not an excepted content type : " + contentType;
+ }
+ }else{
+ status = "bad";
+ }
+ httpCon.disconnect();
+ }catch(java.net.MalformedURLException mue){
+ status = mue.toString();
+ }catch(java.net.UnknownHostException uh){
+ status = uh.toString(); // Mark as a bad URL
+ }catch(java.io.IOException ioe){
+ status = ioe.toString(); // Mark as a bad URL
+ }catch(Exception e){
+ status = e.toString(); // Mark as a bad URL
+ }
+ if(status.length() > 0){
+ System.out.println("IterativeHTMLCrawler parsePage() status=" + status);
+ }
+ // return status;
+ return null;
+ }
+ public static java.util.List handleHTML(HttpURLConnection httpCon) throws java.io.IOException {
+ ContentHandler handler = new HTMLHandler();
+ handler.parse(httpCon.getInputStream());
+ if(handler.getRobotFollow()){
+ return handler.getLinks();
+ }
+ return null;
+ }
+ /**
+ * Parse PDF for links
+ */
+ public void handlePDF(HttpURLConnection httpCon) {
+ log.debug(".handlePDF(): Not handled yet!");
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param url
+ * DOCUMENT ME!
+ * @param currentURLPath
+ * DOCUMENT ME!
+ * @param links
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean filterURL(String url, String currentURLPath, java.util.TreeSet links) {
+ String urlLowCase = url.toLowerCase();
+ if(!(urlLowCase.startsWith("http://") || urlLowCase.startsWith("https://"))){
+ url = parseHREF(url, urlLowCase, currentURLPath);
+ if(url != null){
+ urlLowCase = url.toLowerCase();
+ }
+ }
+ if((url != null) && inScope(url)){
+ if(!links.contains(urlLowCase)){
+ return true;
+ }
+ }else{
+ log.debug("Not in scope: " + url);
+ }
+ return false;
+ }
+ /**
+ * Parse URL and complete if necessary
+ *
+ * @param url
+ * URL from href
+ * @param urlLowCase
+ * url is lower case
+ * @param currentURLPath
+ * URL of current page
+ *
+ * @return Completed URL
+ */
+ public String parseHREF(String url, String urlLowCase, String currentURLPath) {
+ if(urlLowCase.startsWith("http://") || urlLowCase.startsWith("https://")){
+ return url;
+ }
+ // Looks for incomplete URL and completes them
+ if(urlLowCase.startsWith("/")){
+ url = rootURL + url;
+ }else if(urlLowCase.startsWith("./")){
+ url = currentURLPath + url.substring(1, url.length());
+ }else if(urlLowCase.startsWith("../")){
+ int back = 1;
+ // Count number of "../"s
+ while(urlLowCase.indexOf("../", back * 3) != -1)
+ back++;
+ int pos = currentURLPath.length();
+ int count = back;
+ while(count-- > 0){
+ pos = currentURLPath.lastIndexOf("/", pos) - 1;
+ }
+ String dotsRemoved = url.substring(3 * back, url.length());
+ if(dotsRemoved.length() > 0 && dotsRemoved.charAt(0) == '.'){
+ log.error("Parsing failed: " + url + " (" + currentURLPath + ")");
url = null;
- } else {
- url = currentURLPath + "/" + url;
- }
-
- // strip anchor if exists otherwise crawler may index content multiple times
- // links to the same url but with unique anchors would be considered unique
- // by the crawler when they should not be
- if (url != null) {
- int i;
-
- if ((i = url.indexOf("#")) != -1) {
- url = url.substring(0, i);
+ }else{
+ url = currentURLPath.substring(0, pos + 2) + dotsRemoved;
+ }
+ }else if(urlLowCase.startsWith("javascript:")){
+ // handle javascript:...
+ log.debug("\"javascript:\" is not implemented yet!");
+ url = null;
+ }else if(urlLowCase.startsWith("#")){
+ log.debug("\"#\" (anchor) will be ignored!");
+ // internal anchor... ignore.
+ url = null;
+ }else if(urlLowCase.startsWith("mailto:")){
+ log.debug("\"mailto:\" is not a URL to be followed!");
+ // handle mailto:...
+ url = null;
+ }else{
+ url = currentURLPath + "/" + url;
+ }
+ // strip anchor if exists otherwise crawler may index content multiple times
+ // links to the same url but with unique anchors would be considered unique
+ // by the crawler when they should not be
+ if(url != null){
+ int i;
+ if((i = url.indexOf("#")) != -1){
+ url = url.substring(0, i);
+ }
+ }
+ return url;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param url
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean inScope(String url) {
+ for(int i = 0; i < scopeURL.length; i++){
+ if(url.startsWith(scopeURL[i])){
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent
+ * DOCUMENT ME!
+ * @param child
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws MalformedURLException
+ * DOCUMENT ME!
+ */
+ public URL completeURL(URL parent, String child) throws MalformedURLException {
+ return parent;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param url
+ * DOCUMENT ME!
+ */
+ public void dumpHTDoc(URL url) {
+ String ext = getExtension(url);
+ String filename = html_dump_directory + url.getFile();
+ File file = new File(filename);
+ if(filename.charAt(filename.length() - 1) == '/'){
+ file = new File(filename + "index.html");
+ ext = getExtension(file);
+ }
+ if(ext.equals("html") || ext.equals("htm") || ext.equals("txt") || ext.equals("pdf")){
+ try{
+ File parent = new File(file.getParent());
+ if(!parent.exists()){
+ parent.mkdirs();
+ }
+ HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
+ java.io.InputStream in = httpConnection.getInputStream();
+ FileOutputStream out = new FileOutputStream(file);
+ byte[] buffer = new byte[1024];
+ int bytesRead = -1;
+ while((bytesRead = in.read(buffer)) >= 0){
+ out.write(buffer, 0, bytesRead);
}
- }
-
-
- return url;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param url DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean inScope(String url) {
- for (int i = 0; i < scopeURL.length; i++) {
- if (url.startsWith(scopeURL[i])) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param parent DOCUMENT ME!
- * @param child DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws MalformedURLException DOCUMENT ME!
- */
- public URL completeURL(URL parent, String child) throws MalformedURLException {
- return parent;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param url DOCUMENT ME!
- */
- public void dumpHTDoc(URL url) {
- String ext = getExtension(url);
-
- String filename = html_dump_directory + url.getFile();
- File file = new File(filename);
-
- if (filename.charAt(filename.length() - 1) == '/') {
- file = new File(filename + "index.html");
- ext = getExtension(file);
- }
-
- if (ext.equals("html") || ext.equals("htm") || ext.equals("txt") || ext.equals("pdf")) {
- try {
- File parent = new File(file.getParent());
-
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
- java.io.InputStream in = httpConnection.getInputStream();
-
- FileOutputStream out = new FileOutputStream(file);
- byte[] buffer = new byte[1024];
- int bytesRead = -1;
- while ((bytesRead = in.read(buffer)) >= 0) {
- out.write(buffer, 0, bytesRead);
- }
- out.close();
-
-/*
- BufferedInputStream bin = new BufferedInputStream(in);
- BufferedReader reader = new BufferedReader(new InputStreamReader(bin));
-
- java.io.FileWriter fw = new java.io.FileWriter(file);
- int i;
-
- while ((i = reader.read()) != -1) {
- fw.write(i);
- }
-
- fw.close();
-
- bin.close();
-*/
- in.close();
- httpConnection.disconnect();
-
- log.info("URL dumped: " + url + " (" + file + ")");
- } catch (Exception e) {
- log.error("" + e);
- log.error("URL not dumped: " + url);
- }
- } else {
- log.info("URL not dumped: " + url);
- }
- }
-
- /**
- *
- */
-/*
- public void saveToFile(String filename, byte[] bytes)
- throws FileNotFoundException, IOException {
- File file = new File(filename);
-
- if (filename.charAt(filename.length() - 1) == '/') {
- file = new File(filename + "index.html");
- }
-
- File parent = new File(file.getParent());
-
- if (!parent.exists()) {
- log.warn("Directory will be created: " + parent.getAbsolutePath());
- parent.mkdirs();
- }
-
- FileOutputStream out = new FileOutputStream(file.getAbsolutePath());
- out.write(bytes);
- out.close();
- }
-*/
-
- /**
- * DOCUMENT ME!
- *
- * @param url DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getExtension(URL url) {
- return getExtension(new File(url.getPath()));
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param file DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getExtension(File file) {
- StringTokenizer st = new StringTokenizer(file.getPath(), ".");
- String extension = null;
-
- while (st.hasMoreElements()) {
- extension = st.nextToken();
- }
-
- return extension;
- }
+ out.close();
+ /*
+ * BufferedInputStream bin = new BufferedInputStream(in); BufferedReader reader = new BufferedReader(new InputStreamReader(bin));
+ *
+ * java.io.FileWriter fw = new java.io.FileWriter(file); int i;
+ *
+ * while ((i = reader.read()) != -1) { fw.write(i); }
+ *
+ * fw.close();
+ *
+ * bin.close();
+ */
+ in.close();
+ httpConnection.disconnect();
+ log.info("URL dumped: " + url + " (" + file + ")");
+ }catch(Exception e){
+ log.error("" + e);
+ log.error("URL not dumped: " + url);
+ }
+ }else{
+ log.info("URL not dumped: " + url);
+ }
+ }
+ /**
+ *
+ */
+ /*
+ * public void saveToFile(String filename, byte[] bytes) throws FileNotFoundException, IOException { File file = new File(filename);
+ *
+ * if (filename.charAt(filename.length() - 1) == '/') { file = new File(filename + "index.html"); }
+ *
+ * File parent = new File(file.getParent());
+ *
+ * if (!parent.exists()) { log.warn("Directory will be created: " + parent.getAbsolutePath()); parent.mkdirs(); }
+ *
+ * FileOutputStream out = new FileOutputStream(file.getAbsolutePath()); out.write(bytes); out.close(); }
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @param url
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getExtension(URL url) {
+ return getExtension(new File(url.getPath()));
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param file
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getExtension(File file) {
+ StringTokenizer st = new StringTokenizer(file.getPath(), ".");
+ String extension = null;
+ while(st.hasMoreElements()){
+ extension = st.nextToken();
+ }
+ return extension;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/CacheMap.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/CacheMap.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/CacheMap.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/CacheMap.java Wed Jan 30 23:44:03 2008
@@ -14,69 +14,57 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.util.Date;
import java.util.HashMap;
import java.util.SortedMap;
import java.util.TreeMap;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* A map with a maximum capacity. When the map is full, the oldest entry is removed.
*/
public class CacheMap extends HashMap {
-
- private static final Category log = Category.getInstance(CacheMap.class);
-
- /**
- * Ctor.
- * @param capacity The maximum number of entries.
- */
- public CacheMap(int capacity) {
-// assert capacity > -1;
- this.capacity = capacity;
- }
-
- private int capacity;
- private SortedMap timeToKey = new TreeMap();
-
- /**
- * @see java.util.Map#put(Object, Object)
- */
- public Object put(Object key, Object value) {
-
- if (size() == capacity) {
- Object oldestKey = timeToKey.get(timeToKey.firstKey());
- remove(oldestKey);
- if (log.isDebugEnabled()) {
- log.debug("Clearing cache");
- }
- }
- timeToKey.put(new Date(), key);
- return super.put(key, value);
- }
-
-
-
- /**
- * @see java.util.Map#get(java.lang.Object)
- */
- public Object get(Object key) {
- Object result = super.get(key);
- if (log.isDebugEnabled()) {
- if (result != null) {
- log.debug("Using cached object for key [" + key + "]");
- }
- else {
- log.debug("No cached object for key [" + key + "]");
- }
- }
- return result;
- }
-
+ private static final long serialVersionUID = 1L;
+ private static Logger log = Logger.getLogger(CacheMap.class);
+ /**
+ * Ctor.
+ *
+ * @param capacity
+ * The maximum number of entries.
+ */
+ public CacheMap(int capacity) {
+ // assert capacity > -1;
+ this.capacity = capacity;
+ }
+ private int capacity;
+ private SortedMap timeToKey = new TreeMap();
+ /**
+ * @see java.util.Map#put(Object, Object)
+ */
+ public Object put(Object key, Object value) {
+ if(size() == capacity){
+ Object oldestKey = timeToKey.get(timeToKey.firstKey());
+ remove(oldestKey);
+ if(log.isDebugEnabled()){
+ log.debug("Clearing cache");
+ }
+ }
+ timeToKey.put(new Date(), key);
+ return super.put(key, value);
+ }
+ /**
+ * @see java.util.Map#get(java.lang.Object)
+ */
+ public Object get(Object key) {
+ Object result = super.get(key);
+ if(log.isDebugEnabled()){
+ if(result != null){
+ log.debug("Using cached object for key [" + key + "]");
+ }else{
+ log.debug("No cached object for key [" + key + "]");
+ }
+ }
+ return result;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/FileUtil.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/FileUtil.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/FileUtil.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/FileUtil.java Wed Jan 30 23:44:03 2008
@@ -14,9 +14,7 @@
* limitations under the License.
*
*/
-
package org.apache.lenya.util;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -25,223 +23,200 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.StringTokenizer;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* @version $Id$
*/
public final class FileUtil {
- private static Category log = Category.getInstance(FileUtil.class);
-
- /**
- * DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.err.println("Usage: java " + new FileUtil().getClass().getName());
-
+ private static Logger log = Logger.getLogger(FileUtil.class);
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if(args.length == 0){
+ System.err.println("Usage: java " + new FileUtil().getClass().getName());
+ return;
+ }
+ if(args[0].equals("--copy")){
+ if(args.length != 3){
+ System.err.println("Usage: --copy source destination");
return;
- }
-
- if (args[0].equals("--copy")) {
- if (args.length != 3) {
- System.err.println("Usage: --copy source destination");
-
- return;
- }
-
- try {
- System.err.println("cp " + args[1] + " " + args[2]);
- copy(args[1], args[2]);
- } catch (FileNotFoundException e) {
- System.err.println(e);
- } catch (IOException e) {
- System.err.println(e);
- }
-
+ }
+ try{
+ System.err.println("cp " + args[1] + " " + args[2]);
+ copy(args[1], args[2]);
+ }catch(FileNotFoundException e){
+ System.err.println(e);
+ }catch(IOException e){
+ System.err.println(e);
+ }
+ return;
+ }
+ if(args[0].equals("--concatPath")){
+ // FIXME:
+ File file = org.apache.lenya.util.FileUtil.file("/root/temp/jpf-1.9/java/lenya/x/xps/samples/invoices/invoices", "../addresses/lenya.xml");
+ System.out.println(file.getAbsolutePath());
+ }else{
+ }
+ }
+ /**
+ * Copying a file
+ *
+ * @param source_name
+ * DOCUMENT ME!
+ * @param destination_name
+ * DOCUMENT ME!
+ *
+ * @throws FileNotFoundException
+ * DOCUMENT ME!
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public static void copy(String source_name, String destination_name) throws FileNotFoundException, IOException {
+ InputStream source = new FileInputStream(source_name);
+ File destination_file = new File(destination_name);
+ File parent = new File(destination_file.getParent());
+ if(!parent.exists()){
+ parent.mkdirs();
+ log.debug("Directory has been created: " + parent.getAbsolutePath());
+ }
+ OutputStream destination = new FileOutputStream(destination_name);
+ byte[] bytes_buffer = new byte[1024];
+ int bytes_read;
+ while((bytes_read = source.read(bytes_buffer)) >= 0){
+ destination.write(bytes_buffer, 0, bytes_read);
+ }
+ }
+ /**
+ * Copy a single File or a complete Directory including its Contents.
+ *
+ * @param src
+ * the source File.
+ * @param dest
+ * the destiantion File.
+ *
+ * @throws FileNotFoundException
+ * if the source File does not exists.
+ * @throws IOException
+ * if an error occures in the io system.
+ */
+ public static void copy(File src, File dest) throws FileNotFoundException, IOException {
+ if(src.isFile()){
+ copySingleFile(src, dest);
+ }else{
+ File[] contents = src.listFiles();
+ if(contents == null)
return;
- }
-
- if (args[0].equals("--concatPath")) {
- // FIXME:
- File file = org.apache.lenya.util.FileUtil.file(
- "/root/temp/jpf-1.9/java/lenya/x/xps/samples/invoices/invoices",
- "../addresses/lenya.xml");
- System.out.println(file.getAbsolutePath());
- } else {
- }
- }
-
- /**
- * Copying a file
- *
- * @param source_name DOCUMENT ME!
- * @param destination_name DOCUMENT ME!
- *
- * @throws FileNotFoundException DOCUMENT ME!
- * @throws IOException DOCUMENT ME!
- */
- public static void copy(String source_name, String destination_name)
- throws FileNotFoundException, IOException {
- InputStream source = new FileInputStream(source_name);
- File destination_file = new File(destination_name);
- File parent = new File(destination_file.getParent());
-
- if (!parent.exists()) {
- parent.mkdirs();
- log.debug("Directory has been created: " + parent.getAbsolutePath());
- }
-
- OutputStream destination = new FileOutputStream(destination_name);
- byte[] bytes_buffer = new byte[1024];
- int bytes_read;
-
- while ((bytes_read = source.read(bytes_buffer)) >= 0) {
- destination.write(bytes_buffer, 0, bytes_read);
- }
- }
-
- /**
- * Copy a single File or a complete Directory including its Contents.
- *
- * @param src the source File.
- * @param dest the destiantion File.
- *
- * @throws FileNotFoundException if the source File does not exists.
- * @throws IOException if an error occures in the io system.
- */
- public static void copy(File src, File dest) throws FileNotFoundException, IOException {
-
- if (src.isFile()) {
- copySingleFile(src, dest);
- } else {
- File[] contents = src.listFiles();
-
- if (contents == null)
- return;
-
- dest.mkdirs();
-
- for (int i = 0; i < contents.length; i++) {
- String destPath = dest.getAbsolutePath() + File.separator + contents[i].getName();
- copy(contents[i], new File(destPath));
- }
- }
- }
-
- /**
- * Copy a single File.
- *
- * @param src the source File.
- * @param dest the destiantion File.
- *
- * @throws FileNotFoundException if the source File does not exists.
- * @throws IOException if an error occures in the io system.
- */
- protected static void copySingleFile(File src, File dest) throws FileNotFoundException,
- IOException {
-
- dest.getParentFile().mkdirs();
- dest.createNewFile();
- org.apache.commons.io.FileUtils.copyFile(src, dest);
- }
-
- /**
- * Returns a file by specifying an absolute directory name and a relative file name
- *
- * @param absoluteDir DOCUMENT ME!
- * @param relativeFile DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static File file(String absoluteDir, String relativeFile) {
- File file = new File(fileName(absoluteDir, relativeFile));
-
- return file;
- }
-
- /**
- * Returns an absolute file name by specifying an absolute directory name and a relative file
- * name
- *
- * @param absoluteDir DOCUMENT ME!
- * @param relativeFile DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static String fileName(String absoluteDir, String relativeFile) {
- String fileName = null;
- String newAbsoluteDir = null;
-
- if (!(absoluteDir.charAt(absoluteDir.length() - 1) == '/')) {
- newAbsoluteDir = absoluteDir + "/";
- } else {
- newAbsoluteDir = absoluteDir;
- }
-
- if (relativeFile.indexOf("../") == 0) {
- StringTokenizer token = new StringTokenizer(newAbsoluteDir, "/");
- newAbsoluteDir = "/";
-
- int numberOfTokens = token.countTokens();
-
- for (int i = 0; i < (numberOfTokens - 1); i++) {
- newAbsoluteDir = newAbsoluteDir + token.nextToken() + "/";
- }
-
- String newRelativeFile = relativeFile.substring(3, relativeFile.length());
- fileName = fileName(newAbsoluteDir, newRelativeFile);
- } else if (relativeFile.indexOf("./") == 0) {
- fileName = newAbsoluteDir + relativeFile.substring(2, relativeFile.length());
- } else {
- fileName = newAbsoluteDir + relativeFile;
- }
-
- return fileName;
- }
-
- /**
- * Returns an absolute file name by specifying an absolute directory name and a relative file
- * name
- *
- * @param absoluteFile DOCUMENT ME!
- * @param relativeFile DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static String concat(String absoluteFile, String relativeFile) {
- File file = new File(absoluteFile);
-
- if (file.isFile()) {
- return fileName(file.getParent(), relativeFile);
- }
-
- return fileName(absoluteFile, relativeFile);
- }
-
- /**
- * Deletes all dirs up to stop dir or if dirs in hirachy are not empty.
- *
- * @param start File to delete the parents of. The File itself is not deleted.
- * @param stop Stop deleting at this dir. This dir is not deleted.
- * @throws IllegalArgumentException If stop is not a dir or start is not a descending sibling of
- * stop dir.
- */
- public static void deleteParentDirs(File start, File stop) throws IllegalArgumentException {
- if (!stop.isDirectory())
- throw new IllegalArgumentException("Stop dir '" + stop.getAbsolutePath()
- + "' is not a directory");
- if (!start.getAbsolutePath().startsWith(stop.getAbsolutePath()))
- throw new IllegalArgumentException("Start dir '" + start.getAbsolutePath()
- + "' is not a descending sibling of stop directory '" + stop.getAbsolutePath()
- + "'.");
-
- File parent = start.getParentFile();
-
- while (!parent.equals(stop) && parent.delete())
- parent = parent.getParentFile();
- }
+ dest.mkdirs();
+ for(int i = 0; i < contents.length; i++){
+ String destPath = dest.getAbsolutePath() + File.separator + contents[i].getName();
+ copy(contents[i], new File(destPath));
+ }
+ }
+ }
+ /**
+ * Copy a single File.
+ *
+ * @param src
+ * the source File.
+ * @param dest
+ * the destiantion File.
+ *
+ * @throws FileNotFoundException
+ * if the source File does not exists.
+ * @throws IOException
+ * if an error occures in the io system.
+ */
+ protected static void copySingleFile(File src, File dest) throws FileNotFoundException, IOException {
+ dest.getParentFile().mkdirs();
+ dest.createNewFile();
+ org.apache.commons.io.FileUtils.copyFile(src, dest);
+ }
+ /**
+ * Returns a file by specifying an absolute directory name and a relative file name
+ *
+ * @param absoluteDir
+ * DOCUMENT ME!
+ * @param relativeFile
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static File file(String absoluteDir, String relativeFile) {
+ File file = new File(fileName(absoluteDir, relativeFile));
+ return file;
+ }
+ /**
+ * Returns an absolute file name by specifying an absolute directory name and a relative file name
+ *
+ * @param absoluteDir
+ * DOCUMENT ME!
+ * @param relativeFile
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static String fileName(String absoluteDir, String relativeFile) {
+ String fileName = null;
+ String newAbsoluteDir = null;
+ if(!(absoluteDir.charAt(absoluteDir.length() - 1) == '/')){
+ newAbsoluteDir = absoluteDir + "/";
+ }else{
+ newAbsoluteDir = absoluteDir;
+ }
+ if(relativeFile.indexOf("../") == 0){
+ StringTokenizer token = new StringTokenizer(newAbsoluteDir, "/");
+ newAbsoluteDir = "/";
+ int numberOfTokens = token.countTokens();
+ for(int i = 0; i < (numberOfTokens - 1); i++){
+ newAbsoluteDir = newAbsoluteDir + token.nextToken() + "/";
+ }
+ String newRelativeFile = relativeFile.substring(3, relativeFile.length());
+ fileName = fileName(newAbsoluteDir, newRelativeFile);
+ }else if(relativeFile.indexOf("./") == 0){
+ fileName = newAbsoluteDir + relativeFile.substring(2, relativeFile.length());
+ }else{
+ fileName = newAbsoluteDir + relativeFile;
+ }
+ return fileName;
+ }
+ /**
+ * Returns an absolute file name by specifying an absolute directory name and a relative file name
+ *
+ * @param absoluteFile
+ * DOCUMENT ME!
+ * @param relativeFile
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static String concat(String absoluteFile, String relativeFile) {
+ File file = new File(absoluteFile);
+ if(file.isFile()){
+ return fileName(file.getParent(), relativeFile);
+ }
+ return fileName(absoluteFile, relativeFile);
+ }
+ /**
+ * Deletes all dirs up to stop dir or if dirs in hirachy are not empty.
+ *
+ * @param start
+ * File to delete the parents of. The File itself is not deleted.
+ * @param stop
+ * Stop deleting at this dir. This dir is not deleted.
+ * @throws IllegalArgumentException
+ * If stop is not a dir or start is not a descending sibling of stop dir.
+ */
+ public static void deleteParentDirs(File start, File stop) throws IllegalArgumentException {
+ if(!stop.isDirectory())
+ throw new IllegalArgumentException("Stop dir '" + stop.getAbsolutePath() + "' is not a directory");
+ if(!start.getAbsolutePath().startsWith(stop.getAbsolutePath()))
+ throw new IllegalArgumentException("Start dir '" + start.getAbsolutePath() + "' is not a descending sibling of stop directory '" + stop.getAbsolutePath() + "'.");
+ File parent = start.getParentFile();
+ while(!parent.equals(stop) && parent.delete())
+ parent = parent.getParentFile();
+ }
}
Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Globals.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Globals.java?rev=617035&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Globals.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Globals.java Wed Jan 30 23:44:03 2008
@@ -0,0 +1,140 @@
+package org.apache.lenya.util;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+import org.apache.cocoon.environment.http.HttpContext;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.log.ContextMap;
+/**
+ * Static functions for accessing global and thread-based constants.
+ *
+ * @author solprovider
+ * @since 1.3
+ *
+ */
+public final class Globals {
+ private Globals() {
+ }
+ // null
+ static public String getAction() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getAction();
+ }
+ // null
+ static public String getContentType() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getContentType();
+ }
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/authoring/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/cache/module.xmap
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/edit/
+ // ?? Last use of map:mount
+ static public String getContext() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getContext();
+ }
+ static public String getModule() {
+ Source source = getSource();
+ if(null == source)
+ return "";
+ String ret = "";
+ String[] strings = source.getURI().split("^(.*)modules");
+ if(1 < strings.length){
+ strings = strings[1].split("[/\\\\]");
+ if(1 < strings.length){
+ ret = strings[1];
+ }
+ }
+ return ret;
+ }
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/
+ // ??? servletContextPath with protocol
+ static public String getRootContext() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getRootContext();
+ }
+ // Jetty/4.2
+ static public String getServerName() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpContext hc = (HttpContext) map.get("context");
+ return hc.getServerInfo();
+ }
+ // F:\eclipseWS\Lenya13x\build\lenya\webapp
+ // servletContextPath in OS' native format
+ static public String getServletContextPath() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpContext hc = (HttpContext) map.get("context");
+ return hc.getRealPath("");
+ }
+ // Source.getURI() =
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/navigation/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/nav/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/authoring/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/cache/module.xmap
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/edit/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/live/
+ // file:///F:/eclipseWS/Lenya13x/build/lenya/webapp/lenya/modules/xhtml/
+ // ??? The current XMAP (Lenya 1.3 defaults directories to "module.xmap")
+ /**
+ * FileSource
+ */
+ static public Source getSource() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ try{
+ return he.resolveURI("");
+ }catch(MalformedURLException e){
+ System.out.println("Globals.getSource MalformedURLException");
+ }catch(SourceException e){
+ System.out.println("Globals.getSource SourceException");
+ }catch(IOException e){
+ System.out.println("Globals.getSource IOException");
+ }
+ return null;
+ }
+ // C:\DOCUME~1\solprovider\LOCALS~1\Temp\Jetty__8888__
+ static public String getTempDir() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpContext hc = (HttpContext) map.get("context");
+ return (String) hc.getAttribute("javax.servlet.context.tempdir");
+ }
+ // authoring/index.html
+ // edit
+ // live/features_en.html
+ // live/index.html
+ // ??? The current match string for the XMAP.
+ static public String getURI() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getURI();
+ }
+ // default13/
+ static public String getURIPrefix() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getURIPrefix();
+ }
+ // null
+ static public String getView() {
+ ContextMap contextMap = ContextMap.getCurrentContext();
+ Map map = (Map) contextMap.get("objectModel");
+ HttpEnvironment he = (HttpEnvironment) map.get("source-resolver");
+ return he.getView();
+ }
+}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/HTMLHandler.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/HTMLHandler.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/HTMLHandler.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/HTMLHandler.java Wed Jan 30 23:44:03 2008
@@ -14,150 +14,128 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.util.ArrayList;
-
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
-
-import org.apache.log4j.Category;
-
-
-/**
- * DOCUMENT ME!
- */
public class HTMLHandler extends ParserCallback {
- Category log = Category.getInstance(HTMLHandler.class);
- private ArrayList img_src;
- private ArrayList img_src_all;
- private ArrayList a_href;
- private ArrayList a_href_all;
- private ArrayList link_href;
- private ArrayList link_href_all;
-
- /**
- * Creates a new HTMLHandler object.
- */
- public HTMLHandler() {
- img_src_all = new ArrayList();
- img_src = new ArrayList();
- a_href_all = new ArrayList();
- a_href = new ArrayList();
- link_href_all = new ArrayList();
- link_href = new ArrayList();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param tag DOCUMENT ME!
- * @param attributes DOCUMENT ME!
- * @param pos DOCUMENT ME!
- */
- public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) {
- if (tag.equals(HTML.Tag.A)) {
- String href = (String) attributes.getAttribute(HTML.Attribute.HREF);
-
- if (href != null) {
- a_href_all.add(href);
-
- if (!a_href.contains(href)) {
- a_href.add(href);
- }
+ private ArrayList img_src;
+ private ArrayList img_src_all;
+ private ArrayList a_href;
+ private ArrayList a_href_all;
+ private ArrayList link_href;
+ private ArrayList link_href_all;
+ /**
+ * Creates a new HTMLHandler object.
+ */
+ public HTMLHandler() {
+ img_src_all = new ArrayList();
+ img_src = new ArrayList();
+ a_href_all = new ArrayList();
+ a_href = new ArrayList();
+ link_href_all = new ArrayList();
+ link_href = new ArrayList();
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tag
+ * DOCUMENT ME!
+ * @param attributes
+ * DOCUMENT ME!
+ * @param pos
+ * DOCUMENT ME!
+ */
+ public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) {
+ if(tag.equals(HTML.Tag.A)){
+ String href = (String) attributes.getAttribute(HTML.Attribute.HREF);
+ if(href != null){
+ a_href_all.add(href);
+ if(!a_href.contains(href)){
+ a_href.add(href);
}
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param tag DOCUMENT ME!
- * @param attributes DOCUMENT ME!
- * @param pos DOCUMENT ME!
- */
- public void handleSimpleTag(Tag tag, MutableAttributeSet attributes, int pos) {
- if (tag.equals(HTML.Tag.IMG)) {
- String src = (String) attributes.getAttribute(HTML.Attribute.SRC);
-
- if (src != null) {
- img_src_all.add(src);
-
- if (!img_src.contains(src)) {
- img_src.add(src);
- }
+ }
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tag
+ * DOCUMENT ME!
+ * @param attributes
+ * DOCUMENT ME!
+ * @param pos
+ * DOCUMENT ME!
+ */
+ public void handleSimpleTag(Tag tag, MutableAttributeSet attributes, int pos) {
+ if(tag.equals(HTML.Tag.IMG)){
+ String src = (String) attributes.getAttribute(HTML.Attribute.SRC);
+ if(src != null){
+ img_src_all.add(src);
+ if(!img_src.contains(src)){
+ img_src.add(src);
}
- }
-
- if (tag.equals(HTML.Tag.LINK)) {
- String href = (String) attributes.getAttribute(HTML.Attribute.HREF);
-
- if (href != null) {
- link_href_all.add(href);
-
- if (!link_href.contains(href)) {
- link_href.add(href);
- }
+ }
+ }
+ if(tag.equals(HTML.Tag.LINK)){
+ String href = (String) attributes.getAttribute(HTML.Attribute.HREF);
+ if(href != null){
+ link_href_all.add(href);
+ if(!link_href.contains(href)){
+ link_href.add(href);
}
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getImageSrcs() {
- return img_src;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getAllImageSrcs() {
- return img_src_all;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getLinkHRefs() {
- return link_href;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getAllLinkHRefs() {
- return link_href_all;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getAHRefs() {
- return a_href;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public ArrayList getAllAHRefs() {
- return a_href_all;
- }
+ }
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getImageSrcs() {
+ return img_src;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getAllImageSrcs() {
+ return img_src_all;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getLinkHRefs() {
+ return link_href;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getAllLinkHRefs() {
+ return link_href_all;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getAHRefs() {
+ return a_href;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ArrayList getAllAHRefs() {
+ return a_href_all;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Log4Echo.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Log4Echo.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Log4Echo.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Log4Echo.java Wed Jan 30 23:44:03 2008
@@ -14,45 +14,39 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
-import org.apache.log4j.Category;
-
-
+import org.apache.log4j.Logger;
/**
* Can be used within shell scripts resp. batch files
*/
public class Log4Echo {
- private static Category log = Category.getInstance(Log4Echo.class);
-
- /**
- * main
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if (args.length != 2) {
- System.err.println("Usage: java " + new Log4Echo().getClass().getName() + "log-level log-message");
- return;
- }
-
- String level = args[0].toLowerCase();
- String message = args[1];
- if (level.equals("debug")) {
- log.debug(message);
- } else if (level.equals("info")) {
- log.info(message);
- } else if (level.equals("warn")) {
- log.warn(message);
- } else if (level.equals("error")) {
- log.error(message);
- } else if (level.equals("fatal")) {
- log.fatal(message);
- } else {
- log.error("No such log level: " + level + " " + message);
- }
- }
+ private static Logger log = Logger.getLogger(Log4Echo.class);
+ /**
+ * main
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if(args.length != 2){
+ System.err.println("Usage: java " + new Log4Echo().getClass().getName() + "log-level log-message");
+ return;
+ }
+ String level = args[0].toLowerCase();
+ String message = args[1];
+ if(level.equals("debug")){
+ log.debug(message);
+ }else if(level.equals("info")){
+ log.info(message);
+ }else if(level.equals("warn")){
+ log.warn(message);
+ }else if(level.equals("error")){
+ log.error(message);
+ }else if(level.equals("fatal")){
+ log.fatal(message);
+ }else{
+ log.error("No such log level: " + level + " " + message);
+ }
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/SED.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/SED.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/SED.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/SED.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -31,64 +28,58 @@
import java.nio.charset.CharsetDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Similar to the UNIX sed
*/
public class SED {
- static Category log = Category.getInstance(SED.class);
-
- /**
- * Command Line Interface
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Usage: org.apache.lenya.util.SED");
- return;
- }
- }
-
- /**
- * Substitute prefix, e.g. ".*world.*" by "universe"
- *
- * @param file File which sed shall be applied
- * @param prefixSubstitute Prefix which shall be replaced
- * @param substituteReplacement Prefix which is going to replace the original
- *
- * @throws IOException DOCUMENT ME!
- */
- public static void replaceAll(File file, String substitute, String substituteReplacement) throws IOException {
- log.debug("Replace " + substitute + " by " + substituteReplacement);
-
- Pattern pattern = Pattern.compile(substitute);
-
- // Open the file and then get a channel from the stream
- FileInputStream fis = new FileInputStream(file);
- FileChannel fc = fis.getChannel();
-
- // Get the file's size and then map it into memory
- int sz = (int)fc.size();
- MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
-
- // Decode the file into a char buffer
- // Charset and decoder for ISO-8859-15
- Charset charset = Charset.forName("ISO-8859-15");
- CharsetDecoder decoder = charset.newDecoder();
- CharBuffer cb = decoder.decode(bb);
-
- Matcher matcher = pattern.matcher(cb);
- String outString = matcher.replaceAll(substituteReplacement);
- log.debug(outString);
-
-
- FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
- PrintStream ps =new PrintStream(fos);
- ps.print(outString);
- ps.close();
- fos.close();
- }
+ private static Logger log = Logger.getLogger(SED.class);
+ /**
+ * Command Line Interface
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if(args.length == 0){
+ System.out.println("Usage: org.apache.lenya.util.SED");
+ return;
+ }
+ }
+ /**
+ * Substitute prefix, e.g. ".*world.*" by "universe"
+ *
+ * @param file
+ * File which sed shall be applied
+ * @param prefixSubstitute
+ * Prefix which shall be replaced
+ * @param substituteReplacement
+ * Prefix which is going to replace the original
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public static void replaceAll(File file, String substitute, String substituteReplacement) throws IOException {
+ log.debug("Replace " + substitute + " by " + substituteReplacement);
+ Pattern pattern = Pattern.compile(substitute);
+ // Open the file and then get a channel from the stream
+ FileInputStream fis = new FileInputStream(file);
+ FileChannel fc = fis.getChannel();
+ // Get the file's size and then map it into memory
+ int sz = (int) fc.size();
+ MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
+ // Decode the file into a char buffer
+ // Charset and decoder for ISO-8859-15
+ Charset charset = Charset.forName("ISO-8859-15");
+ CharsetDecoder decoder = charset.newDecoder();
+ CharBuffer cb = decoder.decode(bb);
+ Matcher matcher = pattern.matcher(cb);
+ String outString = matcher.replaceAll(substituteReplacement);
+ log.debug(outString);
+ FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
+ PrintStream ps = new PrintStream(fos);
+ ps.print(outString);
+ ps.close();
+ fos.close();
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/ServletHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/ServletHelper.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/ServletHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/ServletHelper.java Wed Jan 30 23:44:03 2008
@@ -14,85 +14,76 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.cocoon.environment.Request;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Servlet utility class.
*/
public final class ServletHelper {
-
- private static Category log = Category.getInstance(ServletHelper.class);
-
- /**
- * Ctor.
- */
- private ServletHelper() {
-
- }
-
- /**
- * Returns the URL inside the web application (without the context prefix).
- * @param request The request.
- * @return A string.
- */
- public static String getWebappURI(Request request) {
- String context = request.getContextPath();
- String requestUri = request.getRequestURI();
- return getWebappURI(context, requestUri);
- }
-
- /**
- * Returns the URL inside the web application (without the context prefix).
- * @param context The context prefix.
- * @param requestUri The complete request URI.
- * @return A string.
- */
- public static String getWebappURI(String context, String requestUri) {
- if (context == null) {
- context = "";
- }
- String url = requestUri.substring(context.length());
- if (url.length() > 0 && !url.startsWith("/")) {
- url = "/" + url;
- }
-
- log.debug(" Context prefix: [" + context + "]");
- log.debug(" Webapp URL: [" + url + "]");
-
- return url;
- }
-
- /**
- * Converts the request parameters to a map.
- * If a key is mapped to multiple parameters, a string array is used as the value.
- * @param request The request.
- * @return A map.
- */
- public static Map getParameterMap(Request request) {
- Map requestParameters = new HashMap();
- for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- String[] values = request.getParameterValues(key);
- Object value;
- if (values.length == 1) {
- value = values[0];
- }
- else {
- value = values;
- }
- requestParameters.put(key, value);
- }
- return requestParameters;
- }
-
+ private static Logger log = Logger.getLogger(ServletHelper.class);
+ /**
+ * Ctor.
+ */
+ private ServletHelper() {
+ }
+ /**
+ * Returns the URL inside the web application (without the context prefix).
+ *
+ * @param request
+ * The request.
+ * @return A string.
+ */
+ public static String getWebappURI(Request request) {
+ String context = request.getContextPath();
+ String requestUri = request.getRequestURI();
+ return getWebappURI(context, requestUri);
+ }
+ /**
+ * Returns the URL inside the web application (without the context prefix).
+ *
+ * @param context
+ * The context prefix.
+ * @param requestUri
+ * The complete request URI.
+ * @return A string.
+ */
+ public static String getWebappURI(String context, String requestUri) {
+ if(context == null){
+ context = "";
+ }
+ String url = requestUri.substring(context.length());
+ if(url.length() > 0 && !url.startsWith("/")){
+ url = "/" + url;
+ }
+ log.debug(" Context prefix: [" + context + "]");
+ log.debug(" Webapp URL: [" + url + "]");
+ return url;
+ }
+ /**
+ * Converts the request parameters to a map. If a key is mapped to multiple parameters, a string array is used as the value.
+ *
+ * @param request
+ * The request.
+ * @return A map.
+ */
+ public static Map getParameterMap(Request request) {
+ Map requestParameters = new HashMap();
+ for(Enumeration e = request.getParameterNames(); e.hasMoreElements();){
+ String key = (String) e.nextElement();
+ String[] values = request.getParameterValues(key);
+ Object value;
+ if(values.length == 1){
+ value = values[0];
+ }else{
+ value = values;
+ }
+ requestParameters.put(key, value);
+ }
+ return requestParameters;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Stack.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Stack.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Stack.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Stack.java Wed Jan 30 23:44:03 2008
@@ -14,49 +14,43 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.util.Vector;
-
-
/**
* DOCUMENT ME!
*/
-
// FIXME: this class seems pretty useless. Why not remove it?
public class Stack extends Vector {
- int maxsize = 0;
-
- /**
- * Creates a new Stack object.
- *
- * @param maxsize DOCUMENT ME!
- */
- public Stack(int maxsize) {
- this.maxsize = maxsize;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param object DOCUMENT ME!
- */
- public void push(Object object) {
- insertElementAt(object, 0);
-
- if (size() == (maxsize + 1)) {
- removeElementAt(maxsize);
- }
- }
+ private static final long serialVersionUID = 1L;
+ int maxsize = 0;
+ /**
+ * Creates a new Stack object.
+ *
+ * @param maxsize
+ * DOCUMENT ME!
+ */
+ public Stack(int maxsize) {
+ this.maxsize = maxsize;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param object
+ * DOCUMENT ME!
+ */
+ public void push(Object object) {
+ insertElementAt(object, 0);
+ if(size() == (maxsize + 1)){
+ removeElementAt(maxsize);
+ }
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/XPSFileOutputStream.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/XPSFileOutputStream.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/XPSFileOutputStream.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/XPSFileOutputStream.java Wed Jan 30 23:44:03 2008
@@ -14,130 +14,124 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.util;
-
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
-
import org.apache.commons.io.FileUtils;
-import org.apache.log4j.Category;
-
-
+import org.apache.log4j.Logger;
/**
* DOCUMENT ME!
*/
public class XPSFileOutputStream extends FileOutputStream {
- static Category log = Category.getInstance(XPSFileOutputStream.class);
- private static final String suffixBase = ".xpstemp";
- protected String realFilename = null;
- protected String suffix = null;
-
- /**
- * Creates a new XPSFileOutputStream object.
- *
- * @param name DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public XPSFileOutputStream(String name) throws IOException {
- super(getTempFilename(name));
- setRealFilename(name);
- }
-
- /**
- * Creates a new XPSFileOutputStream object.
- *
- * @param file DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public XPSFileOutputStream(File file) throws IOException {
- super(getTempFilename(file.getAbsolutePath()));
- setRealFilename(file.getAbsolutePath());
- }
-
- /**
- * Creates a new XPSFileOutputStream object.
- *
- * @param filename DOCUMENT ME!
- * @param append DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public XPSFileOutputStream(String filename, boolean append)
- throws IOException {
- super(getTempFilename(filename), append);
- setRealFilename(filename);
- }
-
- /**
- * We cannot support this version of the constructer because we need to play tricks with the
- * filename. There is no filename available when starting with a FileDescriptor.
- *
- * @param fdObj DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public XPSFileOutputStream(FileDescriptor fdObj) throws IOException {
- super(fdObj);
- throw new IOException(
- "Constructing an XPSFileOutputStream using a FileDescriptor is not suported because we depend on a filename");
- }
-
- /**
- * @param realname DOCUMENT ME!
- * @return DOCUMENT ME!
- */
- // FIXME: the hashCode() is probably not good enough
- // We need to find a better source of a random
- // string that is available to a static method.
- //
- protected static String getTempFilename(String realname) {
- return realname + XPSFileOutputStream.suffixBase + "." + Runtime.getRuntime().hashCode();
- }
-
- /**
- * @return DOCUMENT ME!
- */
- protected String getRealFilename() {
- return this.realFilename;
- }
-
- /**
- * @param filename DOCUMENT ME!
- */
- protected void setRealFilename(String filename) {
- this.realFilename = filename;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public void close() throws IOException {
- super.close();
- File temp = new File(getTempFilename(getRealFilename()));
- File file = new File(getRealFilename());
- FileUtils.copyFile(temp, file);
- boolean deleted = temp.delete();
- if (deleted) {
- log.debug("The temporary file "+temp.getAbsolutePath() +"is deleted");
- } else {
- log.debug("The temporary file "+temp.getAbsolutePath() +" couldn't be deleted");
- }
- log.debug(".close(): mv " + getTempFilename(getRealFilename()) + " " + getRealFilename());
- }
-
- /**
- * DOCUMENT ME!
- */
- public void flush() {
- log.debug("flush() called");
- }
+ private static Logger log = Logger.getLogger(XPSFileOutputStream.class);
+ private static final String suffixBase = ".xpstemp";
+ protected String realFilename = null;
+ protected String suffix = null;
+ /**
+ * Creates a new XPSFileOutputStream object.
+ *
+ * @param name
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public XPSFileOutputStream(String name) throws IOException {
+ super(getTempFilename(name));
+ setRealFilename(name);
+ }
+ /**
+ * Creates a new XPSFileOutputStream object.
+ *
+ * @param file
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public XPSFileOutputStream(File file) throws IOException {
+ super(getTempFilename(file.getAbsolutePath()));
+ setRealFilename(file.getAbsolutePath());
+ }
+ /**
+ * Creates a new XPSFileOutputStream object.
+ *
+ * @param filename
+ * DOCUMENT ME!
+ * @param append
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public XPSFileOutputStream(String filename, boolean append) throws IOException {
+ super(getTempFilename(filename), append);
+ setRealFilename(filename);
+ }
+ /**
+ * We cannot support this version of the constructer because we need to play tricks with the filename. There is no filename available when starting with a FileDescriptor.
+ *
+ * @param fdObj
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public XPSFileOutputStream(FileDescriptor fdObj) throws IOException {
+ super(fdObj);
+ throw new IOException("Constructing an XPSFileOutputStream using a FileDescriptor is not suported because we depend on a filename");
+ }
+ /**
+ * @param realname
+ * DOCUMENT ME!
+ * @return DOCUMENT ME!
+ */
+ // FIXME: the hashCode() is probably not good enough
+ // We need to find a better source of a random
+ // string that is available to a static method.
+ //
+ protected static String getTempFilename(String realname) {
+ return realname + XPSFileOutputStream.suffixBase + "." + Runtime.getRuntime().hashCode();
+ }
+ /**
+ * @return DOCUMENT ME!
+ */
+ protected String getRealFilename() {
+ return this.realFilename;
+ }
+ /**
+ * @param filename
+ * DOCUMENT ME!
+ */
+ protected void setRealFilename(String filename) {
+ this.realFilename = filename;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public void close() throws IOException {
+ super.close();
+ File temp = new File(getTempFilename(getRealFilename()));
+ File file = new File(getRealFilename());
+ FileUtils.copyFile(temp, file);
+ boolean deleted = temp.delete();
+ if(deleted){
+ log.debug("The temporary file " + temp.getAbsolutePath() + "is deleted");
+ }else{
+ log.debug("The temporary file " + temp.getAbsolutePath() + " couldn't be deleted");
+ }
+ log.debug(".close(): mv " + getTempFilename(getRealFilename()) + " " + getRealFilename());
+ }
+ /**
+ * DOCUMENT ME!
+ */
+ public void flush() {
+ log.debug("flush() called");
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/workflow/WorkflowException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/workflow/WorkflowException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/workflow/WorkflowException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/workflow/WorkflowException.java Wed Jan 30 23:44:03 2008
@@ -14,48 +14,43 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.workflow;
-
-
/**
* Workflow exception.
*/
public class WorkflowException extends Exception {
- /**
- *
- */
- public WorkflowException() {
- super();
- }
-
- /**
- * Create a WorkflowException.
- *
- * @param message The message.
- */
- public WorkflowException(String message) {
- super(message);
- }
-
- /**
- * Create a WorkflowException.
- *
- * @param message The message.
- * @param cause The cause.
- */
- public WorkflowException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Create a WorkflowException.
- *
- * @param cause The cause.
- */
- public WorkflowException(Throwable cause) {
- super(cause);
- }
+ private static final long serialVersionUID = 1L;
+ public WorkflowException() {
+ super();
+ }
+ /**
+ * Create a WorkflowException.
+ *
+ * @param message
+ * The message.
+ */
+ public WorkflowException(String message) {
+ super(message);
+ }
+ /**
+ * Create a WorkflowException.
+ *
+ * @param message
+ * The message.
+ * @param cause
+ * The cause.
+ */
+ public WorkflowException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Create a WorkflowException.
+ *
+ * @param cause
+ * The cause.
+ */
+ public WorkflowException(Throwable cause) {
+ super(cause);
+ }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.