Beispiel #1
0
  /**
   * Factory method for Request and Response. It expects the bytes to be correctly formed so it's
   * possible that it throws underflow exceptions but you shouldn't be concerned about that since
   * that all bytes sent in should already be formatted correctly.
   *
   * @param bytes bytes to be converted.
   * @return Request or Response depending on the data.
   * @throws ClassNotFoundException if the Command or Answer can not be formed.
   * @throws
   */
  public static Request parse(final byte[] bytes)
      throws ClassNotFoundException, UnsupportedVersionException {
    ByteBuffer buff = ByteBuffer.wrap(bytes);
    final byte ver = buff.get();
    final Version version = Version.get(ver);
    if (version.ordinal() != Version.v1.ordinal() && version.ordinal() != Version.v3.ordinal()) {
      throw new UnsupportedVersionException(
          "This version is no longer supported: " + version.toString(),
          UnsupportedVersionException.IncompatibleVersion);
    }
    final byte reserved = buff.get(); // tossed away for now.
    final short flags = buff.getShort();
    final boolean isRequest = (flags & FLAG_REQUEST) > 0;

    final long seq = buff.getLong();
    // The size here is uncompressed size, if the data is compressed.
    final int size = buff.getInt();
    final long mgmtId = buff.getLong();
    final long agentId = buff.getLong();

    long via;
    if (version.ordinal() == Version.v1.ordinal()) {
      via = buff.getLong();
    } else {
      via = agentId;
    }

    if ((flags & FLAG_COMPRESSED) != 0) {
      buff = doDecompress(buff, size);
    }

    byte[] command = null;
    int offset = 0;
    if (buff.hasArray()) {
      command = buff.array();
      offset = buff.arrayOffset() + buff.position();
    } else {
      command = new byte[buff.remaining()];
      buff.get(command);
      offset = 0;
    }

    final String content = new String(command, offset, command.length - offset);

    if (isRequest) {
      return new Request(version, seq, agentId, mgmtId, via, flags, content);
    } else {
      return new Response(Version.get(ver), seq, agentId, mgmtId, via, flags, content);
    }
  }
Beispiel #2
0
 public static Version getVersion(final byte[] bytes) throws UnsupportedVersionException {
   try {
     return Version.get(bytes[0]);
   } catch (UnsupportedVersionException e) {
     throw new CloudRuntimeException("Unsupported version: " + bytes[0]);
   }
 }
 private static <R extends AbstractBaseRecord> R record(
     Map<Long, Delta<R>> records, long id, Version version) {
   Delta<R> delta = records.get(id);
   if (delta == null) {
     if (version == Version.NEW) {
       return null;
     }
     throw new AssertionError(String.format("Access to record with id=%d not expected.", id));
   }
   return version.get(delta);
 }
Beispiel #4
0
 /** Return meta tags for character set and generator. */
 public static String getMeta(String applicationName) {
   String charset = StringUtil.getDefaultEncoding();
   StringBuilder buffer = new StringBuilder(512);
   buffer.append("<meta http-equiv=\"Content-Type\"" + " content=\"text/html; charset=");
   buffer.append(charset);
   buffer.append("\">\n" + "<meta name=\"generator\" content=\"");
   buffer.append(applicationName);
   buffer.append(' ');
   buffer.append(Version.get());
   buffer.append(" (http://gogui.sf.net)\">\n");
   return buffer.toString();
 }
Beispiel #5
0
 /**
  * Return a footer. Contains a horizontal line followed by an address element containing the
  * generation (current) date, the generator (applicationName) and a link to the GoGui website.
  */
 public static String getFooter(String applicationName) {
   StringBuilder buffer = new StringBuilder(512);
   buffer.append(
       "<hr style=\"margin-bottom:0\" size=\"1\">\n"
           + "<p style=\"margin-top:1; margin-right:5\""
           + " align=\"right\"><i>"
           + "<small>Generated on ");
   buffer.append(StringUtil.getDateShort());
   buffer.append(" by ");
   buffer.append(applicationName);
   buffer.append(' ');
   buffer.append(Version.get());
   buffer.append(
       " (<a href=\"http://gogui.sf.net\">" + "http://gogui.sf.net</a>)</small></i></p>\n");
   return buffer.toString();
 }
