/** Get continuation lines, if any. */
  private void getContinuation(ConfigEntry configEntry, BufferedReader bin, StringBuilder buf)
      throws IOException {
    for (String line = advance(bin); line != null; line = advance(bin)) {
      int length = buf.length();

      // Look for bad data as this condition did exist
      boolean continuation_expected = length > 0 && buf.charAt(length - 1) == '\\';

      if (continuation_expected) {
        // delete the continuation character
        buf.deleteCharAt(length - 1);
      }

      if (isKeyLine(line)) {
        if (continuation_expected) {
          log.warn(report("Continuation followed by key for", configEntry.getName(), line));
        }

        backup(line);
        break;
      } else if (!continuation_expected) {
        log.warn(report("Line without previous continuation for", configEntry.getName(), line));
      }

      if (!configEntry.allowsContinuation()) {
        log.warn(report("Ignoring unexpected additional line for", configEntry.getName(), line));
      } else {
        if (continuation_expected) {
          buf.append('\n');
        }
        buf.append(line);
      }
    }
  }
  public void run() {
    //		logger.log(Level.INFO, " inGram start");
    if (Global.isDebug) System.out.println(getTaskName() + " start execute");
    String msgBuf = new String(this.inGram.getData(), 0, this.inGram.getLength(), ch);

    if (server.debugPacketsReceived)
      System.err.println("[" + this.inGram.getLength() + "] {" + msgBuf + "}");

    server.displayFeedback("Packets received: " + SyslogServer.packetCount + ".");

    String hostName =
        this.inGram
            .getAddress()
            .getHostAddress(); // if cann't get host name will impact the speed,so use
                               // getHostAddress instead of getHostName();

    if (hostName == null) hostName = "localhost";
    SyslogMessage logMessage = processMessage(msgBuf, hostName);
    //	logger.log(Level.INFO, " for configEntries start");
    for (int eIdx = 0; eIdx < server.configEntries.size(); ++eIdx) {
      ConfigEntry entry = server.configEntries.entryAt(eIdx);
      entry.processMessage(logMessage);
    }
    //	    logger.log(Level.INFO," for configEntries end");
  }
 /**
  * Gets a particular ConfigEntry's value by its type
  *
  * @param type of the ConfigEntry
  * @return the requested value, the default (if there is no entry) or null (if there is no
  *     default)
  */
 public Object getValue(ConfigEntryType type) {
   ConfigEntry ce = table.get(type);
   if (ce != null) {
     return ce.getValue();
   }
   return type.getDefault();
 }
Exemple #4
0
 @Test
 public void testFetchKey() {
   getDs().save(new ConfigEntry(new ConfigKey("env", "key", "subenv")));
   BasicDAO<ConfigEntry, ConfigKey> innerDAO =
       new BasicDAO<ConfigEntry, ConfigKey>(ConfigEntry.class, getDs());
   ConfigEntry entry = innerDAO.find().get();
   entry.setValue("something");
   innerDAO.save(entry);
 }
 private void toConf(StringBuilder buf, Map<String, ConfigEntry> map) {
   for (Map.Entry<String, ConfigEntry> mapEntry : map.entrySet()) {
     ConfigEntry entry = mapEntry.getValue();
     String text = entry.toConf();
     if (text != null && text.length() > 0) {
       buf.append(text);
     }
   }
 }
Exemple #6
0
  private void recalculatePositions() {
    int pos = 0;

    for (ConfigEntry entry : options) {
      entry.setPosition(0, pos);
      pos += entry.height();
    }

    innerPanel.setSize(width(), pos);
    updateScrollbarScale();
  }
