?? htmltemplatedisplay.java
字號(hào):
}
}
}
}
/**
* Checks if the HTML page has any custom tags such as...
* <p><dxtemplate:get-all-attributes style="list"/></p>
* <p><dxtemplate:get-attribute name="cn" style="list"/></p>
* if so it enters the data. If the tag is 'get-all-attributes', all
* the attributes are included in the page. If the tag is 'get-attribute', the
* specific attribute is displayed.
* This method also kicks off the handling of inserting form data.
* @param entry the entry that we are trying to display.
*/
protected void displayData(DXEntry entry)
{
if (entry == null)
{
setEditorText(NODATA);
return;
}
int tagstart = 0; // the start of the ATTRIBTAG html tag
int tagend; // the end of the ATTRIBTAG html tag
//int htmlTagLen = ATTRIBTAG.length();
htmlText = new StringBuffer(baseText);
// check if doco is XHTML, and try to convert to HTML 3.2 by replacing all end tags '/>' with '>'
htmlText = parseXHTML(htmlText);
mediaCheck(entry, "jpegPhoto"); //TE: checks for jpegPhoto and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "audio"); //TE: checks for audio and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "odDocumentDOC"); //TE: checks for odDocumentDOC and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "odSpreadSheetXLS"); //TE: checks for odSpreadSheetXLS and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "odMusicMID"); //TE: checks for odMusicMID and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "odSoundWAV"); //TE: checks for odSoundWAV and creates temporary file that can be later displayed in a template.
mediaCheck(entry, "odMovieAVI"); //TE: checks for odMovieAVI and creates temporary file that can be later displayed in a template.
tagstart = htmlText.indexOf(ATTRIBTAG, tagstart);
while (tagstart >= 0)
{
tagend = htmlText.indexOf(">", tagstart);
String tempTag = htmlText.substring(tagstart, tagend);
String attName = "";
if (tempTag.indexOf("get-all-attributes") > 0) //TE: splat all attribute values onto the page.
attName = "all";
else //TE: get the name of the specific attribute to splat. The next line is basically just getting the attribute name between the quotes e.g. 'cn' from name="cn".
attName = tempTag.substring(tempTag.indexOf("name=\"") + 6, tempTag.indexOf("\"", tempTag.indexOf("name=\"") + 6));
String modifier = null;
if (tempTag.indexOf("style=\"") > 0) //TE: get the name of the specific attribute to splat. The next line is basically just getting the style of display from between the quotes e.g. 'list' from style="list".
modifier = tempTag.substring(tempTag.indexOf("style=\"") + 7, tempTag.indexOf("\"", tempTag.indexOf("style=\"") + 7));
htmlText.delete(tagstart, tagend + 1); //TE: remove the tag, we don't need it anymore.
if (attName.equalsIgnoreCase("all")) //TE: make new tags for all the attributes and splat them into where the old tag use to be.
htmlText.insert(tagstart, formattedAllAttributes(currentEntry, modifier));
else //TE: make a new tag for the attribute specified and splat it into where the old tag use to be.
htmlText.insert(tagstart, formattedAttribute(attName, currentEntry, modifier)); //TE: splat certain attributes.
//TE: moves the position to the beginning of the next custom tag, if there is one and...
//TE: breaks the loop if there are no more tags i.e. tagstart would =-1.
tagstart = htmlText.indexOf(ATTRIBTAG, tagstart);
}
if ((htmlText == null) || (htmlText.length() == 0))
{
log.warning("HTMLTemplateDisplay:displayNodeData - bad html String " + ((htmlText == null) ? " (is null!)" : ""));
setEditorText(NODATA);
return;
}
String htmlString = htmlText.toString().trim();
htmlString = insertFormData(htmlString, entry);
try
{
setEditorText(htmlString);
}
catch (EmptyStackException e) // the amazingly buggy HTML editor has done it again...
{
log.warning("Another Bug in Sun HTML Component: " + e);
}
scrollDisplay.getVerticalScrollBar().setValue(0); //TE: sets the scroll bar back to the top.
viewport.setViewPosition(new Point(0, 0)); //TE: sets the view back to the top.
}
/**
* Checks if there is any jpegPhoto, audio or odDocumentDOC attributes in the entry if so creates temporary files for them
* only if there isn't any already. Gets the byte[] of the jpegPhoto, audio or odDocumentDOC attributes of the entry being
* displayed. Makes a temp directory called 'temp'. Lists all files in the directory, if there are
* any temp files for the jpegPhoto, audio or odDocumentDOC attributes in question it does not recreate them. Otherwise, if
* there isn't any temp files for the entry, it goes ahead and makes them. The temp files are named
* as followed: dn+unique number+.jpg. The temp files and directory are removed when the JX exists.
* @param entry the entry that is to be displayed.
* @param type the type of media being checked for (jpegPhoto, audio or odDocumentDOC).
*/
protected void mediaCheck(DXEntry entry, String type)
{
DXAttribute attribute = null;
attribute = (DXAttribute) entry.get(type);
if (attribute == null)
return;
currentDN = entry.getDN().toString(); //TE: the name of the dn becomes the main part of the temporary jpegPhoto or audio file.
currentDN = Integer.toString(currentDN.hashCode()); //TE: make a hash code of it.
int size = attribute.size(); //TE: the amount of jpegPhoto or audio attributes in the entry.
if (attribute != null)
{
CBCache.createCache(entry.getDN().toString(), entry, type, size); //TE: creates a cache for the jpegPhoto or audio file.
}
}
/**
* Changes XHTML into standard HTML for display.
* (Currently all this involves is changing any string '/>' into '>').
*/
// (Currently all this involves is changing any string '/>' into '>').
static public StringBuffer parseXHTML(StringBuffer html)
{
return CBParse.replaceAllBufferString(html, "/>", ">");
}
/**
* This method looks for form elements, and fills in the initial form values based on
* the entry data received. It is fairly picky about white space - it prefers there to
* be minimal whitespace in the form html. Also, there is minimal form validation; an
* incorrect form will cause all sorts of mess.<p>
* Note that if <i>anything</i> is wrong with the form, this will simply fail with
* an exception (probably a substring exception).
*
*/
// XXX This should be rewritten to correctly use the HTML Document object model, but I don't
// XXX have time right now to work out how to do that :-) - CB
protected String insertFormData(String htmlString, DXEntry entry)
{
if (htmlString.indexOf("<form") < 0)
{
if (currentBinaryAttributes.size() > 0)
currentBinaryAttributes.clear();
return htmlString; // no forms today.
}
try
{
htmlString = insertFormInputData(htmlString, entry);
htmlString = insertFormSelectData(htmlString, entry);
htmlString = insertFormTextAreaData(htmlString, entry);
htmlString = insertFormImageData(htmlString, entry); //TE: inserts jpegPhotos into the html template.
htmlString = insertFormAudioData(htmlString, entry); //TE: inserts a link (or links) to temporary audio files which should be played by the systems default player depending on the extension of the file.
}
catch (Exception e) // usually simply that the value can't be found.
{
if (showHTMLErrors)
{
log.warning("Error parsing form html for value insertion in HTMLTemplateDisplay. \n " + e);
e.printStackTrace();
}
}
return htmlString;
}
// XXX This should be rewritten to correctly use the HTML Document object model,
protected String getTagValue(String tagName, String tag)
{
tag = tag.toLowerCase();
tagName = tagName.toLowerCase();
try
{
int start = tag.indexOf(tagName) + tagName.length();
start = tag.indexOf("\"", start) + 1;
if (start < 0) return null;
int end = tag.indexOf("\"", start);
if (end < 0) return null;
String val = tag.substring(start, end);
return val.trim();
}
catch (Exception e)
{
if (showHTMLErrors)
log.warning("error parsing: " + tagName + "\n " + e);
return null;
}
}
/**
* Goes through the html template, checking for any field tags of text type for example:
* <p>
* <tr>
* <th align="right" width="200">Common Name:</th>
* <td width="230"><input type="text" name="cn" value=""/></td>
* </tr>
* <p>
* If one is found, it checks the name and gets (in this example) the cn value from the entry and inserts
* it into the value part of the tag (for example value="Trudi"). If the attribute is multivalued, the
* input tag (<input type="text" name="cn" value=""/>) is copied and reused until all of the attribute
* values are inserted. For layout, a </br> is added to the end of multivalued attribute tags. The tag
* is then inserted back into the html template and returned.
* @param htmlString the actual html file that is to be displayed.
* @param entry the current entry that the html file is trying to display.
* @return the updated html file (updated with the values of the text fields that are to be displayed).
*/
// XXX This should be rewritten to correctly use the HTML Document object model,
protected String insertFormInputData(String htmlString, DXEntry entry)
{
int tagStart,tagEnd,pos = 0;
StringBuffer multiValuedTag = new StringBuffer(0);
while ((pos = htmlString.indexOf("<input", pos)) >= 0)
{
tagStart = pos;
tagEnd = htmlString.indexOf(">", pos);
String tag = htmlString.substring(tagStart, tagEnd + 1);
String type = getTagValue("type", tag);
String name = getTagValue("name", tag);
DXAttribute attribute = null;
attribute = (DXAttribute) entry.get(name); //TE: get the attribute values that are being processed.
int size = 0;
if (attribute != null)
size = attribute.size(); //TE: get the number of values the attribute has so we can tell if it is multivalued.
if ("text".equalsIgnoreCase(type) && name != null && attribute != null) //TE: if the input type is 'text', and the input name is not null, and the attribute is not null.
{
if (size == 1) //TE: was attribute.size() -> throws a null pointer exception.
tag = insertFormValue(tag, entry, name); //TE: if there is only one value process it normally.
else if (size > 1) //TE: multivalued.
{
for (int i = 0; i < size; i++)
{ //TE: make a new tag for each attribute value (only used for multivalued attributes),
// for example: <input type="text" name="telephoneNumber" value="9727 8941"/><br/>.
// Then append the tag to a string buffer.
multiValuedTag.append(new String(insertFormValue(tag, entry, name, i) + "<br>"));
}
tag = multiValuedTag.toString();
multiValuedTag.setLength(0);
}
}
else if ("hidden".equalsIgnoreCase(type) && name != null)
tag = insertFormValue(tag, entry, name);
else if ("password".equalsIgnoreCase(type) && name != null && attribute != null)
{
if (attribute.size() == 1)
tag = insertFormValue(tag, entry, name);
else if (attribute.size() > 1)
{
for (int i = 0; i < size; i++)
{ //TE: make a new tag for each password value (only used for multivalued attributes),
// for example: <input type="text" name="userPassword" value="*****"/><br/>.
// Then append the tag to a string buffer.
multiValuedTag.append(new String(insertFormValue(tag, entry, name, i) + "<br>"));
}
tag = multiValuedTag.toString();
multiValuedTag.setLength(0);
}
}
pos = tagStart + tag.length(); // reset pos because tag may have grown larger and may now contains multiple html tags.
htmlString = htmlString.substring(0, tagStart) + tag + htmlString.substring(tagEnd + 1); //TE: insert the tag into the htmlString.
}
return htmlString;
}
// XXX This should be rewritten to correctly use the HTML Document object model,
protected String insertFormSelectData(String htmlString, DXEntry entry)
{
int tagStart,tagEnd,pos = 0;
while ((pos = htmlString.indexOf("<select", pos)) >= 0)
{
t
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -