示例#1
0
  /**
   * Constructor
   *
   * @param name name of bot
   * @param path root path of Program AB
   * @param action Program AB action
   */
  public Bot(String name, String path, String action) {
    int cnt = 0;
    int elementCnt = 0;
    this.name = name;
    setAllPaths(path, name);
    this.brain = new Graphmaster(this);

    this.learnfGraph = new Graphmaster(this, "learnf");
    this.learnGraph = new Graphmaster(this, "learn");
    //      this.unfinishedGraph = new Graphmaster(this);
    //  this.categories = new ArrayList<Category>();

    preProcessor = new PreProcessor(this);
    addProperties();
    cnt = addAIMLSets();
    if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " set elements.");
    cnt = addAIMLMaps();
    if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " map elements");
    this.pronounSet = getPronouns();
    AIMLSet number = new AIMLSet(MagicStrings.natural_number_set_name, this);
    setMap.put(MagicStrings.natural_number_set_name, number);
    AIMLMap successor = new AIMLMap(MagicStrings.map_successor, this);
    mapMap.put(MagicStrings.map_successor, successor);
    AIMLMap predecessor = new AIMLMap(MagicStrings.map_predecessor, this);
    mapMap.put(MagicStrings.map_predecessor, predecessor);
    AIMLMap singular = new AIMLMap(MagicStrings.map_singular, this);
    mapMap.put(MagicStrings.map_singular, singular);
    AIMLMap plural = new AIMLMap(MagicStrings.map_plural, this);
    mapMap.put(MagicStrings.map_plural, plural);
    // System.out.println("setMap = "+setMap);
    Date aimlDate = new Date(new File(aiml_path).lastModified());
    Date aimlIFDate = new Date(new File(aimlif_path).lastModified());
    if (MagicBooleans.trace_mode)
      System.out.println("AIML modified " + aimlDate + " AIMLIF modified " + aimlIFDate);
    // readUnfinishedIFCategories();
    MagicStrings.pannous_api_key = Utilities.getPannousAPIKey(this);
    MagicStrings.pannous_login = Utilities.getPannousLogin(this);
    if (action.equals("aiml2csv")) addCategoriesFromAIML();
    else if (action.equals("csv2aiml")) addCategoriesFromAIMLIF();
    else if (action.equals("chat-app")) {
      if (MagicBooleans.trace_mode) System.out.println("Loading only AIMLIF files");
      cnt = addCategoriesFromAIMLIF();
    } else if (aimlDate.after(aimlIFDate)) {
      if (MagicBooleans.trace_mode) System.out.println("AIML modified after AIMLIF");
      cnt = addCategoriesFromAIML();
      writeAIMLIFFiles();
    } else {
      addCategoriesFromAIMLIF();
      if (brain.getCategories().size() == 0) {
        System.out.println("No AIMLIF Files found.  Looking for AIML");
        cnt = addCategoriesFromAIML();
      }
    }
    Category b =
        new Category(
            0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version, "update.aiml");
    brain.addCategory(b);
    brain.nodeStats();
    learnfGraph.nodeStats();
  }
示例#2
0
  public void run() {
    if (clientSocket == null) {
      return;
    }

    PrintStream out = null;

    Utilities.printMsg("creating output stream");

    try {
      out = new PrintStream(clientSocket.getOutputStream());
    } catch (IOException e) {
      System.err.println("Error binding output to socket, " + e);
      System.exit(1);
    }

    Utilities.printMsg("writing current date");

    Date d = new Date();
    out.println(d);

    try {
      out.close();
      clientSocket.close();
    } catch (IOException e) {
    }
  }
