-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
30 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -24,15 +24,10 @@ namespace Toimik.SitemapsProtocol; | |
using System.Xml; | ||
using System.Xml.Schema; | ||
|
||
public class Sitemap | ||
public class Sitemap(SitemapParser parser) | ||
{ | ||
private readonly ISet<SitemapEntry> entries = new HashSet<SitemapEntry>(new EntryComparer()); | ||
|
||
public Sitemap(SitemapParser parser) | ||
{ | ||
Parser = parser; | ||
} | ||
|
||
public Sitemap(Uri location, int entryMaxCount = SitemapParser.DefaultEntryMaxCount) | ||
: this(new SitemapParser(location, entryMaxCount)) | ||
{ | ||
|
@@ -42,7 +37,7 @@ public Sitemap(Uri location, int entryMaxCount = SitemapParser.DefaultEntryMaxCo | |
|
||
public int EntryCount => entries.Count; | ||
|
||
public SitemapParser Parser { get; } | ||
public SitemapParser Parser { get; } = parser; | ||
|
||
public bool AddEntry(SitemapEntry entry) | ||
{ | ||
|
@@ -55,16 +50,12 @@ public bool AddEntry(SitemapEntry entry) | |
/// <summary> | ||
/// Loads, to this instance, the data of a sitemap from a <see cref="string"/>. | ||
/// </summary> | ||
/// <param name="data"> | ||
/// Data of a sitemap. | ||
/// </param> | ||
/// <param name="data">Data of a sitemap.</param> | ||
/// <param name="schemaStream"> | ||
/// <see cref="Stream"/> of schema, which is used to validate the sitemap index against. If | ||
/// <c>null</c>, the default one is used. | ||
/// </param> | ||
/// <remarks> | ||
/// All existing entries, if any, are cleared when this method is called. | ||
/// </remarks> | ||
/// <remarks>All existing entries, if any, are cleared when this method is called.</remarks> | ||
public void Load(string data, Stream? schemaStream = null) | ||
{ | ||
var byteArray = Encoding.UTF8.GetBytes(data); | ||
|
@@ -89,17 +80,13 @@ public void Load(string data, Stream? schemaStream = null) | |
/// <see cref="Stream"/> of schema, which is used to validate the sitemap index against. If | ||
/// <c>null</c>, the default one is used. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task"/>. | ||
/// </returns> | ||
/// <returns>A <see cref="Task"/>.</returns> | ||
/// <exception cref="ObjectDisposedException"> | ||
/// Thrown when <paramref name="dataStream"/> is manually closed. | ||
/// </exception> | ||
/// <remarks> | ||
/// All existing entries, if any, are cleared when this method is called. | ||
/// <para> | ||
/// Call <see cref="Stream.Close()"/> on <paramref name="dataStream"/> to cancel loading. | ||
/// </para> | ||
/// <para>Call <see cref="Stream.Close()"/> on <paramref name="dataStream"/> to cancel loading.</para> | ||
/// </remarks> | ||
public async Task Load(Stream dataStream, Stream? schemaStream = null) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -18,7 +18,7 @@ namespace Toimik.SitemapsProtocol; | |
|
||
using System; | ||
|
||
public class SitemapEntry : IEntry | ||
public class SitemapEntry(string baseLocation) : IEntry | ||
{ | ||
private const string TagForChangeFrequency = "changefreq"; | ||
|
||
|
@@ -28,12 +28,7 @@ public class SitemapEntry : IEntry | |
|
||
private const string TagForPriority = "priority"; | ||
|
||
public SitemapEntry(string baseLocation) | ||
{ | ||
BaseLocation = baseLocation; | ||
} | ||
|
||
public string BaseLocation { get; } | ||
public string BaseLocation { get; } = baseLocation; | ||
|
||
public ChangeFrequency? ChangeFrequency { get; private set; } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -22,7 +22,7 @@ namespace Toimik.SitemapsProtocol; | |
using System.Xml; | ||
using System.Xml.Schema; | ||
|
||
public class SitemapParser | ||
public class SitemapParser(Uri location, int entryMaxCount = SitemapParser.DefaultEntryMaxCount) | ||
{ | ||
// As per standard | ||
internal const int DefaultEntryMaxCount = 50000; | ||
|
@@ -38,15 +38,9 @@ static SitemapParser() | |
SchemaSet = Utils.CreateSchemaSet($"{typeof(Sitemap).Namespace}.Resources.sitemap.xsd"); | ||
} | ||
|
||
public SitemapParser(Uri location, int entryMaxCount = DefaultEntryMaxCount) | ||
{ | ||
Location = Utils.NormalizeLocation(location) ?? throw new ArgumentException($"{nameof(location)} is not in a valid format."); | ||
EntryMaxCount = entryMaxCount; | ||
} | ||
|
||
public int EntryMaxCount { get; } | ||
public int EntryMaxCount { get; } = entryMaxCount; | ||
|
||
public string Location { get; } | ||
public string Location { get; } = Utils.NormalizeLocation(location) ?? throw new ArgumentException($"{nameof(location)} is not in a valid format."); | ||
|
||
public async IAsyncEnumerable<SitemapEntry> Parse(Stream dataStream, Stream? schemaStream = null) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -24,15 +24,10 @@ namespace Toimik.SitemapsProtocol; | |
using System.Xml; | ||
using System.Xml.Schema; | ||
|
||
public class SitemapIndex | ||
public class SitemapIndex(SitemapIndexParser parser) | ||
{ | ||
private readonly ISet<SitemapIndexEntry> entries = new HashSet<SitemapIndexEntry>(new EntryComparer()); | ||
|
||
public SitemapIndex(SitemapIndexParser parser) | ||
{ | ||
Parser = parser; | ||
} | ||
|
||
public SitemapIndex(Uri location, int entryMaxCount = SitemapIndexParser.DefaultEntryMaxCount) | ||
: this(new SitemapIndexParser(location, entryMaxCount)) | ||
{ | ||
|
@@ -42,7 +37,7 @@ public SitemapIndex(Uri location, int entryMaxCount = SitemapIndexParser.Default | |
|
||
public int EntryCount => entries.Count; | ||
|
||
public SitemapIndexParser Parser { get; } | ||
public SitemapIndexParser Parser { get; } = parser; | ||
|
||
public bool AddEntry(SitemapIndexEntry entry) | ||
{ | ||
|
@@ -55,16 +50,12 @@ public bool AddEntry(SitemapIndexEntry entry) | |
/// <summary> | ||
/// Loads, to this instance, the data of a sitemap index from a <see cref="string"/>. | ||
/// </summary> | ||
/// <param name="data"> | ||
/// Data of a sitemap index. | ||
/// </param> | ||
/// <param name="data">Data of a sitemap index.</param> | ||
/// <param name="schemaStream"> | ||
/// <see cref="Stream"/> of schema, which is used to validate the sitemap index against. If | ||
/// <c>null</c>, the default one is used. | ||
/// </param> | ||
/// <remarks> | ||
/// All existing entries, if any, are cleared when this method is called. | ||
/// </remarks> | ||
/// <remarks>All existing entries, if any, are cleared when this method is called.</remarks> | ||
public void Load(string data, Stream? schemaStream = null) | ||
{ | ||
var byteArray = Encoding.UTF8.GetBytes(data); | ||
|
@@ -89,12 +80,8 @@ public void Load(string data, Stream? schemaStream = null) | |
/// <see cref="Stream"/> of schema, which is used to validate the sitemap index against. If | ||
/// <c>null</c>, the default one is used. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task"/>. | ||
/// </returns> | ||
/// <remarks> | ||
/// All existing entries, if any, are cleared when this method is called. | ||
/// </remarks> | ||
/// <returns>A <see cref="Task"/>.</returns> | ||
/// <remarks>All existing entries, if any, are cleared when this method is called.</remarks> | ||
public async Task Load(Stream dataStream, Stream? schemaStream = null) | ||
{ | ||
entries.Clear(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -18,18 +18,13 @@ namespace Toimik.SitemapsProtocol; | |
|
||
using System; | ||
|
||
public class SitemapIndexEntry : IEntry | ||
public class SitemapIndexEntry(string baseLocation) : IEntry | ||
{ | ||
private const string TagForLastModified = "lastmod"; | ||
|
||
private const string TagForLocation = "loc"; | ||
|
||
public SitemapIndexEntry(string baseLocation) | ||
{ | ||
BaseLocation = baseLocation; | ||
} | ||
|
||
public string BaseLocation { get; } | ||
public string BaseLocation { get; } = baseLocation; | ||
|
||
public DateTime? LastModified { get; internal set; } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2021-2022 [email protected] | ||
* Copyright 2021-2024 [email protected] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -22,7 +22,7 @@ namespace Toimik.SitemapsProtocol; | |
using System.Xml; | ||
using System.Xml.Schema; | ||
|
||
public class SitemapIndexParser | ||
public class SitemapIndexParser(Uri location, int entryMaxCount = SitemapIndexParser.DefaultEntryMaxCount) | ||
{ | ||
// As per standard | ||
internal const int DefaultEntryMaxCount = 50000; | ||
|
@@ -38,15 +38,9 @@ static SitemapIndexParser() | |
SchemaSet = Utils.CreateSchemaSet($"{typeof(SitemapIndex).Namespace}.Resources.siteindex.xsd"); | ||
} | ||
|
||
public SitemapIndexParser(Uri location, int entryMaxCount = DefaultEntryMaxCount) | ||
{ | ||
Location = Utils.NormalizeLocation(location) ?? throw new ArgumentException($"{nameof(location)} is not in a valid format."); | ||
EntryMaxCount = entryMaxCount; | ||
} | ||
|
||
public int EntryMaxCount { get; } | ||
public int EntryMaxCount { get; } = entryMaxCount; | ||
|
||
public string Location { get; } | ||
public string Location { get; } = Utils.NormalizeLocation(location) ?? throw new ArgumentException($"{nameof(location)} is not in a valid format."); | ||
|
||
public async IAsyncEnumerable<SitemapIndexEntry> Parse(Stream dataStream, Stream? schemaStream = null) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters