Reading xml from rss feed
package com.example.nasadailyimage;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;
public class NasaDailyImage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nasa_daily_image);
IotdHandler handler = new IotdHandler();
System.out.println("handler object created");
Log.d("NasaDailyImage","handler object created");
new ConfigParser().execute();//here i have called execute on my
AsyncTaskclass
// handler.processFeed();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.nasa_daily_image, menu);
return true;
}
}
and my ConfigParser class
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.os.AsyncTask;
import android.util.Log;
public class ConfigParser extends AsyncTask<Void, Void,Void > {
private String url="http://www.nasa.gov/rss/dyn/image_of_the_day.rss";
@Override
protected Void doInBackground(Void... params) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
IotdHandler handler=new IotdHandler();
reader.setContentHandler(handler);
InputStream inputStream = new URL(url).openStream();
reader.parse(new InputSource(inputStream));
}
catch (Exception e)
{
Log.d("IotdHandler", "Exception");
e.printStackTrace();
}
return null;
}
}
and my IotdHandler Class
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
public class IotdHandler extends DefaultHandler {
private String url="http://www.nasa.gov/rss/dyn/image_of_the_day.rss";
private boolean inUrl = false;
private boolean inTitle = false;
private boolean inDescription = false;
private boolean inItem = false;
private boolean inDate = false;
private Bitmap image = null;
private String title = null;
private StringBuffer description = new StringBuffer();
private String date = null;
private String imageUrl;
private Bitmap getBitmap(String url) {
try {
HttpURLConnection connection = (HttpURLConnection)new
URL(url).openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
return bitmap;
}
catch (IOException ioe)
{ ioe.printStackTrace(); }
return null;
}
public void startElement(String uri, String localName, String
qName,Attributes attributes) throws SAXException {
if (localName.equals("enclosure"))
{ inUrl = true;
imageUrl=attributes.getValue("url");
System.out.println(imageUrl);
}
else { inUrl = false; }
if (localName.startsWith("item"))
{ inItem = true; }
else if (inItem) {
if (localName.equals("title"))
{ inTitle = true;
System.out.println("invtitle");}
else { inTitle = false; }
if (localName.equals("description"))
{ inDescription = true;
System.out.println("indiscription");}
else { inDescription = false; }
if (localName.equals("pubDate"))
{ inDate = true;
System.out.println("dtae");}
else { inDate = false; }
}
}
public void characters(char ch[], int start, int length) {
String chars = new String(ch).substring(start, start + length);
if (inUrl && url == null) { image = getBitmap(imageUrl); }
if (inTitle && title == null) { title = chars; }
if (inDescription) { description.append(chars); }
if (inDate && date == null) { date = chars; }
}
public Bitmap getImage() { return image; }
public String getTitle() { return title; }
public StringBuffer getDescription() { return description; }
public String getDate() { return date; }
}
So basically I want to get daily image updates from NASA, but in my
program everything is returning null I don't know what I am trying wrong,
my xml file is not parsing to avoid the NetworkOnMainTHread I have also
used Async class, any help.
Wednesday, 21 August 2013
Regex for matching anything after particular directory
Regex for matching anything after particular directory
I have a page set up on my wordpress install called /forum.
I want anything that comes after forum e.g. /forum/login.asp?helloworld=hi
etc to be put as a query string to forum so it goes to the forum page and
I can obtain this 'login.asp?helloworld=hi' as a variable.
I've created a rule on my IIS server which is above the default wordpress
rule.
I used this regex:
/forum/(.*)$
to rewrite to this /forum/?test={R:1}
and made it so it stops processing any other rules if we get a match.
All I seem to get is the Wordpress 404 page. Im absolutely useless at
redirects/rewrites/regex etc so any help would be awesome!
I have a page set up on my wordpress install called /forum.
I want anything that comes after forum e.g. /forum/login.asp?helloworld=hi
etc to be put as a query string to forum so it goes to the forum page and
I can obtain this 'login.asp?helloworld=hi' as a variable.
I've created a rule on my IIS server which is above the default wordpress
rule.
I used this regex:
/forum/(.*)$
to rewrite to this /forum/?test={R:1}
and made it so it stops processing any other rules if we get a match.
All I seem to get is the Wordpress 404 page. Im absolutely useless at
redirects/rewrites/regex etc so any help would be awesome!
how to modify date format in wordpress list comments
how to modify date format in wordpress list comments
I want to modify my comments list detail date showing replay button and
etc in my wordpress theme i saw this code and i use it but i need to
modify the date format and the lable and titles and etc i use this code
<?php /*----------------------------------- Template for Comments
---------------------------------------*/ ?>
<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="text-error"><?php _e( 'This post is password protected.
Enter the password to view any comments.', 'cusmagazines' ); ?></p>
</div>
<?php
return;
endif;
?>
<?php if ( have_comments() ) : ?>
<h2 id="comments-title">
<?php
printf( _n( 'One Comment', '%1$s Comments',
get_comments_number(), 'cusmagazines' ), number_format_i18n(
get_comments_number() ) );
?>
<a class="goto goto-respond" href="#respond" title="Add Your
Comment">( Add Comment )</a>
</h2>
<?php if ( get_comment_pages_count() > 1 && get_option(
'page_comments' ) ) : ?>
<div id="comment-nav-above">
<h1 class="assistive-text"><?php _e( 'Comment navigation',
'cusmagazines' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __(
'← Older Comments', 'cusmagazines' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer
Comments →', 'cusmagazines' ) ); ?></div>
</div>
<?php endif; ?>
<div class="commentlist">
<?php
$args = array(
'walker' => null,
'max_depth' => 3,
'style' => 'div',
'callback' => 'custhemes_comment',
'end-callback' => null,
'type' => 'all',
'page' => null,
'per_page' => null,
'avatar_size' => 45,
'reverse_top_level' => null,
'reverse_children' => null );
wp_list_comments($args);
?>
</div>
<?php if ( get_comment_pages_count() > 1 && get_option(
'page_comments' ) ) : ?>
<div id="comment-nav-below">
<h1 class="assistive-text"><?php _e( 'Comment navigation',
'cusmagazines' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __(
'← Older Comments', 'cusmagazines' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer
Comments →', 'cusmagazines' ) ); ?></div>
</div>
<?php endif; ?>
<?php
elseif ( ! comments_open() && ! is_page() && post_type_supports(
get_post_type(), 'comments' ) ) :
?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'cusmagazines'
); ?></p>
<?php endif; ?>
and i add this code to function.php
<?php function custhemes_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] )
? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment,
$args['avatar_size'] ); ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is
awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata">
<?php printf(__('<span class="author-name">%s</span>'),
get_comment_author_link()); ?>
<a href="<?php echo htmlspecialchars( get_comment_link(
$comment->comment_ID ) ) ?>">
<?php printf( __('%1$s - %2$s'), get_comment_date('d.m.Y'),
get_comment_time()); ?>
</a>
<?php edit_comment_link(__('(Edit)'),' ','' );
?>
</div>
<div class="comment-text"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' =>
$add_below, 'depth' => $depth, 'max_depth' =>
$args['max_depth']))) ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php } ?>
now i need to modify date format and the lable of the comments how can i
do that
I want to modify my comments list detail date showing replay button and
etc in my wordpress theme i saw this code and i use it but i need to
modify the date format and the lable and titles and etc i use this code
<?php /*----------------------------------- Template for Comments
---------------------------------------*/ ?>
<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="text-error"><?php _e( 'This post is password protected.
Enter the password to view any comments.', 'cusmagazines' ); ?></p>
</div>
<?php
return;
endif;
?>
<?php if ( have_comments() ) : ?>
<h2 id="comments-title">
<?php
printf( _n( 'One Comment', '%1$s Comments',
get_comments_number(), 'cusmagazines' ), number_format_i18n(
get_comments_number() ) );
?>
<a class="goto goto-respond" href="#respond" title="Add Your
Comment">( Add Comment )</a>
</h2>
<?php if ( get_comment_pages_count() > 1 && get_option(
'page_comments' ) ) : ?>
<div id="comment-nav-above">
<h1 class="assistive-text"><?php _e( 'Comment navigation',
'cusmagazines' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __(
'← Older Comments', 'cusmagazines' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer
Comments →', 'cusmagazines' ) ); ?></div>
</div>
<?php endif; ?>
<div class="commentlist">
<?php
$args = array(
'walker' => null,
'max_depth' => 3,
'style' => 'div',
'callback' => 'custhemes_comment',
'end-callback' => null,
'type' => 'all',
'page' => null,
'per_page' => null,
'avatar_size' => 45,
'reverse_top_level' => null,
'reverse_children' => null );
wp_list_comments($args);
?>
</div>
<?php if ( get_comment_pages_count() > 1 && get_option(
'page_comments' ) ) : ?>
<div id="comment-nav-below">
<h1 class="assistive-text"><?php _e( 'Comment navigation',
'cusmagazines' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __(
'← Older Comments', 'cusmagazines' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer
Comments →', 'cusmagazines' ) ); ?></div>
</div>
<?php endif; ?>
<?php
elseif ( ! comments_open() && ! is_page() && post_type_supports(
get_post_type(), 'comments' ) ) :
?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'cusmagazines'
); ?></p>
<?php endif; ?>
and i add this code to function.php
<?php function custhemes_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] )
? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment,
$args['avatar_size'] ); ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is
awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata">
<?php printf(__('<span class="author-name">%s</span>'),
get_comment_author_link()); ?>
<a href="<?php echo htmlspecialchars( get_comment_link(
$comment->comment_ID ) ) ?>">
<?php printf( __('%1$s - %2$s'), get_comment_date('d.m.Y'),
get_comment_time()); ?>
</a>
<?php edit_comment_link(__('(Edit)'),' ','' );
?>
</div>
<div class="comment-text"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' =>
$add_below, 'depth' => $depth, 'max_depth' =>
$args['max_depth']))) ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php } ?>
now i need to modify date format and the lable of the comments how can i
do that
Tuesday, 20 August 2013
how to use variable with the String in Python
how to use variable with the String in Python
I want to include file name 'main.txt' in the subject for that I am
passing file name from command line. but getting error in doing so
python sample.py main.txt #running python with argument
msg['Subject'] = "Auto Hella Restart Report "sys.argv[1] #line where i am
using that passed argument
I want to include file name 'main.txt' in the subject for that I am
passing file name from command line. but getting error in doing so
python sample.py main.txt #running python with argument
msg['Subject'] = "Auto Hella Restart Report "sys.argv[1] #line where i am
using that passed argument
How can I let my clients subdomain my Ruby On Rails / Heroku app?
How can I let my clients subdomain my Ruby On Rails / Heroku app?
I have an app that I want my clients to be able to subdomain. Right now it
works like this
www.mydomain.com/clientname/
www.mydomain.com/clientname/page1
www.mydomain.com/clientname/page2
How can I structure the app so that my clients can subdomain it like:
dashboard.client1.com -> www.mydomain.com/clientname/
dashboard.client1.com/page1 -> www.mydomain.com/clientname/page1
etc
Can I use wildcard subdomains?
I can't figure out the terminology for what I want to do, but any
references you can provide would be helpful!
I have an app that I want my clients to be able to subdomain. Right now it
works like this
www.mydomain.com/clientname/
www.mydomain.com/clientname/page1
www.mydomain.com/clientname/page2
How can I structure the app so that my clients can subdomain it like:
dashboard.client1.com -> www.mydomain.com/clientname/
dashboard.client1.com/page1 -> www.mydomain.com/clientname/page1
etc
Can I use wildcard subdomains?
I can't figure out the terminology for what I want to do, but any
references you can provide would be helpful!
Efficient strategy to creative a UIView which is the size of device's screen
Efficient strategy to creative a UIView which is the size of device's screen
Context
I'm creating a UIView to act as the "container view" (let's call it
containerView) for a UIScrollView, this UIScrollView will then house a
UIWebView. See this question for more context. Matching subview's width to
it's superview using autolayout
Goal
Have the containerView, when created, be "full screen", i.e. take up the
whole screen. I can then tie the containerView's size, through auto-layout
constraints to the UIWebView and make the UIWebView, be full width of the
screen.
Questions
What is the best strategy for this? Using [[UIScreen mainScreen]
applicationFrame];
Context
I'm creating a UIView to act as the "container view" (let's call it
containerView) for a UIScrollView, this UIScrollView will then house a
UIWebView. See this question for more context. Matching subview's width to
it's superview using autolayout
Goal
Have the containerView, when created, be "full screen", i.e. take up the
whole screen. I can then tie the containerView's size, through auto-layout
constraints to the UIWebView and make the UIWebView, be full width of the
screen.
Questions
What is the best strategy for this? Using [[UIScreen mainScreen]
applicationFrame];
Refactoring fat controllers and handling validation and logging in the service layer
Refactoring fat controllers and handling validation and logging in the
service layer
I currently have an application which suffers from Fat Controllers. I am
trying to pull out the business logic into a service layer and am hoping
to clarify my approach.
For raising Model errors I had planned on using an approach like described
here:
http://www.asp.net/mvc/tutorials/older-versions/models-%28data%29/validating-with-a-service-layer-cs
- about 1/2 of the way down using the IValidationDictionary approach.
But I see this approach is not discussed in newer versions of the
documentation. The validation in the service layer section is completely
removed in the newer versions.
I hope that is enough context for the following questions / validation of
my approach:
I believe that the approach in the link above is outdated and should not
be used in favor of DataAnnotations (and overriding possibly overriding
IsValid - this may be naive, I don't fully understand the workflow of
validating the ModelState.IsValid yet). Am I understanding correctly or
are these somewhat separate concerns?
I would expect to have a mix of strongly typed views to both Entities (on
simple forms that have a 1-1 mapping of fields to the entity) and DTO's
(on forms with a less simple mapping to entities). Is it possible to have
the entity validations bubble up to the DTO's to avoid duplicating
non-business requirement validations? On entity's which could be strongly
typed without a DTO should I be including business logic validations on
the entity (this seems wrong)? Am I even thinking about/approaching this
correctly?
The site is using a repository approach - can I skip the service layer and
have my business logic spread across data annotations and the repository?
Again am I asking the right question?
service layer
I currently have an application which suffers from Fat Controllers. I am
trying to pull out the business logic into a service layer and am hoping
to clarify my approach.
For raising Model errors I had planned on using an approach like described
here:
http://www.asp.net/mvc/tutorials/older-versions/models-%28data%29/validating-with-a-service-layer-cs
- about 1/2 of the way down using the IValidationDictionary approach.
But I see this approach is not discussed in newer versions of the
documentation. The validation in the service layer section is completely
removed in the newer versions.
I hope that is enough context for the following questions / validation of
my approach:
I believe that the approach in the link above is outdated and should not
be used in favor of DataAnnotations (and overriding possibly overriding
IsValid - this may be naive, I don't fully understand the workflow of
validating the ModelState.IsValid yet). Am I understanding correctly or
are these somewhat separate concerns?
I would expect to have a mix of strongly typed views to both Entities (on
simple forms that have a 1-1 mapping of fields to the entity) and DTO's
(on forms with a less simple mapping to entities). Is it possible to have
the entity validations bubble up to the DTO's to avoid duplicating
non-business requirement validations? On entity's which could be strongly
typed without a DTO should I be including business logic validations on
the entity (this seems wrong)? Am I even thinking about/approaching this
correctly?
The site is using a repository approach - can I skip the service layer and
have my business logic spread across data annotations and the repository?
Again am I asking the right question?
Subscribe to:
Posts (Atom)