/**
   * @throws FileNotFoundException
   * @throws XmlPullParserException
   * @throws XmlPullParserException: This parser doesn't support parameter entities
   *     (position:DOCDECL @4:15 in java.io.InputStreamReader@ec20ff4)
   */
  @Test(expected = XmlPullParserException.class)
  public void testDOS_indirections_parameterEntity_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/dos_indirections_parameterEntity.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();

    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken(); // IGNORABLE_WHITESPACE - this call is necessary in order to trigger the
    // exception.
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);
  }
  @Test()
  public void testURLInvocation_schemaLocation() throws Exception {

    SimpleClient http = new SimpleClient();

    // reset the counter
    http.sendGet(_URL_ + "/reset");
    String response = http.sendGet(_URL_ + "/getCounter");
    assertEquals("0", response);

    String xmlFile = "data/data/de.rub.nds.parsers/url_invocation_schemaLocation.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    int i = 0;

    //          parse the entire Document
    while (token != XmlPullParser.END_DOCUMENT) {
      token = parser.nextToken();
      i++;
    }

    response = http.sendGet(_URL_ + "/getCounter");
    assertEquals("0", response);
  }
  @Test
  public void testXInclude() throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/xinclude.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    parser.nextToken(); // element
    name = parser.getName();
    value = parser.getText(); // not used here
    event = parser.getEventType();
    assertEquals("data", name);
    assertEquals(2, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(2, event);
    assertEquals(null, value);
    assertEquals("xi:include", name);
  }
  @Test
  public void testStandard() throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/standard.xml";
    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    //        parser.nextToken(); // element
    parser.nextTag();
    name = parser.getName();
    value = parser.getText(); // not used here
    event = parser.getEventType();
    assertEquals("data", name);
    assertEquals(2, event);

    parser.nextToken(); // the content of the element

    // make sure to override ALL values; otherwise we produce assertion errors!
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(4, event);
    assertEquals("4", value);
  }
 public EventReader provide(InputStream paramInputStream) {
   XmlPullParser localXmlPullParser = factory.newPullParser();
   if (paramInputStream != null) {
     localXmlPullParser.setInput(paramInputStream, null);
   }
   return new PullReader(localXmlPullParser);
 }
 public EventReader provide(Reader paramReader) {
   XmlPullParser localXmlPullParser = factory.newPullParser();
   if (paramReader != null) {
     localXmlPullParser.setInput(paramReader);
   }
   return new PullReader(localXmlPullParser);
 }
  @Override
  protected List<LineStatus> doInBackground(String[]... params) {
    try {
      URL url = new URL(this.url);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setReadTimeout(10000 /* milliseconds */);
      connection.setConnectTimeout(15000 /* milliseconds */);
      connection.setRequestMethod("GET");
      connection.setDoInput(true);
      connection.connect();
      InputStream stream = connection.getInputStream();

      xmlFactoryObject = XmlPullParserFactory.newInstance();
      XmlPullParser xpp = xmlFactoryObject.newPullParser();

      xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
      xpp.setInput(stream, null);

      // Parsing code
      List<LineStatus> result = parseXML(xpp);
      stream.close();

      return result;

    } catch (Exception e) {
      e.printStackTrace();
      Log.e("AsyncTask", "exception");
      return null;
    }
  }
 private static XmlPullParser buildParser(CharSequence contents) throws XmlPullParserException {
   XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   XmlPullParser xpp = factory.newPullParser();
   xpp.setInput(new StringReader(contents.toString()));
   return xpp;
 }
 public List<ControllerConfiguration> parse(InputStream is) throws RobotCoreException {
   this.parser = null;
   try {
     XmlPullParserFactory newInstance = XmlPullParserFactory.newInstance();
     newInstance.setNamespaceAware(true);
     this.parser = newInstance.newPullParser();
     this.parser.setInput(is, null);
     int next = this.parser.getEventType();
     while (next != XmlPullParser.END_DOCUMENT) {
       ConfigurationType type = getConfigurationType(this.parser.getName());
       if (next == XmlPullParser.START_TAG) {
         if (type == ConfigurationType.MOTOR_CONTROLLER) {
           this.controllerConfigurations.add(parseMotorController(true));
         }
         if (type == ConfigurationType.SERVO_CONTROLLER) {
           this.controllerConfigurations.add(parseServoController(true));
         }
         if (type == ConfigurationType.LEGACY_MODULE_CONTROLLER) {
           this.controllerConfigurations.add(parseLegacyModuleController());
         }
         if (type == ConfigurationType.DEVICE_INTERFACE_MODULE) {
           this.controllerConfigurations.add(parseDeviceInterfaceModule());
         }
       }
       next = this.parser.next();
     }
   } catch (XmlPullParserException e) {
     RobotLog.w("XmlPullParserException");
     e.printStackTrace();
   } catch (IOException e2) {
     RobotLog.w("IOException");
     e2.printStackTrace();
   }
   return this.controllerConfigurations;
 }
Exemple #10
0
 @Override
 public Subtitle parse(InputStream inputStream) throws IOException {
   try {
     XmlPullParser xmlParser = xmlParserFactory.newPullParser();
     Map<String, TtmlStyle> globalStyles = new HashMap<>();
     xmlParser.setInput(inputStream, null);
     TtmlSubtitle ttmlSubtitle = null;
     LinkedList<TtmlNode> nodeStack = new LinkedList<>();
     int unsupportedNodeDepth = 0;
     int eventType = xmlParser.getEventType();
     while (eventType != XmlPullParser.END_DOCUMENT) {
       TtmlNode parent = nodeStack.peekLast();
       if (unsupportedNodeDepth == 0) {
         String name = xmlParser.getName();
         if (eventType == XmlPullParser.START_TAG) {
           if (!isSupportedTag(name)) {
             Log.i(TAG, "Ignoring unsupported tag: " + xmlParser.getName());
             unsupportedNodeDepth++;
           } else if (TtmlNode.TAG_HEAD.equals(name)) {
             parseHeader(xmlParser, globalStyles);
           } else {
             try {
               TtmlNode node = parseNode(xmlParser, parent);
               nodeStack.addLast(node);
               if (parent != null) {
                 parent.addChild(node);
               }
             } catch (ParserException e) {
               if (strictParsing) {
                 throw e;
               } else {
                 Log.w(TAG, "Suppressing parser error", e);
                 // Treat the node (and by extension, all of its children) as unsupported.
                 unsupportedNodeDepth++;
               }
             }
           }
         } else if (eventType == XmlPullParser.TEXT) {
           parent.addChild(TtmlNode.buildTextNode(xmlParser.getText()));
         } else if (eventType == XmlPullParser.END_TAG) {
           if (xmlParser.getName().equals(TtmlNode.TAG_TT)) {
             ttmlSubtitle = new TtmlSubtitle(nodeStack.getLast(), globalStyles);
           }
           nodeStack.removeLast();
         }
       } else {
         if (eventType == XmlPullParser.START_TAG) {
           unsupportedNodeDepth++;
         } else if (eventType == XmlPullParser.END_TAG) {
           unsupportedNodeDepth--;
         }
       }
       xmlParser.next();
       eventType = xmlParser.getEventType();
     }
     return ttmlSubtitle;
   } catch (XmlPullParserException xppe) {
     throw new ParserException("Unable to parse source", xppe);
   }
 }
  public static Map<String, String> fetchValuesFromReponse(String response) {
    Map<String, String> responseValues = new HashMap<String, String>();
    try {

      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();

      xpp.setInput(new StringReader(response));
      int eventType = xpp.getEventType();
      String tag = null;
      String value = null;
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG && xpp.getName() != null) {
          tag = xpp.getName();
          eventType = xpp.next();
          value = xpp.getText();
          if (responseValues.keySet().contains(tag)) {
            value = responseValues.get(tag) + "##" + value;
          }
          responseValues.put(tag, value);
        } else {
          eventType = xpp.next();
        }
      }
    } catch (Exception anExcep) {
      anExcep.printStackTrace();
    }
    return responseValues;
  }
