Exemplo n.º 1
0
 public JsonObject toJsonObject() {
   return new JsonObject()
       .put("id", fileId.toString())
       .put("name", name)
       .put("mime_type", mimeType.toString())
       .put("content_length", contentLength)
       .put("generated", generated);
 }
Exemplo n.º 2
0
 /** core method */
 public void writeTo(Writer writer) throws IOException {
   switch (type) {
     case CSS:
       writeCssTo(writer);
       break;
     case JS:
       writeJsTo(writer);
       break;
     default:
       throw new IllegalStateException(type.toString());
   }
 }
Exemplo n.º 3
0
  /**
   * Copied code from java.util.Properties. Parsing the data ourselves is the only way to handle
   * duplicate keys and values.
   */
  private void parseAndStoreReader(BufferedReader in) throws IOException {
    while (true) {
      // Get next line
      String line = in.readLine();
      if (line == null) {
        return;
      }

      if (line.length() > 0) {
        // Continue lines that end in slashes if they are not comments
        char firstChar = line.charAt(0);
        if (firstChar != '#' && firstChar != '!') {
          while (continueLine(line)) {
            String nextLine = in.readLine();
            if (nextLine == null) {
              nextLine = new String("");
            }
            String loppedLine = line.substring(0, line.length() - 1);
            // Advance beyond whitespace on new line
            int startIndex = 0;
            for (; startIndex < nextLine.length(); startIndex++) {
              if (whiteSpaceChars.indexOf(nextLine.charAt(startIndex)) == -1) {
                break;
              }
            }
            nextLine = nextLine.substring(startIndex, nextLine.length());
            line = new String(loppedLine + nextLine);
          }

          // Find start of key
          int len = line.length();
          int keyStart = 0;
          for (; keyStart < len; keyStart++) {
            if (whiteSpaceChars.indexOf(line.charAt(keyStart)) == -1) {
              break;
            }
          }

          // Blank lines are ignored
          if (keyStart == len) {
            continue;
          }

          // Find separation between key and value
          int separatorIndex = keyStart;
          for (; separatorIndex < len; separatorIndex++) {
            char currentChar = line.charAt(separatorIndex);
            if (currentChar == '\\') {
              separatorIndex++;
            } else if (keyValueSeparators.indexOf(currentChar) != -1) {
              break;
            }
          }

          // Skip over whitespace after key if any
          int valueIndex = separatorIndex;
          for (; valueIndex < len; valueIndex++) {
            if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1) {
              break;
            }
          }

          // Skip over one non whitespace key value separators if any
          if (valueIndex < len) {
            if (strictKeyValueSeparators.indexOf(line.charAt(valueIndex)) != -1) {
              valueIndex++;
            }
          }

          // Skip over white space after other separators if any
          while (valueIndex < len) {
            if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1) {
              break;
            }
            valueIndex++;
          }

          String key = line.substring(keyStart, separatorIndex);
          String value = (separatorIndex < len) ? line.substring(valueIndex, len) : "";

          // Convert then store key and value
          key = loadConvert(key);
          value = loadConvert(value);

          try {
            MimeType mime = new MimeType(value);
            if ("text".equals(mime.getPrimaryType())) {
              String charset = mime.getParameter("charset");
              if (DataTransferer.doesSubtypeSupportCharset(mime.getSubType(), charset)) {
                // We need to store the charset and eoln
                // parameters, if any, so that the
                // DataTransferer will have this information
                // for conversion into the native format.
                DataTransferer transferer = DataTransferer.getInstance();
                if (transferer != null) {
                  transferer.registerTextFlavorProperties(
                      key, charset, mime.getParameter("eoln"), mime.getParameter("terminators"));
                }
              }

              // But don't store any of these parameters in the
              // DataFlavor itself for any text natives (even
              // non-charset ones). The SystemFlavorMap will
              // synthesize the appropriate mappings later.
              mime.removeParameter("charset");
              mime.removeParameter("class");
              mime.removeParameter("eoln");
              mime.removeParameter("terminators");
              value = mime.toString();
            }
          } catch (MimeTypeParseException e) {
            e.printStackTrace();
            continue;
          }

          DataFlavor flavor;
          try {
            flavor = new DataFlavor(value);
          } catch (Exception e) {
            try {
              flavor = new DataFlavor(value, (String) null);
            } catch (Exception ee) {
              ee.printStackTrace();
              continue;
            }
          }

          // For text/* flavors, store mappings in separate maps to
          // enable dynamic mapping generation at a run-time.
          if ("text".equals(flavor.getPrimaryType())) {
            store(value, key, getFlavorToNative());
            store(key, value, getNativeToFlavor());
          } else {
            store(flavor, key, getFlavorToNative());
            store(key, flavor, getNativeToFlavor());
          }
        }
      }
    }
  }
Exemplo n.º 4
0
 /**
  * While MimeType(s) are being loaded by the MimeDetector(s) they should be added to the list of
  * known MIME types. It is not mandatory for MimeDetector(s) to do so but they should where
  * possible so that the list is as complete as possible. You can add other MIME types to this list
  * using this method. You can then use the isMimeTypeKnown(...) utility methods to see if a MIME
  * type you have matches one that the utility has already seen.
  *
  * <p>This can be used to limit the mime types you work with i.e. if its not been loaded then
  * don't bother using it as it won't match. This is no guarantee that a match will not be found as
  * it is possible that a particular MimeDetector does not have an initialisation phase that loads
  * all of the MIME types it will match.
  *
  * <p>For instance if you had a MIME type of abc/xyz and passed this to isMimeTypeKnown(...) it
  * would return false unless you specifically add this to the know MIME types using this method.
  *
  * @param mimeType a MIME type you want to add to the known MIME types. Duplicates are ignored.
  * @see #isMimeTypeKnown(String mimeType)
  * @see #isMimeTypeKnown(MimeType mimetType)
  */
 public static void addKnownMimeType(final MimeType mimeType) {
   addKnownMimeType(mimeType.toString());
 }