import java.io.*;
import java.util.*;
//import Html;
//import EndText;
/**
* This type represents an image indicated in a text
* document. The image, as in HTML or another markup system
* is indicated by a certain structure of text within the
* document. These codes are determined by the INDICATOR
* and TERMINATOR static variables. A short example document might
* be...
* Another photo of somebody [image http://www.host.org/images/somebody.jpg]
*
*
*
*
* @see FaqItem, Question, Answer
* @author http://bumble.sf.net
*/
public class Image extends Object
{
//--------------------------------------------
private static String NEWLINE = System.getProperty("line.separator");
//--------------------------------------------
private boolean isGood;
//--------------------------------------------
private String errors;
//--------------------------------------------
private String imageUrl;
//--------------------------------------------
public static String INDICATOR = "[image";
//--------------------------------------------
public static String TERMINATOR = "]";
public Image()
{
this.errors = "";
this.imageUrl = "";
}
//--------------------------------------------
public Image(String sText)
{
this();
this.loadData(sText);
}
//--------------------------------------------
public String getAbsoluteName()
{
if (!this.isGood)
{ return ""; }
return this.imageUrl;
}
//--------------------------------------------
public String getCanonicalName()
{
if (!this.isGood)
{ return ""; }
return this.imageUrl;
}
//--------------------------------------------
public String getImageName()
{
return this.imageUrl;
}
//--------------------------------------------
public void setImageName(String sImageName)
{
this.imageUrl = sImageName;
}
//--------------------------------------------
/** determines if the end of some text begins with
* the start token of an image indicator. This function
* is used by a parsing routine contained in an object
* such as a "document" object. */
public static boolean recognize(String sText)
{
if (!sText.endsWith(Image.INDICATOR))
{ return false; }
//-- allow a single quote character to escape a
//-- the start token. This allows the token to be
//-- included in explanatory text without it
//-- being rendered.
//--
if (sText.endsWith("'" + Image.INDICATOR))
{ return false; }
return true;
}
//--------------------------------------------
public void loadData(String sText)
{
this.isGood = this.isImage(sText);
if (!this.isGood)
{
return;
}
this.imageUrl = sText.trim().substring(
this.INDICATOR.length(),
sText.trim().length() - this.TERMINATOR.length()).trim();
if (this.imageUrl.equals(""))
{
this.imageUrl =
"http://sourceforge.net/sflogo.php?group_id=group_id=15255";
//this.imageUrl = ".";
}
} //-- m: loadData()
//--------------------------------------------
/** checks if this looks like a folder indicator */
public static boolean isImage(String sText)
{
if (sText.trim().length() == 0)
{ return false; }
if (!sText.trim().startsWith(Image.INDICATOR))
{ return false; }
if (!sText.trim().endsWith(Image.TERMINATOR))
{ return false; }
return true;
}
//--------------------------------------------
/** creates a string suitable for a plain text doc */
public String toString()
{
StringBuffer sbReturn = new StringBuffer("");
sbReturn.append(this.INDICATOR);
sbReturn.append(" ");
sbReturn.append(this.imageUrl.toString());
sbReturn.append(this.TERMINATOR);
return sbReturn.toString();
}
//--------------------------------------------
public String printHtml()
{
if (!this.isGood)
{
return "";
}
StringBuffer sbReturn = new StringBuffer("");
String sDisplayName = new String();
sbReturn.append("");
return sbReturn.toString();
} //-- m: printHtml()
//--------------------------------------------
public String printDocBook()
{
if (!this.isGood)
{
return "";
}
StringBuffer sbReturn = new StringBuffer("");
String sDisplayName = new String();
sbReturn.append("");
sbReturn.append("");
sbReturn.append("");
sbReturn.append("");
sbReturn.append("");
return sbReturn.toString();
} //-- m: printDocBook()
//--------------------------------------------
public String printReport()
{
StringBuffer sbReturn = new StringBuffer("");
sbReturn.append("");
sbReturn.append(NEWLINE);
sbReturn.append("Image Url >");
sbReturn.append(this.imageUrl);
sbReturn.append(NEWLINE);
sbReturn.append("Absolute name >");
sbReturn.append(this.getAbsoluteName());
sbReturn.append(NEWLINE);
sbReturn.append("Canonical name >");
sbReturn.append(this.getCanonicalName());
sbReturn.append(NEWLINE);
sbReturn.append("last data good >");
sbReturn.append(this.isGood);
sbReturn.append(NEWLINE);
sbReturn.append("error messages >");
sbReturn.append(this.errors);
sbReturn.append(NEWLINE);
return sbReturn.toString();
}
//--------------------------------------------
public String print()
{
StringBuffer sbReturn = new StringBuffer("");
return this.toString();
}
//--------------------------------------------
/** a main method for testing */
public static void main(String[] args) throws Exception
{
StringBuffer sbUsageMessage = new StringBuffer("");
sbUsageMessage.append("test usage: java Image image-text");
sbUsageMessage.append(NEWLINE);
sbUsageMessage.append(NEWLINE);
if (args.length == 0)
{
System.out.println(sbUsageMessage);
System.exit(-1);
}
StringBuffer sbTest = new StringBuffer("");
Image imageTest = new Image(args[0]);
System.out.println(imageTest.printHtml());
System.out.println(NEWLINE);
System.out.println(imageTest.toString());
System.out.println(NEWLINE);
System.out.println(imageTest.printReport());
} //-- main()
} //-- Image class