View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.tika.parser.mp3;
18  
19  /**
20   * Takes an array of {@link ID3Tags} in preference order, and when asked for
21   * a given tag, will return it from the first {@link ID3Tags} that has it.
22   */
23  public class CompositeTagHandler implements ID3Tags {
24  
25      private ID3Tags[] tags;
26  
27      public CompositeTagHandler(ID3Tags[] tags) {
28          this.tags = tags;
29      }
30  
31      public boolean getTagsPresent() {
32          for (ID3Tags tag : tags) {
33              if (tag.getTagsPresent()) {
34                  return true;
35              }
36          }
37          return false;
38      }
39  
40      public String getTitle() {
41          for (ID3Tags tag : tags) {
42              if (tag.getTitle() != null) {
43                  return tag.getTitle();
44              }
45          }
46          return null;
47      }
48  
49      public String getArtist() {
50          for (ID3Tags tag : tags) {
51              if (tag.getArtist() != null) {
52                  return tag.getArtist();
53              }
54          }
55          return null;
56      }
57  
58      public String getAlbum() {
59          for (ID3Tags tag : tags) {
60              if (tag.getAlbum() != null) {
61                  return tag.getAlbum();
62              }
63          }
64          return null;
65      }
66  
67      public String getYear() {
68          for (ID3Tags tag : tags) {
69              if (tag.getYear() != null) {
70                  return tag.getYear();
71              }
72          }
73          return null;
74      }
75  
76      public String getComment() {
77          for (ID3Tags tag : tags) {
78              if (tag.getComment() != null) {
79                  return tag.getComment();
80              }
81          }
82          return null;
83      }
84  
85      public String getGenre() {
86          for (ID3Tags tag : tags) {
87              if (tag.getGenre() != null) {
88                  return tag.getGenre();
89              }
90          }
91          return null;
92      }
93  
94      public String getTrackNumber() {
95          for (ID3Tags tag : tags) {
96              if (tag.getTrackNumber() != null) {
97                  return tag.getTrackNumber();
98              }
99          }
100         return null;
101     }
102 
103 }