?? htmltemplatedisplay.java
字號:
}
return true;
/*
if (subdir == null) subdir = "";
if (subdir.length() > 0)
if (subdir.endsWith("/") == false)
subdir += "/";
if (baseURL == null) baseURL = "";
if (baseURL.length() > 0)
if (baseURL.endsWith("/") == false)
baseURL += "/";
URL url;
String baseTemplatePath = myProperties.getProperty("dir.templates");
String fileName = baseTemplatePath + templateURL; //TE: gets the path & name of each template that is displayed. I.e when a tab is clicked.
File template = new File(fileName);
try
{
htmlText = new StringBuffer(CBUtility.readTextFile(template));
url = new URL(baseURL + subdir + templateURL);
// parse file and set paths correctly
htmlText = parseNewTemplate(htmlText, url);
baseText = htmlText.toString(); // set the base template text.
}
catch (Exception e)
{
try
{
*/
/**
* Probably not a politically correct way to find out if there are any plugin templates..
* ..but that is what this is doing. If JX can't find a template in the normal JX dir,
* then this checks the plugins dir for a (temporary) template dir. If the template still
* can't be found then it displays the error message.
*
* The template is added to the combo box without the 'templates' prefix i.e: templates/person/whatever.html
* so that normal picking up of the templates can occur in respect of object class. In other words if
* there is a plugins dir of 'person' as well as the default one, JX will display the template that is
* is first in ASCII order.
*
* This assumes that the user places any templates in a zip/jar file in the following dir format...
* templates/"objectclass name"/"template name.html". (replacing names in commars).
*/
/*
String temp = new String(resourceLoader.getResource("templates/" + templateURL)); //TE: read the html template from the zip/jar file.
templateURL = "temp" + File.separator + templateURL; //TE: add the prefix so the HTML file can be found in the zip/jar file.
htmlText = new StringBuffer(temp);
//TODO: get Trudi to explain how this works?
url = new URL(JXplorer.getFileURL(localURL) + templateURL); //TE: point to the templates dir in the plugins dir rather than the one in JX.
// parse file and set paths correctly
htmlText = parseNewTemplate(htmlText, url); //TE: parse as normal.
baseText = htmlText.toString(); //TE: important to set this so JX knows where to find any images etc that are referenced by the HTML template.
}
catch (Exception ee)
{
return CBUtility.error(display, CBIntText.get("Can't find html template! ") + fileName, e);
}
}
return true;
*/
}
/* Pre-parses the html file, doing hack workarounds to make images
* work under broken Java 1.2.0 swing.
*
* All this could be done more aesthetically using the HTMLEditorKit...
* But we're on a deadline, and it doesn't seem to work properly; so
* we'll hack it by hand for the time being... Especially since the
* *(&^ swing HTMLDocument documentBase property doesn't seem to
* work for generated documents (i.e. you can't set it!) so we need
* to stick in fully qualified base refs to things like images etc...
*/
public StringBuffer parseNewTemplate(StringBuffer templateText, URL url)
{
// XXX DANGER WILL ROBINSON
// XXX INCREDIBLY SCREWED SUN URL HANDLING
// XXX file:// HIGHLY UNRELIABLE
//
// bottom code is carefully hacked to produce a base url reference
// that may work on solaris under jre 1.3 as well as normal NT.
// This can be very easily messed up (for example by naively using
// suns URL class as a constructor). Be carefull.
String baseTagURL = url.getPath();
// note - force use of 'file://' prefix. URL constructed version would only
// have file: prefix, ommitting double slash. While both versions may work,
// it seems to be variable...
//XXX should we be trying to do something clever with the File.toURL() method here?
baseTagURL = "file://" + baseTagURL.substring(0, baseTagURL.lastIndexOf('/') + 1);
int headPos = templateText.toString().indexOf("<head>");
String baseTag = "\n<base href=\"" + baseTagURL + "\">\n";
templateText.insert(headPos + 7, baseTag); //TE: was templateText.insert(headPos+6, baseTag); ??? html = <html <base href...> >
// System.out.println(templateText);
return templateText;
}
/**
* Returns a template file given the root path and name of the file.
*
* @param fileNameAndPath the name and path, but <b>not</b> the extension,
* of the template file
*
* @return the File object found. This may be null, or may not exist; these
* conditions must be checked for.
*/
public File getTemplateFile(String fileNameAndPath)
{
String fileName = fileNameAndPath + ".html";
File templateFile = new File(fileName);
if (templateFile.exists() == false) // check file exists, try '.htm' ext. if not
templateFile = new File(fileNameAndPath + ".htm");
return templateFile;
}
public String[] getObjectClasses(DXAttributes atts)
{
try
{
Attribute a = atts.getAllObjectClasses();
if (a == null) return new String[]{};
DXNamingEnumeration en = new DXNamingEnumeration(a.getAll());
en.sort(); // alphabetacize.
String[] ret = en.toStringArray();
return ret;
}
catch (NamingException e)
{
log.warning("unable to read object classes in AttributeDisplay: " + e.toString());
}
return null;
}
/**
* Concatenates a string array of alphabetically ordered object Classes into
* one long string, providing a unique String for this combination of classes.
*
*/
public String getObjectClassSignature(String[] objectClasses)
{
String ret = "";
if (objectClasses == null) return "";
for (int i = 0; i < objectClasses.length; i++)
ret += objectClasses[i];
return ret;
}
/**
* Checks if the list of object classes has changed. If it has,
* reset the 'oldClassSignature' and return true, otherwise return
* false.
*/
public boolean objectClassesChanged(String classesSignature)
{
return !((oldObjectClassesSignature != null) && (oldObjectClassesSignature.equals(classesSignature)));
}
public void displayEntry(DXEntry entry, DataSource formDataSource)
{
if (entry == null || entry.size() == 0)
{
setEditorText(NODATA);
return;
}
currentDataSource = formDataSource; // used by form submission handler in MyHTMLEditorKit.
currentEntry = entry;
String[] objectClasses = getObjectClasses(entry);
if (objectClasses == null)
{
log.warning("unable to find any object classes for " + entry.getDN().toString());
setEditorText(NODATA);
return;
}
setupTemplates(objectClasses, entry); // change templates if necessary...
if (entry == null)
{
CBUtility.error(this, CBIntText.get("Error. No data for this node!"), null);
setEditorText(NODATA);
return;
}
displayData(entry);
}
/**
* Takes a list of object classes, and if the object classes to display have
* changed modifies the list of available templates to display only appropriate
* templates.
*/
void setupTemplates(String[] objectClasses, DXEntry entry)
{
String objectClassesSignature = getObjectClassSignature(objectClasses);
// change the template viewing combo box to a new set of templates, if objectClass has changed
if (objectClassesChanged(objectClassesSignature))
{
// remember the current menu position for later
viewTemplatesPos.put(oldObjectClassesSignature, new Integer(viewTemplates.getSelectedIndex()));
oldObjectClassesSignature = objectClassesSignature;
// disable combo box action listener using flag
settingUpTemplates = true;
// clear all existing combo box templates
viewTemplates.removeAllItems();
// read the list of new templates for the particular object classes this entry has.
String[] templates = readTemplateNames(objectClasses);
if ((templates == null) || (templates.length == 0))
// make sure that we found some! (We *should* find at least the default templates)
log.warning("No templates found for objectClasses " + objectClassesSignature);
else
{
// load the combo box with the listed templates, in the order we got them from readTemplateNames
for (int i = 0; i < templates.length; i++)
viewTemplates.addItem(templates[i]);
if (viewTemplatesPos.containsKey(objectClassesSignature))
{
// If we've viewed this object class set before, try to use the same template as last time.
int indexPos = ((Integer) viewTemplatesPos.get(objectClassesSignature)).intValue();
if (indexPos < templates.length)
viewTemplates.setSelectedIndex(indexPos);
}
else
{
// if we *haven't* viewed this object class set before...
// ... set the combo box to show the first option ('all') by default
viewTemplates.setSelectedIndex(0);
// ... and try to set the view to the most specific available template
attemptToSetOCSpecificTemplate(entry, templates);
}
String templateName = viewTemplates.getSelectedItem().toString();
openNewTemplate(templateName);
}
settingUpTemplates = false; // re-enable combo box action listener
}
}
/**
* This attempts to match a list of template names with the deepest possible
* object class.
*/
protected void attemptToSetOCSpecificTemplate(DXAttributes entry, String[] templates)
{
//String baseOC = ((DXAttributes)entry).getBaseObjectClass();
Vector ocs = (entry).getOrderedOCs();
for (int i = 0; i < ocs.size(); i++)
{
String oc = ((String) ocs.get(i)).toLowerCase();
for (int j = 0; j < templates.length; j++)
{
String template = templates[j].toLowerCase();
if (template.startsWith(oc))
{
settingUpTemplates = true;
viewTemplates.setSelectedIndex(j);
settingUpTemplates = false;
return;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -