Jump to content

awitt

Members
  • Content Count

    62
  • Joined

  • Last visited

Community Reputation

0 Neutral

About awitt

  • Rank
    Newbie
  • Birthday 02/19/1986

Previous Fields

  • Languages
    Javascript, XML, Java, VB, C++, C#, *.NET, T-SQL

Contact Methods

  • MSN
    awitt@dispatch.com
  • Website URL
    http://www.dispatch.com
  • ICQ
    0

Profile Information

  • Location
    Columbus, OH
  1. Hey Guys, I'm designing an online store. I'm using struts to maintain an MVC-type architecture, but I do not think that should have too much an impact on my issues here. So, when you're shoping online, and you click 'Add to Cart' or whatever, and alot of times it brings you to your cart page and shows the stuff. Well, I made a cart widget that sits in the corner, so that, at least until checkout, you don't need to go to a seperate cart page. So the problem here is that when you click add-to-cart, I want that exact same page to reload, with whatever request paramaters it had before (if there was a search, maintain the searched state, or the page number of the results you were viewing, etc.). So here's some code: log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Entered AddToCart\n" ); log.flush(); long id = Long.parseLong( request.getParameter("prodID") ); log.append( "\tProductID to Add: " + id + "\n" ); log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Adding Product to Cart (action class)\n" ); log.flush(); addProduct(id, cart, quantity, log); log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Added Product to Cart (action class)\n" ); log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Putting Cart in Session Object\n" ); log.flush(); session.setAttribute("cart", cart); session.setAttribute("quantity", quantity); log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Cart put in Session Object\n" ); log.flush(); log.append(LogDate.formatDate(Calendar.getInstance()) + " -- Writing Session Data (addtocart)...\n"); writeSessionData(cart, quantity, log, session); log.append(LogDate.formatDate(Calendar.getInstance()) + " -- ...Session Data Written! (addtocart)\n"); String queryString = request.getParameter("sendBackURL"); log.append( "\tQUERYSTRING (sendBackURL) from REQUEST: " + queryString + "\n" ); if ( queryString != null ) { RequestDispatcher dispatcher = request.getRequestDispatcher(ShoppingConstants.homePath + "?" + queryString); log.append( "\tdispatcher.toString(): " + dispatcher.toString() + "\n" ); if (dispatcher != null) {dispatcher.forward(request, response);} } forwardString = "add"; homePath = "shop/shop.do" - it's in a config file of sortsSo, you can see that I do grab the query string successfully, and it gets to the action class, but if you try to use that action, and it tries to dispatch the request to that site, I get an error: The requested resource (Invalid path was requested) is not available. And that's going to be because it maintains both URLs. Here's where it tries to go when the link is clicked:dispatch-eCommerce/shop/shop.do?action=addtocart&prodID=2006&sendBackURL=action=search&d-4929346-p=2&searchWord=ttThe bold is what I want the query string to be - that's it. Once it adds the product to the cart, I don't need to know the 'addtocart' action or the product ID. But, there it is. Is there a way I can modify the code so that when it dispatches, it sends the request to this address?:dispatch-eCommerce/shop/shop.do?action=search&d-4929346-p=2&searchWord=tt
  2. Hey Guys, I'm building a table using Java on a JSP, and I have a portion of the table that I want to either hide or display, depending on if a box is checked or not (it's the old is-your-shipping-address-the-same-as-your-billing checkbox from a checkout page). Here's the JS function that gets called when the box is clicked. <span id="shippingInfo"> <tr> <td colspan="2"><br /><hr /></td> </tr> <tr> <td colspan="2" class="sectionHeader">-- Shipping Information --</td> </tr> <tr> <td colspan="2"><hr /><br /></td> </tr> <tr> <td class="inputDescriptors">First Name:</td> <td> <html:text property="firstName" name="checkoutForm" size="50" maxlength="50" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">Last Name:</td> <td> <html:text property="lastName" name="checkoutForm" size="50" maxlength="100" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">Company Name:</td> <td> <html:text property="companyName" name="checkoutForm" size="50" maxlength="100" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">Address:</td> <td> <html:text property="address1" name="checkoutForm" size="50" maxlength="100" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">Address 2 (optional):</td> <td> <html:text property="address2" name="checkoutForm" size="50" maxlength="50" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">City:</td> <td> <html:text property="city" name="checkoutForm" size="50" maxlength="50" styleClass="inputBoxes" tabindex="" /> </td> </tr> <tr> <td class="inputDescriptors">State:</td> <td> <html:select property="stateID"> <html:option value="0" disabled="true">-- Select State --</html:option> <html:optionsCollection name="checkoutForm" property="stateList" label="label" value="value"> </html:optionsCollection> </html:select> </td> </tr> <tr> <td class="inputDescriptors">Zip Code:</td> <td> <html:text property="postalCode" name="checkoutForm" size="50" maxlength="5" styleClass="inputBoxes" tabindex="" /> </td> </tr> </span> Now, I think one of the issues may be that a div or span tag are not valid tags within a table element. If that's true, then how can I specify what part of the table I want to hide or display? Any help would be appreciated.
  3. awitt

    Jaxp Xml Processing

    I think you're on the right trail. Let me see if I can create a visual:The user wants to watch one of our hosted videos, but that video is hosted somewhere else now. The old link references that video (that used to be on our file system) using the file name, which in the XML file I have, is called originalFileKey. But now, it's in another system, which references the file by a system-generated assetID. The XML file I have is from this new system, so it does contain both the old 'file name' (originalFileKey) and the new 'file name' (assetID). So my purpose is to find out what the new system calls this old file by searching through the XML file and linking up the originalFileKey with the assetID. Eventually, this will turn into an Apache redirect, but for now, I just want to output the assetID onto the page - that's all that is necessary for right now.
  4. awitt

    Jaxp Xml Processing

    Hmm, interesting responses. Firstly, to boen_robot: so you're saying I can use the same methods and such to manipulate the XML DOM, the same way I did with JavaScript? That's what I'd rather do; I know it more and this is a static, hosted XML file, so it's not going to be growing or anything like that. Secondly, to stransky: here's the purpose for my endeavors. I have a static XML file that contains, among other things, an originalFileKey and an AssetID. What's happening is that a user will be visiting a URL with a filename (i.e. the originalFileKey) and I will pull that filename from the URL and then perform a search against the XML file. The search's goal is to match the URL-given filename with the originalFileKey in the XML. Then, once I find an element in the XML file that contains a match, I go through that particular element and grab the corresponding assetID. Once I have the assetID, all I need to do, for now, is output it to the JSP with which I'm working.
  5. awitt

    Jaxp Xml Processing

    While I honestly do appreciate all the info about why or why not XML may be good, I need some help using a Java based approach, specifically outputting a certain attribute within an XML element onto a JSP page. So, really, all I need is some direction or tips using a JAXP API. I've actually done some XML parsing and processing using JavaScript before, but, unfortunately for me, I cannot use that approach this time. Thank you, though, stransky.
  6. awitt

    Jaxp Xml Processing

    I need to do some simple XML processing using Java. All I have to do is step through an XML file until I find a match to a file name that is stored within each element. I use Java often, but I'm unfamiliar with the JAXP APIs. Can anyone get me started?
  7. I need to do some simple XML processing using Java. All I have to do is step through an XML file until I find a match to a file name that is stored within each element. I use Java often, but I'm unfamiliar with the JAXP APIs. Can anyone get me started?
  8. awitt

    Asp Classic Casting

    Does anyone know how I can cast a bit (in an SQL DB) object to a boolean (in ASP Classic)?
  9. I don't know much on the subject,. but I think you're going to be looking at utilizing web services and such. Try doing a little research on that topic.
  10. awitt

    File Watch

    Here's the implementation I used, posted here for posterity's sake.import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileWriter;import java.io.IOException;import java.util.Date;import java.text.Format;import java.text.SimpleDateFormat;public class filename_listing{ public static void main(String[] args) throws IOException { /****************************** DO NOT FORGET THE DOUBLE SLASHES! ******************************/ /**************** DO NOT FORGET THE DOUBLE SLASHES AT THE END OF THE PATH NAME! ****************/ /*~~ //||||||||||||||||||||||||||||||||||/\/~~~---~~~\/\||||||||||||||||||||||||||||||||||\\ ~~*/ String pathName = "E:\\to convert\\"; String logPathName = "C:\\Documents and Settings\\vid\\Desktop\\test-batch\\"; /*~~ //||||||||||||||||||||||||||||||||||\/\~~~---~~~/\/||||||||||||||||||||||||||||||||||\\ ~~*/ /**************** DO NOT FORGET THE DOUBLE SLASHES AT THE END OF THE PATH NAME! ****************/ /****************************** DO NOT FORGET THE DOUBLE SLASHES! ******************************/ // Declare and instantiate all needed variables File myDir = new File(pathName); String[] files = myDir.list(); final int maxLength = 35; int incrementalNumber = 0; int files_deleted = 0; Format formatter = new SimpleDateFormat("MM-dd-yy"); Date now = new Date(); BufferedWriter logOut = new BufferedWriter( new FileWriter(logPathName + formatter.format(now) + "_truncation_log.txt") ); BufferedWriter logOut2 = new BufferedWriter( new FileWriter(logPathName + formatter.format(now) + "_list_of_files_log.csv") ); String[] filter_words = {"forecast", "ohio_weather"}; logOut.write(" LOG OF CHANGES MADE TO VIDEOS\n"); logOut.write("------------------------------------------\n"); logOut.write(" ------------------------------------ \n"); try { // Loop through all files in directory for (int i = 0; i < files.length; i++) { String fileName = files[i].toString().toLowerCase(); // Test each file for a match to any word in the 'filter_words' array for (int a = 0; a < filter_words.length; a++) { String current_word = filter_words[a]; // If it matches, delete it if ( fileName.indexOf(current_word) != -1 ) { File file_to_delete = new File( pathName + files[i].toString() ); file_to_delete.delete(); files_deleted++; break; } } } // Log the total number of deleted files logOut.write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); logOut.write("TOTAL NUMBER OF FILES DELETED: " + files_deleted); logOut.write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); } catch (Exception e) { System.out.println("\nError deleting files:"); System.out.println(e); } // Reset the list of files now that some have been deleted myDir = new File(pathName); files = myDir.list(); // Now comes the renaming of the files try { // Loop through all files in directory for (int i = 0; i < files.length; i++) { String fileName = files[i].toString(); // If its filename is too long, cut it down if(fileName.length() > maxLength) { File f = new File(pathName + fileName); // LOG OLD FILE NAME! logOut.write("OLD FILE NAME: " + fileName + "\n"); // Cut off excess, but keep file extension String possibleFileName = fileName.substring(0, 29); String extension = fileName.substring(fileName.length() - 4, fileName.length()); possibleFileName += extension; File temp2 = new File(pathName + possibleFileName); // If the 'new' filename already exists, try to make it unique while ( temp2.exists() ) { String temp = fileName.substring(0, 29) + incrementalNumber + extension; incrementalNumber++; temp2 = new File(pathName + temp); possibleFileName = temp; } // It's a unique filename, so rename the original now f.renameTo(temp2); // LOG NEW FILE NAME! logOut.write("NEW FILE NAME: " + possibleFileName + "\n"); logOut.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); } // Make sure that every time we touch a file, we dump the recorded info into the log logOut.flush(); } logOut.close(); logOut = null; } catch (FileNotFoundException fnfe) {System.out.println(fnfe);} catch (Exception e) { System.out.println("\nError renaming files:"); System.out.println(e); } // Just makin' sure yo finally { try { if (logOut != null) {logOut.close();} } catch (Exception e) { System.out.println("\nUnknown error:"); System.out.println(e); } } // Reset the list of files now that some have been renamed myDir = new File(pathName); files = myDir.list(); // Create a log of all remaining files within the directory try { for (int i = 0; i < files.length; i++) { String fileName = files[i].toString(); if ( i == (files.length - 1) ) {logOut2.write(fileName);} else {logOut2.write(fileName + ", ");} } logOut2.close(); logOut2 = null; } catch (Exception e) { System.out.println("Error in reading list of files:"); System.out.println(e); } }} Some of that can be cleaned up and made more efficient, and some of the code can be combined with other code so that multiple steps can be condensed to one. I know all that, but this approach worked best for my context. Anyways, hope this helps some people out.
  11. awitt

    Xslt Sort

    It's actually very difficult to accomplish what you want to do using exclusively XSLT directives. What you can do is use a little bit of JavaScript, though, to make sure that you are only grabbing the top ten results. <script type="text/javascript"> var i=0; var array=new Array(); <xsl:for-each select="..."> <xsl:sort select="substring(dateValue,7,2)" order="descending"/> <xsl:sort select="substring(dateValue,3,2)" order="descending"/> <xsl:sort select="substring(dateValue,1,2)" order="descending"/> array[i] = <xsl:value-of select="dateValue"/>; i++; </xsl:for-each></script> So then, you have all your results in the array, and all you have to do is loop through it, stopping once the tenth iteration is reached. for(int j=0;j<10;j++) { // this is where you output to html document.getElementById("someElement").innerHTML=array[j]; } In my experience with XSLT and XML technologies, there is a close relationship with JavaScript, in that it needs to be used often to accomplish programmatic events.
  12. Anyone interested in a solution to this topic? Follow this topic link!
  13. Alrighty - for those of you who had been following this topic - here's the working code that will let you select a distinct (i.e. unique) set of nodes: <xsl:variable name="unique-list" select="closings/county/announcement[not(@id=following::announcement/@id)]" /> <xsl:for-each select="$unique-list"> var closing1=new closing("<xsl:value-of select="./@id" />", "<xsl:value-of select="../@name" />", "<xsl:value-of select="location" />", "<xsl:value-of select="status" />"); table_for_sc[i]=closing1; i++; </xsl:for-each> Now, a couple things to note:1.) This is a solution for attributes. It'd be slightly different if you were trying to select unique locations, for example. If that was your aim, though, this is what you'd be looking at: <xsl:variable name="unique-list" select="closings/county/announcement/location[not(.=following::location)]" />2.) There are some missing variable declarations in the snippets above, but in the actual code from which they came, they are defined and instantiated.And now for the best explanation that I am capable of giving: So, you start by creating a variable in which to store the "new," or filtered, result set (<xsl:variable name="unique-list" ...). Secondly, you tell it what you want put into that variable (... select="closings/county/announcement ...). But wait, that still doesn't make sure that the selected values are unique! Well, that's where one's knowledge of XPath comes in real handy (and my knowledge of XPath is paltry, by the way, so be aware of that as I try my best to explain its role here). So now you've got this piece of code left: [not(@id=following::announcement/@id)] . This is the line that makes sure the elements/nodes you select are, in fact, unique. So, you told it to select all of the announcements in the first part of that line, and then you limit those announcements to only those that are not already in the aforementioned variable that we created to store this information. Now, the reason that you do not specify more of a path inside those brackets is because you already told the XSLT engine to go "into" the announcements node, so that's where you're at when you specify the elements not to pull out. So, since you're already in an announcement node, all you have to do is tell it to test against the id attribute of the announcement element (announcement/@id). After you get all that working, then you go about business as normal, but making sure to pull out further selections from the variable you created in which to store all the unique elements of that XML file: <xsl:for-each select="$unique-list"> . Well, I hope I explained that well enough; my understanding of the topic is quite limited, but I am learning all this as I go, so I feel okay about myself.
  14. Okay, so I think I'm using it correctly now, but it still produces the duplicate results, and I don't know how it's doing that or how to make this do what i want. <xsl:variable name="unique-list" select="closings/county/announcement[not(@id=following::closings/county/announcement/@id)]" /> <xsl:for-each select="$unique-list"> <tr> <xsl:attribute name="id">row_<xsl:value-of select="./@id" /></xsl:attribute> <td class="county_row"> <xsl:value-of select="../@name" /> </td> <td class="location_row"> <xsl:attribute name="id">row_<xsl:value-of select="./@id" />_loc</xsl:attribute> <xsl:value-of select="location" /> </td> <td class="status_row"> <xsl:value-of select="status" /> </td> </tr> </xsl:for-each>
  15. Hmm, I tried doing that, but a couple of problems occur:1.) The XSLT engine yells at me - it says, "ERROR: Error in expression closings/county/announcement/@id[not(.=following::@id)]: Unexpected token [@] after axis name; SystemID: ...", which, through a 'lil trial and error, I found meant that the '@' symbol in the brackets and braces ( [not(.=following::@id)] ) had a symbol that wasn't supposed to be there. 2.) Then it transformed, but the resulting html page was devoid of any data from the XML.So, that didn't work, unfortunately. Does it maybe have to do with the fact that we're trying to select distinct nodes based on an attribute?
×
×
  • Create New...