示例#3
0
  public static Document getAmazonResponse(String url) throws FactoryConfigurationError {
    String page = "";

    boolean done = false;
    int trial = 0;
    do {
      page = Utilities.getPage(url);
      if (page == null && trial < 3) {
        Utilities.sleep(2);
        trial++;
      } else {
        done = true;
      }
    } while (!done);

    Document d;
    if (page == null) {
      System.out.println("Error:" + url);
      // Utilities.sleep(5);
      d = null;
    } else {
      d = Utilities.getXMLFromFile(page);
    }
    return d;
  }
  private String getLink(
      final String event,
      final String label,
      final String css,
      String defaultValue,
      String selectedValue,
      String tooltip) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(tooltip));

    StringBuffer link = new StringBuffer();
    defaultValue = defaultValue == null ? AbstractChip.FALSE : defaultValue;
    selectedValue = selectedValue == null ? AbstractChip.TRUE : selectedValue;
    link.append("<input type=\"hidden\" name=\"" + event + "\" value=\"" + defaultValue + "\" />");
    link.append(
        "<a href=\"#\" onMouseover=\"window.status='"
            + status
            + "'; return true;\" onMouseout=\"window.status=''; return true;\" ");
    if (css != null) {
      link.append("class=\"" + css + "\" ");
    }
    link.append("hidefocus=\"true\" ");
    link.append(
        "onclick=\"document.editorForm.elements['"
            + event
            + "'].value='"
            + selectedValue
            + "';setScrollAndSubmit();return false;\">");
    link.append(label);
    link.append("</a>");
    return link.toString();
  }
示例#5
0
 /**
  * Generates i-th String attribute inside a file description.
  *
  * @param buffer - where to place the description
  */
 private static void generateStringAttr(StringBuffer buffer, int i, int paddingSize) {
   addIndent(buffer, FOLDER_INDENT + 2);
   buffer.append("<attr name=\"key_");
   Utilities.appendNDigits(i, paddingSize, buffer);
   buffer.append("\" stringvalue=\"val_");
   Utilities.appendNDigits(i, paddingSize, buffer);
   buffer.append("\"/>");
   buffer.append('\n');
 }
示例#6
0
  private void end(StringBuilder ans, Pretty pretty, String indent) {
    if (endEncloser == null) return;
    if (!pretty.pretty) ans.append(endEncloser);
    else {
      Utilities.assureEndsWithNewLine(ans);
      ans.append(indent + endEncloser);
      if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment);

      Utilities.assureEndsWithNewLine(ans);
    }
  }
