use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.
the class PageSecureSchematronTools method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
{
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
final BootstrapForm aForm = aToolbar.addAndReturnChild(new BootstrapForm(aWPEC).setFormType(EBootstrapFormType.INLINE));
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(new ExtValidationKeySelect(new RequestField(FIELD_VESID), aDisplayLocale)));
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(new ActionSelect(new RequestField(CPageParam.PARAM_ACTION))));
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_STYLE_OUTPUT, DEFAULT_STYLE_OUTPUT)), new HCTextNode(" format?")));
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(new BootstrapSubmitButton().addChild("Run")));
aNodeList.addChild(aToolbar);
}
final String sVESID = aWPEC.params().getAsString(FIELD_VESID);
final VESID aVESID = VESID.parseIDOrNull(sVESID);
final boolean bStyleOutput = aWPEC.params().isCheckBoxChecked(FIELD_STYLE_OUTPUT, DEFAULT_STYLE_OUTPUT);
final IValidationExecutorSet<IValidationSourceXML> aVES = ExtValidationKeyRegistry.getFromIDOrNull(aVESID);
if (aVES != null) {
if (aWPEC.hasAction(ACTION_SHOW_PREPROCESSED_SCHEMA)) {
LOGGER.info("Showing preprocessed Schematron of " + aVESID.getAsSingleID());
final MapBasedNamespaceContext aNSCtx = new MapBasedNamespaceContext();
aNSCtx.addDefaultNamespaceURI(CSchematron.NAMESPACE_SCHEMATRON);
aNSCtx.addMapping("xsl", "http://www.w3.org/1999/XSL/Transform");
aNSCtx.addMapping("svrl", CSVRL.SVRL_NAMESPACE_URI);
final IXMLWriterSettings XWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN).setNamespaceContext(aNSCtx);
aNodeList.addChild(info("Showing preprocessed version of " + aVESID.getAsSingleID()));
final BootstrapTabBox aTabBox = new BootstrapTabBox();
for (final IValidationExecutor<?> aVE : aVES.getAllExecutors()) {
final IReadableResource aRes = aVE.getValidationArtefact().getRuleResource();
final IValidationType aType = aVE.getValidationArtefact().getValidationArtefactType();
if (aType == EValidationType.SCHEMATRON_PURE || aType == EValidationType.SCHEMATRON_SCH) {
IHCNode aTabContent;
try {
// Read Schematron
final PSSchema aSchema = new PSReader(aRes, null, null).readSchema();
final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow(aSchema.getQueryBinding());
final PSPreprocessor aPreprocessor = PSPreprocessor.createPreprocessorWithoutInformationLoss(aQueryBinding);
// Pre-process
final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
if (aPreprocessedSchema == null)
throw new SchematronPreprocessException("Failed to preprocess schema " + aSchema + " with query binding " + aQueryBinding);
// Convert to XML string
final String sXML = MicroWriter.getNodeAsString(aPreprocessedSchema.getAsMicroElement(), XWS);
IHCNode aCode;
if (bStyleOutput) {
final HCPrismJS aPrism = new HCPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sXML);
aCode = aPrism;
} else
aCode = pre(sXML);
final CollectingPSErrorHandler aErrHdl = new CollectingPSErrorHandler();
aPreprocessedSchema.validateCompletely(aErrHdl);
if (aErrHdl.isEmpty()) {
aTabContent = aCode;
} else {
final HCUL aUL = new HCUL();
aErrHdl.getAllErrors().forEach(x -> aUL.addItem(x.getErrorText(aDisplayLocale)));
aTabContent = new HCNodeList().addChild(error("Errors in the Schematron:").addChild(aUL)).addChild(aCode);
}
} catch (final Exception ex) {
aTabContent = error("Error parsing Schematron: " + ex.getMessage());
}
aTabBox.addTab("t" + aTabBox.getTabCount(), FilenameHelper.getBaseName(aRes.getPath()), aTabContent);
} else if (aType == EValidationType.SCHEMATRON_XSLT) {
final IHCNode aTabContent = info("This is already XSLT");
aTabBox.addTab("t" + aTabBox.getTabCount(), FilenameHelper.getBaseName(aRes.getPath()), aTabContent);
}
}
if (aTabBox.hasNoTabs())
aNodeList.addChild(warn("No Schematron artefacts found"));
else
aNodeList.addChild(aTabBox);
} else if (aWPEC.hasAction(ACTION_SHOW_XSLT)) {
LOGGER.info("Showing XSLT version of " + aVESID.getAsSingleID());
final MapBasedNamespaceContext aNSCtx = new MapBasedNamespaceContext();
aNSCtx.addDefaultNamespaceURI(CSchematron.NAMESPACE_SCHEMATRON);
aNSCtx.addMapping("xsl", "http://www.w3.org/1999/XSL/Transform");
aNSCtx.addMapping("svrl", CSVRL.SVRL_NAMESPACE_URI);
final IXMLWriterSettings XWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN).setNamespaceContext(aNSCtx);
aNodeList.addChild(info("Showing XSLT version of " + aVESID.getAsSingleID()));
final BootstrapTabBox aTabBox = new BootstrapTabBox();
for (final IValidationExecutor<IValidationSourceXML> aVE : aVES.getAllExecutors()) {
final IReadableResource aRes = aVE.getValidationArtefact().getRuleResource();
final IValidationType aType = aVE.getValidationArtefact().getValidationArtefactType();
if (aType == EValidationType.SCHEMATRON_PURE || aType == EValidationType.SCHEMATRON_SCH) {
IHCNode aTabContent;
try {
// Read Schematron
final SchematronResourceSCH aSch = new SchematronResourceSCH(aRes);
if (!aSch.isValidSchematron())
throw new SchematronPreprocessException("Invalid Schematron!");
final Document aXSLT = aSch.getXSLTProvider().getXSLTDocument();
if (aXSLT == null)
throw new SchematronPreprocessException("Failed to convert to XSLT!");
// Convert to XML string
final String sXML = XMLWriter.getNodeAsString(aXSLT, XWS);
// Highlight
if (bStyleOutput) {
final HCPrismJS aPrism = new HCPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sXML);
aTabContent = aPrism;
} else
aTabContent = pre(sXML);
} catch (final Exception ex) {
aTabContent = error("Error parsing Schematron: " + ex.getMessage());
}
aTabBox.addTab("t" + aTabBox.getTabCount(), FilenameHelper.getBaseName(aRes.getPath()), aTabContent);
} else if (aType == EValidationType.SCHEMATRON_XSLT) {
final IHCNode aTabContent = info("This is already XSLT");
aTabBox.addTab("t" + aTabBox.getTabCount(), FilenameHelper.getBaseName(aRes.getPath()), aTabContent);
}
}
if (aTabBox.hasNoTabs())
aNodeList.addChild(warn("No Schematron artefacts found"));
else
aNodeList.addChild(aTabBox);
} else {
// TODO other action when necessary
}
LOGGER.info("Done");
}
}
use of com.helger.photon.core.form.RequestField in project phoss-directory by phax.
the class PagePublicContact method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final boolean bShowForm = true;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
final String sReCaptcha = StringHelper.trim(aWPEC.params().getAsString("g-recaptcha-response"));
if (StringHelper.hasNoText(sName))
aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
if (StringHelper.hasNoText(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
else if (!EmailAddressHelper.isValid(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
if (StringHelper.hasNoText(sText))
aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptcha)) {
if (!CaptchaSessionSingleton.getInstance().isChecked()) {
// Check only if no other errors occurred
if (ReCaptchaServerSideValidator.check("6LfZFS0UAAAAAONDJHyDnuUUvMB_oNmJxz9Utxza", sReCaptcha).isFailure())
aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
else
CaptchaSessionSingleton.getInstance().setChecked();
}
}
if (aFormErrors.isEmpty()) {
final EmailData aEmailData = new EmailData(EEmailType.TEXT);
aEmailData.setFrom(CPDPublisher.EMAIL_SENDER);
aEmailData.to().add(new EmailAddress("pd@helger.com"));
aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
aEmailData.setSubject("[" + CPDPublisher.getApplication() + "] Contact Form - " + sName);
final StringBuilder aSB = new StringBuilder();
aSB.append("Contact form from " + CPDPublisher.getApplication() + " was filled out.\n\n");
aSB.append("Name: ").append(sName).append("\n");
aSB.append("Email: ").append(sEmail).append("\n");
aSB.append("Topic: ").append(sTopic).append("\n");
aSB.append("Text:\n").append(sText).append("\n");
aEmailData.setBody(aSB.toString());
ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
aWPEC.postRedirectGetInternal(success("Thank you for your message. We will come back to you asap."));
}
}
if (bShowForm) {
aNodeList.addChild(info("Alternatively write an email to pd[at]helger.com - usually using the below form is more effective!"));
aNodeList.addChild(warn("Please don't request any change of data via this contact form - contact your service provider instead. Thank you."));
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
aSelect.addOption("SMP integration");
aSelect.addOption("Website");
aSelect.addOption("REST service");
aSelect.addOption("SMP Statement of use");
aSelect.addOption("General question");
aSelect.addOptionPleaseSelect(aDisplayLocale);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
if (!CaptchaSessionSingleton.getInstance().isChecked()) {
// Add visible Captcha
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create("6LfZFS0UAAAAAJaqpHJdFS_xxY7dqMQjXoBIQWOD", aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
}
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EDefaultIcon.YES));
aForm.addChild(new BootstrapButton().addChild("No thanks").setIcon(EDefaultIcon.CANCEL).setOnClick(aWPEC.getLinkToMenuItem(CMenuPublic.MENU_SEARCH_SIMPLE)));
}
}
use of com.helger.photon.core.form.RequestField in project phoss-directory by phax.
the class PageSecureDeleteManually method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
if (aFormErrors.isEmpty()) {
int nDeleted = 0;
try {
nDeleted = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false);
} catch (final IOException ex) {
// ignore
nDeleted = -1;
}
if (nDeleted > 0)
aWPEC.postRedirectGetInternal(success("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted (" + nDeleted + " rows)"));
else
aWPEC.postRedirectGetInternal(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
}
}
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to delete.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Delete from index", EDefaultIcon.DELETE);
}
use of com.helger.photon.core.form.RequestField in project phoss-directory by phax.
the class PageSecureAdminSMLConfiguration method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLInfo aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final boolean bEdit = eFormAction.isEdit();
aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit SML configuration '" + aSelectedObject.getDisplayName() + "'" : "Create new SML configuration"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_DISPLAY_NAME, aSelectedObject != null ? aSelectedObject.getDisplayName() : null))).setHelpText("The name of the SML configuration. This is for informational purposes only and has no effect on the functionality.").setErrorList(aFormErrors.getListOfField(FIELD_DISPLAY_NAME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("DNS Zone").setCtrl(new HCEdit(new RequestField(FIELD_DNS_ZONE, aSelectedObject != null ? aSelectedObject.getDNSZone() : null))).setHelpText(new HCTextNode("The name of the DNS Zone that this SML is working upon (e.g. "), code("acc.edelivery.tech.ec.europa.eu."), new HCTextNode("). The value will automatically converted to all-lowercase!")).setErrorList(aFormErrors.getListOfField(FIELD_DNS_ZONE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Management Service URL").setCtrl(new HCEdit(new RequestField(FIELD_MANAGEMENT_ADDRESS_URL, aSelectedObject != null ? aSelectedObject.getManagementServiceURL() : null))).setHelpText("The service URL where the SML management application is running on including the host name. It may not contain the '" + CSMLDefault.MANAGEMENT_SERVICE_METADATA + "' or '" + CSMLDefault.MANAGEMENT_SERVICE_PARTICIPANTIDENTIFIER + "' path elements!").setErrorList(aFormErrors.getListOfField(FIELD_MANAGEMENT_ADDRESS_URL)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Client Certificate required?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_CLIENT_CERTIFICATE_REQUIRED, aSelectedObject != null ? aSelectedObject.isClientCertificateRequired() : true))).setHelpText("Check this if this SML requires a client certificate for access. Both Peppol production SML and SMK require a client certificate. Only a locally running SML software may not require a client certificate.").setErrorList(aFormErrors.getListOfField(FIELD_CLIENT_CERTIFICATE_REQUIRED)));
}
use of com.helger.photon.core.form.RequestField in project phoss-directory by phax.
the class PageSecureIndexManually method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final FormErrorList aFormErrors = new FormErrorList();
{
final IPDBusinessCardProvider aBCProv = PDMetaManager.getBusinessCardProvider();
if (aBCProv instanceof SMPBusinessCardProvider) {
final SMPBusinessCardProvider aSMPBCProv = (SMPBusinessCardProvider) aBCProv;
if (aSMPBCProv.isFixedSMP()) {
aNodeList.addChild(info("Fixed SMP URI " + aSMPBCProv.getFixedSMPURI() + " is used."));
} else {
aNodeList.addChild(info("The following SMLs are crawled for entries: " + StringHelper.getImplodedMapped(", ", aSMPBCProv.getAllSMLsToUse(), ISMLInfo::getDisplayName)));
}
}
}
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
if (aFormErrors.isEmpty()) {
if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, CPDStorage.OWNER_MANUALLY_TRIGGERED, PDIndexerManager.HOST_LOCALHOST).isChanged()) {
aWPEC.postRedirectGetInternal(success("The indexing of participant ID '" + sParticipantID + "' was successfully triggered!"));
} else {
aWPEC.postRedirectGetInternal(warn("Participant ID '" + sParticipantID + "' is already in the indexing queue!"));
}
}
}
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to index.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Add to queue", EDefaultIcon.YES);
}
Aggregations