CS代写 PST 2006 –>

Computer Science 571 2nd Exam Prof. , April 24, 2012, 5:30pm – 6:40pm
Name: Student ID Number:
1. This is a closed book exam.
2. Please answer all questions on the test

Copyright By PowCoder代写 加微信 powcoder

JavaScript and Ajax Questions [20 pts]
Below is the HTML source code that produces the web page above. There is one edit box, and when each character is typed, a list appears that shows the “suggested” valid answers, obtained from the XML file us-states.xml.

My Fifth Ajax Script

Please enter your state:

Below is the JavaScript source code, script05.js, that was imported into the HTML above, but some of the lines are missing, replaced by XXXXXXXs. Fill in the missing.
window.onload = initAll;
var xhr = false;
var statesArray = new Array();
function initAll() {
document.getElementById(“searchField”).onkeyup = searchSuggest;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
if (xhr) {
xhr.onreadystatechange = setStatesArray; xhr.open(“GET”, “us-states.xml”, true); xhr.send(null);
alert(“Sorry, but I couldn’t create an XMLHttpRequest”); }
function setStatesArray() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
if (xhr.responseXML) {
var allStates = xhr.responseXML.getElementsByTagName(“item”);
for (var i=0; i


Oregano’s Wood-Fired Pizza

4546 Real, #A6
Los Altos
CA
(650) 941-3600 37.401434 -122.114407
4.5 11 11
1326963606 This place is great.

1.19
http://local.yahoo.com/info-21300761- oregano-s-woodfired-pizza-los-altos

When the “output=json”, a JSON response is returned. Please fill in the missing code:
{“ResultSet”: {“Result”:
{“id”:”21300761″,
“Title”:”Oregano’s Wood-Fired Pizza”, “Address”:”4546 Real, #A6″, “City”:”Los Altos”,
“State”:”CA”,
“Phone”:”(650) 941-3600″, “Latitude”:”37.401434″, “Longitude”:”-122.114407″, “Rating”:

{“AverageRating”:”4.5″,
“TotalRatings”:”11″,
“TotalReviews”:”11″, “LastReviewDate”:”1326963606″, “LastReviewIntro”:”This place is great.”}, “Distance”:”1.19″, “Url”:”http:\/\/local.yahoo.com\/info-21300761-
oregano-s-woodfired-pizza-los-altos”, }
XML Schema Question [20 pts]
The Yahoo Maps Simple API includes an “Annotation API” that allows to annotate the maps. The XML Schema for this API, AnnotatedMaps.xsd, includes the following fields, with the noted descriptions (Note: the third through the last field are “item” sub-elements):
Description
Allows grouping of some icons to form a legend at the top of the map. It may enclose an arbitrary number of Group entities. It has one attribute:
• defaultViewNumbered (Boolean). If set to true, the icons on the group legend will be numbered unless overridden by a BaseIcon definition.
Specifies a group as part of the ymaps:Groups. It has two required sub-elements:
• title (string): A title for this group, to be shown in the legend.
• id (string): an id string to allow this group to be referred to in item elements (which may then use the
group icon if one is specified).
There are also three optional sub-elements. These tags serve the same purpose as the ones below, and full documentation may be found there:
• ymaps:BaseIcon (string).
• ymaps:HoverIcon (string).
• ymaps:PopupIcon (string).
(string): The street address of the location. Anything Yahoo! Maps is able to recognize as a valid address can be used here.
PhoneNumber
(string): The phone number for the location, for display in the popup information box.
integer (1-10): The zoom level for the map. Some common zoom levels:
• 2: street level
• 4: city level
• 8: state level
(string): city and state/province of the location.
(integer or ): The five-digit ZIP code, or the five-digit code plus four-digit extension of the location.
BaseIcon, HoverIcon,
(string): A URL to a GIF file

(string): The text for an additional link to be put into the popup information box. Has attributes: • href: The URL that this link should point to.
An item may contain multiple instances of this tag.
ExtraImage
(enclosing tag): Specifies an image file for display in the popup information box. It has two required sub- elements:
• url (string): The URL of the image file.
• title (string): alt text for the image.
There is also an optional sub-element:
• link (string): a URL to specify where the image should link if clicked.
An item may contain multiple instances of this tag.
(string): A URL pointing to html content that should be displayed in an IFRAME inside the popup information box. Only one ItemUrl may be used per item.
The following is a sample XML file returned by using the Yahoo Maps Simple API and that uses the AnnotatedMaps.xsd schema:


Sample XML file Sample result
Fry’s frys

Home Depot homedepot


5
Fry’s Palo Alto Palo Alto Store 340 Portage Ave Palo Alto, CA frys
Fry’s Online


Shop

HomeDepot Campbell Campbell Store 480 E Hamilton Ave Cambell, CA homedepot

Complete the XML Schema that corresponds to the above description and sample. Fill in the missing parts.




name = “Id” type = “xsd:string”/>
name = “BaseIcon” type = “xsd:anyURI”/>
name = “defaultViewNumbered”
type = “xsd:boolean”/>









“Zip” type = “xsd:string”/>
“BaseIcon” type = “xsd:anyURI”/> “PopupIcon” type = “xsd:anyURI”/> “HoverIcon” type = “xsd:anyURI”/>
“ExtraLink”>

















Alternative solution for “ExtraImage”:




Java Servlet Questions [20 pts]

Below is snapshot of a web page that includes a text box and a button labeled Google Search. When a query is entered and the button clicked, a Java Servlet is called that accepts the query and sends it to Google to produce the results.
Below is part of the servlet.
import GoogleSearch.*; import java.io.*;
import java.util.*;
import javax.servlet.*; import javax.servlet.http.*; import java.lang.Object.*;
public final class GoogleAxis extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType(“text/html;charset=UTF-8”); PrintWriter writer = response.getWriter();
writer.println(““);
writer.println(““);
writer.println(“Jinwoo CSCI 571 hw10 advance search“); writer.println(““);
writer.println(““);
GoogleSearchService gss = new GoogleSearchServiceLocator();
GoogleSearchPort port = gss.getGoogleSearchPort(); String key = “Y8YBfK9QFHIX+7XzAnHS7w7OkCLig1+K”; String query=request.getParameter(“q”);

String url_ =””;
boolean filter = false; boolean safeSearch = false; boolean cache=false;
if (request.getParameter(“cache”) != null && request.getParameter(“cache”).equals(“true”))
cache=true;
writer.println(“
THIS IS CACHED PAGE FROM
GOOGLE
“)
if (request.getParameter(“url”) != null) {
url_=request.getParameter(“url”); }
if(cache==true) {
byte [] cachedBytes = port.doGetCachedPage(key,url_); String cachedString = new String(cachedBytes);
writer.println(cachedString); }
else if (cache==false)
GoogleSearchResult result = port.doGoogleSearch(key,
query, start, maxResults, filter, restrict, safeSearch, lr, ie, oe);
writer.println(“

Google Search Results for

” + query + “
“);
int eTRC = result.getEstimatedTotalResultsCount();
ResultElement[] resultElements = result.getResultElements();
RESULT

“);
//for title & hyperlink
writer.println(“Total Results Number: “+eTRC); if(eTRC==0) writer.println(“

NO SEARCH
else if(eTRC!=0)
for (int i=0; i< maxResults; i++){ writer.println("

” +
resultElements[i].getTitle() + “

“); writer.println(resultElements[i].getSnippet());
//Cached size
writer.println(“
“+resultElements[i].getURL()+” – Cached Size: ” +
resultElements[i].getCachedSize());

//Cached site link String k
=”&q=cache&btnG=Advanced+Google+Search&lan=+&maxresult=10&filter=true”; writer.println( “Cached“);
//making related to url String
o_url=resultElements[i].getURL().substring(resultElements[i].getURL().lastIn dexOf(“:”)+3).trim();
String a=”Similar pages“;
writer.println(a);
} catch (java.rmi.RemoteException e) { System.out.println(e); }
} catch (javax.xml.rpc.ServiceException e) { System.out.println(e); }
writer.println(““); writer.println(““); } // end doGet
} // end HttpServlet
[20 pts] The above Java servlet makes use of the Google API for accessing web search results from a program. List all of the Google provided functions and for each one provide a short explanation of the input arguments and the output for each function you identify.
GoogleSearchServiceLocator – create an object of type GoogleSearchService
getGoogleSearchPort – creates an object of type GoogleSearchPort, the basis of all the remaining Google Search APIs
doGetCachedPage(key,url_) – invokes a search for cached pages with given keyword and URL
doGoogleSearch(key, query, start, maxResults, filter, restrict, safeSearch, lr, ie, oe) – the basic google search with all the parameters available in Google Advanced search page, returns an object with all results
getEstimatedTotalResultsCount() – returns the estimated count of total results

getResultElements() – return an array of all results getURL – for a given result returns the URL getCachedSize()) – for a given result returns the cache size getTitle() – for a given result returns the website title getSnippet() – for a given result returns the site summary
Web Performance Questions [10 pts]
List any 5 recent rules (not the initial 14 rules) for faster Web pages from Yahoo‘s YSlow that help speed up web performance.
Avoid empty src or href
Use get for AJAX requests
Reduce number of DOM elements
Avoid HTTP 404 (not found) Error
Reduce cookie size
Use cookie-free domain
Do not scale images in HTML
Make favicon small and cacheable
HTML5 Questions [10 pts]
Each question is worth 2 points.
Q1: The use of the

tag has been replaced by a number of new semantic elements included in HTML5. Name two of them
A1: Any 2 of header, footer, section, article, nav, aside
Q2: Which of the following capabilities have included in HTML5?
[ ] drag file in browser
[ ] interactive canvas gradient [ ] editable content

[ ] geolocation
[ ] drag and drop
[ ] storage
[ ] ALL OF THE ABOVE
Q3: What is the purpose of the different “profiles” included in the H. 264 video standard?
A3: each profile defines a set of optional features that trade complexity for file size. Q4: What is the meaning of the “preload” video attribute?
A4: specifies that the video will be loaded at page load and ready to run.
Q5: Name two popular audio codecs?
A5: mp3, aac, vorbis JSON/AJAX Questions [10 pts]
Each is worth 2 points.
Q1: Which of the following calls to send() is invalid? Circle your answer.
b. send(null)
c. send(“x=1&y=2”)
Q2: What is the problem with mashups?
mashups are insecure
Q3: What are the 4 basic technologies in AJAX?
HTML, CSS, JavaScript, and XML (or JSON)
Q4: Which readyState and status combination should check for to know that an asynchronous request is complete? Circle your answer.
a. 3 and 304
b. 2 and 200

c. 4 and 200
d. 5 and 404
Q5: List 3 properties of JSON
– Subset of ECMA-232 Third Edition – Language independent
– text-based
– light-weight
– Easy to parse
– Not a document format
– Not a markup language
– Not a serialization format

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com