@Override
  public void sendMessage(IridiumMessage msg) throws Exception {
    VehicleType vt = VehiclesHolder.getVehicleWithImc(new ImcId16(msg.getDestination()));
    if (vt == null) {
      throw new Exception("Cannot send message to an unknown destination");
    }
    IridiumArgs args = (IridiumArgs) vt.getProtocolsArgs().get("iridium");
    if (askRockBlockPassword || rockBlockPassword == null || rockBlockUsername == null) {
      Pair<String, String> credentials =
          GuiUtils.askCredentials(
              ConfigFetch.getSuperParentFrame(),
              "Enter RockBlock Credentials",
              getRockBlockUsername(),
              getRockBlockPassword());
      if (credentials == null) return;
      setRockBlockUsername(credentials.first());
      setRockBlockPassword(credentials.second());
      PluginUtils.saveProperties("conf/rockblock.props", this);
      askRockBlockPassword = false;
    }

    String result =
        sendToRockBlockHttp(
            args.getImei(), getRockBlockUsername(), getRockBlockPassword(), msg.serialize());

    if (result != null) {
      if (!result.split(",")[0].equals("OK")) {
        throw new Exception("RockBlock server failed to deliver the message: '" + result + "'");
      }
    }
  }
Пример #2
0
 @Override
 protected Vector<DefaultProperty> additionalProperties() {
   Vector<DefaultProperty> properties = new Vector<DefaultProperty>();
   PluginProperty[] prop = PluginUtils.getPluginProperties(this);
   properties.addAll(Arrays.asList(prop));
   return properties;
 }
 {
   try {
     PluginUtils.loadProperties("conf/rockblock.props", this);
   } catch (Exception e) {
   }
   askGmailPassword = askRockBlockPassword = alwaysAskForPassword;
 }
  @Override
  public Collection<IridiumMessage> pollMessages(Date timeSince) throws Exception {

    if (askGmailPassword || gmailPassword == null || gmailUsername == null) {
      Pair<String, String> credentials =
          GuiUtils.askCredentials(
              ConfigFetch.getSuperParentFrame(),
              "Enter Gmail Credentials",
              getGmailUsername(),
              getGmailPassword());
      if (credentials == null) return null;
      setGmailUsername(credentials.first());
      setGmailPassword(credentials.second());
      PluginUtils.saveProperties("conf/rockblock.props", this);
      askGmailPassword = false;
    }

    Properties props = new Properties();
    props.put("mail.store.protocol", "imaps");
    ArrayList<IridiumMessage> messages = new ArrayList<>();
    try {
      Session session = Session.getDefaultInstance(props, null);
      Store store = session.getStore("imaps");
      store.connect("imap.gmail.com", getGmailUsername(), getGmailPassword());

      Folder inbox = store.getFolder("Inbox");
      inbox.open(Folder.READ_ONLY);
      int numMsgs = inbox.getMessageCount();

      for (int i = numMsgs; i > 0; i--) {
        Message m = inbox.getMessage(i);
        if (m.getReceivedDate().before(timeSince)) {
          break;
        } else {
          MimeMultipart mime = (MimeMultipart) m.getContent();
          for (int j = 0; j < mime.getCount(); j++) {
            BodyPart p = mime.getBodyPart(j);
            Matcher matcher = pattern.matcher(p.getContentType());
            if (matcher.matches()) {
              InputStream stream = (InputStream) p.getContent();
              byte[] data = IOUtils.toByteArray(stream);
              IridiumMessage msg = process(data, matcher.group(1));
              if (msg != null) messages.add(msg);
            }
          }
        }
      }
    } catch (NoSuchProviderException ex) {
      ex.printStackTrace();
      System.exit(1);
    } catch (MessagingException ex) {
      ex.printStackTrace();
      System.exit(2);
    }

    return messages;
  }
Пример #5
0
 public ImageIcon getImageIcon() {
   return ImageUtils.getIcon(PluginUtils.getPluginIcon(this.getClass()));
 }
Пример #6
0
 public String getDescription() {
   return PluginUtils.getPluginDescription(this.getClass());
 }