示例#7
0
  /**
   * Returns the TabularData
   *
   * @return TabularData containing the rows corresponding the NetworkTable
   */
  public TabularData getNetworkTable() {
    try {
      if (table != null)
        return Utilities.getTabularData(this, indexNames, table, instrClassName, null);
      else if (vec != null)
        return Utilities.getTabularData(this, indexNames, vec, instrClassName, null);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return null;
  }
示例#8
0
    public void actionPerformed(java.awt.event.ActionEvent arg0) {

      if (JTable1.getSelectedRowCount() != 1) {

        Utilities.errorMessage(resourceBundle.getString("Please select a view to edit"));
        return;
      }

      views = new ViewsWizard(ViewConfig.this, applet);
      views.setSecurityModel(model);
      Point p = JLabel1.getLocationOnScreen();
      views.setLocation(p);
      views.init();

      views.setState(false);
      Vector viewvec = model.getAllViews();
      for (int i = 0; i < viewvec.size(); i++) {
        String viewname = ((AuthViewWithOperations) viewvec.elementAt(i)).getAuthorizedViewName();
        if (JTable1.getValueAt(JTable1.getSelectedRow(), 0).toString().equals(viewname)) {
          views.setValues((AuthViewWithOperations) viewvec.elementAt(i));
        }
      }

      disableButtons();
      views.setVisible(true);
    }
 /**
  * If the appropriate config property is true (hmc.escape.html), all html content in the given
  * string will be escaped.
  */
 private String escapeHTML(String text) {
   if (ConfigConstants.getInstance().HTML_ESCAPE) {
     return Utilities.escapeHTML(text);
   } else {
     return text;
   }
 }
示例#10
0
 public ObjectWrapper getWrapperSetContent(String classname, String content) {
   SimpleObjectWrapper wrapper;
   Class type = ReflectionUtil.classForName(transfer2classname(classname));
   if (handlers != null && handlers.containsKey(classname)) {
     wrapper = (SimpleObjectWrapper) initWrapper(classname, type);
     wrapper.setObject(Utilities.convertType(content, wrapper.expectedArgType()));
   } else if (type != null && type.isEnum()) {
     wrapper = new EnumWrapper(type);
     wrapper.setObject(Utilities.convertType(content, wrapper.expectedArgType()));
   } else {
     wrapper = new DefaultSimpleTypeWrapper(type);
     wrapper.setObject(Utilities.convertType(content, wrapper.expectedArgType()));
   }
   wrapper.setYamlConfig(this);
   return wrapper;
 }
示例#11
0
 /** new ResourceComposer */
 public ResourceComposer(String resName, String resExt, int foCount, int fileBase) {
   this.foCount = foCount;
   this.paddingSize = Utilities.expPaddingSize(foCount + fileBase - 1);
   this.fileBase = fileBase;
   this.resName = resName;
   this.resExt = resExt;
 }
示例#12
0
    public void actionPerformed(java.awt.event.ActionEvent arg0) {
      if (JTable1.getSelectedRowCount() != 1) {
        Utilities.errorMessage(resourceBundle.getString("Please select a view to delete"));
        return;
      }

      if (JOptionPane.showConfirmDialog(
              null,
              resourceBundle.getString("Are you sure you want to delete the selected view "),
              resourceBundle.getString("Warning!"),
              JOptionPane.YES_NO_OPTION,
              JOptionPane.WARNING_MESSAGE,
              null)
          == JOptionPane.NO_OPTION) return;

      Vector viewvec = model.getAllViews();
      for (int i = 0; i < viewvec.size(); i++) {
        String viewname = ((AuthViewWithOperations) viewvec.elementAt(i)).getAuthorizedViewName();
        if (JTable1.getValueAt(JTable1.getSelectedRow(), 0).toString().equals(viewname)) {
          AuthViewWithOperations avop = (AuthViewWithOperations) viewvec.elementAt(i);

          model.delViewOp(
              avop.getAuthorizedViewName(), avop.getViewProperties(), avop.getOperations());
        }
      }

      disableButtons();
    }
示例#13
0
  /**
   * Returns the TabularData
   *
   * @return TabularData containing the rows corresponding the AlarmTable
   */
  public TabularData getAlarmTable() {

    // User code starts here
    if (true) {
      return getTable();
    }
    // User code ends here

    try {
      if (table != null)
        return Utilities.getTabularData(this, indexNames, table, instrClassName, null);
      else if (vec != null)
        return Utilities.getTabularData(this, indexNames, vec, instrClassName, null);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return null;
  }
示例#14
0
 void doKids(StringBuilder ans, Pretty pretty, String indent) {
   if (kids == null) return;
   for (Rope kid : kids) {
     if (!pretty.pretty) {
       kid.toString(ans, pretty, "");
     } else {
       kid.toString(ans, pretty, indent + getKidIndentIncrement(kid, pretty));
       Utilities.assureEndsWithNewLine(ans);
     }
   }
 }
示例#15
0
 HashSet<String> getPronouns() {
   HashSet<String> pronounSet = new HashSet<String>();
   String pronouns = Utilities.getFile(config_path + "/pronouns.txt");
   String[] splitPronouns = pronouns.split("\n");
   for (int i = 0; i < splitPronouns.length; i++) {
     String p = splitPronouns[i].trim();
     if (p.length() > 0) pronounSet.add(p);
   }
   if (MagicBooleans.trace_mode) System.out.println("Read pronouns: " + pronounSet);
   return pronounSet;
 }
示例#16
0
 private void start(StringBuilder ans, Pretty pretty, String indent) {
   if (startEncloser == null) return;
   if (!pretty.pretty) {
     ans.append(startEncloser);
   } else {
     String comment;
     if (pretty.comments && startComment.length() > 0) comment = " #" + startComment;
     else comment = "";
     ans.append(indent + startEncloser + comment);
     Utilities.assureEndsWithNewLine(ans);
   }
 }
示例#17
0
 /** Creates a network scan over the specified port */
 public NetScan(TransactionId tid, TupleDesc td, int port) {
   try {
     this.tid = tid;
     this.td = td;
     this.port = port;
     serverSocket = Utilities.createServerSocket(port);
   } catch (IOException ioe) {
     ioe.printStackTrace();
     closeConnection();
     throw new RuntimeException(ioe);
   }
 }
示例#18
0
  @RequestMapping(
      value = "/home",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String getCity(HttpServletRequest request, ModelMap model) {

    try {
      List<City> cityList = cityService.getCity();
      utilities.setSuccessResponse(response, cityList);
    } catch (Exception ex) {
      logger.error("getCity :" + ex.getMessage());
    }
    model.addAttribute("model", response);
    return "home";
  }
示例#19
0
  @RequestMapping(
      value = "/getCityApi",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String getCityApi(
      HttpServletRequest request,
      @RequestParam(value = "locationname") String locationname,
      ModelMap model) {

    Map<Object, Object> map = new HashMap<Object, Object>();
    JSONArray jSONArray = new JSONArray();
    try {
      String status = "active";
      List<City> cityList = cityService.getCityApi(locationname, status);
      if (cityList != null && cityList.size() > 0) {
        for (int i = 0; i < cityList.size(); i++) {
          City city = (City) cityList.get(i);
          String cityName = (String) city.getCity();
          String stateName = (String) city.getState();

          int ID = (Integer) (city.getId());
          JSONObject jSONObject = new JSONObject();

          jSONObject.put("id", ID);
          jSONObject.put("text", cityName);
          jSONArray.put(jSONObject);
        }
        utilities.setSuccessResponse(response, jSONArray.toString());
      } else {
        throw new ConstException(ConstException.ERR_CODE_NO_DATA, ConstException.ERR_MSG_NO_DATA);
      }
    } catch (Exception ex) {
      logger.error("getCity :" + ex.getMessage());
      utilities.setErrResponse(ex, response);
    }
    model.addAttribute("model", jSONArray.toString());
    return "home";
  }
示例#20
0
  /** Write all AIML files. Adds categories for BUILD and DEVELOPMENT ENVIRONMENT */
  public void writeAIMLFiles() {
    if (MagicBooleans.trace_mode) System.out.println("writeAIMLFiles");
    HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
    Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
    brain.addCategory(b);
    // b = new Category(0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version,
    // "update.aiml");
    // brain.addCategory(b);
    ArrayList<Category> brainCategories = brain.getCategories();
    Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
    for (Category c : brainCategories) {

      if (!c.getFilename().equals(MagicStrings.null_aiml_file))
        try {
          // System.out.println("Writing "+c.getCategoryNumber()+" "+c.inputThatTopic());
          BufferedWriter bw;
          String fileName = c.getFilename();
          if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
          else {
            String copyright = Utilities.getCopyright(this, fileName);
            bw = new BufferedWriter(new FileWriter(aiml_path + "/" + fileName));
            fileMap.put(fileName, bw);
            bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<aiml>\n");
            bw.write(copyright);
            // bw.newLine();
          }
          bw.write(Category.categoryToAIML(c) + "\n");
          // bw.newLine();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }
    Set set = fileMap.keySet();
    for (Object aSet : set) {
      BufferedWriter bw = fileMap.get(aSet);
      // Close the bw
      try {
        if (bw != null) {
          bw.write("</aiml>\n");
          bw.flush();
          bw.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    File dir = new File(aiml_path);
    dir.setLastModified(new Date().getTime());
  }
示例#21
0
 /** Opens this net scan. */
 public void open() throws DbException {
   try {
     if (socket == null) {
       Debug.println("NetScan accepting @ :" + port);
       socket = Utilities.accept(serverSocket);
       Debug.println("NetScan accepted, creating input stream...");
       in = new DataInputStream(socket.getInputStream());
       Debug.println("NetScan opened");
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
     closeConnection();
     throw new DbException(ioe);
   }
 }
示例#22
0
 /**
  * Assembly fileBase (e.g. 13) with name (e.g. JavaSrc) and ext (e.g. .java) into sbuffer. Do
  * not forget to take into account paddingSize. Result could be e.g. JavaSrc0675.java, with
  * paddingSize 4 and fileBase 675.
  */
 public void assemblyResourceString(StringBuffer sbuffer) {
   sbuffer.append(resName);
   Utilities.appendNDigits(getFileBase(), getPaddingSize(), sbuffer);
   sbuffer.append(resExt);
 }
  /**
   * Method for reading in data file, in a given format. Namely:
   *
   * <pre>
   * 881003,0.0000,14.1944,13.9444,14.0832,2200050,0
   * 881004,0.0000,14.1668,14.0556,14.1668,1490850,0
   * ...
   * 990108,35.8125,36.7500,35.5625,35.8125,4381200,0
   * 990111,35.8125,35.8750,34.8750,35.1250,3920800,0
   * 990112,34.8750,34.8750,34.0000,34.0625,3577500,0
   * </pre>
   *
   * <p>Where the fields represent, one believes, the following:
   *
   * <ol>
   *   <li>The date in 'YYMMDD' format
   *   <li>Open
   *   <li>High
   *   <li>Low
   *   <li>Last
   *   <li>Volume
   *   <li>Open Interest
   * </ol>
   *
   * One will probably make use of the closing price, but this can be redefined via the class
   * variable <code>DATUMFIELD</code>. Note that since the read in data are then used to compute the
   * return, this would be a good place to trap for zero values in the data, which will cause all
   * sorts of problems.
   *
   * @param dirName the directory in which to search for the data file.
   * @param filename the data filename itself.
   * @exception DemoException thrown if there was a problem with the data file.
   */
  private void readRatesFile(String dirName, String filename) throws DemoException {
    java.io.File ratesFile = new File(filename);
    java.io.BufferedReader in;
    try {
      InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filename);

      //    if( ! ratesFile.canRead() ) {
      //      throw new DemoException("Cannot read the file "+ratesFile.toString());
      //    }

      in = new BufferedReader(new InputStreamReader(inputStream));
    } catch (Exception fnfex) {
      throw new DemoException(fnfex.toString());
    }
    //
    // Proceed to read all the lines of data into a Vector object.
    int iLine = 0, initNlines = 100, nLines = 0;

    String aLine;
    java.util.Vector allLines = new Vector(initNlines);
    try {
      while ((aLine = in.readLine()) != null) {
        iLine++;
        //
        // Note, I'm not entirely sure whether the object passed in is copied
        // by value, or just its reference.
        allLines.addElement(aLine);
      }
    } catch (IOException ioex) {
      throw new DemoException("Problem reading data from the file " + ioex.toString());
    }
    nLines = iLine;
    //
    // Now create an array to store the rates data.
    this.pathValue = new double[nLines];
    this.pathDate = new int[nLines];
    nAcceptedPathValue = 0;
    iLine = 0;
    for (java.util.Enumeration enum1 = allLines.elements(); enum1.hasMoreElements(); ) {
      aLine = (String) enum1.nextElement();
      String[] field = Utilities.splitString(",", aLine);
      int aDate = Integer.parseInt("19" + field[0]);
      //
      // static double Double.parseDouble() method is a feature of JDK1.2!
      double aPathValue = Double.valueOf(field[DATUMFIELD]).doubleValue();
      if ((aDate <= MINIMUMDATE) || (Math.abs(aPathValue) < EPSILON)) {
        dbgPrintln("Skipped erroneous data in " + filename + " indexed by date=" + field[0] + ".");
      } else {
        pathDate[iLine] = aDate;
        pathValue[iLine] = aPathValue;
        iLine++;
      }
    }
    //
    // Record the actual number of accepted data points.
    nAcceptedPathValue = iLine;
    //
    // Now to fill in the structures from the 'PathId' class.
    set_name(ratesFile.getName());
    set_startDate(pathDate[0]);
    set_endDate(pathDate[nAcceptedPathValue - 1]);
    set_dTime((double) (1.0 / 365.0));
  }
示例#24
0
  /**
   * Sets the TabularData to the AaplicationTable
   *
   * @param data The TabularData to be set to the AaplicationTable
   */
  public void setAlarmTable(TabularData data) throws Exception {
    AgentException ae = null;

    for (Enumeration e = data.enumerate(); e.hasMoreElements(); ) {
      Object[] index = (Object[]) e.nextElement();
      CompositeData comp = data.getRow(index);

      if (table != null)
        entry =
            (AlarmEntry)
                Utilities.getEntryFromCompositeData(table, comp, indexNames, instrClassName);
      else if (vec != null)
        entry =
            (AlarmEntry) Utilities.getEntryFromCompositeData(vec, comp, indexNames, instrClassName);

      if (comp.getOperationType().equals(CompositeData.CREATED)) { // create new entry

        if (entry != null)
          throw new AgentException("Row already exist", CommonUtils.ROWCREATIONFAILED); // no i18n
        entry = new AlarmEntry();

        if (table != null) table.put(index, entry);
        else if (vec != null) vec.addElement(entry);
        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          try {
            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      } else if (comp.getOperationType().equals(CompositeData.DELETED)) {

        if (table != null) {
          for (Enumeration en = table.keys(); en.hasMoreElements(); ) {
            Object keyObject = en.nextElement();
            if (entry.equals(table.get(keyObject))) table.remove(keyObject);
          }
        } else if (vec != null)
          if (!vec.removeElement(entry))
            throw new AgentException("Invalid Index", CommonUtils.INVALIDINDEX); // no i18n
        data.deleteRow(index);
      } else if (comp.getOperationType().equals(CompositeData.MODIFIED)) {

        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          if (!comp.isModified(key)) continue;
          try {

            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      }

      comp.setOperationType(CompositeData.NOCHANGES);
    }

    if (ae != null) throw ae;
  }
  private String getSimpleImageConfirmLink(
      final String event,
      final String label,
      final String image,
      String imageOver,
      String javascript) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(label));

    if ((imageOver == null) || imageOver.equals("")) {
      imageOver = image;
    }

    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();

    link.append("<input type=\"hidden\" name=\"")
        .append(event)
        .append("\" value=\"")
        .append(AbstractChip.FALSE)
        .append("\" />");
    link.append("<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\"")
        .append(status)
        .append("\" title=\"")
        .append(status)
        .append("\"");
    link.append("onMouseover=\"window.status='")
        .append(status)
        .append("'; swapImage('")
        .append(imageID)
        .append("', '")
        .append(imageOver)
        .append("'); return true;\" ");
    link.append("onMouseout=\"window.status=''; swapImage('")
        .append(imageID)
        .append("', '")
        .append(image)
        .append("'); return true;\" ");
    link.append("onFocus=\"swapImage('")
        .append(imageID)
        .append("', '")
        .append(imageOver)
        .append("'); return true;\" ");
    link.append("onBlur=\"swapImage('")
        .append(imageID)
        .append("', '")
        .append(image)
        .append("'); return true;\" ");
    link.append("onclick=\"document.editorForm.elements['")
        .append(event)
        .append("'].value = ")
        .append(javascript)
        .append("; setScrollAndSubmit(); return false;\">");
    link.append("<img id=\"")
        .append(imageID)
        .append("\" src=\"")
        .append(image)
        .append("\" alt=\"")
        .append(status)
        .append("\">");
    link.append("</a>");

    return link.toString();
  }
示例#26
0
 public void showError(String err) {
   enableButtons();
   Utilities.errorMessage(resourceBundle.getString(err));
 }
  private String getIconButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(label));

    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();
    final String color = isEnabled ? "#ffffff" : "#D8DCE3";

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + status
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + status
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_hover_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_hover_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + status
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_hover__m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_hover__r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + status
            + "\" style=\"vertical-align:middle; width:100%; height:23px; padding:0px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;font-size:1pt;padding:0px;\" background=\"images/icons/icon_button_background_l.gif\"><div style=\"width:3px;\"></div></td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;padding:0px;\" background=\"images/icons/icon_button_background_m.gif\">");

    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle\" src=\"" + image + "\">");
    if (showLabel) {
      link.append("<span style=\"padding-left:5px; color:" + color + "\">" + label + "</span>");
    }

    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;font-size:1pt;padding:0px;\" background=\"images/icons/icon_button_background_r.gif\"><div style=\"width:3px;\"></div></td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }