You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apex.apache.org by NithinPerumal <gi...@git.apache.org> on 2015/12/31 02:15:35 UTC

[GitHub] incubator-apex-malhar pull request: Committing files for additiona...

GitHub user NithinPerumal opened a pull request:

    https://github.com/apache/incubator-apex-malhar/pull/153

    Committing files for additional twitter operators and the RSS parser

    In this commit I have included the necessary JSON files and XML files to make my code work.  All applications were tested on the Sandbox through the Eclipse IDE and they compile + run successfully.  The XML and JSON files are contained in the resource folders, the testing files are in the testing folder and the main folder has the Twitter Demos + RSS parsing.  
    
    I have modified and improved the code as per the feedback provided from my last pull request (Some heavy editing to the RSS reading).  The extraneous operators have also been located and removed.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/NithinPerumal/incubator-apex-malhar devel-3

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-apex-malhar/pull/153.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #153
    
----
commit 90f4b69c2ee006a43ee0e9898511d27920231cb4
Author: NithinPerumal <pe...@rose-hulman.edu>
Date:   2015-12-31T00:59:45Z

    Modified TwitterSampleInput to support new operations

commit 2664e6eacd7117e66ef24e276575987ef78efa10
Author: NithinPerumal <pe...@rose-hulman.edu>
Date:   2015-12-31T01:05:21Z

    Committing files for the RSS feed parser as well as addtional Twitter Applications.  I have also included the necessary JSON and XML files needed to run these and make these work

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: Committing files for additiona...

Posted by gauravgopi123 <gi...@git.apache.org>.
Github user gauravgopi123 commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/153#discussion_r48765084
  
    --- Diff: demos/twitter/src/main/java/com/datatorrent/demos/twitter/RSSFeedExtractor.java ---
    @@ -0,0 +1,133 @@
    +/**
    + * Copyright (C) 2015 DataTorrent, Inc.
    + *
    + * Licensed under the Apache License, Version 2.0 (the "License");
    + * you may not use this file except in compliance with the License.
    + * You may obtain a copy of the License at
    + *
    + *         http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package com.datatorrent.demos.twitter;
    +
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.InputOperator;
    +
    +import java.io.BufferedReader;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.net.URL;
    +
    +import javax.xml.parsers.DocumentBuilder;
    +import javax.xml.parsers.DocumentBuilderFactory;
    +import javax.xml.parsers.ParserConfigurationException;
    +
    +import org.w3c.dom.Document;
    +import org.w3c.dom.Element;
    +import org.w3c.dom.Node;
    +import org.w3c.dom.NodeList;
    +import org.xml.sax.SAXException;
    +
    +/**
    + * <p>
    + * RSSFeedExtractor class.
    + * </p>
    + *
    + * @since 3.3.2
    + */
    +public class RSSFeedExtractor implements InputOperator
    +{
    +  protected String URLToConvert = "";
    +  protected BufferedReader in;
    +  URL rssURL;
    +  DocumentBuilderFactory dbFactory;
    +  DocumentBuilder dBuilder;
    +  public final transient DefaultOutputPort<String> output = new DefaultOutputPort<String>();
    +  DocumentBuilderFactory URLdbFactory;
    +  DocumentBuilder URLdBuilder;
    +  
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +
    +  }
    +
    +  @Override
    +  public void endWindow()
    +  {
    +
    +  }
    +
    +  @Override
    +  public void setup(OperatorContext context)
    +  {
    +    try {
    +      dbFactory = DocumentBuilderFactory.newInstance();
    +      dBuilder = dbFactory.newDocumentBuilder();
    +      InputStream is = this.getClass().getClassLoader()
    +          .getResourceAsStream("RSS.xml");
    +      Document doc = null;
    +      try {
    +        doc = dBuilder.parse(is);
    +      } catch (SAXException e) {
    +        throw new RuntimeException("SAX Exception", e);
    +      }
    +
    +      doc.getDocumentElement().normalize();
    +
    +      NodeList nList = doc.getElementsByTagName("sub");
    +      for (int index = 0; index < nList.getLength(); index++) {
    +        Node nNode = nList.item(index);
    +        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
    +          Element eElement = (Element) nNode;
    +          URLToConvert = eElement.getElementsByTagName("value").item(0)
    +              .getTextContent();
    +        }
    +      }
    +    } catch (ParserConfigurationException e) {
    +      throw new RuntimeException("Parser Configuration Exception", e);
    +
    +    } catch (IOException e) {
    +      throw new RuntimeException("Runtime Exception", e);
    +    }
    +  }
    +
    +  @Override
    +  public void teardown()
    +  {
    +
    +  }
    +  
    +  @Override
    +  public void emitTuples()
    +  {
    +      URLdbFactory = DocumentBuilderFactory.newInstance();
    +      try {
    +		URLdBuilder = URLdbFactory.newDocumentBuilder();
    +		Document page = URLdBuilder.parse(URLToConvert);
    +		NodeList itemList = page.getElementsByTagName("item");
    +		for (int i = 0; i < itemList.getLength(); i++){
    +		  Node it = itemList.item(i);
    +		  NodeList tagList = it.getChildNodes();
    +		  for (int j = 0; j < tagList.getLength(); j++) {
    +			  if (j % 2 != 0) {
    +				String tagName = tagList.item(j).getNodeName().toUpperCase();
    +				String tagValue = tagList.item(j).getTextContent();
    +			    System.out.println(tagName + " : " + tagValue);
    +			  }
    +		  }
    +		  System.out.println();
    +		  System.out.println("-----------------------------------");
    +		  System.out.println();
    +	    }
    --- End diff --
    
    Instead of System.out.println please use logger


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: Committing files for additiona...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-apex-malhar/pull/153


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---