Search in sources :

Example 46 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList 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 47 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class AppCommonUI method _createFormattedID.

@Nonnull
private static IHCNode _createFormattedID(@Nonnull final String sID, @Nullable final String sName, @Nullable final EBootstrapBadgeType eType, final boolean bIsDeprecated, final boolean bInDetails) {
    if (sName == null) {
        // No nice name present
        if (bInDetails)
            return new HCCode().addChild(sID);
        return new HCTextNode(sID);
    }
    final HCNodeList ret = new HCNodeList();
    ret.addChild(new BootstrapBadge(eType).addChild(sName));
    if (bIsDeprecated) {
        ret.addChild(" ").addChild(new BootstrapBadge(EBootstrapBadgeType.WARNING).addChild("Identifier is deprecated"));
    }
    if (bInDetails) {
        ret.addChild(new HCSmall().addChild(" (").addChild(new HCCode().addChild(sID)).addChild(")"));
    }
    return ret;
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapBadge(com.helger.photon.bootstrap4.badge.BootstrapBadge) HCCode(com.helger.html.hc.html.textlevel.HCCode) HCSmall(com.helger.html.hc.html.textlevel.HCSmall) HCTextNode(com.helger.html.hc.impl.HCTextNode) Nonnull(javax.annotation.Nonnull)

Example 48 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class AppCommonUI method getDTAndUser.

@Nullable
public static IHCNode getDTAndUser(@Nonnull final IWebPageExecutionContext aWPEC, @Nullable final LocalDateTime aDateTime, @Nullable final String sUserID) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    String sDateTime = null;
    if (aDateTime != null)
        sDateTime = PDTToString.getAsString(aDateTime, aDisplayLocale);
    IHCNode aUserName = null;
    if (sUserID != null) {
        final IUser aUser = PhotonSecurityManager.getUserMgr().getUserOfID(sUserID);
        aUserName = createViewLink(aWPEC, aUser);
    }
    if (sDateTime != null) {
        if (aUserName != null) {
            // Date and user
            return new HCNodeList().addChildren(new HCTextNode("on " + sDateTime + " by "), aUserName);
        }
        // Date only
        return new HCTextNode("on  " + sDateTime);
    }
    if (aUserName != null) {
        // User only
        return new HCNodeList().addChildren(new HCTextNode("by "), aUserName);
    }
    // Neither nor
    return null;
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) IUser(com.helger.photon.security.user.IUser) PDTToString(com.helger.commons.datetime.PDTToString) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode) Nullable(javax.annotation.Nullable)

Example 49 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class AppCommonUI method getTechnicalDetailsUI.

@Nullable
public static HCNodeList getTechnicalDetailsUI(@Nullable final Throwable t, final boolean bLogException) {
    if (t == null)
        return null;
    if (bLogException)
        LOGGER.warn("Technical details", t);
    final HCNodeList ret = new HCNodeList();
    Throwable aCur = t;
    while (aCur != null) {
        if (ret.hasNoChildren())
            ret.addChild(new HCDiv().addChild("Technical details: " + _getString(aCur)));
        else
            ret.addChild(new HCDiv().addChild("Caused by: " + _getString(aCur)));
        aCur = aCur.getCause();
    }
    return ret;
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCNodeList(com.helger.html.hc.impl.HCNodeList) Nullable(javax.annotation.Nullable)

Example 50 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-directory by phax.

the class PageSecureListIndex method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    // Add toolbar
    {
        final BootstrapButtonToolbar aToolbar = aNodeList.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
        aToolbar.addChild(new BootstrapButton().addChild("Refresh").setIcon(EDefaultIcon.REFRESH).setOnClick(aWPEC.getSelfHref()));
        aToolbar.addChild(span("Current server time: " + PDTToString.getAsString(PDTFactory.getCurrentLocalTime(), aDisplayLocale)).addClass(PDCommonUI.CSS_CLASS_VERTICAL_PADDED_TEXT));
    }
    final LinkedBlockingQueue<Object> aQueue = PDMetaManager.getIndexerMgr().getIndexerWorkQueue().getQueue();
    final int nLength = aQueue.size();
    if (nLength == 0) {
        aNodeList.addChild(success("The Index Queue is currently empty"));
    } else {
        aNodeList.addChild(info("The Index Queue contains " + nLength + " entries"));
        final BootstrapTable aTable = new BootstrapTable(new DTCol("Queue date time").setDisplayType(EDTColType.DATETIME, aDisplayLocale).setInitialSorting(ESortOrder.DESCENDING), new DTCol("Participant ID"), new DTCol("Action"), new DTCol("Owner"), new DTCol("Requestor")).setID("indexqueue");
        for (final Object o : aQueue) if (o instanceof IIndexerWorkItem) {
            final IIndexerWorkItem aObj = (IIndexerWorkItem) o;
            final HCRow aRow = aTable.addBodyRow();
            aRow.addCell(PDTToString.getAsString(aObj.getCreationDateTime(), aDisplayLocale));
            aRow.addCell(aObj.getParticipantID().getURIEncoded());
            aRow.addCell(aObj.getType().getDisplayName());
            aRow.addCell(aObj.getOwnerID());
            aRow.addCell(aObj.getRequestingHost());
        }
        aNodeList.addChild(aTable).addChild(BootstrapDataTables.createDefaultDataTables(aWPEC, aTable));
    }
}
Also used : Locale(java.util.Locale) IIndexerWorkItem(com.helger.pd.indexer.index.IIndexerWorkItem) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) HCRow(com.helger.html.hc.html.tabular.HCRow) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)

Aggregations

HCNodeList (com.helger.html.hc.impl.HCNodeList)123 Locale (java.util.Locale)74 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)42 Nonnull (javax.annotation.Nonnull)41 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)40 HCA (com.helger.html.hc.html.textlevel.HCA)35 PDTToString (com.helger.commons.datetime.PDTToString)28 ISimpleURL (com.helger.commons.url.ISimpleURL)27 HCRow (com.helger.html.hc.html.tabular.HCRow)26 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)24 RequestField (com.helger.photon.core.form.RequestField)24 DTCol (com.helger.photon.uictrls.datatables.column.DTCol)24 HCTable (com.helger.html.hc.html.tabular.HCTable)23 BootstrapViewForm (com.helger.photon.bootstrap4.form.BootstrapViewForm)23 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)21 BootstrapDTColAction (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction)21 FormErrorList (com.helger.photon.core.form.FormErrorList)21 BootstrapDataTables (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)20 HCTextNode (com.helger.html.hc.impl.HCTextNode)19 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)19