This commit is contained in:
Jon Galloway 2017-03-12 22:22:17 -07:00
commit dbd01b4a41
3 changed files with 61 additions and 0 deletions

View File

@ -404,6 +404,12 @@ namespace OpenLiveWriter.BlogClient.Detection
// will be notified that they won't be able to edit with style)
_exception = e;
}
catch (BlogClientAbortGettingTemplateException e)
{
_exception = e;
//Do not proceed with the other strategies if getting the template was aborted.
break;
}
catch (WebException e)
{
_exception = e;
@ -466,6 +472,11 @@ namespace OpenLiveWriter.BlogClient.Detection
templateFiles.Add(new BlogEditingTemplateFile(templateTypes[i], templateFile));
}
catch(BlogClientAbortGettingTemplateException)
{
Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Failed to download template {0}. Aborting getting further templates", templateTypes[i].ToString()));
throw;
}
catch (Exception e)
{
Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Failed to download template {0}: {1}", templateTypes[i].ToString(), e.ToString()));

View File

@ -362,6 +362,10 @@ namespace OpenLiveWriter.BlogClient.Detection
Application.DoEvents();
}
//The Google/Blogger dynamic templates load the pages dynmaically usig Ajax, so we dont have any template to use.
if (IsUsingDynamicTemplate(doc2))
throw new BlogClientAbortGettingTemplateException();
IHTMLElement[] titles = FindText(_titleText, doc2.body);
IHTMLElement[] bodies = FindText(_bodyText, doc2.body);
if (titles.Length == 0 || bodies.Length == 0)
@ -406,6 +410,44 @@ namespace OpenLiveWriter.BlogClient.Detection
return false;
}
private static bool IsUsingDynamicTemplate(IHTMLDocument2 doc2)
{
IHTMLElement head = GetHeadElement(doc2);
if(head != null)
{
var template = GetMetaTagContent(head, "blogger-template");
return template == "dynamic";
}
return false;
}
private static IHTMLElement GetHeadElement(IHTMLDocument2 doc2)
{
foreach(IHTMLElement element in doc2.all)
{
if(element.tagName.ToLower() == "head")
{
return element;
}
}
return null;
}
private static string GetMetaTagContent(IHTMLElement head, string name)
{
foreach(IHTMLElement element in (IHTMLElementCollection)head.children)
{
if(element.tagName.ToLower() == "meta" && (string)element.getAttribute("name") == name)
{
return (string)element.getAttribute("content");
}
}
return null;
}
private IHTMLElement ScrubPostBodyRegionParentElements(IHTMLElement postBodyElement)
{
//Note: This method prevents the case where the post content consists of a single line of text, so surrounding elements

View File

@ -195,6 +195,14 @@ namespace OpenLiveWriter.Extensibility.BlogClient
}
}
public class BlogClientAbortGettingTemplateException : BlogClientException
{
public BlogClientAbortGettingTemplateException()
: base(StringId.BCEOperationCancelledTitle, StringId.BCEOperationCancelledMessage)
{
}
}
public class BlogClientMethodUnsupportedException : BlogClientException
{
public BlogClientMethodUnsupportedException(string methodName)