Exemple #12
0
  public static void main(String args[]) throws XmlPullParserException, IOException {

    XmlPullParserFactory factory =
        XmlPullParserFactory.newInstance(
            System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
    factory.setNamespaceAware(false);
    System.err.println("using factory " + factory.getClass());

    XmlPullParser xpp = factory.newPullParser();
    System.err.println("using parser " + xpp.getClass());

    XmlPullCount app = new XmlPullCount();

    app.verbose = true;
    for (int c = 0; c < 2; ++c) {
      System.err.println("run#" + c);
      app.resetCounters();
      if (args.length == 0) {
        System.err.println("Parsing simple sample XML length=" + SAMPLE_XML.length());
        xpp.setInput(new StringReader(SAMPLE_XML));
        app.countXml(xpp);
      } else {
        // r (int i = 0; i < args.length; i++) {

        File f = new File(args[0]);
        System.err.println("Parsing file: " + args[0] + " length=" + f.length());
        // xpp.setInput ( new FileReader ( args [0] ) );
        xpp.setInput(new FileInputStream(args[0]), "UTF8");
        app.countXml(xpp);
        //
      }
      app.printReport();
    }
    System.err.println("finished");
  }
 private void readXML() throws XmlPullParserException, IOException {
   String tagName = "";
   XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   XmlPullParser xpp = factory.newPullParser();
   try {
     InputStream in = openFileInput("settings.xml");
     InputStreamReader isr = new InputStreamReader(in);
     BufferedReader reader = new BufferedReader(isr);
     String str;
     StringBuffer buf = new StringBuffer();
     while ((str = reader.readLine()) != null) {
       buf.append(str);
     }
     in.close();
     xpp.setInput(new StringReader(buf.toString()));
     int eventType = xpp.getEventType();
     while (eventType != XmlPullParser.END_DOCUMENT) {
       if (eventType == XmlPullParser.START_DOCUMENT) {
       } else if (eventType == XmlPullParser.END_DOCUMENT) {
       } else if (eventType == XmlPullParser.START_TAG) {
         tagName = xpp.getName();
       } else if (eventType == XmlPullParser.END_TAG) {
       } else if (eventType == XmlPullParser.TEXT) {
         if (tagName.contains("sound_setting")) {
           soundEnabled = Boolean.parseBoolean(xpp.getText().toString());
         }
       }
       eventType = xpp.next();
     }
   } catch (Exception FileNotFoundException) {
     System.out.println("File Not Found");
   }
 }
Exemple #14
0
  public void testSetReader() throws Exception {
    XmlPullParser xpp = factory.newPullParser();
    assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));

    xpp.setInput(null);
    assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
    try {
      xpp.next();
      fail("exception was expected of next() if no input was set on parser");
    } catch (XmlPullParserException ex) {
    }

    // make input suspectible to read ...
    ReaderWrapper reader =
        new ReaderWrapper(
            new StringReader("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><foo/>"));
    assertEquals("no read() called in just contructed reader", false, reader.calledRead());

    xpp.setInput(reader);
    checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
    assertEquals("read() not called before next()", false, reader.calledRead());

    xpp.next();
    assertEquals("read() must be called after next()", true, reader.calledRead());
    checkParserStateNs(
        xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, true /*empty*/, 0);
  }
Exemple #15
0
  public static String getMediaUrl(String response) throws XmlPullParserException, IOException {

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser parser = factory.newPullParser();

    String result = null;

    parser.setInput(new StringReader(response));
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      String name = null;
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          break;
        case XmlPullParser.START_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("mediaurl")) {
            result = parser.nextText();
          }
          break;
        case XmlPullParser.END_TAG:
          break;
      }
      eventType = parser.next();
    }

    return result;
  }
Exemple #16
0
  /*
   * Parse 'content'
   *
   * Logs used to debug
   */
  public String parseThumbLink(String str) throws XmlPullParserException, IOException {
    String src = null;

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xpp = factory.newPullParser();

    xpp.setInput(new StringReader(str));
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_DOCUMENT) {
        // Log.d(logtag, "Start document");
      } else if (eventType == XmlPullParser.START_TAG) {
        // Log.d(logtag, "Start tag " + xpp.getName());
        if (xpp.getName().equals("img")) {
          src = xpp.getAttributeValue(null, "src");
          Log.d(logtag, "src: " + xpp.getAttributeValue(null, "src"));
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        // Log.d(logtag, "End tag " + xpp.getName());
      } else if (eventType == XmlPullParser.TEXT) {
        // Log.d(logtag, "Text " + xpp.getText());
      }
      eventType = xpp.next();
    }

    return src;
  }