Beispiel #6
0
  String version(Version version, String mask) {
    if (version == null) {
      String v = domain.getProperty("@");
      if (v == null) {
        domain.error(
            "No version specified for ${version} or ${range} and no implicit version ${@} either, mask=%s",
            mask);
        v = "0";
      }
      version = new Version(v);
    }

    StringBuilder sb = new StringBuilder();
    String del = "";

    for (int i = 0; i < mask.length(); i++) {
      char c = mask.charAt(i);
      String result = null;
      if (c != '~') {
        if (i == 3) {
          result = version.getQualifier();
        } else if (Character.isDigit(c)) {
          // Handle masks like +00, =+0
          result = String.valueOf(c);
        } else {
          int x = version.get(i);
          switch (c) {
            case '+':
              x++;
              break;
            case '-':
              x--;
              break;
            case '=':
              break;
          }
          result = Integer.toString(x);
        }
        if (result != null) {
          sb.append(del);
          del = ".";
          sb.append(result);
        }
      }
    }
    return sb.toString();
  }
 private void showUpdatesStatus(Future<HttpResponse> status) {
   String versionMsg = "<h3 align=center>Cannot get version information </h3>";
   try {
     HttpResponse response = status.get();
     updateStatusLabel.setText("");
     String file = null;
     for (Header header : response.getHeaders("Content-Disposition")) {
       Matcher matcher = Pattern.compile("filename=\"([^\"]+)\"").matcher(header.getValue());
       while (matcher.find()) {
         file = matcher.group(1);
       }
     }
     if (file != null) {
       String[] installerPatterns = {
         "PdfMetadataEditor-(\\d+)\\.(\\d+)\\.(\\d+)-installer.jar",
         "pdf-metadata-edit-(\\d+)\\.(\\d+)\\.(\\d+)-installer.jar",
       };
       Version.VersionTuple current = Version.get();
       Version.VersionTuple latest = null;
       for (String pattern : installerPatterns) {
         latest = new Version.VersionTuple(file, pattern);
         if (latest.parseSuccess) {
           break;
         }
       }
       if (current.cmp(latest) < 0) {
         versionMsg =
             "<h3 align=center>New version available: <a href='http://broken-by.me/pdf-metadata-editor/#download'>"
                 + latest.getAsString()
                 + "</a> , current: "
                 + current.getAsString()
                 + "</h3>";
         updateStatusLabel.setText("Newer version available:" + latest.getAsString());
       } else {
         versionMsg =
             "<h3 align=center>Version " + current.getAsString() + " is the latest version</h3>";
       }
     }
   } catch (InterruptedException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
   } catch (ExecutionException e1) {
     versionMsg += "<h4 align=center>Error: " + e1.getCause().getLocalizedMessage() + "</h4>";
   } finally {
     txtpnDf.setText(aboutMsg + versionMsg);
   }
 }
 @Override
 public Map<String, Variant> getAboutData(String language) throws ErrorReplyBusException {
   Map<String, Variant> aboutData = new HashMap<String, Variant>();
   // nonlocalized values
   aboutData.put(
       "AppId", new Variant(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}));
   aboutData.put("DefaultLanguage", new Variant("en"));
   aboutData.put("DeviceId", new Variant("93c06771-c725-48c2-b1ff-6a2a59d445b8"));
   aboutData.put("ModelNumber", new Variant("A1B2C3"));
   aboutData.put("SupportedLanguages", new Variant(new String[] {"en"}));
   aboutData.put("DateOfManufacture", new Variant("2014-09-23"));
   aboutData.put("SoftwareVersion", new Variant("1.0"));
   aboutData.put("AJSoftwareVersion", new Variant(Version.get()));
   aboutData.put("HardwareVersion", new Variant("0.1alpha"));
   aboutData.put("SupportUrl", new Variant("http://www.example.com/support"));
   aboutData.put("DeviceName", new Variant("A device name"));
   aboutData.put("AppName", new Variant("An application name"));
   aboutData.put("Manufacturer", new Variant("A mighty manufacturing company"));
   aboutData.put(
       "Description", new Variant("Sample showing the about feature in a service application"));
   return aboutData;
 }