LetsTalkCode.com
Programmers talking about code

Going to Mix10

March 2, 2010 02:57 by jeremysharp

Work was attempting to get in the way of my trip to Mix10. As of now I am going. Are you?

Mix10_LoveFest_blk_240


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Sitecore - Changing the Url not to match what is in the content tree

March 1, 2010 10:03 by JeremySharp

I’m new to Sitecore and I was working on a new installation. I ran into trouble trying to shorten my Sitecore generated URL’s. Once I was done I thought that wasn't so bad. But the path to get there was painful.

What I am solving for:
When Sitecore generates the url’s for our files it uses the exact hierarchy that is setup in the content tree(this is a good thing). But in our case, we have a lot of Products & Recipes. Because of this we have ‘extra’ folders in our content tree that should never be seen by our web user. I did two things that together gave me the result I was looking for. 

Based on our folder structure in our content tree, Sitecore was generating the following url’s:

Seems easy enough here is how I did it:

Step 1:
Create a custom linkManager method that inherits from the standard sitecore linkmanager class. This new class will show Sitecore how I want my web links constructed.  Essentially for our case we want to avoid a folder that is in our content tree. 

A. Find the following LinkManager entry in my web.Config file. You need to change the Type attribute of the Sitecore ‘add’ node. This Type attribute should point to a newly created class file.    ( /configuraiton/sitecore/linkManager in the web.config file )

   1: <linkManager defaultProvider="sitecore">
   2:   <providers>
   3:     <clear />
   4:     <add name="sitecore" type="Library.Links.CustomFileName, nameSpace.NameSpace" addAspxExtension="true" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="true" />
   5:   </providers>
   6: </linkManager>

B. Create a class (CustomFileName) file. This new custom class should inherit from: Sitecore.Links.LinkProvider. In addition it needs to match the web.Config entry above. The new class file will have a single override for the GetItemUrl method:

   1: //Override of Sitecore GetItemUrl
   2: public override string GetItemUrl(Sitecore.Data.Items.Item item, UrlOptions options)
   3: {
   4:     if (item != null)
   5:     {
   6:        string templateName = item.Template.Name.ToLower();
   7:        //Verify the template name is products. 
   8:        //That is our qualifier for if the url should be scrubbed.
   9:        if (templateName == "product") 
  10:        {
  11:           string link = "/products/" + item.DisplayName;
  12:           //AddAspxExtension is False by default
  13:           if (this.AddAspxExtension == true) link += ".aspx";
  14:           return link; 
  15:        }
  16:        //If in recipe section of site scrub url
  17:        if (templateName == "recipe")
  18:        {
  19:           //Url qualifies replace the old url with new one 
  20:           //http://domain/recipes/recipe_name.aspx
  21:           string link = "/recipes/" + item.DisplayName;
  22:           //False by default
  23:           if (this.AddAspxExtension == true) link += ".aspx";
  24:           return link;
  25:        }               
  26:     }
  27:     return base.GetItemUrl(item, options);
  28: }

Step 2:
Next, create an Item Resolver class this will show Sitecore how to reconstruct the Url to accurately point to an item in the content tree. Remember in step 1 you changed how the links shows up in the browser. But in step 2 we are going to intercept that request coming from the browser and tell Sitecore where the content item lives in the content tree. 

A. Lets go back to the web.config file add an entry directly above the HttpRequest.LayoutResolver <processor> in the httpRequestBegin node.

   1: <httpRequestBegin>
   2: <processor type="Link.ClassFile.CustomUrlResolver, XXX.NameSpace" />
   3: </httpRequestBegin>

B. In this newly created class file we are going to change reconstruct our path to accurately point to the content tree content item. The example below adds the folder we previously stripped out (in step 1).

   1: public void Process(HttpRequestArgs args1)
   2: {
   3:    if (Sitecore.Context.Item == null)
   4:    { //item not found
   5:  
   6:       //get name of requested item, without the path
   7:       // WebUtil.GetUrlName(0) doesn't seem to work here - maybe hasn't been instantiated yet?
   8:       // so we'll just split the URL on '/' and grab the last element in the array
   9:       char[] splitter = { '/' };
  10:       string[] reqitempath_ar = args1.LocalPath.Split(splitter);
  11:       string reqItemName = reqitempath_ar[reqitempath_ar.Length - 1];
  12:                   
  13:       //Check for product in query string
  14:       if(reqitempath_ar[1] == "products")
  15:       {
  16:          //get prod/brand code
  17:          int prodbrand = 0;
  18:          if (int.TryParse(reqItemName.Replace("-", ""), out prodbrand) == true)
  19:          {
  20:             //sitecore query find me the item where the display name = prod/brand
  21:             int product = reqItemName.IndexOf('-');
  22:             string prodCode = reqItemName.Substring(0, product);
  23:             string brandCode = reqItemName.Substring(product + 1);
  24:             
  25:             // Sitecore query for the content item
  26:             string productItemQuery = string.Format("/sitecore/content/Foodservice/Home/Products//*[@Product Code='{0}' and @Brand Code='{1}']", prodCode, brandCode);
  27:             Sitecore.Data.Items.Item productItem = Sitecore.Context.Database.SelectSingleItem(productItemQuery);
  28:             Sitecore.Context.Item = productItem;
  29:          }
  30:       }
  31:       //Check for recipes in query string            
  32:       if(reqitempath_ar[1] == "recipes")
  33:       {
  34:          // Sitecore query for the content item
  35:          
  36:          //@@name is case sensitive because the request is coming from the url (all lowercase) I have capitalized the first letter of every word.
  37:          // If there is an error make sure the ITEM NAME of the recipe is capatalized.
  38:          string reqItemNameCaps = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reqItemName);
  39:          string recipeItemQuery = string.Format("/sitecore/content/Foodservice/Home/Recipes//*[@@Name='{0}']", reqItemNameCaps);
  40:          Sitecore.Data.Items.Item recipeItem = Sitecore.Context.Database.SelectSingleItem(recipeItemQuery);
  41:          Sitecore.Context.Item = recipeItem;       
  42:       }
  43:    }
  44: }

