Search in sources :

Example 16 with RequestField

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");
    }
}
Also used : Locale(java.util.Locale) PrismPluginLineNumbers(com.helger.photon.uictrls.prism.PrismPluginLineNumbers) HCNodeList(com.helger.html.hc.impl.HCNodeList) VESID(com.helger.phive.api.executorset.VESID) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) IReadableResource(com.helger.commons.io.resource.IReadableResource) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) PSReader(com.helger.schematron.pure.exchange.PSReader) Document(org.w3c.dom.Document) PSSchema(com.helger.schematron.pure.model.PSSchema) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) IValidationType(com.helger.phive.api.IValidationType) SchematronPreprocessException(com.helger.schematron.pure.preprocess.SchematronPreprocessException) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) RequestField(com.helger.photon.core.form.RequestField) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) ExtValidationKeySelect(com.helger.peppol.phive.ExtValidationKeySelect) IXMLWriterSettings(com.helger.xml.serialize.write.IXMLWriterSettings) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) IXMLWriterSettings(com.helger.xml.serialize.write.IXMLWriterSettings) IValidationExecutor(com.helger.phive.api.execute.IValidationExecutor) HCPrismJS(com.helger.photon.uictrls.prism.HCPrismJS) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) PSPreprocessor(com.helger.schematron.pure.preprocess.PSPreprocessor) SchematronPreprocessException(com.helger.schematron.pure.preprocess.SchematronPreprocessException) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCUL(com.helger.html.hc.html.grouping.HCUL) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) IPSQueryBinding(com.helger.schematron.pure.binding.IPSQueryBinding) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode)

Example 17 with RequestField

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)));
    }
}
Also used : Locale(java.util.Locale) HCExtSelect(com.helger.photon.uicore.html.select.HCExtSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) EmailData(com.helger.smtp.data.EmailData) EmailAddress(com.helger.commons.email.EmailAddress) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 18 with RequestField

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);
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) IOException(java.io.IOException) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) RequestField(com.helger.photon.core.form.RequestField)

Example 19 with RequestField

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)));
}
Also used : RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) HCTextNode(com.helger.html.hc.impl.HCTextNode) RequestField(com.helger.photon.core.form.RequestField)

Example 20 with RequestField

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);
}
Also used : SMPBusinessCardProvider(com.helger.pd.indexer.businesscard.SMPBusinessCardProvider) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

RequestField (com.helger.photon.core.form.RequestField)40 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)37 HCEdit (com.helger.html.hc.html.forms.HCEdit)34 Locale (java.util.Locale)29 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)24 HCNodeList (com.helger.html.hc.impl.HCNodeList)23 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)20 FormErrorList (com.helger.photon.core.form.FormErrorList)18 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)12 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)12 PDTToString (com.helger.commons.datetime.PDTToString)11 RequestFieldBoolean (com.helger.photon.core.form.RequestFieldBoolean)10 HCTextArea (com.helger.html.hc.html.forms.HCTextArea)9 Nonnull (javax.annotation.Nonnull)9 HCA (com.helger.html.hc.html.textlevel.HCA)8 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)8 HCRow (com.helger.html.hc.html.tabular.HCRow)7 HCTextNode (com.helger.html.hc.impl.HCTextNode)7 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)7 ICommonsList (com.helger.commons.collection.impl.ICommonsList)6