Exemple #7
0
  private void addRow(String text, GuiElement element) {
    int pos = 0;
    if (options.size() > 0) {
      ConfigEntry last = options.get(options.size() - 1);
      pos = last.relativeY() + last.height();
    }

    ConfigEntry entry = new ConfigEntry(text, element, pos);
    options.add(entry);
    innerPanel.addElement(entry);
    // entry.anchor(AnchorPoint.TOP_LEFT, AnchorPoint.TOP_RIGHT);
  }
 /**
  * Gets the value for the given key.
  *
  * @param key
  * @param c
  * @return The value, null if not found.
  */
 public <T extends Object> T getValue(EntryType type, String key, Class<T> c) {
   T ret = null;
   synchronized (data) {
     ConfigEntry entry = data.get(type).get(key);
     if (entry != null) {
       Object value = entry.getValue();
       if (c.isInstance(value)) {
         ret = c.cast(value);
       }
     }
   }
   return ret;
 }
  private void toConf(StringBuilder buf, ConfigEntryType[] category) {
    for (int i = 0; i < category.length; i++) {

      ConfigEntry entry = table.get(category[i]);

      if (entry != null && !entry.getType().isSynthetic()) {
        String text = entry.toConf();
        if (text != null && text.length() > 0) {
          buf.append(entry.toConf());
        }
      }
    }
  }
Exemple #10
0
  private void addThemeRow(GuiElement element) {
    int pos = 0;
    if (options.size() > 0) {
      ConfigEntry last = options.get(options.size() - 1);
      pos = last.relativeY() + last.height();
    }

    currentThemeSource = new CurrentThemeTextSource();
    currentThemeSource.currentThemeName = ThemeManager.currentThemeName;
    ConfigEntry entry = new ConfigEntry(currentThemeSource, element, pos);
    options.add(entry);
    innerPanel.addElement(entry);
    // entry.anchor(AnchorPoint.TOP_LEFT, AnchorPoint.TOP_RIGHT);
  }
 public <T extends Object> List<T> getValues(EntryType type, Class<T> c) {
   List<T> ret = new ArrayList<T>();
   synchronized (data) {
     LinkedHashMap<String, ConfigEntry> mappings = data.get(type);
     for (String key : mappings.keySet()) {
       ConfigEntry entry = mappings.get(key);
       Object value = entry.getValue();
       if (c.isInstance(value)) {
         T casted = c.cast(value);
         ret.add(casted);
       }
     }
   }
   return ret;
 }
Exemple #12
0
  public void updateScrollbarScale() {
    float end = 0;

    if (options.size() > 0) {
      ConfigEntry last = options.get(options.size() - 1);
      end = last.relativeY() + last.height() - height();
    }

    if (end < 0) {
      end = 0;
    }

    scrollBar.setRowSize(8);
    scrollBar.setScale(0, end);
  }
 /**
  * @param entry
  * @return
  * @throws Exception
  */
 private String safelyGetSaveString(ConfigEntry entry) {
   String saveString = null;
   try {
     saveString = entry.getSaveString();
   } catch (Exception e) {
     LOG.log(Level.WARNING, "Cannot get the save string for: " + entry, e);
   }
   return saveString;
 }
  /** Build an ordered map so that it displays in a consistent order. */
  private void toOSIS(
      OSISUtil.OSISFactory factory, Element ele, String aTitle, Map<String, ConfigEntry> map) {
    Element title = null;
    for (Map.Entry<String, ConfigEntry> mapEntry : map.entrySet()) {
      ConfigEntry entry = mapEntry.getValue();
      Element configElement = null;

      if (entry != null) {
        configElement = entry.toOSIS();
      }

      if (title == null && configElement != null) {
        // I18N(DMS): use aTitle to lookup translation.
        title = factory.createHeader();
        title.addContent(aTitle);
        ele.addContent(title);
      }

      if (configElement != null) {
        ele.addContent(configElement);
      }
    }
  }
  /** Build an ordered map so that it displays in a consistent order. */
  private void toOSIS(
      OSISUtil.OSISFactory factory, Element ele, String aTitle, ConfigEntryType[] category) {
    Element title = null;
    for (int i = 0; i < category.length; i++) {
      ConfigEntry entry = table.get(category[i]);
      Element configElement = null;

      if (entry != null) {
        configElement = entry.toOSIS();
      }

      if (title == null && configElement != null) {
        // I18N(DMS): use aTitle to lookup translation.
        title = factory.createHeader();
        title.addContent(aTitle);
        ele.addContent(title);
      }

      if (configElement != null) {
        ele.addContent(configElement);
      }
    }
  }
 /**
  * Sets the value for the given key to the given newValue.
  *
  * @param key
  * @param newValue
  * @param index TODO
  * @return True if anything changed. False otherwise.
  */
 public boolean setEntry(EntryType type, String key, ConfigEntry newValue) {
   if (key == null || type == null) {
     return false;
   }
   boolean changed = false;
   synchronized (data) {
     if (data.containsKey(type)) {
       LinkedHashMap<String, ConfigEntry> mappings = data.get(type);
       ConfigEntry oldValue = mappings.get(key);
       changed |= !(newValue == oldValue || newValue != null && newValue.equals(oldValue));
       if (newValue == null) {
         mappings.remove(key);
       } else {
         mappings.put(key, newValue);
       }
     }
   }
   return changed;
 }
