1 package com.ca.directory.jxplorer.viewer; 2 3 import com.ca.commons.cbutil.*; 4 import com.ca.commons.naming.*; 5 import com.ca.directory.jxplorer.*; 6 import com.ca.directory.jxplorer.tree.SmartTree; 7 8 import javax.naming.NamingEnumeration ; 9 import javax.naming.NamingException ; 10 import javax.naming.directory.Attribute ; 11 import javax.naming.directory.Attributes ; 12 import javax.swing.*; 13 import javax.swing.event.HyperlinkEvent ; 14 import javax.swing.event.HyperlinkListener ; 15 import java.awt.*; 16 import java.awt.event.ActionEvent ; 17 import java.awt.event.ActionListener ; 18 import java.io.*; 19 import java.net.*; 20 import java.util.*; 21 import java.util.logging.Logger ; 22 import java.util.logging.Level ; 23 import java.util.zip.ZipException ; 24 25 35 36 37 48 49 public class HTMLTemplateDisplay extends JPanel 50 implements DataSink, PluggableEditor 51 { 52 JScrollPane scrollDisplay; 53 54 DataSource currentDataSource = null; 55 56 JEditorPane editor; 57 JViewport viewport; JTextArea bloop; 59 60 String baseText; StringBuffer htmlText; 66 Component display; 68 public static final String DEFAULTTEXT = "<html><head><title>Default Template</title></head><body> <dxtemplate:get-all-attributes> <br> </body></html>"; 69 public static final String ATTRIBTAG = "<dxtemplate:"; 70 public static String NOVALUEFOUND; 71 public static final String JPEGEXTENSION = ".jpg"; public static final String DOCEXTENSION = ".doc"; public static final String XLSEXTENSION = ".xls"; public static final String WAVEXTENSION = ".wav"; public static final String AVIEXTENSION = ".avi"; public static final String MIDEXTENSION = ".mid"; 78 public static final String startFile = "start"; 80 public static final int MAX_LEGAL_VALUE_LENGTH = 500; 81 public static final String ILLEGAL_VALUE = "[ATTRIBUTE TOO LARGE TO DISPLAY]"; 82 83 public static final String DEFAULT = "defaulttemplate"; 85 Properties myProperties; 87 JToolBar toolBar; 89 93 94 CBJComboBox viewTemplates; 96 97 Hashtable viewTemplatesPos = new Hashtable(); 101 Hashtable templates = new Hashtable(100); 103 104 String oldObjectClassesSignature = ""; 106 107 File baseTemplateDir; 109 110 File pluginTemplateDirectory = null; 112 113 DXEntry currentEntry = null; static String currentTemplateName = ""; 118 public static String NODATA; 120 public boolean showHTMLErrors = true; 122 protected MyHyperlinkListener hyperlinkListener; 123 protected MyHTMLEditorKit htmlEditorKit; 124 125 protected boolean settingUpTemplates = false; 127 Vector currentBinaryAttributes = new Vector(0); 129 CBResourceLoader resourceLoader = null; 131 protected String currentDN; 133 SmartTree smartTree = null; 134 135 private static Logger log = Logger.getLogger(HTMLTemplateDisplay.class.getName()); 136 137 140 141 public HTMLTemplateDisplay(Component owner, Properties props, CBResourceLoader resourceLoader) 142 { 143 commonConstructorCode(owner, props, resourceLoader); 144 setToDefault(); 145 } 146 147 protected void setToDefault() 148 { 149 htmlText = new StringBuffer (DEFAULTTEXT); 150 baseText = new String (DEFAULTTEXT); 151 } 152 153 156 class MyHyperlinkListener implements HyperlinkListener 157 { 158 public void hyperlinkUpdate(final HyperlinkEvent e) 159 { 160 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 161 { 162 SwingUtilities.invokeLater(new Runnable () 163 { 164 public void run() 165 { 166 String desc = e.getDescription(); 167 168 if (desc.toLowerCase().startsWith("dn:")) { 170 String dn = desc.substring(desc.indexOf(":") + 1); 171 172 if (smartTree != null) 173 { 174 smartTree.readAndExpandDN(new DN(dn)); 175 } 176 } 177 else if (desc.toLowerCase().startsWith(".." + File.separator + "temp" + File.separator + "audio" + File.separator) || desc.toLowerCase().startsWith(".." + File.separator + ".." + File.separator + "temp" + File.separator + "audio" + File.separator)) { if (!System.getProperty("os.name").equalsIgnoreCase("SunOS")) { 181 String path = CBCache.getAudioDirPath(); 182 String audioFilePath = desc.substring(desc.indexOf("temp", desc.lastIndexOf("\""))); 183 String audioFileName = audioFilePath.substring(audioFilePath.lastIndexOf("\\")); 184 String extension = audioFileName.substring(audioFileName.indexOf(".")); 185 186 if (extension.equalsIgnoreCase(".xxx")) 187 CBUtility.error(CBIntText.get("Unable to play unknown audio file type")); 188 else 189 CBLauncher.launchProgram(extension, path + audioFileName); 190 } 191 } 192 else if (desc.toLowerCase().startsWith(".." + File.separator + "temp" + File.separator) || desc.toLowerCase().startsWith(".." + File.separator + ".." + File.separator + "temp" + File.separator)) { if (!System.getProperty("os.name").equalsIgnoreCase("SunOS")) { 196 String path = CBCache.getDirPath(); 197 String filePath = desc.substring(desc.indexOf("temp", desc.lastIndexOf("\""))); 198 String fileName = filePath.substring(filePath.indexOf("\\")); 199 String extension = fileName.substring(fileName.indexOf(".")); 200 201 CBLauncher.launchProgram(extension, path + fileName); 202 } 203 } 204 else if (!System.getProperty("os.name").equalsIgnoreCase("SunOS") && desc.toLowerCase().startsWith("mailto")) { launchClient(desc); 207 } 208 else 209 { 210 URL url = e.getURL(); 211 212 217 218 if (url.getProtocol().equals("file")) { 221 222 String fullFileName = ""; 223 String baseTemplateDirPath = ""; 224 String pluginTemplateDirectoryPath = ""; 225 try 226 { 227 fullFileName = new File(URLDecoder.decode(url.getFile(), "UTF-8")).getCanonicalPath(); baseTemplateDirPath = baseTemplateDir.getCanonicalPath(); 230 if (pluginTemplateDirectory != null) 231 pluginTemplateDirectoryPath = pluginTemplateDirectory.getCanonicalPath(); 232 } 233 catch (IOException e) { 235 log.log(Level.WARNING, "Exception trying to access HTML file urls " + url.getFile().toString(), e); 236 } 237 String fileName = ""; 238 239 if (fullFileName.startsWith(baseTemplateDirPath)) 240 { 241 fileName = fullFileName.substring(baseTemplateDirPath.length()); 242 } 243 else if (pluginTemplateDirectory!=null && fullFileName.startsWith(pluginTemplateDirectoryPath)) 245 { 246 fileName = fullFileName.substring(pluginTemplateDirectoryPath.length()); 247 } 248 249 if (fileName.startsWith(File.separator)) 250 fileName = fileName.substring(1); 251 252 fileName = (new File(fileName)).toString(); 253 254 if (templateExists(fileName)) 255 { 256 setNewTemplate(fileName); 257 } 258 else 259 { 260 openPage(url); 261 } 262 } 263 else 264 { if ((JXplorer.getProperty("option.url.handling")).equalsIgnoreCase("Launch")) 266 launchClient(desc); 267 else 269 openPage(url); 270 } 271 } 272 } 273 }); 274 } 275 } 276 }; 277 278 279 280 284 285 public void setEditorText(String htmlText) 286 { 287 289 Dimension current = null; 290 if (editor != null) { 293 try 294 { 295 editor.setText(htmlText); 296 } 297 catch (Exception e) { 299 recreateEditor(current, htmlText); 300 } 301 } 302 else 303 { 304 recreateEditor(current, htmlText); 305 } 306 editor.validate(); 307 308 try 312 { 313 viewport.setView(editor); 314 } 315 catch (ArrayIndexOutOfBoundsException e) { 317 viewport = new JViewport(); 318 viewport.setView(editor); 319 scrollDisplay.setViewport(viewport); 320 } 321 } 322 323 329 private void recreateEditor(Dimension current, String htmlText) 330 { 331 editor = getNewEditor(); 332 if (current == null) { 334 current = new Dimension (400,400); 336 } 337 editor.setSize(current); 338 editor.setText(htmlText); 339 } 340 341 342 352 353 protected JEditorPane getNewEditor() 354 { 355 359 361 JEditorPane newEditor = new JEditorPane(); 362 363 newEditor.setEditorKitForContentType("text/html", htmlEditorKit); 364 newEditor.addHyperlinkListener(hyperlinkListener); 365 newEditor.setEditable(false); 366 newEditor.setMinimumSize(new Dimension(400, 400)); 367 newEditor.setContentType("text/html"); 368 369 return newEditor; 370 371 } 372 373 380 private void commonConstructorCode(Component owner, Properties props, CBResourceLoader resourceLoader) 381 { 382 initMyProperties(props); 383 384 this.resourceLoader = resourceLoader; 385 386 setupTemplateLists(); 387 388 401 initGUI(owner); 402 403 setStartPage(); 404 405 406 407 } 408 409 413 private void setupTemplateLists() 414 { 415 try 416 { 417 initZipTemplates(); 419 420 baseTemplateDir = getBaseTemplateDirectory(); 422 String baseTemplate = baseTemplateDir.getCanonicalPath(); 423 424 String [] defaultTemplates = CBUtility.readFilteredDirectory(baseTemplate, new String []{"html", "htm"}); 426 427 addToGlobalTemplateList(defaultTemplates, DEFAULT); 428 429 if (pluginTemplateDirectory != null) 431 { 432 433 defaultTemplates = CBUtility.readFilteredDirectory(pluginTemplateDirectory.getCanonicalPath(), new String []{"html", "htm"}); 434 addToGlobalTemplateList(defaultTemplates, ""); 435 } 436 437 if (defaultTemplates == null || defaultTemplates.length == 0) 438 log.warning("Warning - can't find any default html templates in " + baseTemplate); 439 440 String [] objectClassFolders = getAllTemplateSubDirectories(baseTemplateDir); 442 addIndividualObjectClassTemplates(objectClassFolders, baseTemplate); 443 444 if (pluginTemplateDirectory != null) 446 { 447 objectClassFolders = getAllTemplateSubDirectories(pluginTemplateDirectory); 448 addIndividualObjectClassTemplates(objectClassFolders, pluginTemplateDirectory.toString()); 449 } 450 451 } 453 catch (FileNotFoundException e) 454 { 455 log.warning("Error initialising HTML Template: " + e.toString()); 456 } 457 catch (IOException e2) 458 { 459 log.warning("Error initialising HTML Template file paths: " + e2.toString()); 460 } 461 } 462 480 private void addIndividualObjectClassTemplates(String [] objectClassFolders, String baseTemplate) 481 { 482 for (int i = 0; i < objectClassFolders.length; i++) 484 { 485 String folderName = baseTemplate + File.separator + objectClassFolders[i]; 486 String objectClass = objectClassFolders[i]; 487 String [] ocTemplates = CBUtility.readFilteredDirectory(folderName, new String []{"html", "htm"}); 488 addToGlobalTemplateList(ocTemplates, objectClass); 489 } 490 } 491 492 497 private void addToGlobalTemplateList(String [] fileNames, String folderName) 498 { 499 if (fileNames == null) return; 501 502 String objectClass = folderName.toLowerCase(); 503 504 File[] fileList = new File[fileNames.length]; 505 for (int i = 0; i < fileNames.length; i++) 506 { 507 if (DEFAULT.equals(folderName)) 508 fileList[i] = new File(fileNames[i]); 509 else 510 fileList[i] = new File(folderName, fileNames[i]); 511 } 512 513 templates.put(objectClass, fileList); 515 } 516 517 523 private String [] getAllTemplateSubDirectories(File baseTemplateDir) 524 { 525 String [] childDirectories = baseTemplateDir.list(new FilenameFilter() 526 { 527 public boolean accept(File dir, String name) 528 { 529 File candidate = new File(dir, name); 530 return candidate.isDirectory(); 531 } 532 }); 533 534 return childDirectories; 535 } 536 537 544 private File getBaseTemplateDirectory() 545 throws FileNotFoundException 546 { 547 File baseTemplateDir = new File(myProperties.getProperty("dir.templates")); 548 if (!baseTemplateDir.exists()) 549 { 550 log.warning("can't find html template directory " + baseTemplateDir + " - trying to find /templates directory"); 551 baseTemplateDir = new File(JXplorer.localDir + "templates" + File.separator); 552 if (!baseTemplateDir.exists()) 553 { 554 throw new FileNotFoundException("ERROR - Cannot find backup /template directory in " + baseTemplateDir); 555 } 556 } 557 return baseTemplateDir; 558 } 559 560 570 private void initZipTemplates() 571 { 572 String [] zipTemplates = null; 574 File pluginDirectory = new File(JXplorer.getProperty("dir.plugins")); 575 if (!pluginDirectory.exists()) 576 pluginDirectory.mkdirs(); 577 578 580 582 zipTemplates = resourceLoader.getPrefixedResources("templates/"); 583 584 if (zipTemplates.length == 0) 585 return; 587 pluginTemplateDirectory = new File(pluginDirectory, "templates/"); 588 589 591 int prefixSize = "templates/".length(); 592 593 for (int i = 0; i < zipTemplates.length; i++) 594 { 595 String templateName = zipTemplates[i]; 597 598 if (templateName.length() > prefixSize) 599 { 600 String templateRelativeFileName = CBParse.replaceAllChar(new StringBuffer (templateName), '/', File.separator); 601 602 File pluginTemplateFile = new File(pluginDirectory + File.separator + templateRelativeFileName); 603 604 try 605 { 606 if ((pluginTemplateFile.exists() == false) || 609 (pluginTemplateFile.lastModified() < resourceLoader.getLastModified(templateName))) 610 { 611 if (templateRelativeFileName.endsWith(File.separator)) { 613 pluginTemplateFile.mkdirs(); 614 } 615 else 616 { 617 if (!pluginTemplateFile.getParentFile().exists()) 618 pluginTemplateFile.getParentFile().mkdirs(); 619 620 byte[] b = resourceLoader.getResource(templateName); 622 try 623 { 624 FileOutputStream output = new FileOutputStream(pluginTemplateFile); 625 output.write(b); 626 output.close(); 627 } 628 catch (java.io.IOException e) 629 { 630 CBUtility.error("Problem writing unpacked plugin template file: " + pluginTemplateFile + " to disk \n ", e); 631 } 632 } 633 } 634 } 635 catch (ZipException e) 636 { 637 CBUtility.error("Problem accessing plugin zip file: " + e); 638 } 639 } 640 } 641 653 } 654 655 664 private void setStartPage() 665 { 666 667 if (editor == null) editor = getNewEditor(); 668 669 670 String htmldocs = myProperties.getProperty("dir.htmldocs", JXplorer.localDir + "htmldocs" + File.separator); 671 try 672 { 673 final String language = Locale.getDefault().getLanguage(); 674 File localeSpecificStartFile = new File(htmldocs + startFile + "_" + language + ".html"); 675 if (localeSpecificStartFile.exists() == false) 676 { 677 log.warning("unable to find locale specific start file: " + localeSpecificStartFile); 678 localeSpecificStartFile = new File(htmldocs + startFile + ".html"); 679 if (localeSpecificStartFile.exists() == false) 680 { 681 log.warning("unable to find locale specific start file: " + localeSpecificStartFile); 682 editor.setText("<html><head><title>JXplorer Start Screen</title></head>" + 683 "<body><h2><font face=\"arial\">Welcome to JXplorer...</font></h2><p>" + 684 "<font face=\"arial\">This panel will display the results of your directory browsing and searches.</font></p>" + 685 "<p><font face=\"arial\">If you need any assistance, use the help option on the menu bar above.</font></p>" + 686 "</body></html>"); 687 validate(); return; 689 } 690 } 691 openPage(localeSpecificStartFile.toURL()); 692 validate(); } 694 catch (IOException e) 695 { 696 log.warning("unable to open welcome page. " + e); 697 } 698 } 699 700 704 private void initGUI(Component owner) 705 { 706 setLayout(new BorderLayout()); 707 NODATA = "<html><head><title>" + CBIntText.get("No Data") + "</title></head><body><h2><font face=\"arial\">" + CBIntText.get("Select an entry to view data") + "</font></h2></body></html>"; 708 NOVALUEFOUND = "<i>" + CBIntText.get("No Value Found") + "</i>"; 709 viewport = new JViewport(); scrollDisplay = new JScrollPane(); 711 initToolBar(); 712 add(toolBar, BorderLayout.NORTH); 713 add(scrollDisplay); 714 htmlEditorKit = new MyHTMLEditorKit(this); 715 hyperlinkListener = new MyHyperlinkListener(); 716 editor = getNewEditor(); 717 viewport.setView(editor); 718 scrollDisplay.setViewport(viewport); 719 display = owner; 720 } 721 722 private void initMyProperties(Properties props) 723 { 724 if (props == null) 725 { 726 CBUtility.error("unable to find html templates", new Exception ("Null properties list passed to HTML template display - unable to use templates...")); 727 myProperties = new Properties(); 728 } 729 else 730 myProperties = props; 731 } 732 733 738 739 protected boolean templateExists(String candidate) 740 { 741 747 748 749 for (int i = 0; i < viewTemplates.getItemCount(); i++) 750 { 751 String name = (String ) viewTemplates.getItemAt(i); 752 if (name.equalsIgnoreCase(candidate)) return true; } 754 return false; 755 } 756 757 762 763 public void initToolBar() 764 { 765 toolBar = new JToolBar(); 766 String [] errorMessage = {CBIntText.get("no templates found")}; 767 String [] templates = readTemplateNames(new String []{}); 768 if (templates == null || templates.length == 0) 769 templates = errorMessage; 770 771 viewTemplates = new CBJComboBox(templates); 772 viewTemplates.setEditable(false); 773 viewTemplates.setAlignmentY(Component.TOP_ALIGNMENT); 774 775 viewTemplates.setToolTipText(CBIntText.get("Select a template to view attributes with")); 776 777 toolBar.add(viewTemplates); 778 779 782 viewTemplates.addActionListener(new ActionListener () 783 { 784 public void actionPerformed(ActionEvent e) 785 { 786 if (settingUpTemplates == true) return; 788 if ((e == null) || (e.getSource() == null)) return; if (viewTemplates.getSelectedItem() == null) return; 791 String templateName = viewTemplates.getSelectedItem().toString(); 792 if (templateName.equalsIgnoreCase(currentTemplateName)) return; 794 setNewTemplate(templateName); 795 796 repaint(); 797 } 798 }); 799 800 } 801 802 803 public void setNewTemplate(String templateName) 804 { 805 String current = (String ) viewTemplates.getSelectedItem(); 806 if (templateName.equalsIgnoreCase(current) == false) { 808 viewTemplates.setSelectedItem(templateName); 809 } 810 currentTemplateName = templateName; 811 812 openNewTemplate(templateName); 813 displayEntry(currentEntry, currentDataSource); } 815 816 817 821 822 private void addFileListToTemplateNames(ArrayList templateNames, File[] fileList) 823 { 824 if (fileList == null) 825 { 826 return; 827 } 828 829 for (int i = 0; i < fileList.length; i++) 830 { 831 templateNames.add(fileList[i].toString()); 832 } 833 } 834 835 838 839 public String [] readTemplateNames(String [] objectClassNames) 840 { 841 843 ArrayList templateNames = new ArrayList(); 845 846 addFileListToTemplateNames(templateNames, (File[]) templates.get(DEFAULT)); 848 849 for (int classNo = 0; classNo < objectClassNames.length; classNo++) 851 { 852 String className = objectClassNames[classNo].toLowerCase(); 853 addFileListToTemplateNames(templateNames, (File[]) templates.get(className)); 854 } 855 856 String [] templates = (String []) templateNames.toArray(new String [templateNames.size()]); 858 859 Arrays.sort(templates); 860 861 return templates; 862 } 863 864 865 871 872 public boolean openNewTemplate(String templateName) 873 { 874 File templateFile = new File(baseTemplateDir, templateName); 876 if (templateFile.exists() == false) 877 { 878 templateFile = new File(pluginTemplateDirectory, templateName); 880 if (templateFile.exists() == false) 881 return CBUtility.error(display, CBIntText.get("Can't find html template! ") + templateName); 882 } 883 884 try 885 { 886 htmlText = new StringBuffer (CBUtility.readTextFile(templateFile)); 887 888 htmlText = parseNewTemplate(htmlText, templateFile.toURI().toURL()); 890 baseText = htmlText.toString(); } 892 catch (IOException e) 893 { 894 return CBUtility.error(display, CBIntText.get("Can't read html template! ") + templateFile.getAbsolutePath()); 895 } 896 return true; 897 898 932 946 967 } 968 969 970 980 981 public StringBuffer parseNewTemplate(StringBuffer templateText, URL url) 982 { 983 992 String baseTagURL = url.getPath(); 993 994 998 1000 baseTagURL = "file://" + baseTagURL.substring(0, baseTagURL.lastIndexOf('/') + 1); 1001 1002 int headPos = templateText.toString().indexOf("<head>"); 1003 1004 String baseTag = "\n<base HREF=\"" + baseTagURL + "\">\n"; 1005 1006 templateText.insert(headPos + 7, baseTag); return templateText; 1009 } 1010 1011 1020 1021 public File getTemplateFile(String fileNameAndPath) 1022 { 1023 String fileName = fileNameAndPath + ".html"; 1024 File templateFile = new File(fileName); 1025 if (templateFile.exists() == false) templateFile = new File(fileNameAndPath + ".htm"); 1027 return templateFile; 1028 } 1029 1030 1031 public String [] getObjectClasses(DXAttributes atts) 1032 { 1033 try 1034 { 1035 Attribute a = atts.getAllObjectClasses(); 1036 1037 if (a == null) return new String []{}; 1038 1039 DXNamingEnumeration en = new DXNamingEnumeration(a.getAll()); 1040 en.sort(); 1042 String [] ret = en.toStringArray(); 1043 1044 return ret; 1045 } 1046 catch (NamingException e) 1047 { 1048 log.warning("unable to read object classes in AttributeDisplay: " + e.toString()); 1049 } 1050 return null; 1051 } 1052 1053 1058 1059 public String getObjectClassSignature(String [] objectClasses) 1060 { 1061 String ret = ""; 1062 if (objectClasses == null) return ""; 1063 for (int i = 0; i < objectClasses.length; i++) 1064 ret += objectClasses[i]; 1065 return ret; 1066 } 1067 1068 1069 1074 1075 public boolean objectClassesChanged(String classesSignature) 1076 { 1077 return !((oldObjectClassesSignature != null) && (oldObjectClassesSignature.equals(classesSignature))); 1078 } 1079 1080 1081 public void displayEntry(DXEntry entry, DataSource formDataSource) 1082 { 1083 if (entry == null || entry.size() == 0) 1084 { 1085 setEditorText(NODATA); 1086 return; 1087 } 1088 1089 currentDataSource = formDataSource; 1091 currentEntry = entry; 1092 1093 String [] objectClasses = getObjectClasses(entry); 1094 if (objectClasses == null) 1095 { 1096 log.warning("unable to find any object classes for " + entry.getDN().toString()); 1097 setEditorText(NODATA); 1098 return; 1099 } 1100 1101 setupTemplates(objectClasses, entry); 1103 1104 if (entry == null) 1105 { 1106 CBUtility.error(this, CBIntText.get("Error. No data for this node!"), null); 1107 setEditorText(NODATA); 1108 return; 1109 } 1110 displayData(entry); 1111 } 1112 1113 1118 void setupTemplates(String [] objectClasses, DXEntry entry) 1119 { 1120 String objectClassesSignature = getObjectClassSignature(objectClasses); 1121 1122 if (objectClassesChanged(objectClassesSignature)) 1124 { 1125 viewTemplatesPos.put(oldObjectClassesSignature, new Integer (viewTemplates.getSelectedIndex())); 1127 oldObjectClassesSignature = objectClassesSignature; 1128 1129 settingUpTemplates = true; 1131 1132 viewTemplates.removeAllItems(); 1134 1135 String [] templates = readTemplateNames(objectClasses); 1137 1138 if ((templates == null) || (templates.length == 0)) 1139 log.warning("No templates found for objectClasses " + objectClassesSignature); 1141 else 1142 { 1143 for (int i = 0; i < templates.length; i++) 1145 viewTemplates.addItem(templates[i]); 1146 1147 1148 if (viewTemplatesPos.containsKey(objectClassesSignature)) 1149 { 1150 int indexPos = ((Integer ) viewTemplatesPos.get(objectClassesSignature)).intValue(); 1152 if (indexPos < templates.length) 1153 viewTemplates.setSelectedIndex(indexPos); 1154 } 1155 else 1156 { 1157 viewTemplates.setSelectedIndex(0); 1160 1161 attemptToSetOCSpecificTemplate(entry, templates); 1163 } 1164 String templateName = viewTemplates.getSelectedItem().toString(); 1165 openNewTemplate(templateName); 1166 } 1167 settingUpTemplates = false; } 1169 } 1170 1171 1175 1176 protected void attemptToSetOCSpecificTemplate(DXAttributes entry, String [] templates) 1177 { 1178 Vector ocs = (entry).getOrderedOCs(); 1180 1181 for (int i = 0; i < ocs.size(); i++) 1182 { 1183 String oc = ((String ) ocs.get(i)).toLowerCase(); 1184 for (int j = 0; j < templates.length; j++) 1185 { 1186 String template = templates[j].toLowerCase(); 1187 if (template.startsWith(oc)) 1188 { 1189 settingUpTemplates = true; 1190 viewTemplates.setSelectedIndex(j); 1191 settingUpTemplates = false; 1192 return; 1193 } 1194 } 1195 } 1196 } 1197 1198 1199 1209 1210 protected void displayData(DXEntry entry) 1211 { 1212 if (entry == null) 1213 { 1214 setEditorText(NODATA); 1215 return; 1216 } 1217 1218 int tagstart = 0; int tagend; 1221 1223 htmlText = new StringBuffer (baseText); 1224 1225 htmlText = parseXHTML(htmlText); 1227 1228 1229 mediaCheck(entry, "jpegPhoto"); mediaCheck(entry, "audio"); mediaCheck(entry, "odDocumentDOC"); mediaCheck(entry, "odSpreadSheetXLS"); mediaCheck(entry, "odMusicMID"); mediaCheck(entry, "odSoundWAV"); mediaCheck(entry, "odMovieAVI"); 1237 1238 tagstart = htmlText.indexOf(ATTRIBTAG, tagstart); 1239 while (tagstart >= 0) 1240 { 1241 tagend = htmlText.indexOf(">", tagstart); 1242 String tempTag = htmlText.substring(tagstart, tagend); 1243 1244 String attName = ""; 1245 if (tempTag.indexOf("get-all-attributes") > 0) attName = "all"; 1247 else attName = tempTag.substring(tempTag.indexOf("name=\"") + 6, tempTag.indexOf("\"", tempTag.indexOf("name=\"") + 6)); 1249 1250 String modifier = null; 1251 1252 if (tempTag.indexOf("style=\"") > 0) modifier = tempTag.substring(tempTag.indexOf("style=\"") + 7, tempTag.indexOf("\"", tempTag.indexOf("style=\"") + 7)); 1254 1255 htmlText.delete(tagstart, tagend + 1); if (attName.equalsIgnoreCase("all")) htmlText.insert(tagstart, formattedAllAttributes(currentEntry, modifier)); 1258 else htmlText.insert(tagstart, formattedAttribute(attName, currentEntry, modifier)); 1261 tagstart = htmlText.indexOf(ATTRIBTAG, tagstart); 1264 1265 } 1266 if ((htmlText == null) || (htmlText.length() == 0)) 1267 { 1268 log.warning("HTMLTemplateDisplay:displayNodeData - bad html String " + ((htmlText == null) ? " (is null!)" : "")); 1269 setEditorText(NODATA); 1270 return; 1271 } 1272 1273 String htmlString = htmlText.toString().trim(); 1274 1275 htmlString = insertFormData(htmlString, entry); 1276 1277 1278 try 1279 { 1280 setEditorText(htmlString); 1281 } 1282 catch (EmptyStackException e) { 1284 log.warning("Another Bug in Sun HTML Component: " + e); 1285 } 1286 1287 scrollDisplay.getVerticalScrollBar().setValue(0); viewport.setViewPosition(new Point(0, 0)); } 1290 1291 1292 1302 1303 protected void mediaCheck(DXEntry entry, String type) 1304 { 1305 DXAttribute attribute = null; 1306 attribute = (DXAttribute) entry.get(type); 1307 1308 if (attribute == null) 1309 return; 1310 1311 currentDN = entry.getDN().toString(); currentDN = Integer.toString(currentDN.hashCode()); 1314 int size = attribute.size(); 1316 if (attribute != null) 1317 { 1318 CBCache.createCache(entry.getDN().toString(), entry, type, size); } 1320 } 1321 1322 1323 1324 1328 1330 static public StringBuffer parseXHTML(StringBuffer html) 1331 { 1332 return CBParse.replaceAllBufferString(html, "/>", ">"); 1333 } 1334 1335 1344 1345 1348 protected String insertFormData(String htmlString, DXEntry entry) 1349 { 1350 if (htmlString.indexOf("<form") < 0) 1351 { 1352 if (currentBinaryAttributes.size() > 0) 1353 currentBinaryAttributes.clear(); 1354 return htmlString; } 1356 1357 try 1358 { 1359 htmlString = insertFormInputData(htmlString, entry); 1360 htmlString = insertFormSelectData(htmlString, entry); 1361 htmlString = insertFormTextAreaData(htmlString, entry); 1362 htmlString = insertFormImageData(htmlString, entry); htmlString = insertFormAudioData(htmlString, entry); } 1365 catch (Exception e) { 1367 if (showHTMLErrors) 1368 { 1369 log.warning("Error parsing form html for value insertion in HTMLTemplateDisplay. \n " + e); 1370 e.printStackTrace(); 1371 } 1372 } 1373 1374 return htmlString; 1375 } 1376 1377 protected String getTagValue(String tagName, String tag) 1379 { 1380 tag = tag.toLowerCase(); 1381 tagName = tagName.toLowerCase(); 1382 try 1383 { 1384 int start = tag.indexOf(tagName) + tagName.length(); 1385 start = tag.indexOf("\"", start) + 1; 1386 if (start < 0) return null; 1387 int end = tag.indexOf("\"", start); 1388 if (end < 0) return null; 1389 String val = tag.substring(start, end); 1390 return val.trim(); 1391 } 1392 catch (Exception e) 1393 { 1394 if (showHTMLErrors) 1395 log.warning("error parsing: " + tagName + "\n " + e); 1396 return null; 1397 } 1398 } 1399 1400 1401 1402 1419 1420 protected String insertFormInputData(String htmlString, DXEntry entry) 1422 { 1423 int tagStart,tagEnd,pos = 0; 1424 StringBuffer multiValuedTag = new StringBuffer (0); 1425 1426 while ((pos = htmlString.indexOf("<input", pos)) >= 0) 1427 { 1428 tagStart = pos; 1429 tagEnd = htmlString.indexOf(">", pos); 1430 1431 String tag = htmlString.substring(tagStart, tagEnd + 1); 1432 1433 String type = getTagValue("type", tag); 1434 String name = getTagValue("name", tag); 1435 1436 DXAttribute attribute = null; 1437 attribute = (DXAttribute) entry.get(name); 1439 int size = 0; 1440 1441 if (attribute != null) 1442 size = attribute.size(); 1444 if ("text".equalsIgnoreCase(type) && name != null && attribute != null) { 1446 if (size == 1) tag = insertFormValue(tag, entry, name); else if (size > 1) { 1450 for (int i = 0; i < size; i++) 1451 { multiValuedTag.append(new String (insertFormValue(tag, entry, name, i) + "<br>")); 1455 } 1456 tag = multiValuedTag.toString(); 1457 multiValuedTag.setLength(0); 1458 } 1459 } 1460 else if ("hidden".equalsIgnoreCase(type) && name != null) 1461 tag = insertFormValue(tag, entry, name); 1462 else if ("password".equalsIgnoreCase(type) && name != null && attribute != null) 1463 { 1464 if (attribute.size() == 1) 1465 tag = insertFormValue(tag, entry, name); 1466 else if (attribute.size() > 1) 1467 { 1468 for (int i = 0; i < size; i++) 1469 { multiValuedTag.append(new String (insertFormValue(tag, entry, name, i) + "<br>")); 1473 } 1474 tag = multiValuedTag.toString(); 1475 multiValuedTag.setLength(0); 1476 } 1477 } 1478 pos = tagStart + tag.length(); htmlString = htmlString.substring(0, tagStart) + tag + htmlString.substring(tagEnd + 1); } 1481 return htmlString; 1482 } 1483 1484 protected String insertFormSelectData(String htmlString, DXEntry entry) 1486 { 1487 int tagStart,tagEnd,pos = 0; 1488 while ((pos = htmlString.indexOf("<select", pos)) >= 0) 1489 { 1490 tagStart = pos; 1491 tagEnd = htmlString.indexOf("</select>", pos); 1492 1493 String tag = htmlString.substring(tagStart, tagEnd); 1494 1495 String name = getTagValue("name", tag); 1496 1497 if (name != null) 1498 { 1499 try 1500 { 1501 Attribute a = entry.get(name); 1502 if (a == null) return htmlString; if (a.get() == null) return htmlString; 1505 String entryValue = ((String ) a.get()).toLowerCase(); 1506 1507 String lowerCaseTag = tag.toLowerCase(); 1508 int valPos = lowerCaseTag.indexOf(entryValue); 1509 int valTag = lowerCaseTag.lastIndexOf("value", valPos); if (valTag > -1 && valTag > valPos - 9) { tag = tag.substring(0, valTag - 1) + " selected " + tag.substring(valTag); 1513 htmlString = htmlString.substring(0, tagStart) + tag + htmlString.substring(tagEnd); 1514 } 1515 } 1516 catch (Exception e) 1517 { 1518 if (showHTMLErrors) 1519 { 1520 e.printStackTrace(); 1521 log.warning("Error getting value for " + name + " value :\n " + e); } 1523 } 1524 } 1525 1526 pos = tagEnd; 1527 } 1528 return htmlString; 1529 } 1530 1531 1532 1533 1550 1551 protected String insertFormTextAreaData(String htmlString, DXEntry entry) 1553 { 1554 int tagStart,tagEnd,pos = 0; 1555 while ((pos = htmlString.indexOf("<textarea", pos)) >= 0) 1556 { 1557 tagStart = pos; 1558 tagEnd = htmlString.indexOf(">", pos); 1559 String tag = htmlString.substring(tagStart, tagEnd); 1560 1561 String name = getTagValue("name", tag); 1562 1563 DXAttribute attribute = null; 1564 attribute = (DXAttribute) entry.get(name); 1566 int size = 0; 1567 1568 if (attribute != null) 1569 size = attribute.size(); 1571 int nextTag = htmlString.indexOf("</textarea>", tagEnd); 1572 1573 if (nextTag > 0) 1574 { 1575 String betweenTagText = htmlString.substring(tagEnd + 1, nextTag); 1576 if (betweenTagText.trim().length() == 0) { 1578 if (size == 1) 1579 { 1580 String text = getAttValue(name, entry); 1581 if (text != null && attribute != null) { 1583 if (name.toLowerCase().indexOf("address") > 0) 1585 text = text.replace('$', '\n'); 1586 1587 htmlString = htmlString.substring(0, tagEnd + 1) + text + htmlString.substring(nextTag); 1588 } 1589 } 1590 else if (size > 1) { 1592 String text; 1593 String textAreaStartTag = htmlString.substring(tagStart, tagEnd + 1); String textAreaEndTag = htmlString.substring(tagEnd + 1, htmlString.indexOf(">", tagEnd + 1) + 1); 1596 StringBuffer multiValuedTag = new StringBuffer (); 1597 for (int i = 0; i < size; i++) 1598 { text = getAttValue(name, entry, i); 1602 text = text.replace('$', '\n'); 1603 multiValuedTag.append(new String (textAreaStartTag + text + textAreaEndTag + "<br>")); } 1605 1606 String multiTag = multiValuedTag.toString(); 1607 htmlString = htmlString.substring(0, tagStart) + multiTag + htmlString.substring(nextTag); 1608 } 1609 } 1610 } 1611 pos = tagEnd; 1612 } 1613 return htmlString; 1614 } 1615 1616 1617 1638 1639 protected String insertFormImageData(String htmlString, DXEntry entry) 1640 { 1641 int tagStart,tagEnd,pos = 0; 1642 1643 DXAttribute attribute = null; 1644 attribute = (DXAttribute) entry.get("jpegPhoto"); 1646 while ((pos = htmlString.indexOf("Image N/A", pos)) >= 0) 1647 { 1648 tagStart = pos; 1649 tagEnd = htmlString.indexOf("<", pos); 1650 1651 String tag = htmlString.substring(tagStart, tagEnd); 1653 if ("Image N/A".equalsIgnoreCase(tag) && tag != null && attribute != null) 1654 { 1655 if (attribute.size() != 0) 1656 { 1657 int tagPos = htmlString.indexOf(tag); 1659 String htmlCopyStart = htmlString.substring(0, tagPos); String htmlCopyEnd = htmlString.substring(htmlString.indexOf("<", tagPos)); 1662 File fileDir = CBCache.getCacheDirectory(); String [] allFiles = fileDir.list(); 1665 String [] currentFiles = new String [allFiles.length]; 1666 1667 StringBuffer imageTags = new StringBuffer (); 1668 1669 int x = 0; 1671 for (int i = 0; i < allFiles.length; i++) 1672 { 1673 if (allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(JPEGEXTENSION)) 1676 { 1677 currentFiles[x] = allFiles[i].toString(); 1678 1679 imageTags.append(new String ("<img SRC=\".." + File.separator + ".." + File.separator + "temp" + File.separator + currentFiles[x] + "\" border=\"1\"><br>")); x++; 1681 } 1682 } 1683 htmlString = htmlCopyStart + imageTags.toString() + htmlCopyEnd; } 1685 } 1686 pos = tagEnd; 1687 } 1688 return htmlString; 1689 } 1690 1691 1692 1713 1714 protected String insertFormAudioData(String htmlString, DXEntry entry) 1715 { 1716 int tagStart,tagEnd,pos = 0; 1717 1718 DXAttribute attribute = null; 1719 attribute = (DXAttribute) entry.get("audio"); 1721 while ((pos = htmlString.indexOf("Audio N/A", pos)) >= 0) 1722 { 1723 tagStart = pos; 1724 tagEnd = htmlString.indexOf("<", pos); 1725 1726 String tag = htmlString.substring(tagStart, tagEnd); 1728 if ("Audio N/A".equalsIgnoreCase(tag) && tag != null && attribute != null) 1729 { 1730 if (attribute.size() != 0) 1731 { 1732 int tagPos = htmlString.indexOf(tag); 1734 String htmlCopyStart = htmlString.substring(0, tagPos); String htmlCopyEnd = htmlString.substring(htmlString.indexOf("<", tagPos)); 1737 File fileDir = CBCache.getAudioCacheDirectory(); String [] allFiles = fileDir.list(); 1740 String [] currentFiles = new String [allFiles.length]; 1741 1742 StringBuffer audioTags = new StringBuffer (); 1743 1744 int x = 0; 1746 for (int i = 0; i < allFiles.length; i++) 1747 { 1748 if (allFiles[i].startsWith(currentDN) && !allFiles[i].endsWith(JPEGEXTENSION)) 1751 { 1752 currentFiles[x] = allFiles[i].toString(); 1753 1754 audioTags.append(new String ("<a HREF=\"" + ".." + File.separator + ".." + File.separator + "temp" + File.separator + "audio" + File.separator + currentFiles[x] + "\">Sound File</a><br>")); x++; 1756 } 1757 } 1758 htmlString = htmlCopyStart + audioTags.toString() + htmlCopyEnd; } 1760 } 1761 pos = tagEnd; 1762 } 1763 return htmlString; 1764 } 1765 1766 1767 1774 1775 protected String insertFormValue(String tag, DXEntry entry, String name) 1776 { 1777 String newTag = insertFormValue(tag, entry, name, 0); return newTag; 1779 } 1780 1781 1782 1790 1791 protected String insertFormValue(String tag, DXEntry entry, String name, int position) 1793 { 1794 String val = getTagValue(" value", tag); 1795 1796 if (val == null) return tag; if (val.trim().length() > 0) return tag; 1799 1801 int pos = tag.indexOf(" value"); 1802 pos = tag.indexOf("\"", pos) + 1; 1803 int end = tag.indexOf("\"", pos); 1804 1805 String entryValue = getAttValue(name, entry, position); if (entryValue != null) 1807 tag = tag.substring(0, pos) + entryValue + tag.substring(end); 1808 1809 return tag; 1810 } 1811 1812 1813 1819 1820 protected String getAttValue(String name, DXEntry entry) 1821 { 1822 String newTag = getAttValue(name, entry, 0); return checkLength(newTag); 1824 } 1825 1826 1831 1832 private String checkLength(String checkString) 1833 { 1834 return (checkString.length() > MAX_LEGAL_VALUE_LENGTH) ? ILLEGAL_VALUE : checkString; 1835 } 1836 1837 1838 1850 1851 protected String getAttValue(String name, DXEntry entry, int position) 1852 { 1853 int numberValues; 1855 if (name == null) return "No name given in HTMLTemplateDisplay.getAttValue()"; 1856 1857 1858 try 1859 { 1860 Attribute a = entry.get(name); 1861 if (a == null) return null; numberValues = a.size(); 1863 if (numberValues == 0 || a.get() == null) return null; if (numberValues <= position) return null; 1866 Object attValue = a.get(position); 1868 1874 1875 if (numberValues > 1) 1876 { 1877 boolean namingMagic = false; 1879 String namingValue = null; 1880 1881 1884 1885 String [] namingTypes = entry.getRDN().getAtts(); 1886 if (namingTypes != null) 1887 { 1888 for (int i = 0; i < namingTypes.length; i++) 1889 if (namingTypes[i].equalsIgnoreCase(name)) 1890 { 1891 namingMagic = true; 1892 namingValue = entry.getRDN().getRawVals()[i]; 1893 } 1894 } 1895 1896 1899 1900 if (namingMagic) 1901 { 1902 if (position == 0) 1903 { 1904 return checkLength(namingValue); 1905 } 1906 else if (attValue.equals(namingValue)) 1907 { 1908 return checkLength((String ) a.get(0)); 1909 } 1910 } 1911 1912 } 1913 1914 if (attValue instanceof String ) 1915 { 1916 return checkLength((String ) attValue); 1917 } 1918 else 1919 { 1920 if (attValue instanceof byte[]) 1921 { 1922 currentBinaryAttributes.add(name); 1923 return CBBase64.binaryToString((byte[]) attValue); 1925 } 1926 } 1927 return "Unable to get Att Value for " + name + "!"; 1928 1929 } 1930 catch (NamingException e) 1931 { 1932 if (showHTMLErrors) 1933 log.warning("Form Value Error getting value for " + name + " value :\n " + e); return ""; 1935 } 1936 } 1937 1938 1939 1951 1952 public String formattedAttribute(String attType, Attributes attributes, String modifier) 1953 { 1954 Attribute theAttribute = attributes.get(attType); 1955 if (theAttribute == null) 1957 { 1958 log.warning("can't find attribute: '" + attType + "'"); 1959 return ""; 1960 } 1962 return formattedAttribute(theAttribute, modifier); 1963 } 1964 1965 1976 1977 public String formattedAttribute(Attribute theAttribute, String modifier) 1978 { 1979 1981 try 1982 { 1983 if (theAttribute == null) return NOVALUEFOUND; 1984 1985 String syntaxOID = ""; 1986 if (theAttribute instanceof DXAttribute) 1987 syntaxOID = ((DXAttribute) theAttribute).getSyntaxOID(); 1988 1989 if (theAttribute.size() == 1) 1991 { 1992 Object o = theAttribute.get(); 1993 if (o == null) 1994 return NOVALUEFOUND; 1995 else if (o instanceof String ) 1996 { 1997 if ("1.3.6.1.4.1.1466.115.121.1.12".equals(syntaxOID)) 1998 return "<a HREF=\"dn:" + o.toString() + "\">" + o.toString() + "</a>"; else if ("1.3.6.1.4.1.1466.115.121.1.26".equalsIgnoreCase(syntaxOID)) 2000 return "<a HREF=\"mailto:" + o.toString() + "\">" + o.toString() + "</a>"; else if ((((String ) o).toLowerCase()).startsWith("http://")) 2002 return "<a HREF=\"" + o + "\">" + o + "</a>"; else 2004 return CBParse.toHTML(syntaxParse(o.toString(), syntaxOID)); 2005 } 2006 } 2011 NamingEnumeration values = theAttribute.getAll(); 2012 if (values == null) return NOVALUEFOUND; 2013 2014 2016 return formattedListAttribute(values, modifier, syntaxOID, theAttribute.getID()); 2017 } 2018 catch (NamingException e) 2019 { 2020 return "<i>" + CBIntText.get("Error: exception reading value") + "</i>"; 2021 } 2022 } 2023 2024 public String syntaxParse(String s, String syntaxOID) 2025 { 2026 if (!("".equals(syntaxOID))) 2027 { 2028 if ("1.3.6.1.4.1.1466.115.121.1.41".equals(syntaxOID)) s = s.replace('$', '\n'); 2030 } 2031 return s; 2032 } 2033 2034 2035 2048 2049 2050 2061 2062 public String formattedListAttribute(NamingEnumeration attlist, String modifier, String syntaxOID, String syntaxID) 2063 { 2064 String listStart = ""; 2065 String listEnd = ""; 2066 String itemStart = ""; 2067 String itemEnd = ""; 2068 2069 if ((modifier == null) || (modifier.equalsIgnoreCase("list"))) 2070 { 2071 listStart = "<ul>\n"; 2072 listEnd = "</ul>\n"; 2073 itemStart = "<li>"; 2074 itemEnd = "</li>"; 2075 } 2076 else if (modifier.equalsIgnoreCase("table")) 2077 { 2078 listStart = "<table>\n"; 2079 listEnd = "</table>\n"; 2080 itemStart = "<tr><td valign=top>"; 2081 itemEnd = "</td></tr>"; 2082 } 2083 else if (modifier.equalsIgnoreCase("plain")) 2084 { 2085 itemEnd = "\n"; 2086 } 2087 else 2088 { 2089 } 2090 2091 return formattedListWithModifiers(attlist, listStart, listEnd, itemStart, itemEnd, syntaxOID, syntaxID); 2092 } 2093 2094 2095 2107 2108 private String formattedListWithModifiers(NamingEnumeration attlist, String listStart, String listEnd, String itemStart, String itemEnd, String syntaxOID, String syntaxID) 2109 { 2110 if (attlist == null) return NOVALUEFOUND; 2111 2112 if (syntaxOID != null) 2113 { 2114 if (syntaxOID.equalsIgnoreCase("1.3.6.1.4.1.1466.115.121.1.28")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "jpegPhoto")); else if (syntaxOID.equalsIgnoreCase("1.3.6.1.4.1.1466.115.121.1.4")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "audio")); } 2119 2120 if (syntaxID.equalsIgnoreCase("odDocumentDOC")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "odDocumentDOC")); if (syntaxID.equalsIgnoreCase("odSpreadSheetXLS")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "odSpreadSheetXLS")); if (syntaxID.equalsIgnoreCase("odMusicMID")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "odMusicMID")); if (syntaxID.equalsIgnoreCase("odMovieAVI")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "odMovieAVI")); if (syntaxID.equalsIgnoreCase("odSoundWAV")) return new String (getMediaTags(listStart, listEnd, itemStart, itemEnd, "odSoundWAV")); 2131 StringBuffer formattedList = new StringBuffer (); 2132 while (attlist.hasMoreElements()) 2133 { 2134 Object temp = attlist.nextElement(); 2135 2136 String value = ""; 2137 if (temp != null) value = (temp instanceof String ) ? temp.toString() : "(Binary Value)"; 2138 2139 2143 if (value.length()>2 && (value.charAt(0) == 0 || value.charAt(1) == 0)) value = "(Binary Data in String)"; 2145 2146 if (syntaxOID != null && syntaxOID.equalsIgnoreCase("1.3.6.1.4.1.1466.115.121.1.12")) formattedList.append(itemStart + "<a HREF=\"dn:" + value + "\">" + value + "</a>" + itemEnd); 2148 else if (syntaxOID != null && syntaxOID.equalsIgnoreCase("1.3.6.1.4.1.1466.115.121.1.26")) 2149 formattedList.append(itemStart + "<a HREF=\"mailto:" + value + "\">" + value + "</a>" + itemEnd); else if ((value.toLowerCase()).startsWith("http://")) 2151 formattedList.append(itemStart + "<a HREF=\"" + value + "\">" + value + "</a>" + itemEnd); else 2153 formattedList.append(itemStart + CBParse.toHTML(syntaxParse(value, syntaxOID)) + itemEnd); 2154 } 2155 return new String (listStart + formattedList.toString() + listEnd); 2156 } 2157 2158 2159 2171 2172 public String getMediaTags(String listStart, String listEnd, String itemStart, String itemEnd, String type) 2173 { 2174 StringBuffer htmlStringBuffer = new StringBuffer (); 2175 2176 File fileDir = type.equalsIgnoreCase("audio") ? CBCache.getAudioCacheDirectory() : CBCache.getCacheDirectory(); 2178 String [] allFiles = fileDir.list(); String fileName; 2180 2181 for (int i = 0; i < allFiles.length; i++) 2182 { 2183 if (type.equalsIgnoreCase("audio") && allFiles[i].startsWith(currentDN) && !allFiles[i].endsWith(JPEGEXTENSION)) { fileName = allFiles[i].toString(); 2186 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + "audio" + File.separator + fileName + "\" + >audio</a>" + itemEnd + listEnd)); 2187 } 2188 else if (type.equalsIgnoreCase("jpegPhoto") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(JPEGEXTENSION)) { fileName = allFiles[i].toString(); 2191 htmlStringBuffer.append(new String (listStart + itemStart + "<img SRC=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" " + "border=\"1\">" + itemEnd + listEnd)); 2192 } 2193 else if (type.equalsIgnoreCase("odDocumentDOC") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(DOCEXTENSION)) { fileName = allFiles[i].toString(); 2196 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" + >document</a>" + itemEnd + listEnd)); 2197 } 2198 else if (type.equalsIgnoreCase("odSpreadSheetXLS") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(XLSEXTENSION)) { fileName = allFiles[i].toString(); 2201 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" + >spreadsheet</a>" + itemEnd + listEnd)); 2202 } 2203 else if (type.equalsIgnoreCase("odMusicMID") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(MIDEXTENSION)) { fileName = allFiles[i].toString(); 2206 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" + >audio</a>" + itemEnd + listEnd)); 2207 } 2208 else if (type.equalsIgnoreCase("odSoundWAV") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(WAVEXTENSION)) { fileName = allFiles[i].toString(); 2211 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" + >audio</a>" + itemEnd + listEnd)); 2212 } 2213 else if (type.equalsIgnoreCase("odMovieAVI") && allFiles[i].startsWith(currentDN) && allFiles[i].endsWith(AVIEXTENSION)) { fileName = allFiles[i].toString(); 2216 htmlStringBuffer.append(new String (listStart + itemStart + "<a HREF=" + "\".." + File.separator + "temp" + File.separator + fileName + "\" + >movie</a>" + itemEnd + listEnd)); 2217 } 2218 } 2219 return htmlStringBuffer.toString(); 2220 } 2221 2222 2223 2224 2233 2234 public String formattedAllAttributes(DXEntry attributes, String modifier) 2235 { 2236 2237 2241 if (modifier == null) modifier = "list"; 2243 NamingEnumeration attributeList; 2244 2245 attributeList = attributes.getAllNonNull(); 2246 2247 StringBuffer list = new StringBuffer (""); 2248 2249 if (modifier.equalsIgnoreCase("list")) list.append("<table>"); 2250 2251 try 2252 { 2253 while (attributeList.hasMore()) 2254 { 2255 Attribute theAttribute = (Attribute ) attributeList.next(); 2256 2257 String syntaxOID = (theAttribute instanceof DXAttribute) ? ((DXAttribute) theAttribute).getSyntaxOID() : ""; 2258 2259 if (modifier.equalsIgnoreCase("list")) { 2261 list.append("<tr>" + theAttribute.getID() + "</td><td valign=top>"); 2262 list.append(formattedListAttribute(theAttribute.getAll(), modifier, syntaxOID, theAttribute.getID()) + "</tr>\n"); 2263 } 2265 else if (modifier.equalsIgnoreCase("table")) { 2267 list.append(formattedListAttribute(theAttribute.getAll(), modifier, syntaxOID, theAttribute.getID())); 2268 } 2269 else { 2271 list.append(theAttribute.getID() + ":\n" + formattedAttribute(theAttribute, "plain") + "\n\n"); 2272 } 2273 } 2274 2275 if (modifier.equalsIgnoreCase("list")) list.append("</table>"); 2276 } 2277 catch (NamingException e) 2278 { 2279 log.warning("naming exception in formattedAllAttributes() " + e); 2280 } 2281 2282 return list.toString(); 2283 } 2284 2285 2286 2292 2301 2308 2309 public boolean openDocumentURL(String docURL) 2310 { 2311 if (docURL.startsWith("http:")) return openPage(docURL); 2313 else 2314 { 2315 File document = new File(myProperties.getProperty("dir.htmldocs") + docURL); 2316 try 2317 { 2318 return openPage(document.toURL()); 2319 } 2320 catch (MalformedURLException e) 2321 { 2322 log.warning("Bad URL '" + document.toString() + "'\n" + e); 2323 return false; 2324 } 2325 } 2326 } 2328 2329 2330 2338 2339 public void launchClient(String desc) 2340 { 2341 try 2342 { 2343 File file = new File("temp.bat"); file.deleteOnExit(); 2346 FileWriter output = new FileWriter(file); 2347 output.write("start " + desc); output.close(); 2349 2350 Runtime r = Runtime.getRuntime(); 2351 r.exec("temp.bat"); } 2353 catch (Exception e) 2354 { 2355 CBUtility.error("Error launching default mail client " + e); 2356 } 2357 } 2358 2359 2360 2367 public boolean openPage(String urlString) 2368 { 2369 if (urlString == null) return false; 2370 2371 if (urlString.toLowerCase().startsWith("dn:")) { 2373 String dn = urlString.substring(3); 2374 if (dn.startsWith("/")) dn = dn.substring(1); 2375 if (dn.startsWith("/")) dn = dn.substring(1); 2376 DN linkDN = new DN(dn); 2377 if (linkDN.size() > 0) 2378 { 2379 currentDataSource.getEntry(linkDN); 2380 } 2381 2382 return true; 2383 } 2384 else 2385 { 2386 2387 try 2388 { 2389 URL url = new URL(urlString); 2390 return openPage(url); 2391 } 2392 catch (MalformedURLException e) 2393 { 2394 log.warning("Bad URL '" + urlString + "'\n" + e); 2395 return false; 2396 } 2397 } 2398 } 2399 2400 2409 public boolean openPage(URL url) 2410 { 2411 if (url == null) return false; 2412 URL original = editor.getPage(); 2413 2414 2415 try 2416 { 2417 setEditor(url); 2418 2419 return true; 2420 } 2421 catch (IOException e) { 2423 e.printStackTrace(); 2424 JOptionPane.showMessageDialog(this, CBIntText.get("Can't follow link ") + url.toString(), 2425 CBIntText.get("Invalid URL"), JOptionPane.ERROR_MESSAGE); 2426 log.warning("unable to follow url " + url.toString() + "\n" + e); 2427 try 2428 { 2429 if (original != null) 2430 editor.setPage(original); else 2432 setToDefault(); 2433 } catch (Exception e3) 2435 { 2436 log.warning("fnord: " + e3); 2437 setToDefault(); 2438 } 2439 return false; 2440 } 2441 catch (Exception e2) { 2443 log.warning("Wierd Java exception thrown on setPage in AttributeDisplay\n" + e2); 2444 try 2445 { 2446 if (original != null) 2447 editor.setPage(original); else 2449 setToDefault(); 2450 } catch (Exception e3) 2452 { 2453 setToDefault(); 2454 } 2455 return false; 2456 } 2457 } 2458 2459 2463 2464 protected void setEditor(URL url) throws IOException 2465 { 2466 if (editor == null) editor = getNewEditor(); 2467 editor.setPage(url); validate(); 2469 } 2470 2471 2472 public JComponent getDisplayComponent() 2473 { 2474 return this; 2475 } 2476 2477 public String toString() 2478 { 2479 return htmlText.toString(); 2480 } 2481 2482 public String getName() 2483 { 2484 return CBIntText.get("HTML View"); 2485 } 2486 2487 public ImageIcon getIcon() 2488 { 2489 return new ImageIcon("images" + File.separator + "html.gif"); 2490 } 2492 public String getToolTip() 2493 { 2494 return CBIntText.get("The HTML View is used to view and edit the data in purpose constructed HTML templates."); 2495 } 2497 2498 2501 public Component getPrintComponent() 2502 { 2503 return editor; 2504 } 2505 2506 2507 public boolean isUnique() 2508 { 2509 return false; 2510 } 2511 2512 2513 public DataSink getDataSink() 2514 { 2515 return this; 2516 } 2517 2518 public boolean canCreateEntry() 2519 { 2520 return false; 2521 } 2522 2523 public void registerComponents(JMenuBar menu, JToolBar buttons, JTree tree, JPopupMenu treeMenu, JFrame jx) 2524 { 2525 smartTree = (SmartTree) tree; 2526 } 2527 2528 public void unload() 2529 { 2530 } 2531 2532 2533 2537 2538 public ImageIcon getTreeIcon(String rdn) 2539 { 2540 return null; 2541 } 2542 2543 2546 2547 public JPopupMenu getPopupMenu(String rdn) 2548 { 2549 return null; 2550 } 2551 2552 2555 2556 public boolean hideSubEntries(String rdn) 2557 { 2558 return false; 2559 } 2560 2561 2562} | Popular Tags |