-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AGPL license to all files, fix namespace
- Loading branch information
Showing
72 changed files
with
1,511 additions
and
1,385 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
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,7 +1,9 @@ | ||
Copyright (C) | ||
Copyright (C) Jonathan Shull | ||
|
||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/. | ||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/. | ||
|
||
To Contact: Create an issue on https://github.com/aMytho/pdf-acc-toolset |
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
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
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
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
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
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
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
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
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 +1,2 @@ | ||
@* Copyright (C) Jonathan Shull - See license file at github.com/amytho/pdf-acc-toolset *@ | ||
@layout DocumentationLayout |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,114 +1,119 @@ | ||
|
||
// Copyright (C) Jonathan Shull - See license file at github.com/amytho/pdf-acc-toolset | ||
using iText.Kernel.Pdf.Tagutils; | ||
using Pdf_Acc_Toolset.Services; | ||
using Pdf_Acc_Toolset.Services.Tools.Selection; | ||
using Pdf_Acc_Toolset.Services.Util; | ||
using Pdf_Acc_Toolset.Services; | ||
|
||
namespace Pdf_Acc_Toolset.Pages.Selection | ||
namespace Pdf_Acc_Toolset.Pages.Selection; | ||
|
||
public static class SelectionValidator | ||
{ | ||
public static class SelectionValidator | ||
/// <summary> | ||
/// Validates a selection model. Shows warnings to the user if invalid | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <returns></returns> | ||
public static bool Validate(Selection.SelectionModel model) | ||
{ | ||
/// <summary> | ||
/// Validates a selection model. Shows warnings to the user if invalid | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <returns></returns> | ||
public static bool Validate(Selection.SelectionModel model) | ||
// Check limit | ||
if (model.Limit < 1) | ||
{ | ||
// Check limit | ||
if (model.Limit < 1) { | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid limit. Limit must be greater than 1"); | ||
return false; | ||
} | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid limit. Limit must be greater than 1"); | ||
return false; | ||
} | ||
|
||
// Based on selection, check the data entered | ||
// Handle tag errors | ||
if (model.selection.type == SelectionType.SSelectionType.Tag) { | ||
Console.WriteLine(model.selection.type + " is the type"); | ||
Console.WriteLine(Enum.IsDefined(typeof(TagType), model.selection.tag)); | ||
if (!Enum.IsDefined(typeof(TagType), model.selection.tag)) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid tag. Select a valid tag for targeting."); | ||
return false; | ||
} | ||
// Based on selection, check the data entered | ||
// Handle tag errors | ||
if (model.selection.type == SelectionType.SSelectionType.Tag) | ||
{ | ||
Console.WriteLine(model.selection.type + " is the type"); | ||
Console.WriteLine(Enum.IsDefined(typeof(TagType), model.selection.tag)); | ||
if (!Enum.IsDefined(typeof(TagType), model.selection.tag)) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid tag. Select a valid tag for targeting."); | ||
return false; | ||
} | ||
// Handle attribute errors | ||
if (model.selection.type == SelectionType.SSelectionType.Attribute) { | ||
if (model.selection.attrWithVal.val == null || model.selection.attrWithVal.val.Length < 1) { | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid attribute value. You must provide a value"); | ||
return false; | ||
} | ||
} | ||
// Handle attribute errors | ||
if (model.selection.type == SelectionType.SSelectionType.Attribute) | ||
{ | ||
if (model.selection.attrWithVal.val == null || model.selection.attrWithVal.val.Length < 1) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, "Invalid attribute value. You must provide a value"); | ||
return false; | ||
} | ||
} | ||
|
||
if ( | ||
model.selection.type == SelectionType.SSelectionType.Default | ||
|| model.selection.type == SelectionType.SSelectionType.Tag | ||
) | ||
{ | ||
// Prevent inserting adjacent to the document root | ||
if ( | ||
model.selection.type == SelectionType.SSelectionType.Default | ||
|| model.selection.type == SelectionType.SSelectionType.Tag | ||
(model.InsertionPoint == Services.Tools.Selection.InsertionPoint.BeforeSelection | ||
|| model.InsertionPoint == Services.Tools.Selection.InsertionPoint.AfterSelection) | ||
&& (model.selection.type == SelectionType.SSelectionType.Default | ||
|| model.selection.tag == TagType.Document) | ||
) | ||
{ | ||
// Prevent inserting adjacent to the document root | ||
if ( | ||
(model.InsertionPoint == Services.Tools.Selection.InsertionPoint.BeforeSelection | ||
|| model.InsertionPoint == Services.Tools.Selection.InsertionPoint.AfterSelection) | ||
&& (model.selection.type == SelectionType.SSelectionType.Default | ||
|| model.selection.tag == TagType.Document) | ||
) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, | ||
"You cannot use Before Selection or After Selection on the Document Root. Try a child selection instead!"); | ||
return false; | ||
} | ||
NotificationUtil.Inform(NotificationType.Error, | ||
"You cannot use Before Selection or After Selection on the Document Root. Try a child selection instead!"); | ||
return false; | ||
} | ||
|
||
// Probably fine | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Based on the model type, create the proper selection class | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <param name="tag">The root tag</param> | ||
/// <returns></returns> | ||
public static Services.Tools.Selection.Selection CreateSelection(Selection.SelectionModel model, TagTreePointer tag) | ||
// Probably fine | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Based on the model type, create the proper selection class | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <param name="tag">The root tag</param> | ||
/// <returns></returns> | ||
public static Services.Tools.Selection.Selection CreateSelection(Selection.SelectionModel model, TagTreePointer tag) | ||
{ | ||
return model.selection.type switch | ||
{ | ||
return model.selection.type switch | ||
{ | ||
SelectionType.SSelectionType.Default => new DefaultSelection(tag, model.InsertionPoint, model.Limit), | ||
SelectionType.SSelectionType.Attribute => new AttributeSelection(tag, model.InsertionPoint, model.selection.attrWithVal.attr, model.selection.attrWithVal.val, model.Limit), | ||
SelectionType.SSelectionType.Tag => new TagSelection(tag, model.InsertionPoint, model.selection.tag, model.Limit), | ||
_ => null | ||
}; | ||
} | ||
SelectionType.SSelectionType.Default => new DefaultSelection(tag, model.InsertionPoint, model.Limit), | ||
SelectionType.SSelectionType.Attribute => new AttributeSelection(tag, model.InsertionPoint, model.selection.attrWithVal.attr, model.selection.attrWithVal.val, model.Limit), | ||
SelectionType.SSelectionType.Tag => new TagSelection(tag, model.InsertionPoint, model.selection.tag, model.Limit), | ||
_ => null | ||
}; | ||
} | ||
|
||
public static bool CheckSelectionMatches(Selection.SelectionModel selectionModel) | ||
public static bool CheckSelectionMatches(Selection.SelectionModel selectionModel) | ||
{ | ||
// Validate selection | ||
if (!Validate(selectionModel)) | ||
{ | ||
// Validate selection | ||
if (!Validate(selectionModel)) | ||
{ | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
// Create selection class from model | ||
TagTreePointer pointer = PdfManager.GetTagRoot(); | ||
Services.Tools.Selection.Selection selection = CreateSelection(selectionModel, pointer); | ||
if (selection == null) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, "No selection class matches the input."); | ||
return false; | ||
} | ||
// Create selection class from model | ||
TagTreePointer pointer = PdfManager.GetTagRoot(); | ||
Services.Tools.Selection.Selection selection = CreateSelection(selectionModel, pointer); | ||
if (selection == null) | ||
{ | ||
NotificationUtil.Inform(NotificationType.Error, "No selection class matches the input."); | ||
return false; | ||
} | ||
|
||
// See if any matches are found | ||
selection.FindElements(); | ||
if (selection.FoundSelection()) | ||
{ | ||
NotificationUtil.Inform( | ||
NotificationType.Success, "Found " + selection.GetSelection().Count + " Element(s)" | ||
); | ||
return true; | ||
} else { | ||
NotificationUtil.Inform(NotificationType.Warning, "No elements found!"); | ||
return false; | ||
} | ||
// See if any matches are found | ||
selection.FindElements(); | ||
if (selection.FoundSelection()) | ||
{ | ||
NotificationUtil.Inform( | ||
NotificationType.Success, "Found " + selection.GetSelection().Count + " Element(s)" | ||
); | ||
return true; | ||
} | ||
else | ||
{ | ||
NotificationUtil.Inform(NotificationType.Warning, "No elements found!"); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.