/java/src/com/google/gdata/data/media/mediarss/MediaContent.java

http://gdata-java-client.googlecode.com/ · Java · 207 lines · 145 code · 33 blank · 29 comment · 7 complexity · a9a2937363708a308d4c4c9c92c2af3d MD5 · raw file

  1. /* Copyright (c) 2008 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. package com.google.gdata.data.media.mediarss;
  16. import com.google.gdata.data.AttributeGenerator;
  17. import com.google.gdata.data.AttributeHelper;
  18. import com.google.gdata.data.ExtensionDescription;
  19. import com.google.gdata.util.ParseException;
  20. /**
  21. * {@code <media:content>}.
  22. *
  23. * See description on
  24. * <a href="http://search.yahoo.com/mrss">http://search.yahoo.com/mrss</a>.
  25. *
  26. *
  27. */
  28. @ExtensionDescription.Default(
  29. nsAlias = MediaRssNamespace.PREFIX,
  30. nsUri = MediaRssNamespace.URI,
  31. localName = "content"
  32. )
  33. public class MediaContent extends AbstractMediaResource {
  34. private long fileSize;
  35. private String type;
  36. private String medium;
  37. private boolean isDefault;
  38. private Expression expression;
  39. private int bitrate;
  40. private int framerate;
  41. private int samplingrate;
  42. private int channels;
  43. private int duration;
  44. private String language;
  45. /**
  46. * Describes the tag to an {@link com.google.gdata.data.ExtensionProfile}.
  47. *
  48. * @param repeat if true, the description will be repeatable (MediaContent
  49. * can be repeated when inside MediaGroup, but not when inside BaseEntry.)
  50. */
  51. public static ExtensionDescription getDefaultDescription(boolean repeat) {
  52. ExtensionDescription retval =
  53. ExtensionDescription.getDefaultDescription(MediaContent.class);
  54. retval.setRepeatable(repeat);
  55. return retval;
  56. }
  57. public int getBitrate() {
  58. return bitrate;
  59. }
  60. public void setBitrate(int bitrate) {
  61. this.bitrate = bitrate;
  62. }
  63. public int getChannels() {
  64. return channels;
  65. }
  66. public void setChannels(int channels) {
  67. this.channels = channels;
  68. }
  69. public int getDuration() {
  70. return duration;
  71. }
  72. public void setDuration(int duration) {
  73. this.duration = duration;
  74. }
  75. public String getLanguage() {
  76. return language;
  77. }
  78. public void setLanguage(String language) {
  79. this.language = language;
  80. }
  81. public Expression getExpression() {
  82. return expression;
  83. }
  84. public void setExpression(Expression expression) {
  85. this.expression = expression;
  86. }
  87. public long getFileSize() {
  88. return fileSize;
  89. }
  90. public void setFileSize(long fileSize) {
  91. this.fileSize = fileSize;
  92. }
  93. public int getFramerate() {
  94. return framerate;
  95. }
  96. public void setFramerate(int framerate) {
  97. this.framerate = framerate;
  98. }
  99. public boolean isDefault() {
  100. return isDefault;
  101. }
  102. public void setDefault(boolean aDefault) {
  103. isDefault = aDefault;
  104. }
  105. public String getMedium() {
  106. return medium;
  107. }
  108. public void setMedium(String medium) {
  109. this.medium = medium;
  110. }
  111. public int getSamplingrate() {
  112. return samplingrate;
  113. }
  114. public void setSamplingrate(int samplingrate) {
  115. this.samplingrate = samplingrate;
  116. }
  117. public String getType() {
  118. return type;
  119. }
  120. public void setType(String type) {
  121. this.type = type;
  122. }
  123. @Override
  124. protected void putAttributes(AttributeGenerator generator) {
  125. super.putAttributes(generator);
  126. if (fileSize > 0) {
  127. generator.put("fileSize", fileSize);
  128. }
  129. generator.put("type", type);
  130. generator.put("medium", medium);
  131. if (isDefault) {
  132. generator.put("isDefault", isDefault);
  133. }
  134. generator.put("expression", expression,
  135. new AttributeHelper.LowerCaseEnumToAttributeValue<Expression>());
  136. if (bitrate > 0) {
  137. generator.put("bitrate", bitrate);
  138. }
  139. if (framerate > 0) {
  140. generator.put("framerate", framerate);
  141. }
  142. if (samplingrate > 0) {
  143. generator.put("samplingrate", samplingrate);
  144. }
  145. if (channels > 0) {
  146. generator.put("channels", channels);
  147. }
  148. if (duration > 0) {
  149. generator.put("duration", duration);
  150. }
  151. generator.put("language", language);
  152. }
  153. @Override
  154. protected void consumeAttributes(AttributeHelper attrsHelper)
  155. throws ParseException {
  156. super.consumeAttributes(attrsHelper);
  157. fileSize = attrsHelper.consumeLong("fileSize", false);
  158. type = attrsHelper.consume("type", false);
  159. medium = attrsHelper.consume("medium", false);
  160. isDefault = attrsHelper.consumeBoolean("isDefault", false);
  161. expression =
  162. attrsHelper.consumeEnum("expression", false, Expression.class);
  163. bitrate = attrsHelper.consumeInteger("bitrate", false);
  164. framerate = attrsHelper.consumeInteger("framerate", false);
  165. samplingrate = attrsHelper.consumeInteger("samplingrate", false);
  166. channels = attrsHelper.consumeInteger("channels", false);
  167. duration = attrsHelper.consumeInteger("duration", false);
  168. language = attrsHelper.consume("language", false);
  169. }
  170. /** Values for the expression attribute: sample, full and nonstop. */
  171. public enum Expression {
  172. SAMPLE, FULL, NONSTOP
  173. }
  174. }