Conclusion – To shorten a url you need to create a custom link provider which is nothing more than an override. As well as an UrlResolver class to catch the request and point it to the content item in the content tree. Hope this helps you as much as it would have helped me :).

 Related Blogs:

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .NET | Sitecore
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Playing around with Video Production

November 15, 2009 02:43 by JeremySharp

Started working on some Video produciton. This is a minute long tribute to the man 'dax' for his efforts in our City Basketball league this year. 

The below video was done over several hours of work using Free tools.

Equipment: Flip Ultra HD (this takes great video I'm still learning)
Software: iMovie, iDVD (both built into the Mac OS)


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Video
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Dabbling with Mac development

October 18, 2009 02:59 by jeremysharp

IMG_0439

Hope to have more of a write up soon. I have started setting up my environment.Thanks to @RyanWells for the Mac support.  I’m a few days into this different type of development. Traditionally I am a .NET web developer and although i have no intentions of leaving that role.

I have begun to dabble a little with the Mac development world.

Anyone else taking on a similar change lately?  Any hurtles I should be aware of?


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Where is the iPhone UserGroup meeting?

July 9, 2009 05:33 by JeremySharp

Hope this helps…

Go to the intersection of Cambridge St and the new Don Tyson parkway. CLICK HERE for a map. At that intersection you will see the below parking lot showing you where to park. From the parking lot there is a walkway to where we are meeting.

iPhoneMeeting 

Above is the overhead view. Below is what the parking lot looks like. See that path on the left walk down there!!

Parkinglot

GO TO THE "X" :) [pictures below]

 STEP1 STEP2

Sitting area (door in left corner)

 STEP3 STEP4

You will see the door once you get to the sitting area shown above.

July Northwest Arkansas CocoaHeads meeting.  Thursday, July 9, 6-8pm

Come learn about Apple development for the Mac and iPhone with other local Apple users.  All levels of skill and interest are welcome, from experts to the merely curious!  This month's speaker is Andrew Money, owner of AwesomeSauce Apps.  His talk, titled "I'm in the App Store -- Now what?!", will cover some of the less technical gotchas developers can run into after publishing their iPhone apps, including payment receipt, feedback tracking, and other issues.

Thanks,
Jeremy


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Going to Austin Code Camp 5/30

May 21, 2009 08:01 by JeremySharp
U coming?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

NWA CocoaHeads Meeting 5/14

May 13, 2009 06:04 by JeremySharp

NWA CocoaHeads
Apple Mac & iPhone Development Interest Group
 
Thursday, May 14, 6-8pm
Sales Tracking and Analytics for iPhone Apps
(Andrew Money, AwesomeSauce Apps)
Corporate HQ Discovery Center  

nwacocoa@gmail.com
http://cocoaheads.org/us/FayettevilleArkansas/index.html 

 

Google Maps of location 


 

The next meeting of the Northwest Arkansas CocoaHeads will be Thursday, May 14, from 6pm to 8pm at Discover Center.  Andrew Money, founder of AwesomeSauce Apps, will present on sales tracking and analytics for iPhone apps.  The goal of the Northwest Arkansas CocoaHeads group is to foster a local community of Apple developers in the Northwest Arkansas, Eastern Oklahoma, and Southwest Missouri.    

More information is available at:  NWA CocoaHeads 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Events | NwaCocoaHeads
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

NWA Code Camp 2009

April 25, 2009 13:47 by JeremySharp

NWAcodeCampAwesome event great showing by our locals! I truly enjoyed this event and I hope you did as well.

#NwaCodeCamp was the best local event I have been to in a long time. I saw a lot of Very good sessions. I think Jason Vogel & @JaySmith ran an amazing event.

I had the opportunity to present on Silverlight DeepZoom. I wanted to post my PPT for anyone who attended and wanted the links. If you have any questions related to the event or to my presentation post away, I’ll either answer them or get you an answer.  I'm going to work on a blog post to go into some detail on using the Jellyfish Framework.

Silverlight DeepZoom PowerPoint Link: SilverlightDeepZoom.zip (382.51 kb)

nwaKeyNote 

**Also someone asked me what I was using to ZOOM on m desktop. Here is a link to that as well, it’s not in my PowerPoint.

Thanks
Jeremy


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

NWA Code Camp 09

April 21, 2009 03:21 by JeremySharp

 

Join me at NWA Code Camp 2009 I have a session on “Silverlight DeepZoom applications with Jellyfish” (an open source library for DeepZoom). I will be presenting after lunch check out all the topics at the Agenda page. Still not sure if you want to make it? My session was inspired by @KENAZUMA talk at MIX this year. Cllick here to watch it. (DONT WORRY) my session will be different and just as informative.

Check out these random DeepZoom sites to get a better feel for the technology:

thanks,
Jeremy


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

MIX09 - Pics

March 19, 2009 08:43 by JeremySharp

Silverlight-BF IMG_3213 

GUandME IMG_3195

IMG_3211 IMG_3193


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5