Exemple #17
0
  private void widthChanged() {
    boolean heightChange = false;

    for (ConfigEntry entry : options) {
      int prevHeight = entry.height();
      entry.setSize(width(), entry.height());
      entry.recalculateHeight();

      if (entry.height() != prevHeight) {
        heightChange = true;
      }
    }

    if (heightChange) {
      recalculatePositions();
    }
  }
  /**
   * Generate the GUI components to show the config for a given project
   *
   * @param projectName
   */
  private void generateGUIGonfiguration(String projectName) {
    boolean configExists = true;

    Element frameworkElement = null;

    String configFileName =
        Configuration.sourceDirPrefix
            + "/"
            + Configuration.projectDirInSourceFolder
            + "/"
            + projectName
            + "/"
            + Configuration.configfileFileName;
    File configFile = new File(configFileName);
    if (!configFile.exists()) {
      configExists = false;
    } else
      try {
        Document doc = new SAXBuilder().build(configFile);
        Element root = doc.getRootElement();
        frameworkElement = root.getChild("Framework");
        Element custom = root.getChild("Custom");
        if (custom == null) {
          Main.fatalError(
              "Invalid configuration file: A Custom entry is missing.\n"
                  + "The file needs to be of the following form: \n"
                  + "<Document>\n  <Framework>...</Framework>\n  <Custom></Custom>\n</Document>");
        }
        if (frameworkElement == null) {
          Main.fatalError(
              "Invalid configuration file: A 'framework' entry is missing.\n"
                  + "The file needs to be of the following form: \n"
                  + "<Document>\n  <Framework>...</Framework>\n  <Custom></Custom>\n</Document>");
        }
      } catch (JDOMException e1) {
        Main.fatalError("Invalid configuration file:\n\n" + e1.getMessage());
      } catch (IOException e1) {
        Main.fatalError("Cannot open or read from configuration file:\n\n" + e1.getMessage());
      }

    projectEntries = new Vector<ConfigEntry>();

    String sectionName = "";

    Class<?> configClass = Configuration.class;
    // We assume here that the fields are returned in the order they are listed in the java file!
    Field[] fields = configClass.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      Field field = fields[i];
      try {
        // read the annotations for this field
        Configuration.DefaultInConfigFile dan =
            field.getAnnotation(Configuration.DefaultInConfigFile.class);
        Configuration.OptionalInConfigFile oan =
            field.getAnnotation(Configuration.OptionalInConfigFile.class);
        Configuration.SectionInConfigFile san =
            field.getAnnotation(Configuration.SectionInConfigFile.class);
        if (dan != null || oan != null) {
          if (san != null) { // get the title
            sectionName = san.value();
            projectEntries.add(
                new ConfigEntry(
                    sectionName, "", Configuration.SectionInConfigFile.class, "", false, field));
          }
          String description = dan != null ? dan.value() : oan.value(); // the description text
          // test whether the XML file contains an entry for this field
          String value = null;
          if (configExists) {
            Element e = frameworkElement.getChild(field.getName());
            if (e != null) {
              value = e.getAttributeValue("value"); // null if not there
            }
          }
          if (value == null) {
            // there was no entry in the config-file. Take the default value.
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    Configuration.getConfigurationText(field.get(null)),
                    field.getType(),
                    description,
                    oan != null,
                    field));
          } else { // there is an entry in the XML file
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    value,
                    field.getType(),
                    description,
                    oan != null,
                    field)); // elem.comment
          }
        } else if (field.getName().equals("edgeType")) {
          // NOTE: the edgeType member does not carry any annotations (exception)
          String comment = "The default type of edges to be used";
          String value = null;
          if (configExists) {
            Element e = frameworkElement.getChild(field.getName());
            if (e != null) {
              value = e.getAttributeValue("value"); // null if not there
            }
          }
          if (value == null) {
            // there was no entry in the config-file. Take the default value.
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    Configuration.getEdgeType(),
                    field.getType(),
                    comment,
                    oan != null,
                    field));
          } else {
            projectEntries.add(
                new ConfigEntry(
                    field.getName(), value, field.getType(), comment, oan != null, field));
          }
        }
      } catch (IllegalArgumentException e) {
        Main.fatalError(e);
      } catch (IllegalAccessException e) {
        Main.fatalError(e);
      }
    }

    // for each entry, create the corresponding GUI components

    asynchronousSimulationCB = null;
    mobilityCB = null;
    for (ConfigEntry e : projectEntries) {
      String ttt =
          e.comment.equals("")
              ? null
              : e.comment; // the tool tip text, don't show at all, if no text to display

      // creating the text field
      UnborderedJTextField label;
      if (e.entryClass == Configuration.SectionInConfigFile.class) {
        label = new UnborderedJTextField(e.key.toString(), Font.BOLD);
      } else {
        label = new UnborderedJTextField("         " + e.key.toString(), Font.PLAIN);
      }
      label.setToolTipText(ttt);
      e.textComponent = label;

      if (e.entryClass == boolean.class) {
        String[] ch = {"true", "false"};
        MultiLineToolTipJComboBox booleanChoice = new MultiLineToolTipJComboBox(ch);
        if ((e.value).compareTo("true") != 0) {
          booleanChoice.setSelectedItem("false");
        } else {
          booleanChoice.setSelectedItem("true");
        }
        booleanChoice.addActionListener(
            userInputListener); // ! add this listener AFTER setting the value!
        booleanChoice.setToolTipText(ttt);
        e.valueComponent = booleanChoice;
        // special case: mobility can only be changed if simulation is in sync mode.
        if (e.key.equals("asynchronousMode")) {
          asynchronousSimulationCB = booleanChoice;
          if (mobilityCB != null && (e.value).equals("true")) {
            mobilityCB.setSelectedItem("false");
            mobilityCB.setEnabled(false);
          }
        }
        if (e.key.equals("mobility")) {
          mobilityCB = booleanChoice;
          if (asynchronousSimulationCB != null
              && asynchronousSimulationCB.getSelectedItem().equals("true")) {
            mobilityCB.setSelectedItem("false");
            mobilityCB.setEnabled(false);
          }
        }
      } else if (e.entryClass == Configuration.SectionInConfigFile.class) {
        e.valueComponent = null; // there's no component for the section
      } else {
        // special case for some text fields that expect the name of an implementation. They
        // should show the available implementations in a drop down field
        ImplementationChoiceInConfigFile ian =
            e.field.getAnnotation(ImplementationChoiceInConfigFile.class);
        if (ian != null) {
          Vector<String> ch = Global.getImplementations(ian.value(), true);
          MultiLineToolTipJComboBox choice = new MultiLineToolTipJComboBox(ch);
          choice.setEditable(
              true); // let the user the freedom to enter other stuff (which is likely to be
                     // wrong...)
          choice.setSelectedItem(e.value);
          choice.addActionListener(
              userInputListener); // ! add this listener AFTER setting the value!
          choice.setToolTipText(ttt);
          e.valueComponent = choice;
        } else {
          if (e.key.equals("javaCmd")) { // special case - this field may contain a lot of text
            JTextArea textArea = new MultiLineToolTipJTextArea(e.value.toString());
            textArea.setToolTipText(ttt);
            textArea.setBorder((new JTextField()).getBorder()); // copy the border
            textArea.setLineWrap(true);
            // textArea.setPreferredSize(new Dimension(50, 30));
            textArea.addKeyListener(userInputListener);
            e.valueComponent = textArea;
          } else {
            MultiLineToolTipJTextField textField =
                new MultiLineToolTipJTextField(e.value.toString());
            textField.setToolTipText(ttt);
            textField.addKeyListener(userInputListener);
            e.valueComponent = textField;
          }
        }
      }
    }
    // and finally add all the entries
    insertProjectEntries();

    customConfigurationPanel.removeAll();

    // And add the custom entries

    //   this code snipped was used to redirect the mouse wheel applied on this
    //   text field to the entire tab when the custom config was below the framework config
    //		// remove all mouse wheel listeners from the text input
    //		for(MouseWheelListener mwl : customParameters.getMouseWheelListeners()) {
    //			customParameters.removeMouseWheelListener(mwl);
    //		}
    //		// and add the 'global' one
    //		customParameters.addMouseWheelListener(new
    // MouseWheelForwarder(scrollableConfigurationPane.getMouseWheelListeners()));

    customParameters.setTabSize(3);
    customParameters.setLineWrap(true);
    customParameters.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    if (configExists) {
      customParameters.setText(getCustomText(configFile));
    } else {
      customParameters.setText("");
    }

    customParameters.addKeyListener(
        userInputListener); // ! add this listener AFTER setting the text !

    JScrollPane customScroll =
        new JScrollPane(
            customParameters,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    customScroll.setWheelScrollingEnabled(true);
    customConfigurationPanel.add(customScroll);

    userInputListener.reset();

    super.repaint();
  }
  private void loadContents(BufferedReader in) throws IOException {
    StringBuilder buf = new StringBuilder();
    while (true) {
      // Empty out the buffer
      buf.setLength(0);

      String line = advance(in);
      if (line == null) {
        break;
      }

      // skip blank lines
      if (line.length() == 0) {
        continue;
      }

      Matcher matcher = KEY_VALUE_PATTERN.matcher(line);
      if (!matcher.matches()) {
        log.warn("Expected to see '=' in " + internal + ": " + line);
        continue;
      }

      String key = matcher.group(1).trim();
      String value = matcher.group(2).trim();
      // Only CIPHER_KEYS that are empty are not ignored
      if (value.length() == 0 && !ConfigEntryType.CIPHER_KEY.getName().equals(key)) {
        log.warn("Ignoring empty entry in " + internal + ": " + line);
        continue;
      }

      // Create a configEntry so that the name is normalized.
      ConfigEntry configEntry = new ConfigEntry(internal, key);

      ConfigEntryType type = configEntry.getType();

      ConfigEntry e = table.get(type);

      if (e == null) {
        if (type == null) {
          log.warn("Extra entry in " + internal + " of " + configEntry.getName());
          extra.put(key, configEntry);
        } else if (type.isSynthetic()) {
          log.warn("Ignoring unexpected entry in " + internal + " of " + configEntry.getName());
        } else {
          table.put(type, configEntry);
        }
      } else {
        configEntry = e;
      }

      buf.append(value);
      getContinuation(configEntry, in, buf);

      // History is a special case it is of the form History_x.x
      // The config entry is History without the x.x.
      // We want to put x.x at the beginning of the string
      value = buf.toString();
      if (ConfigEntryType.HISTORY.equals(type)) {
        int pos = key.indexOf('_');
        value = key.substring(pos + 1) + ' ' + value;
      }

      configEntry.addValue(value);
    }
  }
 // MJD latest change in jsword
 public boolean match(ConfigEntryType type, String search) {
   ConfigEntry ce = table.get(type);
   return ce != null && ce.match(search);
 }
 public boolean setEntry(String key, ConfigEntry newValue) {
   if (key == null || newValue == null) {
     return false;
   }
   return setEntry(newValue.getEntryType(), key, newValue);
 }