Пример #7
0
 public String getName() {
   return PluginUtils.getPluginName(this.getClass());
 }
Пример #8
0
 @Override
 public String[] getPropertiesErrors(Property[] properties) {
   return PluginUtils.validatePluginProperties(this, properties);
 }
Пример #9
0
 @Override
 public String getPropertiesDialogTitle() {
   return PluginUtils.getPluginName(this.getClass()) + " parameters";
 }
Пример #10
0
 @Override
 public void setProperties(Property[] properties) {
   PluginUtils.setPluginProperties(this, properties);
 }
Пример #11
0
 @Override
 public DefaultProperty[] getProperties() {
   return PluginUtils.getPluginProperties(this);
 }
Пример #12
0
  @SuppressWarnings("unchecked")
  private <T> PluginProperty extractPluginProperty(Field f, T class1) {
    NeptusProperty neptusProperty = f.getAnnotation(NeptusProperty.class);
    Object fieldValue = null;
    try {
      fieldValue = f.get(class1);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    // Name
    String nameRaw = neptusProperty.name();
    String displayName;
    if (nameRaw == null || nameRaw.length() == 0) {
      nameRaw = f.getName();
      char firstLetter = Character.toUpperCase(nameRaw.charAt(0));
      displayName = firstLetter + nameRaw.substring(1);
    } else {
      displayName = nameRaw;
    }
    // Type
    Class<?> type = f.getType();

    PluginProperty pp = new PluginProperty(nameRaw, type, fieldValue);
    pp.setValue(fieldValue);

    // Editable
    if (neptusProperty.editable() == false) {
      pp.setEditable(false);
    } else {
      pp.setEditable(true);
    }
    // Display name
    // signal the scope is the whole Neptus
    if (class1.getClass().equals(GeneralPreferences.class))
      displayName = "* " + I18n.text(displayName);
    else displayName = I18n.text(displayName);
    pp.setDisplayName(displayName);
    // Category
    if (neptusProperty.category() != null) {
      pp.setCategory(I18n.text(neptusProperty.category()));
    }
    // Short description
    Map<String, PluginProperty> hashMap = PluginUtils.getDefaultsValues(class1);
    StringBuilder description = new StringBuilder();
    description.append(I18n.text(neptusProperty.description()));
    String defaultValue;
    if (hashMap == null) {
      // no value!
      defaultValue =
          I18n.textf("No default found for class %className", class1.getClass().getSimpleName());
    } else {
      PluginProperty pluginProperty = hashMap.get(f.getName());
      if (pluginProperty == null) {
        // no value!
        defaultValue = I18n.textf("No default found for field %fieldName", f.getName());
      } else {
        Object defaultPropValue = pluginProperty.getValue();
        defaultValue =
            (defaultPropValue == null
                ? I18n.text("Absence of value")
                : ((f.getType().getEnumConstants() != null
                    ? I18n.text(defaultPropValue.toString())
                    : defaultPropValue.toString())));
      }
    }
    description.append(" (");
    description.append(I18n.text("Default value"));
    description.append(": ");
    description.append(defaultValue);
    description.append(")");
    pp.setShortDescription(description.toString());

    // Editor class - ATTENTION must be the last or wont work!
    Class<? extends PropertyEditor> editClass = null;
    if (neptusProperty.editorClass() != PropertyEditor.class) {
      editClass = neptusProperty.editorClass();
    }
    if (editClass != null) {
      pEditorRegistry.registerEditor(pp, editClass);
    } else {
      if (ReflectionUtil.hasInterface(f.getType(), PropertyType.class)) {
        PropertyType pt = (PropertyType) fieldValue;
        pEditorRegistry.registerEditor(pp, pt.getPropertyEditor());
      }
      if (f.getType().getEnumConstants() != null) {
        if (fieldValue != null) {
          pEditorRegistry.registerEditor(
              pp, new EnumEditor((Class<? extends Enum<?>>) fieldValue.getClass()));
        }
      }
    }
    return pp;
  }
 @Override
 public Image getIconImage() {
   return ImageUtils.getImage(PluginUtils.getPluginIcon(this.getClass()));
 }