Exemple #17
0
  public List<Bird> parseXML(Context context) {

    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();

      InputStream stream = context.getResources().openRawResource(com.example.birdnote.R.raw.birds);
      xpp.setInput(stream, null);

      int eventType = xpp.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          handleStartTag(xpp.getName());
        } else if (eventType == XmlPullParser.END_TAG) {
          currentTag = null;
        } else if (eventType == XmlPullParser.TEXT) {
          handleText(xpp.getText());
        }
        eventType = xpp.next();
      }

    } catch (NotFoundException e) {
      Log.d(LOGTAG, e.getMessage());
    } catch (XmlPullParserException e) {
      Log.d(LOGTAG, e.getMessage());
    } catch (IOException e) {
      Log.d(LOGTAG, e.getMessage());
    }

    return birds;
  }
Exemple #18
0
  /**
   * Convert XMPPIQ to XMPPBean to simplify the handling of the IQ using the beanPrototypes.
   *
   * @param iq the XMPPIQ
   * @return the related XMPPBean or null if something goes wrong
   */
  public XMPPBean convertXMPPIQToBean(XMPPIQ iq) {

    try {
      String childElement = iq.element;
      String namespace = iq.namespace;
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      XmlPullParser parser = factory.newPullParser();
      parser.setInput(new StringReader(iq.payload));
      XMPPBean bean = null;

      Log.v(
          TAG,
          "prototypes contains ns: "
              + namespace
              + "? "
              + this.beanPrototypes.containsKey(namespace));
      if (this.beanPrototypes.containsKey(namespace))
        Log.v(
            TAG,
            "prototypes contains ce: "
                + childElement
                + "? "
                + this.beanPrototypes.get(namespace).containsKey(childElement));

      synchronized (this.beanPrototypes) {
        if (namespace != null
            && this.beanPrototypes.containsKey(namespace)
            && this.beanPrototypes.get(namespace).containsKey(childElement)) {

          bean = (this.beanPrototypes.get(namespace).get(childElement)).clone();
          bean.fromXML(parser);

          bean.setId(iq.packetID);
          bean.setFrom(iq.from);
          bean.setTo(iq.to);

          switch (iq.type) {
            case XMPPIQ.TYPE_GET:
              bean.setType(XMPPBean.TYPE_GET);
              break;
            case XMPPIQ.TYPE_SET:
              bean.setType(XMPPBean.TYPE_SET);
              break;
            case XMPPIQ.TYPE_RESULT:
              bean.setType(XMPPBean.TYPE_RESULT);
              break;
            case XMPPIQ.TYPE_ERROR:
              bean.setType(XMPPBean.TYPE_ERROR);
              break;
          }

          return bean;
        }
      }
    } catch (Exception e) {
      Log.e(TAG, "ERROR while parsing XMPPIQ to XMPPBean: " + e.getMessage());
    }

    return null;
  }
    @Override
    protected Boolean doInBackground(Object... params) {
      boolean result = false;

      String pathToData = (String) params[0];
      table = (TableLayout) params[1];

      XmlPullParser data;
      try {
        Log.i("Comment", "Connecting to " + pathToData);

        URL xmlUrl = new URL(pathToData);
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        data = factory.newPullParser();
        data.setInput(xmlUrl.openStream(), null);
      } catch (XmlPullParserException e) {
        data = null;
        e.printStackTrace();
      } catch (IOException e) {
        data = null;
        e.printStackTrace();
      }

      if (data != null) {
        try {
          Log.i("Note", "Processing XML");
          processHistory(data);
        } catch (XmlPullParserException e) {
          Log.e("My Debug Tag", "Pull Parser failure", e);
        } catch (IOException e) {
          Log.e("My Debug Tag", "IO Exception parsing XML", e);
        }
      }
      return result;
    }
