Skip to content

Idea: get the service by ID #4

@TorstenH82

Description

@TorstenH82

To simplify usage of the libary or would be great to have a function to filter the xml for the service of interest. Currently I need to do that:

HttpURLConnection conn = (HttpURLConnection) new URL(sSiUrl).openConnection();

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser parser = factory.newPullParser();
        InputStream inputStream = conn.getInputStream();
        parser.setInput(inputStream, "UTF-8");

        List<StationImage> listStationImages = new ArrayList<>();

        boolean xmlFoundId = false;
        String xmlCurrentId = null;

        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
          if (eventType == XmlPullParser.START_TAG) {
            if ("service".equalsIgnoreCase(parser.getName())) {
              listStationImages.clear();
            } else if ("bearer".equalsIgnoreCase(parser.getName())) {
              String id = parser.getAttributeValue(null, "id");
              if (idToFind.equalsIgnoreCase(id)) xmlFoundId = true;
            } else if ("multimedia".equalsIgnoreCase(parser.getName())) {
              String mimeValueValue = parser.getAttributeValue(null, "mimeValue");
              String typeValue = parser.getAttributeValue(null, "type");
              String urlValue = parser.getAttributeValue(null, "url");
              if (urlValue != null) {
                // && ((mimeValueValue != null && mimeValueValue.toLowerCase().contains("image"))
                //    || (typeValue != null && typeValue.toLowerCase().contains("logo")))) {
                String widthValue = parser.getAttributeValue(null, "width");
                String heightValue = parser.getAttributeValue(null, "height");
                try {
                  int iWidth = Integer.valueOf(widthValue);
                  int iHeight = Integer.valueOf(heightValue);

                  StationImage stationImage = new StationImage(idToFind, urlValue, iWidth, iHeight);
                  listStationImages.add(stationImage);
                } catch (NumberFormatException ex1) {
                  continue;
                }
              }
            }
          } else if (eventType == XmlPullParser.END_TAG) {
            if ("service".equalsIgnoreCase(parser.getName())) {
              if (xmlFoundId) break;
            }
          }
          eventType = parser.next();
        }
        inputStream.close();

        if (listStationImages.size() == 0) {
          Logger.d(
              String.format(
                  "RadioDnsLogo: station image not found for id '%s' in '%s'", idToFind, sSiUrl));
          return RETURN_IMAGE_NOT_FOUND;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions