use of com.helger.photon.uictrls.prism.PrismPluginLineNumbers 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.uictrls.prism.PrismPluginLineNumbers in project peppol-practical by phax.
the class PageSecurePeppolSendAS4 method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIF = Phase4PeppolSender.IF;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.params().hasStringValue(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM)) {
final String sSenderID = aWPEC.params().getAsStringTrimmed(FIELD_SENDER_ID);
final IParticipantIdentifier aSenderID = aIF.parseParticipantIdentifier(sSenderID);
final String sReceiverID = aWPEC.params().getAsStringTrimmed(FIELD_RECEIVER_ID);
final IParticipantIdentifier aReceiverID = aIF.parseParticipantIdentifier(sReceiverID);
final String sDocTypeID = aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIF.parseDocumentTypeIdentifier(sDocTypeID);
final String sProcessID = aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID);
final IProcessIdentifier aProcessID = aIF.parseProcessIdentifier(sProcessID);
final String sPayload = aWPEC.params().getAsStringTrimmed(FIELD_PAYLOAD);
final Document aPayloadDoc = DOMReader.readXMLDOM(sPayload);
if (StringHelper.hasNoText(sSenderID))
aFormErrors.addFieldError(FIELD_SENDER_ID, "A sending participant ID must be provided.");
else if (aSenderID == null)
aFormErrors.addFieldError(FIELD_SENDER_ID, "The sending participant ID could not be parsed.");
if (StringHelper.hasNoText(sReceiverID))
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "A receiving participant ID must be provided.");
else if (aReceiverID == null)
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "The receiving participant ID could not be parsed.");
if (StringHelper.hasNoText(sDocTypeID))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "A document type ID must be provided.");
else if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "The document type ID could not be parsed.");
if (StringHelper.hasNoText(sProcessID))
aFormErrors.addFieldError(FIELD_PROCESS_ID, "A process ID must be provided.");
else if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID, "The process ID could not be parsed.");
if (StringHelper.hasNoText(sPayload))
aFormErrors.addFieldError(FIELD_PAYLOAD, "A payload must be provided.");
else if (aPayloadDoc == null)
aFormErrors.addFieldError(FIELD_PAYLOAD, "The payload is not wellformed XML.");
if (aFormErrors.isEmpty()) {
final HCDiv aNL = new HCDiv().addStyle(CCSSProperties.MAX_WIDTH.newValue("80vw"));
final String sAS4PayloadDoc = XMLWriter.getNodeAsString(aPayloadDoc);
final byte[] aAS4PayloadBytes = XMLWriter.getNodeAsBytes(aPayloadDoc);
aNL.addChild(h3("Sending document"));
// Show payload
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sAS4PayloadDoc));
final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {
public void onAS4Message(final AbstractAS4Message<?> aMsg) {
final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
}
};
try {
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST);
// What to remember
final Wrapper<String> aEndpointURL = new Wrapper<>();
final Wrapper<X509Certificate> aEndpointCert = new Wrapper<>();
final Wrapper<EPeppolCertificateCheckResult> aEndpointCertCheck = new Wrapper<>();
final Wrapper<Phase4Exception> aSendEx = new Wrapper<>();
final Wrapper<byte[]> aResponseBytes = new Wrapper<>();
final Wrapper<Ebms3SignalMessage> aResponseMsg = new Wrapper<>();
LOGGER.info("Sending Peppol AS4 message from '" + aSenderID.getURIEncoded() + "' to '" + aReceiverID.getURIEncoded() + "' using document type '" + aDocTypeID.getURIEncoded() + "' and process ID '" + aProcessID.getURIEncoded() + "'");
// Try to send message
final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().cryptoFactory(AS4_CF).documentTypeID(aDocTypeID).processID(aProcessID).senderParticipantID(aSenderID).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aAS4PayloadBytes).smpClient(aSMPClient).endpointURLConsumer(aEndpointURL::set).certificateConsumer((cert, dt, res) -> {
aEndpointCert.set(cert);
aEndpointCertCheck.set(res);
}).validationConfiguration(null).buildMessageCallback(aBuildMessageCallback).outgoingDumper(new AS4OutgoingDumperFileBased()).incomingDumper(new AS4IncomingDumperFileBased()).rawResponseConsumer(r -> aResponseBytes.set(r.getResponse())).signalMsgConsumer(aResponseMsg::set).sendMessageAndCheckForReceipt(aSendEx::set);
LOGGER.info("Sending Peppol AS4 message resulted in " + eResult);
if (aEndpointURL.isSet())
aNL.addChild(div("Sending to this endpoint URL: ").addChild(code(aEndpointURL.get())));
if (aEndpointCert.isSet())
aNL.addChild(div("The message is encrypted for the following receiver: ").addChild(code(aEndpointCert.get().getSubjectX500Principal().getName())));
if (aEndpointCertCheck.isSet())
aNL.addChild(div("The certificate verification resulted in: ").addChild(code(aEndpointCertCheck.get().name())));
if (eResult.isSuccess())
aNL.addChild(success("Successfully send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())));
else
aNL.addChild(error().addChild(div("Failed to send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())).addChild(" with result ").addChild(code(eResult.name()))).addChild(AppCommonUI.getTechnicalDetailsUI(aSendEx.get(), true)));
boolean bShowRaw = true;
if (aResponseMsg.isSet()) {
// Don't do XSD validation here because there is no defined
// "SignalMessage" element
final String sSignalMessage = new GenericJAXBMarshaller<>(Ebms3SignalMessage.class, GenericJAXBMarshaller.createSimpleJAXBElement(new QName(com.helger.phase4.ebms3header.ObjectFactory._Messaging_QNAME.getNamespaceURI(), "SignalMessage"), Ebms3SignalMessage.class)).setFormattedOutput(true).getAsString(aResponseMsg.get());
if (StringHelper.hasText(sSignalMessage)) {
// Show payload
aNL.addChild(div("Response ebMS Signal Message"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sSignalMessage));
bShowRaw = false;
}
}
if (aResponseBytes.isSet()) {
if (bShowRaw) {
aNL.addChild(div("Response message - NOT a valid response"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(new String(aResponseBytes.get(), StandardCharsets.UTF_8)));
}
// Else already shown above
} else {
if (eResult.isSuccess())
aNL.addChild(error("Received no response content :("));
}
} catch (final SMPDNSResolutionException ex) {
aNL.addChild(error(div("Error creating the SMP client.")).addChild(AppCommonUI.getTechnicalDetailsUI(ex, false)));
}
if (true)
aNodeList.addChild(aNL);
else
aWPEC.postRedirectGetInternal(aNL);
}
}
aNodeList.addChild(h3("Send new Peppol AS4 message (Test network only)"));
final BootstrapForm aForm = aNodeList.addAndReturnChild(new BootstrapForm(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Sending participant ID").setCtrl(new HCEdit(new RequestField(FIELD_SENDER_ID, DEFAULT_SENDER_ID))).setHelpText(span("The sending Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_SENDER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Receiving participant ID").setCtrl(new HCEdit(new RequestField(FIELD_RECEIVER_ID, DEFAULT_RECEIVER_ID))).setHelpText(span("The receiving Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_RECEIVER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document type ID").setCtrl(new HCEdit(new RequestField(FIELD_DOCTYPE_ID, DEFAULT_DOCTYPE_ID))).setHelpText(span("The Peppol document type identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_DOCTYPE_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Process ID").setCtrl(new HCEdit(new RequestField(FIELD_PROCESS_ID, DEFAULT_PROCESS_ID))).setHelpText(span("The Peppol process identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_PROCESS_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("XML Payload to be send").setCtrl(new HCTextArea(new RequestField(FIELD_PAYLOAD, DEFAULT_PAYLOAD.get())).setRows(8)).setHelpText("This MUST be wellformed XML - e.g. a UBL Invoice or a CII Invoice. NO Schematron validation is performed. The SBDH is added automatically.").setErrorList(aFormErrors.getListOfField(FIELD_PAYLOAD)));
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send Peppol AS4 message"));
}
Aggregations