Exemple #20
0
  public static ArrayList<NewsData> getDataFromUrl(String urlString) {
    try {
      // configurating connection
      URL url = new URL(urlString);
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();

      conn.setReadTimeout(10000 /* milliseconds */);
      conn.setConnectTimeout(15000 /* milliseconds */);
      conn.setRequestMethod("GET");
      conn.setDoInput(true);

      // Starts the query
      conn.connect();
      InputStream stream = conn.getInputStream();

      XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
      XmlPullParser parser = xmlFactoryObject.newPullParser();

      parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
      parser.setInput(stream, null);

      // parsing data from response
      ArrayList<NewsData> newsDatas = parseNewsData(parser);

      stream.close();

      return newsDatas;
    } catch (Exception e) {
      return null;
    }
  }
    @Override
    protected void onPostExecute(String result) {
      try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(result));

        ArrayList<String> routeNumbers = XmlParser.getRouteNumbers(xpp);
        xpp.setInput(new StringReader(result)); // reset parser
        ArrayList<String> routeNames = XmlParser.getRouteNames(xpp);

        ArrayList<Map<String, String>> routes = new ArrayList<Map<String, String>>();
        for (int i = 0; i < routeNames.size(); i++) {
          Map<String, String> map = new HashMap<String, String>();
          map.put("routeNumber", routeNumbers.get(i));
          map.put("routeName", routeNames.get(i));
          routes.add(map);
        }

        listView = (ListView) getView().findViewById(R.id.busListView);
        adapter = new BusStopsAdapter(routes, getActivity());
        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(BusFragment.this);

        progressDialog.dismiss();
      } catch (XmlPullParserException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  // -----------------------------------------------------------------------------------
  private static String getXMLMessage(String msg)
      throws JSONException, XmlPullParserException, IOException {

    String xmlMessage = null;
    InputStream is = new ByteArrayInputStream(msg.getBytes());
    // Using Pull Parser
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xmlPullParser = factory.newPullParser();
    xmlPullParser.setInput(is, "UTF-8");

    // --------------------------------------------------------
    // Start Parsing XML Data
    // --------------------------------------------------------
    while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {

      if (xmlPullParser.getEventType() == XmlPullParser.START_TAG) {
        if (xmlPullParser.getName().equals("string")) {
          xmlPullParser.next();
          xmlMessage = xmlPullParser.getText();
          break;
        }
      }
    }

    return xmlMessage;
  }
  public List<Employee> parse(InputStream inputStream) {
    XmlPullParserFactory factory = null;
    XmlPullParser parser = null;

    try {
      factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      parser = factory.newPullParser();

      parser.setInput(inputStream, null);

      int eventType = parser.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagname = parser.getName();

        switch (eventType) {
          case XmlPullParser.START_TAG:
            if (tagname.equalsIgnoreCase("employee")) {
              // create a new instance of employess
              employee = new Employee();
            }
            break;

          case XmlPullParser.TEXT:
            text = parser.getText();
            break;

          case XmlPullParser.END_TAG:
            if (tagname.equalsIgnoreCase("employee")) {
              // add employee object to list
              employees.add(employee);
            } else if (tagname.equalsIgnoreCase("name")) {
              employee.setName(text);
            } else if (tagname.equalsIgnoreCase("id")) {
              employee.setId(Integer.parseInt(text));
            } else if (tagname.equalsIgnoreCase("department")) {
              employee.setDepartment(text);
            } else if (tagname.equalsIgnoreCase("email")) {
              employee.setEmail(text);
            } else if (tagname.equalsIgnoreCase("type")) {
              employee.setType(text);
            }
            break;

          default:
            break;
        }

        eventType = parser.next();
      }
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return employees;
  }
 /**
  * Allocate and initial an XmlPullParser
  *
  * <p>At the time this code was written the XmlPullParser did not support validation, so the call
  * to setValidating() is passed "false".
  */
 private XmlPullParser getParser() throws XmlPullParserException {
   XmlPullParserFactory factory;
   factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   factory.setValidating(false);
   XmlPullParser parser = factory.newPullParser();
   return parser;
 } // getParser
Exemple #25
0
  public MimeTypes fromXml(InputStream in) throws XmlPullParserException, IOException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

    mXpp = factory.newPullParser();
    mXpp.setInput(new InputStreamReader(in));

    return parse();
  }
 private XmlPullParser createXmlPullParser(BufferedInputStream bufferedInputStream)
     throws XmlPullParserException {
   if (PARSER_FACTORY == null) {
     throw new XmlPullParserException("XML Parser Factory has not been initialized properly");
   }
   XmlPullParser xmlPullParser = PARSER_FACTORY.newPullParser();
   xmlPullParser.setInput(bufferedInputStream, null);
   return xmlPullParser;
 }
  protected XmlPullParser buildXmlParser(String xml) throws XmlPullParserException {
    XmlPullParser xpp = null;

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    xpp = factory.newPullParser();
    xpp.setInput(new StringReader(xml));

    return xpp;
  }
  public boolean process() {
    boolean status = true;
    Application currentRecord = null;
    boolean inEntry = false;
    String textValue = "";

    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();
      xpp.setInput(new StringReader(this.xmlData));
      int eventType = xpp.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagName = xpp.getName();
        switch (eventType) {
          case XmlPullParser.START_TAG:
            // Log.d("ParseApplications", "Starting tag for " + tagName);
            if (tagName.equalsIgnoreCase("entry")) {
              inEntry = true;
              currentRecord = new Application();
            }
            break;

          case XmlPullParser.TEXT:
            textValue = xpp.getText();
            break;

          case XmlPullParser.END_TAG:
            // Log.d("ParseApplications", "Ending tag for " + tagName);
            if (inEntry) {
              if (tagName.equalsIgnoreCase("entry")) {
                applications.add(currentRecord);
                inEntry = false;
              } else if (tagName.equalsIgnoreCase("name")) {
                currentRecord.setName(textValue);
              } else if (tagName.equalsIgnoreCase("artist")) {
                currentRecord.setArtist(textValue);
              } else if (tagName.equalsIgnoreCase("releaseDate")) {
                currentRecord.setReleaseDate(textValue);
              }
            }
            break;

          default:
            // nothing else to do
        }
        eventType = xpp.next();
      }

    } catch (Exception e) {
      status = false;
      e.printStackTrace();
    }
    return true;
  }
