apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinmaykolhatkar <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: Files for the twitter demos an...
Date Thu, 24 Dec 2015 11:27:22 GMT
Github user chinmaykolhatkar commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/146#discussion_r48410709
  
    --- Diff: demos/twitter/src/main/java/com/datatorrent/demos/twitter/TwitterURLExtractorWithFilter.java
---
    @@ -0,0 +1,108 @@
    +/**
    + * 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 java.io.BufferedReader;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +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;
    +
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.common.util.BaseOperator;
    +
    +import twitter4j.Status;
    +import twitter4j.URLEntity;
    +
    +/**
    + * <p>
    + * TwitterStatusURLExtractorWithFilter class.
    + * </p>
    + *
    + * @since 0.3.2
    + */
    +public class TwitterURLExtractorWithFilter extends BaseOperator
    +{
    +
    +  protected List<String> myList = new ArrayList<String>();
    +  BufferedReader in;
    +
    +  public final transient DefaultOutputPort<String> url = new DefaultOutputPort<String>();
    +  public final transient DefaultInputPort<Status> input = new DefaultInputPort<Status>()
    +  {
    +    @Override
    +    public void process(Status status)
    +    {
    +      if (myList.isEmpty()) {
    +        try {
    +          DocumentBuilderFactory dbFactory = DocumentBuilderFactory
    +              .newInstance();
    +          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    +          InputStream is = this.getClass().getClassLoader()
    +              .getResourceAsStream("domainlist.xml");
    +          Document doc = dBuilder.parse(is);
    +          doc.getDocumentElement().normalize();
    +          NodeList nList = doc.getElementsByTagName("sub");
    +
    +          for (int temp = 0; temp < nList.getLength(); temp++) {
    --- End diff --
    
    Is there a chance that nList can be null? What happens then?


---
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.
---

Mime
View raw message