Exemple #29
0
  private static XmlPullParser CreatePullParser(InputStream readerStream)
      throws XmlPullParserException {
    XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
    xppf.setNamespaceAware(false);

    XmlPullParser xpp = xppf.newPullParser();
    xpp.setInput(readerStream, null);

    return xpp;
  }
  @Override
  protected Map<String, EpisodeMetadata> doInBackground(Void... params) {
    // Create resulting data structure and file stream
    Map<String, EpisodeMetadata> result = new ConcurrentHashMap<>();
    InputStream fileStream = null;

    try {
      // 1. Build parser
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      // Create the parser to use
      XmlPullParser parser = factory.newPullParser();

      // 2. Open default podcast file
      fileStream = context.openFileInput(EpisodeManager.METADATA_FILENAME);
      parser.setInput(fileStream, StoreFileTask.FILE_ENCODING);

      // 3. Parse the OPML file
      int eventType = parser.next();

      // Read complete document
      while (eventType != XmlPullParser.END_DOCUMENT) {
        // We only need start tags here
        if (eventType == XmlPullParser.START_TAG) {
          String tagName = parser.getName();

          // Metadata found
          if (tagName.equalsIgnoreCase(METADATA)) {
            final String key = parser.getAttributeValue(null, EPISODE_URL);
            final EpisodeMetadata metadata = readMetadata(parser);

            result.put(key, metadata);
          }
        }

        // Done, get next parsing event
        eventType = parser.next();
      }

      // 4. Do some house keeping since file availability might have
      // changed
      cleanMetadata(result);
    } catch (Exception e) {
      // Pass, metadata might be empty, that's okay
    } finally {
      // Make sure we close the file stream
      if (fileStream != null)
        try {
          fileStream.close();
        } catch (IOException e) {
          // Nothing we can do here
        }
    }

    return result;
  }