//FILENAME: gazelle/main.java package gazelle; import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; import x30_pkg.x30_util; import static x30_pkg.x30_util.l; import static x30_pkg.x30_util.indexOf; import static x30_pkg.x30_util.getOpt; import static x30_pkg.x30_util.setOpt; import static x30_pkg.x30_util.callOpt; import static x30_pkg.x30_util.get; import static x30_pkg.x30_util.assertTrue; import static x30_pkg.x30_util.isTrue; import loadableUtils.utils; import loadableUtils.utils.CloseablesHolder; import loadableUtils.utils.UploadedImage; import loadableUtils.utils.UploadedFile; import loadableUtils.utils.WithTimestamp; import static loadableUtils.utils.fail; import static loadableUtils.utils.javaCompileToJar_localLibraries; import static loadableUtils.utils.dm_current_mandatory; import static loadableUtils.utils.match; import static loadableUtils.utils.getField; import static loadableUtils.utils.format3; import static loadableUtils.utils.struct; import static loadableUtils.utils.structure; import static loadableUtils.utils.cset; import static loadableUtils.utils.DynamicObject_loading; import static loadableUtils.utils.rethrow; import loadableUtils.utils.F1; import loadableUtils.utils.IF0; import loadableUtils.utils.IF1; import loadableUtils.utils.IVF1; import loadableUtils.utils.IVF2; import loadableUtils.utils.Matches; import loadableUtils.utils.Q; import loadableUtils.utils.structure_Data; import loadableUtils.utils.structure_ClassInfo; import loadableUtils.utils.MultiSet; import loadableUtils.utils.Concept; import loadableUtils.utils.Concepts; import loadableUtils.utils.IConceptCounter; import loadableUtils.utils.IFieldIndex; import loadableUtils.utils.SecretValue; import static loadableUtils.utils.dynamicObjectIsLoading_threadLocal; import loadableUtils.utils.HCRUD; import loadableUtils.utils.HCRUD_Data; import loadableUtils.utils.HCRUD_Concepts; import loadableUtils.utils.HTML; import static loadableUtils.utils.startsWithOneOf; import static loadableUtils.utils.appendParamsToURL; import static loadableUtils.utils.litset; import static loadableUtils.utils.printStackTrace; import static loadableUtils.utils.loadJQuery2; import static loadableUtils.utils.cget; import static loadableUtils.utils.javaTok; import static loadableUtils.utils.getConcept; import static loadableUtils.utils.addPrefix; import static loadableUtils.utils.targetBlank; import static loadableUtils.utils.b; import static loadableUtils.utils.i; import static loadableUtils.utils.n; import static loadableUtils.utils.p; import static loadableUtils.utils.addParamToURL; import static loadableUtils.utils.match2; import static loadableUtils.utils.trueOrNull; import static loadableUtils.utils.callMain; import static loadableUtils.utils.empty; import static loadableUtils.utils.containsAngleBracketVars; import static loadableUtils.utils.list; import static loadableUtils.utils.hasMethod; import static loadableUtils.utils.cic; import static loadableUtils.utils.remove; import static loadableUtils.utils.programID; import static loadableUtils.utils.hselect; import static loadableUtils.utils.print_byThread; import static loadableUtils.utils.conceptsWhere; import static loadableUtils.utils.charAt; import static loadableUtils.utils.conceptWhere; import static loadableUtils.utils.getSnippetTitles; import static loadableUtils.utils.dropTrailingSlash; import static loadableUtils.utils.getOuterClass; import static loadableUtils.utils.cloneList; import static loadableUtils.utils.hstyle_sourceCodeLikeInRepo; import static loadableUtils.utils.ping; import static loadableUtils.utils.formatFunctionCall; import static loadableUtils.utils.ahref_onClick; import static loadableUtils.utils.getDBProgramID; import static loadableUtils.utils.countConceptsCI; import static loadableUtils.utils.div_center; import static loadableUtils.utils.divUnlessEmpty; import static loadableUtils.utils.parseLong; import static loadableUtils.utils.uniqCI2; import static loadableUtils.utils.js_setRedirect; import static loadableUtils.utils.tok_tokenBeforeLonelyReturnValue; import static loadableUtils.utils.eqOneOf; import static loadableUtils.utils.joinWithBR; import static loadableUtils.utils.javaxDataDir; import static loadableUtils.utils.substring; import static loadableUtils.utils.cleanUp; import static loadableUtils.utils.mapPutInRange; import static loadableUtils.utils.getConceptOpt; import static loadableUtils.utils.hhtml; import static loadableUtils.utils.appendBracketed; import static loadableUtils.utils.js_evalOnWebSocketMessage; import static loadableUtils.utils.aGlobalID; import static loadableUtils.utils.synchroWeakHashSet; import static loadableUtils.utils.toDouble; import static loadableUtils.utils.boostHashCombine; import static loadableUtils.utils.formatDoubleArrowMap_horizontallyAligned; import static loadableUtils.utils.thinAProgramsBackups; import static loadableUtils.utils.tempSetTL; import static loadableUtils.utils.dottedSpan; import static loadableUtils.utils.pnl; import static loadableUtils.utils.hPopDownButton; import static loadableUtils.utils.hcenter3; import static loadableUtils.utils.shortName; import static loadableUtils.utils.camelCase; import static loadableUtils.utils.subBot_noCacheHeaders; import static loadableUtils.utils.instancesOf; import static loadableUtils.utils.swic; import static loadableUtils.utils.unnull; import static loadableUtils.utils.joinWithComma; import static loadableUtils.utils.conceptsWithFieldGreaterThan_sorted; import static loadableUtils.utils.replaceDollarVars; import static loadableUtils.utils.postPage; import static loadableUtils.utils.subList; import static loadableUtils.utils.evalWithTimeoutOrFail; import static loadableUtils.utils.addAll; import static loadableUtils.utils.getVar; import static loadableUtils.utils.ahref; import static loadableUtils.utils.serveJSON_breakAtLevels; import static loadableUtils.utils.unlock; import static loadableUtils.utils.replaceVars; import static loadableUtils.utils.psI; import static loadableUtils.utils.warn; import static loadableUtils.utils.isStringList; import static loadableUtils.utils.plural; import static loadableUtils.utils.addIfNotNull; import static loadableUtils.utils.distinctCIFieldValuesOfConcepts; import static loadableUtils.utils.startQ; import static loadableUtils.utils.filterKeys; import static loadableUtils.utils.htmlencode; import static loadableUtils.utils.pair; import static loadableUtils.utils.hbutton; import static loadableUtils.utils.parseInt; import static loadableUtils.utils.hbuttonLink; import static loadableUtils.utils.lastIndexOf; import static loadableUtils.utils.parseFirstLong; import static loadableUtils.utils.vmBus_timerStarted; import static loadableUtils.utils.litciset; import static loadableUtils.utils.joinWithSpace; import static loadableUtils.utils.printIndent; import static loadableUtils.utils.put; import static loadableUtils.utils.fileNotEmpty; import static loadableUtils.utils.deleteConcepts; import static loadableUtils.utils.conceptID; import static loadableUtils.utils.isSubclassOf; import static loadableUtils.utils.joinSubList; import static loadableUtils.utils._hashCode; import static loadableUtils.utils.className; import static loadableUtils.utils.isSnippetID; import static loadableUtils.utils.hjs_copyToClipboard; import static loadableUtils.utils.codeTokens; import static loadableUtils.utils.listPlus; import static loadableUtils.utils.jreplace; import static loadableUtils.utils.fromSingleQuoteIdentifier; import static loadableUtils.utils.small; import static loadableUtils.utils.h2_title; import static loadableUtils.utils.sortedIC; import static loadableUtils.utils.addAnchorToURL; import static loadableUtils.utils.pcallF; import static loadableUtils.utils.replace; import static loadableUtils.utils.ownResource; import static loadableUtils.utils.makePostData; import static loadableUtils.utils.dynamize_noEncode; import static loadableUtils.utils.wrapInDiv; import static loadableUtils.utils.hjs; import static loadableUtils.utils.getClassName; import static loadableUtils.utils.sortedByCalculatedFieldDesc; import static loadableUtils.utils.iterateWithIndex1; import static loadableUtils.utils.sleepSeconds; import static loadableUtils.utils.values; import static loadableUtils.utils.parseLongOpt; import static loadableUtils.utils.toObjectArray; import static loadableUtils.utils.loadTextFile; import static loadableUtils.utils.mapValues; import static loadableUtils.utils.hbody; import static loadableUtils.utils.stringIf; import static loadableUtils.utils.third; import static loadableUtils.utils.hsansserif; import static loadableUtils.utils.div_vbar; import static loadableUtils.utils.isSingleQuoteIdentifier; import static loadableUtils.utils.javaTokWithAngleBrackets; import static loadableUtils.utils.conceptsWhereCI; import static loadableUtils.utils.callF; import static loadableUtils.utils.eqic_gen; import static loadableUtils.utils.trim; import static loadableUtils.utils.replaceAngleBracketVars_curly; import static loadableUtils.utils.phraseCache; import static loadableUtils.utils.htitle_h2; import static loadableUtils.utils.htitle_h1; import static loadableUtils.utils.stdFunctions_cached; import static loadableUtils.utils.domain; import static loadableUtils.utils.hreconnectingWebSockets; import static loadableUtils.utils.hscript; import static loadableUtils.utils.exceptionToStringShort; import static loadableUtils.utils.toString; import static loadableUtils.utils.div; import static loadableUtils.utils.stepAllWithTimeout; import static loadableUtils.utils.sortedByConceptIDDesc; import static loadableUtils.utils.joinNemptiesWithColon; import static loadableUtils.utils.joinNemptiesWithSpace; import static loadableUtils.utils.conceptsWhereIC; import static loadableUtils.utils.dropLoadableUtilsPackageFromStruct; import static loadableUtils.utils.hashCode; import static loadableUtils.utils.shortClassName; import static loadableUtils.utils.postProcess; import static loadableUtils.utils.htextfield; import static loadableUtils.utils.hhidden; import static loadableUtils.utils.print; import static loadableUtils.utils.mapPairs; import static loadableUtils.utils.lock; import static loadableUtils.utils.firstToLower; import static loadableUtils.utils.simpleSpacesTrim_javaTok; import static loadableUtils.utils.hpostform; import static loadableUtils.utils.litlist; import static loadableUtils.utils.cancelTimer; import static loadableUtils.utils.map; import static loadableUtils.utils.isStringCollection; import static loadableUtils.utils.max; import static loadableUtils.utils.addParamsToURL; import static loadableUtils.utils.md5; import static loadableUtils.utils.javaValueToHTML; import static loadableUtils.utils.isTrue_getOpt; import static loadableUtils.utils.htmlEncode_quote; import static loadableUtils.utils.indexConceptFieldIC; import static loadableUtils.utils.hotwire_makeClassLoader; import static loadableUtils.utils.deref; import static loadableUtils.utils.dbBot; import static loadableUtils.utils.putAll; import static loadableUtils.utils.sourceCodeToHTML_noEncode; import static loadableUtils.utils.dropSuffix; import static loadableUtils.utils.subBot_serveWithContentType; import static loadableUtils.utils.cForwardAndBackRefsWithFieldIndicator; import static loadableUtils.utils.objectsWhereCI; import static loadableUtils.utils.getStringOpt; import static loadableUtils.utils.pIfNempty; import static loadableUtils.utils.removeAll; import static loadableUtils.utils.isURL; import static loadableUtils.utils.elapsedSeconds_sysNow; import static loadableUtils.utils.pairsA; import static loadableUtils.utils.swic_notSame; import static loadableUtils.utils.hstyle; import static loadableUtils.utils.uncurly; import static loadableUtils.utils.min; import static loadableUtils.utils.htmlTable2_noHtmlEncode; import static loadableUtils.utils.parseSecondLong; import static loadableUtils.utils.cloneMap; import static loadableUtils.utils.ifThenElse; import static loadableUtils.utils.himgsnippet; import static loadableUtils.utils.jsQuote; import static loadableUtils.utils.htmlEncode2_nlToBr; import static loadableUtils.utils.ymd_minus_hms; import static loadableUtils.utils.hsnippetimg_scaleToWidth; import static loadableUtils.utils.evalWithTimeout; import static loadableUtils.utils.lookupPossiblyCI; import static loadableUtils.utils.strOrNull; import static loadableUtils.utils._close; import static loadableUtils.utils.starsToAngleBracketedNumbers; import static loadableUtils.utils.countPred; import static loadableUtils.utils.jsonDecodeMap; import static loadableUtils.utils._entrySet; import static loadableUtils.utils.first; import static loadableUtils.utils.span; import static loadableUtils.utils.litorderedmap; import static loadableUtils.utils.tok_subListWithoutBorderNTokens; import static loadableUtils.utils.multiSetToPairsByPopularity; import static loadableUtils.utils.mapPut; import static loadableUtils.utils.objectToMap; import static loadableUtils.utils.hsnippetimg; import static loadableUtils.utils.renderEqualsCommaProperties; import static loadableUtils.utils.hmobilefix; import static loadableUtils.utils.dropDollarPrefix; import static loadableUtils.utils.printVars_str; import static loadableUtils.utils.hotwire; import static loadableUtils.utils.round; import static loadableUtils.utils.span_title; import static loadableUtils.utils.hNotificationPopups; import static loadableUtils.utils.firstNotNull; import static loadableUtils.utils.score; import static loadableUtils.utils.quote; import static loadableUtils.utils.htmlEncode_nlToBr_withIndents; import static loadableUtils.utils.htmlTable2; import static loadableUtils.utils.contains; import static loadableUtils.utils.countConceptsWhereCI; import static loadableUtils.utils.uniqCI; import static loadableUtils.utils.jsonEncodeMap; import static loadableUtils.utils.sleep; import static loadableUtils.utils.allConcepts; import static loadableUtils.utils.isB; import static loadableUtils.utils.subBot_serveRedirect; import static loadableUtils.utils.uniquifyCI; import static loadableUtils.utils.close; import static loadableUtils.utils.standardClassesMap; import static loadableUtils.utils.conceptWhereIC; import static loadableUtils.utils.swing; import static loadableUtils.utils.stdFunctions_uncached; import static loadableUtils.utils.findEndOfBracketPart; import static loadableUtils.utils._getClass; import static loadableUtils.utils.indentStructureString_firstLevels; import static loadableUtils.utils.add; import static loadableUtils.utils.ciMultiMap; import static loadableUtils.utils.hcss; import static loadableUtils.utils.mapKeys; import static loadableUtils.utils.clearTokens; import static loadableUtils.utils.subBot_serve500; import static loadableUtils.utils.saveTextFile; import static loadableUtils.utils.conceptWhereCI; import static loadableUtils.utils.pnlToString; import static loadableUtils.utils.lines; import static loadableUtils.utils.unquote; import static loadableUtils.utils.tok_expandIfQuoted; import static loadableUtils.utils.nempty; import static loadableUtils.utils.serveText; import static loadableUtils.utils.sortByConceptID; import static loadableUtils.utils.shorten; import static loadableUtils.utils.jfindAll; import static loadableUtils.utils.litmap; import static loadableUtils.utils.weakSet; import static loadableUtils.utils.myClassLoader; import static loadableUtils.utils.hrefresh; import static loadableUtils.utils.countConceptsWhereIC; import static loadableUtils.utils.beforeVerticalBar; import static loadableUtils.utils.isIdentifier; import static loadableUtils.utils.dropTrailingSlashIfNemptyAfterwards; import static loadableUtils.utils.neq; import static loadableUtils.utils.all; import static loadableUtils.utils.paramsPlus_inFront; import static loadableUtils.utils.inputText; import static loadableUtils.utils.uniq; import static loadableUtils.utils.collect; import static loadableUtils.utils.scanForComponents; import static loadableUtils.utils.nullIfEmpty; import static loadableUtils.utils.isSafeStandardFunction; import static loadableUtils.utils.indent; import static loadableUtils.utils.angleBracketVarsToStars; import static loadableUtils.utils.derefRef; import static loadableUtils.utils.dbBotStandardName; import static loadableUtils.utils.joinNempties; import static loadableUtils.utils.optCast; import static loadableUtils.utils.reversed; import static loadableUtils.utils.done2_always; import static loadableUtils.utils.programFile; import static loadableUtils.utils.dropFirstAndLast; import static loadableUtils.utils.dm_doEvery; import static loadableUtils.utils.setOptAllDyn_pcall; import static loadableUtils.utils.onIndividualConceptChange_notOnAllChanged; import static loadableUtils.utils.pcallOpt; import static loadableUtils.utils.nonNulls; import static loadableUtils.utils.hinputfield; import static loadableUtils.utils.replaceAngleBracketVars; import static loadableUtils.utils.litobjectarray; import static loadableUtils.utils.strOrEmpty; import static loadableUtils.utils.call; import static loadableUtils.utils.cnew; import static loadableUtils.utils.uniqCI_returnIfNew; import static loadableUtils.utils.run; import static loadableUtils.utils.isInteger; import static loadableUtils.utils.cdelete; import static loadableUtils.utils.now; import static loadableUtils.utils.csetIfUnset; import static loadableUtils.utils.hsubmit; import static loadableUtils.utils.eqicOneOf; import static loadableUtils.utils.htitle; import static loadableUtils.utils.htmlEncode2; import static loadableUtils.utils.hdiv; import static loadableUtils.utils.dropLeadingSlash; import static loadableUtils.utils.optPar; import static loadableUtils.utils.allPlus; import static loadableUtils.utils.h1_title; import static loadableUtils.utils.javaTokC; import static loadableUtils.utils.callFAll; import static loadableUtils.utils.match3_withIntsAndIDs; import static loadableUtils.utils.getClass; import static loadableUtils.utils.containsKey; import static loadableUtils.utils.jsonEncode; import static loadableUtils.utils.joinNemptiesWithVBar; import static loadableUtils.utils.mapGet; import static loadableUtils.utils.parseSnippetID; import static loadableUtils.utils.firstToUpper; import static loadableUtils.utils.asList; import static loadableUtils.utils.neatMechListURL; import static loadableUtils.utils.endsWith; import static loadableUtils.utils.listSet; import static loadableUtils.utils.hfulltag; import static loadableUtils.utils.allBackRefs; import static loadableUtils.utils.vmBus_send; import static loadableUtils.utils.serveJSON; import static loadableUtils.utils.set; import static loadableUtils.utils.hselect_list; import static loadableUtils.utils.sfu; import static loadableUtils.utils.getStackTrace; import static loadableUtils.utils.javax; import static loadableUtils.utils.isQuoted; import static loadableUtils.utils.hhiddenMulti; import static loadableUtils.utils.isFalse; import static loadableUtils.utils.eq; import static loadableUtils.utils.hinlinepostform; import static loadableUtils.utils.hform; import static loadableUtils.utils.h1; import static loadableUtils.utils.h2; import static loadableUtils.utils.h3; import static loadableUtils.utils.random; import static loadableUtils.utils.md5OrNull; import static loadableUtils.utils.pcallFAll; import static loadableUtils.utils.getString; import static loadableUtils.utils.conceptsFile; import static loadableUtils.utils.urlencode; import static loadableUtils.utils.hr; import static loadableUtils.utils.join; import static loadableUtils.utils.fsI; import static loadableUtils.utils.clamp; import static loadableUtils.utils.binaryMimeType; import static loadableUtils.utils.stringTree2_javaTok; import static loadableUtils.utils.lmap; import static loadableUtils.utils.ahref_undecorated; import static loadableUtils.utils.replaceDollarVars_dyn; import static loadableUtils.utils.change; import static loadableUtils.utils.assertEquals; import static loadableUtils.utils.tlft; import static loadableUtils.utils.dm_startQ; import static loadableUtils.utils.ll; import static loadableUtils.utils.n2; import static loadableUtils.utils.second; import static loadableUtils.utils.replaceTokens; import static loadableUtils.utils.takeFirst; import static loadableUtils.utils.hparagraphs; import static loadableUtils.utils.jsonEncode_breakAtLevel1; import static loadableUtils.utils.keys; import static loadableUtils.utils.uniqCI2_sync; import static loadableUtils.utils.smartIndexOf; import static loadableUtils.utils.parseDouble; import static loadableUtils.utils.ol; import static loadableUtils.utils.or; import static loadableUtils.utils.dropPunctuation; import static loadableUtils.utils.rtrim; import static loadableUtils.utils.iterator; import static loadableUtils.utils.putMultipleKeys; import static loadableUtils.utils.assertNotNull; import static loadableUtils.utils.str; import static loadableUtils.utils.tempInterceptPrint; import static loadableUtils.utils.printWithIndent; import static loadableUtils.utils.hfullcenter; import static loadableUtils.utils.syncAddOrCreate; import static loadableUtils.utils.appendRoundBracketed; import static loadableUtils.utils.getMainClass; import static loadableUtils.utils.asCISet; import static loadableUtils.utils.th; import static loadableUtils.utils.syncMapToPairs; import static loadableUtils.utils.tt; import static loadableUtils.utils.dm_moduleID; import static loadableUtils.utils.doublePut; import static loadableUtils.utils.conceptIDOrNull; import static loadableUtils.utils.ul; import static loadableUtils.utils.programDir; import static loadableUtils.utils.or2; import static loadableUtils.utils._get; import static loadableUtils.utils.div_alignRight; import static loadableUtils.utils.gazelle_allSyntacticPatternsFromInput; import static loadableUtils.utils.eqGet; import static loadableUtils.utils.ul_htmlEncode; import static loadableUtils.utils.eqic; import static loadableUtils.utils.hpre_htmlencode; import static loadableUtils.utils.pairA; import static loadableUtils.utils._handleException; import static loadableUtils.utils.longSnippetLink; import static loadableUtils.utils.pairB; import static loadableUtils.utils.htitledSectionWithDiv; import static loadableUtils.utils.urldecode; import static loadableUtils.utils.dropPrefix; import static loadableUtils.utils.getClientIPFromHeaders; import static loadableUtils.utils.allToString; import static loadableUtils.utils.filter; import static loadableUtils.utils.getWeakRef; import static loadableUtils.utils.doLater; import static loadableUtils.utils.ensureDBNotRunning; import static loadableUtils.utils.findBackRefs; import static loadableUtils.utils.htmlEncode_nlToBR; import static loadableUtils.utils.tok_findEndOfStatement; import static loadableUtils.utils.stringTreeLeafValue2; import static loadableUtils.utils.syncL; import static loadableUtils.utils.htextarea; import static loadableUtils.utils.hhead; import static loadableUtils.utils.toLong; import static loadableUtils.utils.localTimeWithSeconds; import static loadableUtils.utils.hjs_selectize; import static loadableUtils.utils.concatLists; import static loadableUtils.utils.isInQ; import static loadableUtils.utils.countTokens; import static loadableUtils.utils.unicode_smallDownPointingTriangle; import static loadableUtils.utils.renderVars; import static loadableUtils.utils.ahref_possiblyTargetBlank; import static loadableUtils.utils.sysNow; import static loadableUtils.utils.countConcepts; import static loadableUtils.utils.hPopDownButtonWithText; import static loadableUtils.utils.getAll; import static loadableUtils.utils.hjavascript_src_snippet; import static loadableUtils.utils.countWordsWithoutAngleBracketedAndStars; import static loadableUtils.utils.startsWith; import loadableUtils.utils.Scorer; import loadableUtils.utils.ConceptsRefChecker; import loadableUtils.utils.ConceptFieldIndexDesc; import loadableUtils.utils.IWebRequest; import loadableUtils.utils.Flag; import loadableUtils.utils.StringBufferWithMaxSize; import loadableUtils.utils.IFieldsToList; import loadableUtils.utils.DynNewBot2; import loadableUtils.utils.DynGazelleRocks; import loadableUtils.utils.ConceptWithGlobalID; import loadableUtils.utils.Timestamp; import loadableUtils.utils.MultiMap; import loadableUtils.utils.HTMLTabs; import loadableUtils.utils.BreadthFirstPathFinder_withLinkType; import loadableUtils.utils.ReliableSingleThread_Multi; import loadableUtils.utils.Steppable; import loadableUtils.utils.Pair; import loadableUtils.utils.HTMLFramer1; import loadableUtils.utils.JavaXClassLoader; import loadableUtils.utils.StringTree2; import loadableUtils.utils.IntRange; import loadableUtils.utils.FieldIndicator; import loadableUtils.utils.JavaXClassLoaderWithParent2; import loadableUtils.utils.HDivWithVerticalExpandButton; import loadableUtils.utils.CMissingObject; import loadableUtils.utils.ConceptsShadowLogger; import loadableUtils.utils.ConceptClassesDependentValue; import loadableUtils.utils.ConceptShadow; import loadableUtils.utils.HTMLPopDownButton; import loadableUtils.utils.TransitiveHull; import loadableUtils.utils.CreatedDeletedChanged; import loadableUtils.utils.HTMLPaginator; import static loadableUtils.utils.parseEqualsProperties; import static loadableUtils.utils.nItems; import static loadableUtils.utils.prependParamIfOddCount; import static loadableUtils.utils.objectsWhereNotIC; import static loadableUtils.utils._className; import static loadableUtils.utils.replaceConceptAndUpdateRefs; import static loadableUtils.utils.afterDollar; import static loadableUtils.utils.collectAngleBracketVars; import static loadableUtils.utils.regexpToLongIC; import static loadableUtils.utils.countWhereCI; import static loadableUtils.utils.regexpReplace_directWithRefs; import static loadableUtils.utils.regexpExtractGroups; import static loadableUtils.utils.rcallOpt; import static loadableUtils.utils.htmlEncode2_str; import static loadableUtils.utils.vmClassNameToSubPath; import static loadableUtils.utils.unicode_thumbsUp; import static loadableUtils.utils.lastTiming_formatted; import static loadableUtils.utils.putKeysFirst; import static loadableUtils.utils.diffConceptShadows; import static loadableUtils.utils.addByteCodePathToClassLoader; import static loadableUtils.utils.allConceptShadows; import static loadableUtils.utils.hasMethodNamed; import static loadableUtils.utils.indexConceptFieldCIWithTopTen; import static loadableUtils.utils.startsWithAny; import static loadableUtils.utils.assertSame; import static loadableUtils.utils.byteCodePathForClass; import static loadableUtils.utils.fourth; import static loadableUtils.utils.shorten_str; import static loadableUtils.utils.combinePrintParameters; import static loadableUtils.utils.format_quoted; import static loadableUtils.utils.unnullForIteration; import static loadableUtils.utils.mapToLinkedHashSet; import static loadableUtils.utils.js_redirectAutoScroll2; import static loadableUtils.utils.pcall; import static loadableUtils.utils.dm_mediumRefreshTranspiler; import static loadableUtils.utils.compileRegexpPossiblyIC_unicodeCase; import static loadableUtils.utils.getBoolOpt; import static loadableUtils.utils.printVars; import static loadableUtils.utils.profileThisThreadToString; import static loadableUtils.utils.getStandardFunctionHolder; import static loadableUtils.utils.renderConceptClassesWithCount; import static loadableUtils.utils.tok_integers; import static loadableUtils.utils.fileExistsInInDirOrZip; import static loadableUtils.utils.formatGMTWithMilliseconds_24; import static loadableUtils.utils.subBot_serveFileWithName; import static loadableUtils.utils.joinNemptiesWithEmptyLines; import static loadableUtils.utils.findBackRefsWithField; import static loadableUtils.utils.filesFromClassLoader; import static loadableUtils.utils.leadingAngleBracketStuff; import static loadableUtils.utils.jquery_submitFormOnCtrlEnter; import static loadableUtils.utils.nDiffs; import static loadableUtils.utils.fixHTML; import static loadableUtils.utils.dm_reloadModule; import static loadableUtils.utils.concatMap_lists; import static loadableUtils.utils.findConcept; import static loadableUtils.utils.hijackPrintPlusResult_text; import static loadableUtils.utils.indexConceptClass; import static loadableUtils.utils.regexpFindRangesIC; import static loadableUtils.utils.cCall; import static loadableUtils.utils.toCIMap; import static loadableUtils.utils.nPatterns; import static loadableUtils.utils.containsStars; import static loadableUtils.utils.assertNempty; import static loadableUtils.utils.call_optional; import static loadableUtils.utils.distinctCIFieldValuesOfConcepts_multiSet; import static loadableUtils.utils.transpilerErrorSourceFile; import static loadableUtils.utils.combineAutoCloseables; import static loadableUtils.utils.jfind_any; import static loadableUtils.utils.hjs_handleScrollToAnchor; import static loadableUtils.utils.unicode_thumbsDown; import static loadableUtils.utils.id; import static loadableUtils.utils.unlistedCopyToClass_withConverter; import static loadableUtils.utils.returnTimed; import static loadableUtils.utils.cgetOpt; import static loadableUtils.utils.dropDotSuffix; import static loadableUtils.utils.classLoaderPathsCount; import static loadableUtils.utils.csetAndReturn; import static loadableUtils.utils.htmlDecode_dropTags; import static loadableUtils.utils.dm_reloadModuleIn; import static loadableUtils.utils.appendSquareBracketed; import static loadableUtils.utils.truncateListFromStart; import static loadableUtils.utils.getAny; import static loadableUtils.utils.joinWithDot; import static loadableUtils.utils.ul_htmlEncode2; import static loadableUtils.utils.wideningListCast; import static loadableUtils.utils.dm_moduleClassLoader; import static loadableUtils.utils.hSingleRowTable_withSpacing; import static loadableUtils.utils.transpileAndCompileForHotwiring; import static loadableUtils.utils.transpileAndCompileForHotwiring_src; import static loadableUtils.utils.printAllConceptChanges; import static loadableUtils.utils.setMinus_inPlace; import static loadableUtils.utils.tok_dropCurlyBrackets; import static loadableUtils.utils.classLoader_loadClass; import static loadableUtils.utils.getConceptOrMarkMissingObject; import static loadableUtils.utils.keysAndValuesToString; import static loadableUtils.utils.dm_addByteCodePathToModuleClassLoader; import static loadableUtils.utils.flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_first; import static loadableUtils.utils.regexpFirstGroups; import static loadableUtils.utils.dm_rstMulti; import static loadableUtils.utils.syncLinkedHashSet; import static loadableUtils.utils.listPlusItems_inPlace; import static loadableUtils.utils.cCallOpt; import static loadableUtils.utils.find; import static loadableUtils.utils.subBot_serveText; import static loadableUtils.utils.mapToValues_ciMap; import static loadableUtils.utils.tok_identifiers; import static loadableUtils.utils.get2; import static loadableUtils.utils.cPcall; import static loadableUtils.utils.renameFileVerbose; import static loadableUtils.utils.jMatchStart; import static loadableUtils.utils.llNempties; import static loadableUtils.utils.getIntOpt; import static loadableUtils.utils.bitSetStreaksAndNonStreaks; import static loadableUtils.utils.classLoaderContainsByteCodePath; import static loadableUtils.utils.quickImportMainConcepts; import static loadableUtils.utils.dotToDollar; import static loadableUtils.utils.dm_onSnippetTranspiled; import static loadableUtils.utils.assertStringList; import static loadableUtils.utils.stepAllAndGet; import static loadableUtils.utils.nObjects; import static loadableUtils.utils.setFieldToIF1Proxy; import static loadableUtils.utils.aname; import static loadableUtils.utils.mapToKey; import static loadableUtils.utils.regexpGroups; import static loadableUtils.utils.filePrintWriter_append; import static loadableUtils.utils.parseDateWithMillisecondsGMT; import loadableUtils.utils.TimedCache; import loadableUtils.utils.JS; import static loadableUtils.utils.hcenter; import static loadableUtils.utils.hlinkButton; import static loadableUtils.utils.parseFirstLong_regexp; import static loadableUtils.utils.makeAbsoluteURL; import static loadableUtils.utils.shortClassName_dropNumberPrefix; import static loadableUtils.utils.dm_vmBus_answerToMessage; import static loadableUtils.utils.pre_htmlEncode; import static loadableUtils.utils.methodsSortedByNameIC; import static loadableUtils.utils.unlistedCopyToClass_withConverter_pcall; import static loadableUtils.utils.addFilenameHeader; import static loadableUtils.utils.isIntegerOrIdentifier; import static loadableUtils.utils.splitAtSpace_trim; import static loadableUtils.utils.userAgentIsBot; import static loadableUtils.utils.deleteConceptsWhereIC; import static loadableUtils.utils.linesLL; import static loadableUtils.utils.hjs_selectizeClickable; import static loadableUtils.utils.routeThroughAll; import static loadableUtils.utils.eqOrEqic; import static loadableUtils.utils.nemptyLinesLL; import static loadableUtils.utils.syncCompactSet; import static loadableUtils.utils.getMigration; import static loadableUtils.utils.ahref_noFollow; import static loadableUtils.utils.actualMCDollar; import static loadableUtils.utils.inlineSwappable; import static loadableUtils.utils.startsWith_addingSlash; import static loadableUtils.utils.waitForQToEmpty; import static loadableUtils.utils.tok_integersAsLongs; import static loadableUtils.utils.snippetURL; import static loadableUtils.utils.inQ; import static loadableUtils.utils.addLibrariesToClassLoader; import static loadableUtils.utils.trailingLong_regexp; import static loadableUtils.utils.addSlashSuffix; import static loadableUtils.utils.renderStackTrace; import static loadableUtils.utils.isTrueOpt; import static loadableUtils.utils.dynShortClassName; import static loadableUtils.utils.structure_convertTokenMarkersToExplicit; import static loadableUtils.utils.shortenStr; import static loadableUtils.utils.fixConceptIDs; import static loadableUtils.utils.nCodeTokens; import static loadableUtils.utils.targetBlank_noFollow; import static loadableUtils.utils.withoutInstancesOf; import static loadableUtils.utils.assertSameVerbose; import static loadableUtils.utils.getInnerClass; import static loadableUtils.utils.realMC; import static loadableUtils.utils.getProgramURL; import static loadableUtils.utils.allLiveMethodsBelowClass; import static loadableUtils.utils.dateWithSecondsUTC; import loadableUtils.utils.F3; import loadableUtils.utils.ConceptFieldIndexCI_certainValues; import loadableUtils.utils.User; import loadableUtils.utils.UserPost; import loadableUtils.utils.Conversation; import loadableUtils.utils.ExecutedStep; import loadableUtils.utils.InputHandled; import loadableUtils.utils.AuthedDialogID; import loadableUtils.utils.UploadedSound; import static loadableUtils.utils.passwordSalt; public class main { static public class UnvaxxedSite extends GazelleBEA { public void init() { super.init(); botName = heading = adminName = "Unvaxxed // Still Alive"; showCRUDToEveryone = false; showInputAndPatternNavItems = false; } } static public boolean _moduleClass_UnvaxxedSite = true; static { mainLibID = "#1030952"; } static public String programID; static public void _onLoad_initUtils() { utils.__javax = javax(); } static public ThreadLocal dynamicObjectIsLoading_threadLocal() { return DynamicObject_loading; } static public class BEACalculations { public GazelleBEA mod; public BEACalculations(GazelleBEA mod) { this.mod = mod; } transient public int liveOutputDelay = 1000; transient public double algoTimeout = 30.0; public void reactAllInputsWithSomePatterns() { for (BEAObject input : mod.beaObjectsOfType("input")) { ReactInputWithSomePatterns r = new ReactInputWithSomePatterns(); r.input = input; r.ccOut = db_mainConcepts(); r.max = 10; r.start(); stepAllWithTimeout(10.0, r); } } public void reactAllInputsWithAllSyntacticPatterns() { for (BEAObject input : mod.beaList("input")) { ping(); for (BEAObject pattern : mod.beaList("Syntactic Pattern")) { ping(); { if (patternAlwaysMatches(pattern)) continue; } reactInputWithPattern(input, pattern); } } } public void reactAllInputsWithPattern(BEAObject pattern) { for (BEAObject input : mod.beaList("input")) { ping(); reactInputWithPattern(input, pattern); } } public boolean patternAlwaysMatches(BEAObject pat) { return isTrue_getOpt("alwaysMatches", pat); } public class ReactInputWithSomePatterns implements Steppable { public BEAObject input; public Concepts ccOut; public int max = 3, n; public Iterator patterns; public void start() { n = countConceptsWhereIC(ccOut, BEAObject.class, "input", input, "type", "match"); patterns = iterator(sortByConceptID(conceptsWhereIC(BEAObject.class, "type", "Pattern"))); } public boolean step() { if (n >= max) return false; if (!patterns.hasNext()) return false; if (reactInputWithPattern(input, patterns.next(), ccOut) != null) ++n; return true; } } public Pair> matchInputWithPatternList(String text, BEAObject patternList) { List patterns = (List) (cget("patterns", patternList)); for (BEAObject pattern : unnullForIteration(patterns)) { Map mapping = matchInputWithPattern(text, pattern); if (mapping != null) return pair(pattern, mapping); } return null; } public ThreadLocal matchInput_droppedPunctuation = new ThreadLocal(); public Map matchInputWithPattern(BEAObject input, BEAObject pattern) { String text = getString("text", input); return matchInputWithPattern(text, pattern); } public Map matchInputWithPattern(String text, BEAObject pattern) { String pat = getString("text", pattern); boolean punctuationOnly = isTrue_getOpt("punctuationOnly", pattern); if (pattern.typeIs("Syntactic Pattern")) return matchInputWithSyntacticPattern(text, pat, punctuationOnly); else if (eqic_gen(getOpt("subType", pattern), "PhraseCache")) return phraseCache(pat, text) ? litmap() : null; else return matchInputWithPattern(text, pat, punctuationOnly); } public Map matchInputWithSyntacticPattern(String text, String pat) { return matchInputWithSyntacticPattern(text, pat, false); } public Map matchInputWithSyntacticPattern(String text, String pat, boolean punctuationOnly) { pat = starsToAngleBracketedNumbers(pat); return matchInputWithPattern(text, pat, punctuationOnly); } public Map matchInputWithPattern(String text, String pat) { return matchInputWithPattern(text, pat, false); } public Map matchInputWithPattern(String text, String pat, boolean punctuationOnly) { Map mapping = flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_first(pat, text); if (mapping != null || punctuationOnly) return mapping; return null; } public BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern) { return reactInputWithPattern(input, pattern, db_mainConcepts()); } public BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern, Concepts ccOut) { if (input == null || pattern == null) return null; matchInput_droppedPunctuation.set(false); Map mapping = matchInputWithPattern(input, pattern); if (mapping == null) return null; BEAObject match = uniqCI(ccOut, BEAObject.class, "type", "Match", "input", input, "pattern", pattern); cset(match, "mapping", mapping, "droppedPunctuation", trueOrNull(matchInput_droppedPunctuation.get())); return match; } public Object serveAnalyzeInput(GazelleBEA.Req req) { Concepts ccOut = new Concepts(); BEAObject input = getConcept(BEAObject.class, parseLong(req.get("id"))); if (input == null) input = cnew(ccOut, BEAObject.class, "type", "Input", "text", req.get("q")); String text = getString("text", input); ReactInputWithSomePatterns r = new ReactInputWithSomePatterns(); r.input = input; r.ccOut = ccOut; r.max = 1000; r.start(); stepAllWithTimeout(10.0, r); Collection matches = conceptsWhereIC(ccOut, BEAObject.class, "type", "Match"); return h1_title("Analyze Input") + p("Input: " + b(htmlEncode_nlToBr_withIndents(text))) + p(empty(matches) ? "No matches" : "Matches") + ul_htmlEncode(matches); } public Object serveQueryPage(GazelleBEA.Req req) { return serveQueryPage(req, false); } public Object serveQueryPage(GazelleBEA.Req req, boolean withFrame) { String q = req.get("q"), algorithm = req.get("algorithm"); boolean dontRun = eq(req.get("dontRun"), "1"); boolean liveOutput = eq(req.get("liveOutput"), "1"); if (liveOutput) req.noSpam(); if (eqic(algorithm, "process input")) algorithm = "Process new input v3"; Map> algorithms = algorithms(); String output = empty(algorithm) || dontRun ? null : doAlgorithm(algorithms, algorithm, q, liveOutput); if (liveOutput) return jsonEncode(litorderedmap("answer", output)); String right = withFrame ? "" : mod.html_loggedIn(); Algorithm alg = callF(lookupPossiblyCI(algorithms, algorithm)); if (alg != null) { alg.q = q; alg.req = mod.currentReq(); } String centered = (withFrame ? "" : htitle_h2(ahref(mod.baseLink + "/", "Gazelle") + " Query" + htmlEncode2((empty(q) ? "" : ": " + q) + appendSquareBracketed(algorithm)))) + hscript(replaceVars("\r\n var sugLoading = false, sugTriggerAgain = false;\r\n\r\n function sugTrigger() {\r\n console.log(\"sugTrigger\");\r\n if (sugLoading) { sugTriggerAgain = true; return; }\r\n\r\n // get form data as JSON\r\n \r\n var data = {\r\n \"liveOutput\" : \"1\",\r\n \"q\": $(\"textarea[name=q]\").val(),\r\n \"algorithm\": $(\"select[name=algorithm]\").val(),\r\n \"algorithmID\": $(\"select[name=algorithmID]\").val(), // XXX: do this for all additional alg parameters\r\n };\r\n \r\n const url = \"/query\";\r\n console.log(\"Loading \" + url + \" with \" + data);\r\n sugLoading = true;\r\n $.post(url, data,\r\n function(result) {\r\n console.log(\"Suggestor result: \" + result);\r\n const answer = !result ? \"\" : JSON.parse(result).answer;\r\n if (answer) {\r\n $(\"#liveResult .sectionContents\").html(answer);\r\n $(\"#liveResult\").show();\r\n } else\r\n $(\"#liveResult\").hide();\r\n //$(\"#suggestorResult\").html(answer ? \"Suggestor says: \" + answer : \"\");\r\n }\r\n ).always(function() {\r\n console.log(\"sug loading done\");\r\n setTimeout(function() {\r\n sugLoading = false;\r\n if (sugTriggerAgain) { sugTriggerAgain = false; sugTrigger(); }\r\n }, liveOutputDelay);\r\n });\r\n }\r\n\r\n $(document).ready(function() {\r\n $(\"textarea[name=q], input[name=q], select[name=algorithm]\").on('input propertychange change', sugTrigger);\r\n sugTrigger();\r\n });\r\n ", "liveOutputDelay", liveOutputDelay)) + hform(p("Query (Ctrl+Enter): " + htextarea(q, "id", "mainInput", "name", "q", "class", "auto-expand", "style", "width: 300px", "onkeydown", jquery_submitFormOnCtrlEnter(), "autofocus", dontRun || empty(q) ? true : null) + " " + (alg == null ? "" : alg.additionalInputs()) + "   Algorithm: " + hselect_list(keys(algorithms), algorithm, "name", "algorithm") + "   " + hbutton("Go"))); String content = (empty(right) ? "" : div_alignRight(right)) + div_center(centered) + htitledSectionWithDiv("Live Result", "", "id", "liveResult", "style", "display: none", "innerDivStyle", "max-height: 150px; overflow: auto") + (output == null ? "" : h3(algorithm) + output); if (withFrame) { req.framer.addInHead(hjs_handleScrollToAnchor()); req.framer.add(content); return mod.completeFrame(req); } else return hhtml(hhead(hmobilefix() + hsansserif() + loadJQuery2() + hjs_handleScrollToAnchor() + hjs_autoExpandingTextAreas() + mod.webSocketHeadStuff(req) + hNotificationPopups()) + hbody(content)); } public String doAlgorithm(Map> algorithms, String algorithm, String q, boolean liveMode) { GazelleBEA.Req req = mod.currentReq(); StringBufferWithMaxSize out = new StringBufferWithMaxSize(1000000); IF0 algo = lookupPossiblyCI(algorithms, algorithm); if (algo == null) out.append("Algorithm not found: " + algorithm); else { if (isB(evalWithTimeout(algoTimeout, new Runnable() { public void run() { try { AutoCloseable __21 = mod.enter(); try { AutoCloseable __22 = tempSetTL(mod.currentReq, req); try { Algorithm alg = algo.get(); alg.liveMode = liveMode; alg.out = out; alg.q = q; alg.req = mod.currentReq(); alg.runIt(); } finally { _close(__22); } } finally { _close(__21); } } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "temp mod.enter();\r\n temp tempSetTL(mod.currentReq, req);\r\n Algo..."; } }))) out.append("\n[algorithm timeout]"); } return str(out); } public class Algorithm implements Runnable { public String q; public GazelleBEA.Req req; public Appendable out; public boolean liveMode = false; public Concepts localConcepts = db_mainConcepts(); public List nonMatches; public void run() { try { } catch (Exception __e) { throw rethrow(__e); } } public void runLiveMode() { } public String additionalInputs() { return ""; } public void appendHTML(String html) { appendHTML(this.out, html); } public void appendHTML(Appendable out, String html) { try { if (empty(html)) return; html = wrapInDiv(html, "style", "margin-top: 0.5em"); out.append(html).append("\n"); } catch (Exception __e) { throw rethrow(__e); } } public void appendHTML_raw(String html) { try { out.append(html).append("\n"); } catch (Exception __e) { throw rethrow(__e); } } public void appendText(String text) { appendText(this.out, text); } public void appendText(Appendable out, String text) { try { if (empty(text)) return; out.append(hpre_htmlencode(rtrim(text))); } catch (Exception __e) { throw rethrow(__e); } } public void appendTextBold(String text) { appendTextBold(this.out, text); } public void appendTextBold(Appendable out, String text) { try { if (empty(text)) return; out.append(b(hpre_htmlencode(rtrim(text)))); } catch (Exception __e) { throw rethrow(__e); } } public void allowSuggestingAnswer(BEAObject input) { if (input == null) return; String text = input.text(); String url = mod.baseLink + "/saveAnswer"; appendHTML(hpostform("Suggest an answer to " + htmlEncode_quote(text) + ": " + htextarea(text, "id", "suggestAnswer", "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("inputID", input.id) + hhidden("redirect", "") + " " + hsubmit("Save answer") + " [Optional rewrite type: " + hinputfield("rewriteType", "style", "width: 100px") + " ]", "action", url, "onsubmit", js_setRedirect())); } public void allowSuggestingPattern(BEAObject input) { if (input == null) return; String text = input.text(); String url = mod.baseLink + "/savePattern"; appendHTML(hpostform("Suggest a pattern (with angle bracket vars): " + htextarea(text, "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("fromInput", conceptIDOrNull(input)) + hhidden("userTyped", true) + hhidden("redirect", "") + " " + hsubmit("Save pattern"), "action", url, "onsubmit", js_setRedirect())); } public void allowSuggestingSyntacticPattern(BEAObject input) { if (input == null) return; String text = input.text(); String url = mod.baseLink + "/saveSyntacticPattern"; appendHTML(hpostform("Suggest a syntactic pattern (with * vars): " + htextarea(text, "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("fromInput", conceptIDOrNull(input)) + hhidden("userTyped", true) + hhidden("redirect", "") + " " + hsubmit("Save syntactic pattern"), "action", url, "onsubmit", js_setRedirect())); } public BEAObject saveInput(String q) { if (userAgentIsBot(beaMod().currentUserAgent())) return null; Pair p = uniqCI2(BEAObject.class, "type", "Input", "text", q); BEAObject input = p.a; mod.saveUserAgent(input); if (p.b) { csetIfUnset(input, "createdBy", mod.user(mod.currentReq())); appendHTML("Input saved"); } return input; } public void runNonMatches() { if (nempty(nonMatches)) { appendHTML(hr()); callFAll(nonMatches); } } public void addNonMatch(Runnable r) { add(nonMatches, r); } public void runIt() { if (liveMode) runLiveMode(); else run(); runNonMatches(); } } public class ReverseInput extends Algorithm { public void run() { try { appendText(reversed(q)); } catch (Exception __e) { throw rethrow(__e); } } public void runLiveMode() { run(); } } public class TimeoutTest extends Algorithm { public void run() { try { sleepSeconds(120); } catch (Exception __e) { throw rethrow(__e); } } } public class RunPattern extends Algorithm { public void run() { try { BEAObject pattern = mod.beaGet(parseFirstLong(q)); if (pattern == null) { appendText("Pattern not found"); return; } appendText("Pattern: " + pattern); for (BEAObject input : mod.beaList("Input")) { String text = input.text(); Map mapping = matchInputWithPattern(input, pattern); if (mapping == null) addNonMatch(new Runnable() { public void run() { try { appendText("Checking Input: " + input + " - No match"); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "appendText(\"Checking Input: \" + input + \" - No match\");"; } }); else { String result = "\n" + renderMappingAsText(mapping); appendText("Checking Input: " + input + result); allowStoringMatch(this, input, pattern, mapping); } } } catch (Exception __e) { throw rethrow(__e); } } } public String renderMappingAsText(Map mapping) { return indent(formatDoubleArrowMap_horizontallyAligned(mapping)); } public class FindRewrites extends Algorithm { public void run() { try { BEAObject match = mod.beaGet(parseFirstLong(q)); if (match == null || !match.typeIs("Match")) { appendText("Match not found"); return; } BEAObject pattern = (BEAObject) (cget("pattern", match)); BEAObject input = (BEAObject) (cget("input", match)); Map mapping = (Map) (get("mapping", match)); appendText("Match: " + match); appendText("Input: " + input); appendText("Pattern: " + pattern); appendText("Mapping:\n" + renderMappingAsText(mapping)); appendRewrites(this, input, input.text(), pattern, match, mapping); } catch (Exception __e) { throw rethrow(__e); } } } public List appendRewrites(Algorithm algo, BEAObject input, String inputText, BEAObject pattern, BEAObject match, Map mapping) { Collection rewrites = mod.beaBackRefs(pattern, "Rewrite"); List texts = new ArrayList(); for (BEAObject r : rewrites) { String text = r.text(); String textWithVars = text; if (pattern.typeIs("Syntactic pattern")) textWithVars = starsToAngleBracketedNumbers(text); String text2 = replaceAngleBracketVars_curly(textWithVars, mapping); algo.appendText(" Using pattern rewrite: " + text); algo.appendTextBold(" " + inputText + "\n" + " => " + text2); texts.add(text2); BEAObject existing = match == null || input == null ? null : conceptWhereIC(BEAObject.class, "type", "Rewrite", "input", input, "text", text2, "match", match, "patternRewrite", r, "label", "good"); if (existing != null) algo.appendHTML("Rewrite exists: " + mod.beaLinkHTML(existing)); else if (match == null) algo.appendText("[Can't save, no match]"); else if (input == null) algo.appendText("[Can't save, no input object]"); else algo.appendHTML(hinlinepostform(hhiddenMulti("action", "create", "f_type", "Rewrite", "f_text", text2, "f_input", input.id, "metaInfo_input", "concept", "f_match", match.id, "metaInfo_match", "concept", "f_patternRewrite", r.id, "metaInfo_patternRewrite", "concept", "f_label", "good") + hbutton("Good rewrite"), "target", "_blank", "action", mod.crudLink(BEAObject.class))); } return texts; } public class ProcessNewInput extends Algorithm { public void run() { try { BEAObject input = handleInput(this, q = trim(q), false); for (BEAObject pattern : mod.beaListAny("Pattern", "Syntactic Pattern")) { checkPattern(this, input, q, pattern); } } catch (Exception __e) { throw rethrow(__e); } } } public void checkPattern(Algorithm algo, BEAObject input, String q, BEAObject pattern) { Map mapping = matchInputWithPattern(q, pattern); if (mapping == null) algo.addNonMatch(new Runnable() { public void run() { try { algo.appendText("Checking Pattern: " + pattern + " - No match"); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "algo.appendText(\"Checking Pattern: \" + pattern + \" - No match\");"; } }); else { String result = "\n" + renderMappingAsText(mapping); algo.appendText("Checking Pattern: " + pattern + result); if (input == null) { } else allowStoringMatch(algo, input, pattern, mapping); appendRewrites(algo, input, q, pattern, null, mapping); } } public class ProcessNewInput_v2 extends Algorithm { public void run() { try { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); if (input != null) { Collection rewrites = mod.beaBackRefs(input, "Rewrite"); BEAObject rewrite = random(rewrites); if (rewrite != null) appendHTML("My answer: " + b(htmlEncode2(rewrite.text())) + " " + ahref(mod.beaShortURL(rewrite), "[source]")); } allowSuggestingAnswer(input); allowSuggestingPattern(input); allowSuggestingSyntacticPattern(input); for (BEAObject pattern : syntacticPatternsSortedBySpecificityDesc()) { { if (patternAlwaysMatches(pattern)) continue; } Map mapping = matchInputWithPattern(q, pattern); if (mapping == null) addNonMatch(new Runnable() { public void run() { try { appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern) + " - No match"); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "appendHTML(\"Checking Syntactic Pattern: \" + mod.beaLinkHTML(pattern) + \" - No..."; } }); else { String result = "Grouped as: " + replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), mapping) + "\n" + renderMappingAsText(mapping); appendHTML(hr()); appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern)); appendText(result); BEAObject match = null; if (input == null) { } else match = allowStoringMatch(this, input, pattern, mapping); MultiMap subInputRewrites = ciMultiMap(); for (String subInput : uniquifyCI(values(mapping))) if (!eqic(subInput, q)) { BEAObject subInputObj = handleInput(this, subInput, "Sub-Input", true); if (subInputObj != null) { List subRewrites = concatLists(conceptsWhereCI(BEAObject.class, "type", "Rewrite", "input", subInputObj), conceptsWhereCI(BEAObject.class, "type", "Rewrite", "isRewriteOf", subInputObj)); for (BEAObject r : subRewrites) appendHTML("  Sub-Rewrite found: " + r); subInputRewrites.putAll(subInput, subRewrites); } } appendRewrites(this, input, q, pattern, match, mapping); Map rewrittenMapping = mapValues(mapping, s -> { BEAObject rewrite = random(subInputRewrites.get(s)); return rewrite == null ? s : uncurly(rewrite.text()); }); String randomRewrite = replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), rewrittenMapping); if (neq(randomRewrite, q)) appendText("Random rewrite from sub-inputs: " + randomRewrite); } } } catch (Exception __e) { throw rethrow(__e); } } } public class ProcessNewInput_v3 extends Algorithm { public void run() { try { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); HTMLTabs tabs = new HTMLTabs(); { StringBuffer toTab = new StringBuffer(); Algorithm alg = new ProcessNewInput_v2(); alg.q = q; alg.out = toTab; alg.runIt(); tabs.add("Match input with patterns", toTab); } { StringBuffer toTab = new StringBuffer(); Algorithm alg = new SyntacticPatternFromInput(); alg.q = q; alg.out = toTab; alg.runIt(); tabs.add("Make syntactic pattern", toTab); } appendHTML(tabs.html()); } catch (Exception __e) { throw rethrow(__e); } } } public BEAObject allowStoringMatch(Algorithm algo, BEAObject input, BEAObject pattern, Map mapping) { BEAObject match = conceptWhereCI(BEAObject.class, "type", "Match", "pattern", pattern, "input", input, "mapping", mapping); if (match != null) { algo.appendHTML("Match exists: " + mod.beaLinkHTML(match)); return match; } algo.appendHTML(joinWithSpace(storeMatchForm(input, pattern, "good"), storeMatchForm(input, pattern, "bad"))); return null; } public String storeMatchForm(BEAObject input, BEAObject pattern, String label) { return hinlinepostform(hhiddenMulti("pattern", pattern.id, "input", input.id, "label", label, "redirect", "") + hbutton(firstToUpper(label) + " match"), "action", mod.baseLink + "/storeMatch", "onsubmit", js_redirectAutoScroll2()); } public class MakeSyntacticPatterns extends Algorithm implements Runnable { public void run() { try { for (BEAObject p : mod.beaList("Pattern")) { appendText(p + " => " + makeSyntacticPattern(p)); } } catch (Exception __e) { throw rethrow(__e); } } } public String syntacticPatternText(BEAObject p) { return simpleSpacesTrim_javaTok(angleBracketVarsToStars(p.text())); } public BEAObject makeSyntacticPattern(BEAObject p) { if (p == null || !p.typeIs("Pattern") || empty(p.text())) return null; String text = syntacticPatternText(p); BEAObject sp = uniqCI(BEAObject.class, "type", "Syntactic Pattern", "text", text); cset(p, "syntacticPattern", sp); return sp; } public String processInputURL(String q) { return addParamsToURL(mod.baseLink + "/query", "q", q, "algorithm", "process input"); } public BEAObject handleInput(Algorithm algo, String q, boolean showProcessLink) { return handleInput(algo, q, "Input", showProcessLink); } public BEAObject handleInput(Algorithm algo, String q, String desc, boolean showProcessLink) { algo.appendHTML(hSingleRowTable_withSpacing((desc + ":"), tt(htmlEncode_nlToBr_withIndents(q)), !showProcessLink ? "" : targetBlank_noFollow(processInputURL(q), "Process"))); BEAObject input = mod.findInput(q); algo.appendHTML(inputHTML(input, desc, q)); return input; } public String inputHTML(BEAObject input, String q) { return inputHTML(input, "Input", q); } public String inputHTML(BEAObject input, String desc, String q) { return input != null ? (desc + " exists: ") + mod.beaLinkHTML(input) : !mod.requestAuthed() && !mod.allowAnonymousInputUpload ? null : hinlinepostform(hhiddenMulti("text", q, "redirect", "") + hbutton(("Save " + desc)), "action", mod.baseLink + "/saveInput", "onsubmit", js_setRedirect()); } public String syntacticPatternLinkHTML(BEAObject obj, String text) { return syntacticPatternLinkHTML(obj, text, null); } public String syntacticPatternLinkHTML(BEAObject obj, String text, BEAObject fromInput) { String desc = "Syntactic pattern"; return obj != null ? mod.beaLinkHTML(obj) : !mod.requestAuthed() ? null : hinlinepostform(hhiddenMulti("text", text, "fromInput", conceptIDOrNull(fromInput), "redirect", "") + hbutton(("Save " + (firstToLower(desc)))), "action", mod.baseLink + "/saveSyntacticPattern", "onsubmit", js_setRedirect()); } public class SyntacticPatternFromInput extends Algorithm implements Runnable { public void run() { try { BEAObject input = handleInput(this, q, false); if (countTokens(q) > 10) { appendText("Input too long to extract syntactic patterns"); return; } String q2 = dropPunctuation(q); List data = new ArrayList(); for (String pat : sortedIC(gazelle_allSyntacticPatternsFromInput(q))) { Map mapping = matchInputWithSyntacticPattern(q2, pat); BEAObject obj = conceptWhereIC(BEAObject.class, "type", "Syntactic Pattern", "text", pat); Map row = litorderedmap("Syntactic Pattern", htmlEncode2(pat), "In database", syntacticPatternLinkHTML(obj, pat, input)); for (Map.Entry __19 : _entrySet(mapping)) { String key = __19.getKey(); String val = __19.getValue(); row.put("Argument " + key, htmlEncode2(val)); } data.add(row); } appendHTML(htmlTable2_noHtmlEncode(data)); } catch (Exception __e) { throw rethrow(__e); } } } public class ApplyTextFunctions extends Algorithm { public void run() { try { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); LinkedHashSet objectsMade = new LinkedHashSet(); for (BEAObject f : mod.beaList("JavaX Standard Function")) { try { addIfNotNull(objectsMade, reactFunctionWithInput(this, f, input)); } catch (Throwable __e) { printStackTrace(__e); } } appendHTML(h3("Results of function calls")); HCRUD crud = mod.makeCRUD(BEAObject.class, mod.currentReq()); HCRUD_Concepts crudData = (HCRUD_Concepts) (crud.data); crudData.listConcepts_firstStep = () -> objectsMade; appendHTML(crud.renderTable(true)); } catch (Exception __e) { throw rethrow(__e); } } } public class FindPath extends Algorithm { public BreadthFirstPathFinder_withLinkType pathFinder = new BreadthFirstPathFinder_withLinkType(); public BEAObject start, dest; public void run() { try { start = mod.beaGet(parseFirstLong(q)); dest = mod.beaGet(parseSecondLong(q)); if (start == null || dest == null) { appendText("Please supply object IDs of start and end"); return; } appendHTML("Looking for path from " + mod.beaToHTML(start) + " to " + mod.beaToHTML(dest)); pathFinder.getChildren = o -> cForwardAndBackRefsWithFieldIndicator(BEAObject.class, o); pathFinder.add(start); while (!pathFinder.nodeReached(dest) && pathFinder.step()) { } List> path = pathFinder.examplePathWithTypes(start, dest); if (path == null) appendText("No path found!"); else { appendHTML(b("Path found!")); appendHTML(ol(map(path, p -> { String html = mod.beaHTML(p.a); if (p.b == null) return html; String arrow = ifThenElse(p.b.forward, ">>", "<<"); return html + " " + htmlEncode2(joinNemptiesWithSpace(arrow, p.b.field, arrow)); }))); } } catch (Exception __e) { throw rethrow(__e); } } } public class ExecuteTextQuery extends Algorithm { public void run() { try { saveInput(q = trim(q)); appendHTML(h3("Result")); appendHTML(htmlEncode2(strOrEmpty(executeTextQuery(q)))); } catch (Exception __e) { throw rethrow(__e); } } } public class InputSummary extends Algorithm { public void run() { try { BEAObject mainInput = saveInput(q = trim(q)); Collection inputs = conceptsWhere(BEAObject.class, "type", "Input", "text", q); if (l(inputs) > 1) appendHTML("Note: Input appears " + l(inputs) + " times in the database: " + joinWithSpace(map(o -> mod.beaToHTML(o), inputs))); for (BEAObject input : inputs) { if (input != mainInput) { appendHTML(hr()); appendHTML("Input: " + input); } Collection rewrites = mod.beaBackRefs(input, "Rewrite"); if (empty(rewrites)) appendHTML(h3("No rewrites")); else for (Pair __17 : iterateWithIndex1(rewrites)) { int i = pairA(__17); BEAObject r = pairB(__17); appendHTML("Rewrite " + i + ": " + ahref(mod.beaURL(r), tok_dropCurlyBrackets(r.text()))); } } } catch (Exception __e) { throw rethrow(__e); } } } public class ApplyPatternList extends Algorithm { public String additionalInputs() { return hselect("patternListID", mapToKey(__50 -> conceptID(__50), mod.beaList("Pattern List")), req.get("patternListID")); } public void run() { try { BEAObject input = handleInput(this, q = trim(q), false); BEAObject patternList = mod.beaGet("patternListID", req); if (patternList == null) return; List patterns = (List) (cget("patterns", patternList)); appendHTML("Pattern list: " + mod.beaHTML(patternList)); for (BEAObject pattern : unnullForIteration(patterns)) { appendText("Trying pattern " + pattern); checkPattern(this, input, q, pattern); } } catch (Exception __e) { throw rethrow(__e); } } } public class ApplyAlgorithmObject extends Algorithm { public String additionalInputs() { return hselect("algorithmID", mapToKey(__51 -> conceptID(__51), concatLists(wideningListCast(Concept.class, list(BEARegExpReplacement.class)), wideningListCast(Concept.class, conceptsWhereIC(UserPost.class, "type", "JavaX Code (HTML Bot)")))), req.get("algorithmID")); } public void runLiveMode() { Concept algo = getConcept(parseLongOpt(req.get("algorithmID"))); appendHTML("Algorithm object: " + htmlEncode2_nlToBr(str(algo))); if (algo instanceof UserPost) { Object result = mod.callHtmlBot_dropMadeByComment(((UserPost) algo).id, req.params()); appendText("Result: " + result); } else if (algo instanceof BEARegExpReplacement) { Object result = ((BEARegExpReplacement) algo).apply(q); appendText("Result: " + result); } else if (algo == null) appendText("Algorithm object not found"); else appendText("Unknown algorithm object type: " + _className(algo)); } } public class ApplyRegExpReplacement extends Algorithm { public void run() { try { BEARegExpReplacement regExpReplacement = (BEARegExpReplacement) (mod.beaGet(q)); if (regExpReplacement == null) { appendText("Please enter reg exp replacement ID"); return; } appendHTML("Applying " + beaHTML(regExpReplacement)); for (BEAObject input : sortedByConceptIDDesc(mod.beaList("Input"))) { String text = input.text(); String replaced = regExpReplacement.apply(text); if (neq(text, replaced)) { appendHTML(hr()); appendText(" " + text + "\n=> " + replaced); appendPossibleRewrite(this, input, replaced, litmap("f_regularExpression", regExpReplacement.id, "metaInfo_regularExpression", "concept")); } } } catch (Exception __e) { throw rethrow(__e); } } } public class BackEndAlgorithm extends Algorithm { public String prefix() { return shortClassName(this) + ": "; } @Override public void appendText(String s) { printWithIndent(prefix(), s); } @Override public void appendHTML(String s) { appendText(htmlDecode_dropTags(s)); } @Override public void addNonMatch(Runnable r) { r.run(); } } public class MatchInputWithAllPatternLists extends Algorithm { public void run() { try { BEAObject input = saveInput(q); for (BEAObject patternList : sortedByConceptIDDesc(beaList("Pattern List"))) reactInputWithPatternList(this, input, q, patternList, 1, 2); } catch (Exception __e) { throw rethrow(__e); } } } public class RunTestCasesOnCodePost extends Algorithm { public String additionalInputs() { MultiSet ms = distinctCIFieldValuesOfConcepts_multiSet(BEAObject.class, "type"); List types = filter(pairsA(multiSetToPairsByPopularity(ms)), type -> cic(type, "test case")); return "Test case type: " + hselect_list("testCaseType", types, req.get("testCaseType")) + " " + hselect("algorithmID", mapToKey(__52 -> conceptID(__52), conceptsWhereIC(UserPost.class, "type", "JavaX Code (HTML Bot)")), req.get("algorithmID")); } public void run() { try { String testCaseType = req.get("testCaseType"); Concept algo = getConcept(parseLongOpt(req.get("algorithmID"))); Collection testCases = beaList(testCaseType); appendText(n2(testCases, "test case") + " found for type " + quote(testCaseType)); appendHTML("Algorithm object: " + htmlEncode2_nlToBr(str(algo))); if (!(algo instanceof UserPost)) return; Scorer scorer = new Scorer(); for (BEAObject testCase : testCases) { ping(); Map fields = toCIMap(objectToMap(testCase)); String input = str(getAny(fields, "input")); String expected = str(getAny(fields, "output", "result")); String result = str(mod.callHtmlBot_dropMadeByComment(algo.id, litmap("q", input))); boolean ok = eq(result, expected); appendText((ok ? "OK" : "BAD") + ": Input: " + quote(input) + ", expected output: " + quote(expected) + ", result: " + quote(result)); scorer.add(ok); } appendText(str(scorer)); } catch (Exception __e) { throw rethrow(__e); } } } public void reactInputWithPatternList(Algorithm algo, BEAObject input, String text, BEAObject patternList, int level, int recursionLevels) { Pair> match = matchInputWithPatternList(text, patternList); algo.appendHTML(hr()); algo.appendHTML(joinNemptiesWithColon(level == 1 ? beaHTML(patternList) : null, stringIf(match == null, "No match"))); if (match != null) { BEAObject pattern = match.a; Map mapping = match.b; algo.appendHTML("Matched as " + beaHTML(pattern)); algo.appendText(renderMappingAsText(mapping)); if (input != null) { BEAObject matchObj = uniqCI(algo.localConcepts, BEAObject.class, "type", "Match", "input", input, "patternList", patternList, "winningPattern", pattern, "mapping", mapping); algo.appendHTML("Match saved as: " + beaHTML(matchObj)); } if (level < recursionLevels) { algo.appendHTML_raw("
    "); for (Map.Entry __18 : _entrySet(mapping)) { String key = __18.getKey(); String subInput = __18.getValue(); if (!eqic(key, text)) { algo.appendHTML_raw("
  • "); algo.appendText("Processing sub-Input: " + subInput); reactInputWithPatternList(algo, null, subInput, patternList, level + 1, recursionLevels); algo.appendHTML_raw("
  • "); } } algo.appendHTML_raw("
"); } } } public int patternSpecificity(BEAObject pattern) { return countWordsWithoutAngleBracketedAndStars(pattern.text()); } public List syntacticPatternsSortedBySpecificityDesc() { return sortedByCalculatedFieldDesc(__53 -> patternSpecificity(__53), mod.beaList("Syntactic Pattern")); } public Object executeTextQuery(String s) { Matches m = new Matches(); if (match3_withIntsAndIDs("all references in field of object ", s, m)) { Object value = cget(mod.beaGet(m.unq(1)), m.unq(0)); return value instanceof Collection ? instancesOf(BEAObject.class, (Collection) value) : value instanceof BEAObject ? ll((BEAObject) value) : ll(); } return new QueryNotUnderstood(s); } static public class QueryNotUnderstood implements IFieldsToList { public String s; public QueryNotUnderstood() { } public QueryNotUnderstood(String s) { this.s = s; } public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + s + ")"; } public boolean equals(Object o) { if (!(o instanceof QueryNotUnderstood)) return false; QueryNotUnderstood __23 = (QueryNotUnderstood) o; return eq(s, __23.s); } public int hashCode() { int h = 1528655894; h = boostHashCombine(h, _hashCode(s)); return h; } public Object[] _fieldsToList() { return new Object[] { s }; } } public String beaToHTML(BEAObject o) { return mod.beaToHTML(o); } public String beaHTML(BEAObject o) { return mod.beaHTML(o); } public String beaURL(BEAObject o) { return mod.beaURL(o); } public boolean isSyntacticPattern(BEAObject pat) { return pat != null && pat.typeIs("Syntactic pattern"); } public String patternTextWithAngleBracketVars(BEAObject pat) { String text = pat.text(); return isSyntacticPattern(pat) ? starsToAngleBracketedNumbers(text) : text; } public boolean isCommentOrFeedback(BEAObject o) { return o != null && o.typeIsOneOf("Comment", "Useful", "Feedback"); } public String feedbackHTML(BEAObject o) { Collection l = filter(__54 -> isCommentOrFeedback(__54), mod.beaBackRefs(o)); return joinWithBR(map(l, c -> c.typeIs("Comment") ? ahref(beaURL(c), htmlEncode2(c.text())) : beaHTML(c))); } public String bestInputURL(String text) { text = trim(text); BEAObject input = mod.findInput(text); return input != null ? beaURL(input) : processInputURL(text); } public String bestInputHTML(String text) { if (empty(text)) return ""; return ahref(bestInputURL(text), span(htmlEncode2(text), "style", "background-color: #ccc")); } public String performRewrite(BEAObject rewrite, Map mapping) { String rewriteText = starsToAngleBracketedNumbers(rewrite.text()); return replaceAngleBracketVars(rewriteText, mapping); } public Pair exampleForPatternRewrite(BEAObject pattern, BEAObject rewrite) { String patText = patternTextWithAngleBracketVars(pattern); Set vars = collectAngleBracketVars(patText); Map mapping = mapToValues_ciMap(vars, var -> "$" + var); return pair(replaceAngleBracketVars(patText, mapping), performRewrite(rewrite, mapping)); } public class RegExpToPossibleSubInputs extends Algorithm implements IFieldsToList { public BEAObject input; public BEAObject regExp; public RegExpToPossibleSubInputs() { } public RegExpToPossibleSubInputs(BEAObject input, BEAObject regExp) { this.regExp = regExp; this.input = input; } public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + input + ", " + regExp + ")"; } public boolean equals(Object o) { if (!(o instanceof RegExpToPossibleSubInputs)) return false; RegExpToPossibleSubInputs __16 = (RegExpToPossibleSubInputs) o; return eq(input, __16.input) && eq(regExp, __16.regExp); } public int hashCode() { int h = -208954156; h = boostHashCombine(h, _hashCode(input)); h = boostHashCombine(h, _hashCode(regExp)); return h; } public Object[] _fieldsToList() { return new Object[] { input, regExp }; } public void run() { try { String text = input.text(); String pat = regExp.text(); for (IntRange r : regexpFindRangesIC(pat, text)) appendHTML(beaHTML(csetAndReturn(uniq(localConcepts, BEAObject.class, "type", "Possible Sub-Input", "input", input, "characterRange", r, "text", substring(text, r)), "regExp", regExp, "byAlgorithm", shortName(this)))); } catch (Exception __e) { throw rethrow(__e); } } } public void appendPossibleRewrite(Algorithm algo, BEAObject input, String text) { appendPossibleRewrite(algo, input, text, null); } public void appendPossibleRewrite(Algorithm algo, BEAObject input, String text, Map moreInfo) { BEAObject existing = input == null ? null : conceptWhereIC(BEAObject.class, "type", "Rewrite", "input", input, "text", text, "label", "good"); if (existing != null) algo.appendHTML("Rewrite exists: " + mod.beaLinkHTML(existing)); else if (input != null) algo.appendHTML(joinWithSpace(map(ll("good", "bad"), label -> hinlinepostform(hhiddenMulti("action", "create", "f_type", "Rewrite", "f_text", text, "f_input", input.id, "metaInfo_input", "concept", "f_label", label, "redirectAfterSave", "") + hhiddenMulti(moreInfo) + hbutton(firstToUpper(label) + " rewrite", "onclick", js_redirectAutoScroll2()), "action", mod.crudLink(BEAObject.class))))); } public BEAObject reactFunctionWithInput(Algorithm algo, BEAObject f, BEAObject input) { String fName = getString("name", f); if (!isIdentifier(fName)) return null; if (!isSafeStandardFunction(fName)) { { if (algo != null) algo.addNonMatch(new Runnable() { public void run() { try { algo.appendText("Function " + fName + " not safe"); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "algo.appendText(\"Function \" + fName + \" not safe\");"; } }); } return null; } BEAObject o = cnew(algo.localConcepts, BEAObject.class, "type", "Function Result", "function", f, "functionCalled", fName, "input", input, "calculating", true); print("Function result: " + o); try { Object holder = getStandardFunctionHolder(fName); Object result = evalWithTimeoutOrFail(10.0, () -> call(holder, fName, input.text())); if (!(result instanceof List) && isStringCollection(result)) result = asList((Collection) result); if (result == null) cset(o, "resultType", "null"); else if (result instanceof String) cset(o, "resultType", "string", "result", result); else if (isStringList(result)) cset(o, "resultType", "list of strings", "result", result); else cset(o, "result", "other" + appendRoundBracketed(className(result)), "result", shorten(1000, str(result))); } catch (Throwable e) { cset(o, "resultType", "error", "error", getStackTrace(e)); } cset(o, "calculating", null); return o; } public BEAObject convertSyntacticToSemanticMatch(BEAObject match, BEAObject semanticPattern) { BEAObject syntacticPattern = beaGet("pattern", match); BEAObject input = beaGet("input", match); String pat2 = syntacticPattern.text(); String pat1 = semanticPattern.text(); List vars = new ArrayList(); String pat2b = angleBracketVarsToStars(pat1, vars); String warning = eq(pat2, pat2b) ? null : "Patterns don't match: " + quote(pat2) + " / " + quote(pat2b); Map mapping = (Map) (cget("mapping", match)); Map mapping2 = mapKeys(mapping, key -> or(_get(vars, parseInt(key) - 1), key)); mapping2 = putKeysFirst(vars, mapping2); BEAObject match2 = uniqCI(BEAObject.class, "type", "Match", "input", input, "pattern", semanticPattern, "fromSyntacticMatch", match); cset(match2, "mapping", mapping2); return match2; } public Collection convertSyntacticToSemanticMatches(BEAObject match) { List out = new ArrayList(); BEAObject syntacticPattern = beaGet("pattern", match); for (BEAObject semanticPattern : mod.beaList("Pattern", "syntacticPattern", syntacticPattern)) { try { out.add(convertSyntacticToSemanticMatch(match, semanticPattern)); } catch (Throwable __e) { printStackTrace(__e); } } return out; } public Collection convertSyntacticToSemanticMatchesForWholePattern(BEAObject pattern) { if (pattern.typeIs("Syntactic Pattern")) return concatMap_lists(__55 -> convertSyntacticToSemanticMatches(__55), mod.beaList("Match", "pattern", pattern)); else { List out = new ArrayList(); BEAObject syntacticPattern = beaGet("syntacticPattern", pattern); if (syntacticPattern != null) for (BEAObject match : mod.beaList("Match", "pattern", syntacticPattern)) out.add(convertSyntacticToSemanticMatch(match, pattern)); return out; } } public BEAObject beaGet(String field, BEAObject o) { return mod.beaGet(field, o); } public Collection beaList(String type, Object... params) { return mod.beaList(type, params); } public int simpleObjectScore(BEAObject o) { int score = 0; if (eqic_gen(getOpt("label", o), "good")) ++score; else if (eqic_gen(getOpt("label", o), "bad")) --score; Collection l = findBackRefsWithField(BEAObject.class, "object", o); score += countWhereCI(l, "type", "Useful"); score -= countWhereCI(l, "type", "Bad"); return score; } public List sortedBySimpleObjectScore(int minScore, Collection l) { return sortedByCalculatedFieldDesc(__56 -> simpleObjectScore(__56), filter(l, o -> simpleObjectScore(o) >= minScore)); } public BEAObject createPatternListFromUsefulSyntacticPatterns() { List patterns = sortedBySimpleObjectScore(0, beaList("Syntactic Pattern")); return mod.autoMigrateToCustomClass(uniqCI(BEAObject.class, "type", "Pattern List", "byFunction", "createPatternListFromUsefulSyntacticPatterns", "patterns", patterns)); } public Map> algorithms() { return litorderedmap("Process new input v3", (IF0) () -> new ProcessNewInput_v3(), "Process new input v2", (IF0) () -> new ProcessNewInput_v2(), "Process new input", (IF0) () -> new ProcessNewInput(), "Run pattern", (IF0) () -> new RunPattern(), "Find rewrites for match", (IF0) () -> new FindRewrites(), "Reverse input (test algorithm)", (IF0) () -> new ReverseInput(), "Timeout test", (IF0) () -> new TimeoutTest(), "Syntactic pattern from input", (IF0) () -> new SyntacticPatternFromInput(), "Apply all text functions", (IF0) () -> new ApplyTextFunctions(), "Find Path", (IF0) () -> new FindPath(), "Execute text query", (IF0) () -> new ExecuteTextQuery(), "Make syntactic patterns for all patterns in DB", (IF0) () -> new MakeSyntacticPatterns(), "Input summary", (IF0) () -> new InputSummary(), "Apply pattern list", (IF0) () -> new ApplyPatternList(), "Apply regular expression replacement to all inputs", (IF0) () -> new ApplyRegExpReplacement(), "Match input with all pattern lists", (IF0) () -> new MatchInputWithAllPatternLists(), "Apply algorithm object", (IF0) () -> new ApplyAlgorithmObject(), "Run test cases on code post", (IF0) () -> new RunTestCasesOnCodePost()); } public void putAlgorithmsInDatabase() { for (String name : keys(algorithms())) uniq(BEAObject.class, "type", "Classic Query Algorithm", "name", name); } } abstract static public class GazelleBEA extends DynGazelleRocks { static public boolean _switchableField_mirrorBEAObjects = true; public boolean mirrorBEAObjects = false; static public boolean _switchableField_enableAutoRuns = true; public boolean enableAutoRuns = true; static public boolean _switchableField_enableNewBEAObjectNotis = true; public boolean enableNewBEAObjectNotis = true; static public boolean _switchableField_printAllConceptChanges = true; public boolean printAllConceptChanges = false; static public boolean _switchableField_useShadowLogger = true; public boolean useShadowLogger = false; static public boolean _switchableField_autoActivateDynamicObjects = true; public boolean autoActivateDynamicObjects = true; static public boolean _switchableField_reloadWhenMainLibUpdates = true; public boolean reloadWhenMainLibUpdates = false; static public boolean _switchableField_baseSystemVersion = true; public String baseSystemVersion = "1"; static public boolean _switchableField_backupFrequency = true; public int backupFrequency = 5; static public boolean _switchableField_gazelleServerGlobalID = true; public String gazelleServerGlobalID = aGlobalID(); transient public boolean allObjectsActivated = false; transient public Throwable startError; static public boolean _switchableField_activateOnlyTheseIDs = true; public String activateOnlyTheseIDs; static public boolean _switchableField_dontActivateTheseIDs = true; public String dontActivateTheseIDs; transient public ReliableSingleThread_Multi rstAutoRuns = dm_rstMulti(this, 1000, __40 -> performAutoRuns(__40)); transient public Q notificationQ; transient public ReliableSingleThread_Multi rstDistributeNewObject = dm_rstMulti(this, 1000, __41 -> distributeNewObject_impl(__41)); transient public Set newObjectsDistributed = weakSet(); transient public ReliableSingleThread_Multi rstUpdateBEAMirrors = dm_rstMulti(this, 100, c -> c.updateMirrorPost()); transient public ReliableSingleThread_Multi rstAutoActivateDynamicObjects = dm_rstMulti(this, 100, __42 -> autoActivateDynamicObject(__42)); transient public BEACalculations calculations = new BEACalculations(this); transient public BEACalculations calc = calculations; transient public int newFieldsToShow = 3; transient public boolean allowAnonymousInputUpload = true; static public boolean _switchableField_maxInputLength = true; public int maxInputLength = 50000; static public boolean _switchableField_mainDomainWithProtocol = true; public String mainDomainWithProtocol = "https://bea.gazelle.rocks"; static public boolean _switchableField_grabUsersFromDomain = true; public String grabUsersFromDomain = "https://gazelle.rocks"; static public boolean _switchableField_verboseQStartsAndStops = true; public boolean verboseQStartsAndStops = false; transient public ConceptClassesDependentValue inputsWithoutRewrites; transient public ConceptClassesDependentValue inputsWithoutMatches; transient public ConceptClassesDependentValue syntacticPatternsWithoutRewrites; transient public Set deadClassPaths = syncLinkedHashSet(); transient public x30_pkg.x30_util.BetterThreadLocal beaThreadOwner = new x30_pkg.x30_util.BetterThreadLocal(); static public boolean _switchableField_beaHomePageID = true; public long beaHomePageID; public boolean verboseClassLoading = false; transient public boolean saveAllQsAsInput = true; transient public boolean moveNavItemsToMisc = false; transient public boolean additionalCommandsForObjects = true; transient public boolean exportUsersInVM, exportUsersGlobally; transient public boolean sourceIsPublic = true; transient public boolean makeAnonymousUsers = true; transient public boolean showInputAndPatternNavItems = true; transient public IConceptCounter beaModifiedIndex; transient public boolean showInputCounts = false; transient public ConceptFieldIndexCI_certainValues serviceIndex; transient public boolean quickDBReloadEnabled = false; public Concepts _getReloadData() { return db_mainConcepts(); } public void _setReloadData_early(Object data) { quickImportMainConcepts(data, () -> quickDBReloadEnabled); } public void init() { super.init(); botName = heading = adminName = "Gazelle"; enableVars = true; showTalkToBotLink = false; phoneNumberSpecialInputField = false; showMetaBotOnEveryPage = false; showDeliveredDomains = false; showCRUDToEveryone = true; } public Class lookForClass(ClassLoader cl, String name) { try { if (!name.startsWith(DynClassName_mainPrefixForVM())) return null; if (verboseClassLoading) print("Looking for class " + name); DynClassName dcn = DynClassName_parse(name); if (dcn == null) { vmBus_send("lookingForClass_noDCNParse", name); return null; } String subPath = vmClassNameToSubPath(dcn.fullClassNameForVM()); File byteCode = dcn.byteCodeFile(); vmBus_send("lookingForClass_haveByteCodeFile", byteCode); if (classLoaderContainsByteCodePath(cl, byteCode)) { vmBus_send("lookingForClass_haveByteCodePath", byteCode); return null; } boolean exists = fileExistsInInDirOrZip(byteCode, subPath); printVars("exists", exists, "subPath", subPath, "byteCode", byteCode); if (!exists) { vmBus_send("lookingForClass_subPathNotInByteCode", byteCode, subPath); throw fail("Class not found: " + subPath + " in " + byteCode); } addByteCodePathToClassLoader(cl, byteCode); assertTrue("Byte code added", classLoaderContainsByteCodePath(cl, byteCode)); vmBus_send("lookingForClass_byteCodePathAdded", byteCode); return (Class) call(cl, "super_findClass", name); } catch (Throwable __e) { printStackTrace(__e); } return null; } public void db() { main.db(); } public void startDB() { ClassLoader cl = dm_moduleClassLoader(); setOpt(cl, "verbose", verboseClassLoading); setFieldToIF1Proxy(cl, "findClass_extension", (IF1) name -> { vmBus_send("lookingForClass", cl, name); Class c = lookForClass(cl, name); vmBus_send("lookingForClass_result", cl, name, c); return c; }); String mainPrefix = dotToDollar(DynClassName_mainPrefix()); Object classFinder = _defaultClassFinder(); db_mainConcepts().classFinder = new F1() { public Class get(String name) { try { AutoCloseable __32 = enter(); try { print("Deserializing class " + name); try { String name2 = dropPrefix(mcName() + "$", name); if (name2.startsWith(mainPrefix)) { String vmName = DynClassName_parse(name2).fullClassNameForVM(); if (verboseClassLoading) print("Loading dynamic class " + vmName); Class c = classLoader_loadClass(module(), vmName); return c; } Class c = (Class) (callF(classFinder, name)); print("c", c); return c; } catch (Throwable e) { printStackTrace(e); throw rethrow(e); } } finally { _close(__32); } } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "temp enter();\r\n //ret syncGetOrCreate(classesCache, name, () -> {\r\n ..."; } }; db(); Concepts concepts = db_mainConcepts(); concepts.useBackRefsForSearches = true; concepts.newBackupEveryXMinutes = backupFrequency; fixConceptIDs(); inputsWithoutRewrites = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Input"), c -> empty(beaBackRefs(c, "Rewrite")))); inputsWithoutMatches = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Input"), c -> empty(beaBackRefs(c, "Match")))); syntacticPatternsWithoutRewrites = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Syntactic Pattern"), c -> empty(beaBackRefs(c, "Rewrite")))); if (useShadowLogger) { ConceptsShadowLogger shadowLogger = new ConceptsShadowLogger(db_mainConcepts()); shadowLogger.install(); shadowLogger.writer = filePrintWriter_append(programFile("shadow.log")); dm_doEvery(10.0, new Runnable() { public void run() { try { shadowLogger.flush(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "shadowLogger.flush();"; } }); ownResource(shadowLogger); } if (printAllConceptChanges) printAllConceptChanges(); } public Map emergencyFlags() { return (Map) parseEqualsProperties(joinNemptiesWithEmptyLines(loadTextFile(programFile("gazelle-emergency-options.txt")), loadTextFile(javaxDataDir("gazelle-emergency-options.txt")))); } public void start() { try { start2(); } catch (Throwable e) { printStackTrace(e); startError = e; } } public void start2() { print("Module ID: " + dm_moduleID()); useBotNameAsModuleName = false; setOptAllDyn_pcall(module(), pnl("emergencyFlags", emergencyFlags())); change(); String name = actualMCDollar() + "BEAObject"; print("name", name); assertEquals(BEAObject.class, callF(defaultDefaultClassFinder(), name)); assertEquals(ConceptWithGlobalID.class, callF(defaultDefaultClassFinder(), mcDollar() + "ConceptWithGlobalID")); botDisabled = true; storeBaseClassesInStructure = true; super.start(); assertSameVerbose("miscMap me", db_mainConcepts().miscMapGet(DynNewBot2.class), this); assertSameVerbose("beaMod()", main.beaMod(), this); print("main concepts: " + db_mainConcepts() + ", count: " + db_mainConcepts().countConcepts()); print(renderConceptClassesWithCount(db_mainConcepts())); print("Inputs: " + n2(beaCount("Input"))); dm_onSnippetTranspiled(mainLibID, new Runnable() { public void run() { try { if (reloadWhenMainLibUpdates) { setField("reloadWhenMainLibUpdates", false); dm_reloadModule(); } } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "if (reloadWhenMainLibUpdates) {\r\n setField(reloadWhenMainLibUpdates ..."; } }); if (!enabled) return; if (exportUsersInVM) { dm_vmBus_answerToMessage("lookupGazelleUser", new F3() { public Object get(String name, String pw, String salt) { try { if (!eq(salt, passwordSalt())) return null; User user = conceptWhereCI(User.class, "name", name); if (user == null) return null; if (!eq(getVar(user.passwordMD5), hashPW(pw))) return null; return user; } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "if (!eq(salt, passwordSalt())) null;\r\n User user = conceptWhereCI User..."; } }); } rstUpdateBEAMirrors.addAll(list(BEAObject.class)); newObjectsDistributed.addAll(list(BEAObject.class)); onIndividualConceptChange_notOnAllChanged(BEAObject.class, o -> { if (enableAutoRuns) rstAutoRuns.add(o); if (enableNewBEAObjectNotis && newObjectsDistributed.add(o)) rstDistributeNewObject.add(o); }); notificationQ = dm_startQ(); dm_doEvery(5 * 60.0, new Runnable() { public void run() { try { { AutoCloseable __33 = enter(); try { print(new ConceptsRefChecker(db_mainConcepts()).runAndFixAll()); } finally { _close(__33); } } } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "{ temp enter();\r\n print(ConceptsRefChecker(db_mainConcepts()).runAndFixA..."; } }); setField("activateOnlyTheseIDs", nemptyLinesLL(loadTextFile(programDir("gazelle-activate-only")), loadTextFile(javaxDataDir("gazelle-activate-only")))); Set ids = activateOnlyTheseIDs(); Set antiIDs = dontActivateTheseIDs(); print("Object IDs to activate: " + (ids == null ? "ALL" : ids)); if (nempty(antiIDs)) print("Object IDs not to activate: " + (ids == null ? "ALL" : ids)); for (BEAObject bea : list(BEAObject.class)) if ((ids == null || contains(ids, bea.id)) && !contains(antiIDs, bea.id)) { callActivate(bea); } cleanReifiedWebSockets(); allObjectsActivated = true; print("All objects activated"); } public void makeIndices() { super.makeIndices(); indexConceptClass(BSettings.class); beaModifiedIndex = (IConceptCounter) indexConceptFieldDesc_v2(BEAObject.class, "_modified"); indexConceptFieldCIWithTopTen(BEAObject.class, "type"); indexConceptFieldIC(BEAObject.class, "text"); indexConceptFieldIC(BEAObject.class, "purpose"); serviceIndex = new ConceptFieldIndexCI_certainValues(BEAObject.class, "meta_isService") { public boolean isApplicableValue(Object o) { return o != null; } }; } public boolean isMaster(Req req) { return req == null ? null : req.masterAuthed; } @Override public List crudClasses(DynGazelleRocks.Req req) { var l = super.crudClasses(req); l.add(BEAObject.class); if (masterAuthed(req)) l.add(AuthedDialogID.class); return l; } public Set hiddenCrudClasses() { Set set = super.hiddenCrudClasses(); set.remove(UploadedSound.class); addAll(set, Conversation.class, ExecutedStep.class, InputHandled.class); return set; } public String authFormHeading() { return h3(adminName); } transient public IF0 authFormMoreContent; public String authFormMoreContent() { return authFormMoreContent != null ? authFormMoreContent.get() : authFormMoreContent_base(); } final public String authFormMoreContent_fallback(IF0 _f) { return _f != null ? _f.get() : authFormMoreContent_base(); } public String authFormMoreContent_base() { String html = p(html_loggedIn(false)); HTMLFramer1 framer = new HTMLFramer1(); if (anonymousUserWarning(currentReq(), framer)) html += lines(framer.contents); return html + super.authFormMoreContent(); } public HTMLFramer1 newFramerInstance() { return new BEAHTMLFramer(); } @Override public void makeFramer(DynGazelleRocks.Req req) { super.makeFramer(req); if (!allObjectsActivated) req.framer.add(p("WARNING: Start failure")); if (startError != null) req.framer.add(pre_htmlEncode("WARNING: Start error\n\n" + renderStackTrace(startError))); req.framer.addInHead(hjs_selectize()); req.framer.addInHead(hjs_selectizeClickable()); req.framer.addInHead(hjs_autoExpandingTextAreas()); } @Override public HCRUD_Concepts crudData(Class c, DynGazelleRocks.Req _req) { Req req = (Req) _req; HCRUD_Concepts cc = super.crudData(c, req); if (c == UploadedSound.class || c == UploadedFile.class || c == UploadedImage.class) { cc.onCreate.add(o -> cset(o, "createdBy", currentUser())); cc.emptyConcept = () -> { Concept ccc = cc.emptyConcept_base(); cset(ccc, "isPublic", true); return (A) ccc; }; } if (c == BEAObject.class) { cc.lsMagic = true; cc.humanizeFieldNames = false; cc.convertConceptValuesToRefs = true; cc.itemName = () -> "BEA Object"; cc.addRenderer("meta_code", new HCRUD_Data.AceEditor(80, 20)); cc.titleForObjectID = id -> beaHTML(beaGet(toLong(id))); cc.isEditableValue = o -> cc.isEditableValue_base(o) && !eq(shortClassName(o), "MultiSet"); cc.conceptClassForComboBoxSearch = (info, query) -> { if (endsWith(info, "_nativeValue")) return Concept.class; return cc.conceptClassForComboBoxSearch_base(info, query); }; cc.comboBoxSearchBaseItems = (info, query) -> { Matches m = new Matches(); printVars("comboBoxSearchBaseItems", "info", info); if (jMatchStart("type=", info, m)) { var l = beaList(m.unq(0)); print("Got " + nItems(l)); return cc.comboBoxItems(l); } return cc.comboBoxSearchBaseItems_base(info, query); }; cc.massageItemMapForUpdate = (o, map) -> { cc.massageItemMapForUpdate_base(o, map); if (!isMaster(req)) { Object createdByOld = cget("createdBy", o); if (createdByOld != null || map.get("createdBy") != user(req)) map.remove("createdBy"); } }; cc.onCreate.add(o -> cset(o, "createdBy", currentUser())); cc.getObjectForDuplication = id -> { BEAObject o = beaGet(toLong(id)); Map item = cc.getObjectForDuplication_base(id); item.put("createdBy", req.auth.user.get()); item.put("meta_createdFrom", o); item = or((Map) pcallOpt(cget("cleanObjectForDuplication", websiteEnhancersObject()), "cleanObjectForDuplication", o, item), item); return item; }; cc.emptyObject = () -> { Map item = cc.emptyObject_base(); item.put("type", ""); return item; }; Set deletableRefs = litciset("Match"); cc.objectCanBeDeleted = id -> { BEAObject o = (BEAObject) (cc.conceptForID(id)); return userCanEditObject(user(req), o) && all(findBackRefs(BEAObject.class, o), x -> contains(deletableRefs, x.type())); }; cc.actuallyDeleteConcept = o -> { deleteConcepts(filter(findBackRefs(BEAObject.class, o), o2 -> contains(deletableRefs, o2.type()))); cdelete(o); }; } return cc; } public boolean newLinkTargetBlank_base(Class c) { return super.newLinkTargetBlank_base(c) || c == BEAObject.class; } public HCRUD makeCRUDBase(Class c, DynGazelleRocks.Req req, HTMLFramer1 framer) { HCRUD crud = super.makeCRUD(c, req, framer); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); crud.showOnlySelected = true; crud.showSearchField = true; if (data.customFilter == null) crud.descending = true; crud.cleanItemIDs = true; if (c == BEAObject.class) customizeBEACrud(crud, req, framer); return crud; } @Override public HCRUD makeCRUD(Class c, DynGazelleRocks.Req req, HTMLFramer1 framer) { HCRUD crud = makeCRUDBase(c, req, framer); if (c == BEAObject.class) optimizeBEACrud(crud); return crud; } public void customizeBEACrud(HCRUD crud, DynGazelleRocks.Req req, HTMLFramer1 framer) { HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); crud.allowFieldRenaming = true; var renderValue_old = crud.renderValue; crud.renderValue = (field, value) -> { String html = crud.renderValue_fallback(renderValue_old, field, value); return addShowMoreButton(html); }; crud.haveSelectizeClickable = true; crud.cellColumnToolTips = true; crud.unshownFields = litset("mirrorPost", "globalID"); crud.uneditableFields = litset("log", "meta_dependsOnCode"); crud.showTextFieldsAsAutoExpandingTextAreas = true; crud.duplicateInNewTab = true; crud.customizeACEEditor = ace -> { ace.onKeyDown = "function(event) { " + jquery_submitFormOnCtrlEnter() + " }"; }; HCRUD_Concepts cc = (HCRUD_Concepts) (crud.data); String typeFilter = req.get("type"); if (nempty(typeFilter)) cc.addCIFilter("type", typeFilter); crud.renderCmds = map -> { BEAObject o = getConcept(BEAObject.class, crud.itemIDAsLong(map)); if (o == null) return ""; List cmds = new ArrayList(); addAll(cmds, allToString(optCast(Collection.class, pcall(o, "cmds")))); if (fileNotEmpty(javaSourceFileForObject(o))) cmds.add(targetBlank(baseLink + "/javaSource?id=" + o.id, "Show Java source")); for (String field : ll("text", "what", "type")) { String text = getStringOpt(o, field); if (nempty(text)) cmds.add(targetBlank_noFollow(addParamsToURL(baseLink + "/query", "q", text, "algorithm", "process input"), "Use field " + quote(field) + " as query")); } if (o.typeIs("Input")) { cmds.add(ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Pattern For Input", "f_type", "Pattern", "f_text", getStringOpt("text", o), "f_shouldMatch", o.id, "metaInfo_shouldMatch", "concept"), "Add pattern")); cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.text(), "algorithm", "Apply all text functions"), "Apply all text functions")); } if (o.typeIs("Pattern")) cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.id, "algorithm", "Run pattern"), "Try-run pattern against all inputs")); if (o.typeIsOneOf("Pattern", "Syntactic Pattern")) { cmds.add(ahref(appendParamsToURL(baseLink + "/reactAllInputsWithPattern", "patternID", o.id), "React pattern with all inputs")); cmds.add(ahref(appendParamsToURL(baseLink + "/convertSyntacticToSemanticMatchesForWholePattern", "patternID", o.id), "Convert all syntactic matches to semantic matches")); } if (o.typeIs("Match")) { cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.id, "algorithm", "Find rewrites for match"), "Find rewrites")); if (beaTypeIs(beaGet("pattern", o), "Syntactic Pattern")) cmds.add(ahref(appendParamsToURL(baseLink + "/convertSyntacticToSemanticMatches", "matchID", o.id), "Convert to semantic matches")); } cmds.add(targetBlank(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "newField1_name", "inReferenceTo", "newField1_type", "BEAObject", "newField1_conceptValue", o.id), "Reference this")); cmds.add(ahref_noFollow(addParamsToURL(baseLink + "/markUseful", "redirect", beaShortURL(o), "objectID", o.id), "Mark useful")); cmds.add(ahref_noFollow(addParamsToURL(baseLink + "/markBad", "redirect", beaShortURL(o), "objectID", o.id), "Mark bad")); cmds.add(addCommentHTML(o)); if (o.typeIsOneOf("Script", "Step in script") || eqic(beforeVerticalBar(o.type()), "Instruction")) cmds.add(ahref(addParamsToURL(baseLink + "/runInstruction", "instruction", o.id), "Run")); if (o.typeIs("Function Result")) { if (eqic_gen(cget("resultType", o), "string")) cmds.add(ahref(addParamsToURL(baseLink + "/convertResultToInput", "result", o.id), "Convert to input")); } if (o.typeIs("Auto Run")) cmds.add(ahref(addParamsToURL(baseLink + "/performAutoRunOnAllObjects", "autoRun", o.id), "Run on all objects")); if (o.getClass() != BEAObject.class) cmds.add(ahref(addParamsToURL(baseLink + "/migrateToBase", "id", o.id), "Migrate to BEAObject")); cmds.add(ahref(addParamsToURL(baseLink + "/performAutoRuns", "onObject", o.id), "Perform auto runs on this object")); framer.addInHead(hjs_copyToClipboard()); cmds.add(ahref_onClick(formatFunctionCall("copyToClipboard", jsQuote(o.globalIDStr())), "Copy global ID [" + o.globalIDStr() + "]")); List items = llNempties(crud.renderCmds_base(map), !o.typeIsOneOf("Input", "Pattern", "Syntactic Pattern") ? null : addRewriteHTML(o), !canAutoMigrate(o) ? null : ahref(addParamsToURL(baseLink + "/autoMigrate", "id", o.id), "Auto-migrate to " + shortClassName(defaultCustomClass(o)))); if (isObjectWithCode(o) && isMasterAuthed(req)) { String link = baseLink + "/activateDynamicObject?id=" + o.id; if (!codeHashUpToDate(o)) if (cget("meta_codeHash", o) == null) items.add(ahref(link, "Compile new code", "title", "Object has not been compiled yet")); else items.add(ahref(link, "Compile changed code", "title", "Code has changed afer last compilation")); else if (compileErrorInObject(o)) items.add("Code error. " + ahref(link, "Compile again", "title", "Object has code errors - maybe recompiling fixes them?")); else if (o.customCodeLoaded()) items.add(ahref(link, "Compile again", "title", "Custom code is loaded. Click if you want to recompile anyway")); else items.add(ahref(link, "Compile & load")); } if (additionalCommandsForObjects) { if (o.canRenderHTML()) items.add(targetBlank(beaMod().baseLink + "/beaHTML/" + o.id, "Show HTML")); if (nempty(getStringOpt("meta_code", o))) items.add(targetBlank(addParamsToURL(beaMod().baseLink + "/get-field", "obj", o.id, "field", "meta_code", "enhance", "JavaX"), "Show code")); String codeState = getStringOpt("meta_codeState", o); if (swic(codeState, "error")) items.add(targetBlank(addParamsToURL(beaMod().baseLink + "/beaHTML/249697", "obj", o.id, "field", "meta_codeState"), "Show compile error")); boolean master = beaMod().isMasterAuthed(); if (hasMethod(o, "_activate")) { boolean active = isTrue(pcallOpt(o, "_active")); boolean shouldActivate = isTrue(getOpt(o, "meta_shouldActivate")); if (active != shouldActivate) items.add("Warning: Object is semi-activated"); else if (active) items.add("Object is active"); else items.add("Object is inactive"); if (master) { if (!active || !shouldActivate) items.add(ahref(addParamsToURL(beaMod().baseLink + "/activateObject", "id", o.id), "ACTIVATE")); if (active || shouldActivate) items.add(ahref(addParamsToURL(beaMod().baseLink + "/deactivateObject", "id", o.id), "DEACTIVATE")); } } if (master) { List methodCalls = new ArrayList(); for (Method method : methodsSortedByNameIC(allLiveMethodsBelowClass(o, BEAObject.class))) { Map params = litorderedmap("id", o.id, "name", method.getName()); boolean incomplete = false, problem = false; var types = method.getParameterTypes(); for (int i = 1; i <= l(types); i++) { var argType = types[i - 1]; incomplete = true; if (eq(argType, String.class)) params.put("arg" + i, "putArgHere"); else if (isSubclassOf(argType, BEAObject.class)) params.put("conceptArg" + i, "putArgHere"); else { params.put("arg" + i, "missingConverterProblem"); problem = true; } } String url = addParamsToURL("/callAnyMethod", params); String html = method.getName(); if (problem) html += appendBracketed("probably can't call, need converter"); else if (incomplete) html += appendBracketed("fill in parameters first"); methodCalls.add(targetBlank(url, html)); } if (nempty(methodCalls)) items.add(hPopDownButtonWithText("Call a method", methodCalls)); } } try { addAll(items, o.directCmds()); } catch (Throwable __e) { printStackTrace(__e); } try { addAll(items, (List) callOpt(getWebsiteEnhancer("commandsForObject"), "commandsFor", o)); } catch (Throwable __e) { printStackTrace(__e); } items.add(hPopDownButton(cmds)); return joinNemptiesWithVBar(items); }; cc.massageItemMapForList = (item, map) -> { BEAObject o = (BEAObject) item; if (o.typeIs("Input")) { Collection matches = objectsWhereNotIC(objectsWhereCI(findBackRefs(o, BEAObject.class), "type", "match"), "label", "bad"); ((Map) map).put("Best Matches", new HTML(hparagraphs(lmap(__57 -> matchDescHTML(__57), takeFirst(3, matches))))); } String idField = crud.idField(); Object id = ((Map) map).get(idField); if (id instanceof String) ((Map) map).put(idField, new HTML(ahref(beaShortURL(o), id))); if (o.typeIs("Function Result")) { Object value = getOpt("result", o); ((Map) map).put("result", new HTML(javaValueToHTML(value))); } if (o.typeIs("Match")) { Map mapping = o.mapping(); if (mapping != null) ((Map) map).put("mapping", new HTML(joinWithBR(map(mapping, (k, v) -> htmlEncode2(k) + "=" + calculations.bestInputHTML(v))))); } if (o.getClass() != BEAObject.class) ((Map) map).put("Java Class", dropPrefix(actualMCDollar(), className(o))); if (eq(req.get("showSimpleObjectScore"), "1")) ((Map) map).put("Simple object score", calculations.simpleObjectScore(o)); o.massageItemMapForList(((Map) map)); }; crud.massageFormMatrix = (map, matrix) -> { for (int i = 1; i <= newFieldsToShow; i++) { String nf = "newField" + i; String key = (nf + "_conceptValue"); BEAObject refValue = beaGet(req.get(key)); String refSelector = crud.renderInput(key, cc.makeConceptsComboBox(key, BEAObject.class), refValue) + hjs("$(\"[name=" + key + "]\").hide()"); String nativeSelector = crud.renderInput((nf + "_nativeValue"), cc.makeConceptsComboBox((nf + "_nativeValue"), Concept.class), null) + hjs("$(\"[name=" + nf + "_nativeValue]\").hide()"); List types = ll("String", "BEAObject", "Bool", "Native"); String toggleVis = "\r\n $(\"[name=" + nf + "_value]\").toggle(value == \"String\" || value == \"Bool\");\r\n $(\"#" + nf + "_refBox\").toggle(value == \"BEAObject\");\r\n $(\"#" + nf + "_nativeSel\").toggle(value == \"Native\");\r\n "; String type = req.get((nf + "_type")); String typeSelector = hselect_list(types, type, "name", (nf + "_type"), "onchange", "var value = this.value;" + toggleVis); if (nempty(type)) typeSelector += hscript("(function(value) {" + toggleVis + "})(" + jsQuote(type) + ")"); matrix.add(ll("Add field:
" + htextfield((nf + "_name"), req.get((nf + "_name")), "title", "New field name"), htmlTable2_noHtmlEncode(ll(ll(crud.renderTextField((nf + "_value"), "", 40) + span(refSelector, "id", (nf + "_refBox"), "style", "display: none"), span(nativeSelector, "id", (nf + "_nativeSel"), "style", "display: none"), "Type", typeSelector)), "noHeader", true, "tableParams", litobjectarray("style", "width: 100%")))); } }; crud.preprocessUpdateParams = params -> { params = cloneMap(params); params = mapValues(params, v -> eq(v, "") ? null : v); for (int i = 1; i <= max(newFieldsToShow, 10); i++) { String nf = "newField" + i; String name = trim(params.get((nf + "_name"))), type = params.get((nf + "_type")), refValue = params.get((nf + "_conceptValue")), nativeValue = params.get((nf + "_nativeValue")), value = params.get((nf + "_value")); if (eqic(type, "BEAObject")) { value = refValue; params.put("metaInfo_" + name, "concept"); } else if (eqic(type, "Native")) { value = nativeValue; params.put("metaInfo_" + name, "concept"); } else if (eqic(type, "Bool")) params.put("metaInfo_" + name, "bool"); if (eq(value, "")) value = null; if (nempty(name)) params.put(crud.fieldPrefix + name, value); } return params; }; if (!isMasterAuthed(req)) cc.objectCanBeEdited = id -> userCanEditObject(user(req), (BEAObject) cc.conceptForID(id)); } public void optimizeBEACrud(HCRUD crud) { HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); if (empty(data.filters) && empty(data.ciFilters)) { crud.sortByField = "_modified"; crud.descending = true; data.listConcepts_firstStep = () -> (List) cloneList(beaModifiedIndex.allConcepts()); data.defaultSortField = () -> pair("_modified", true); data.defaultSort = __43 -> id(__43); } } public boolean userCanEditObject(User user, BEAObject o) { return user != null && (user.isMaster || cget("createdBy", o) == user); } @Override public Object servePossiblyUserlessBotFunction(DynGazelleRocks.Req req, String function, Map data, User user) { if (eq(function, "beaExport")) { Collection ids = concatLists(tok_integersAsLongs(urldecode(req.subURI)), tok_integersAsLongs(req.get("ids"))); var objects = map(__58 -> beaGet(__58), ids); return serveJSON_breakAtLevels(2, "result", map(objects, obj -> litorderedmap("id", obj.id, "gid", str(obj.globalID()), "struct", obj.structureString()))); } return super.servePossiblyUserlessBotFunction(req, function, data, user); } @Override public Object serveBotFunction(DynGazelleRocks.Req req, String function, Map data, User user) { if (eq(function, "beaList")) { long changedAfter = toLong(data.get("changedAfter")); double pollFor = min(bot_maxPollSeconds, toLong(data.get("pollFor"))); long startTime = sysNow(); if (changedAfter > 0 && changedAfter == now()) sleep(1); Collection objects; while (true) { objects = changedAfter == 0 ? list(BEAObject.class) : conceptsWithFieldGreaterThan_sorted(BEAObject.class, "_modified", changedAfter); if (nempty(objects) || pollFor == 0 || elapsedSeconds_sysNow(startTime) >= pollFor) return serveJSON_breakAtLevels(2, "result", map(objects, obj -> litorderedmap("gid", str(obj.globalID()), "struct", obj.structureString()))); sleep(bot_pollInterval); } } return super.serveBotFunction(req, function, data, user); } @Override public Object serveOtherPage2(DynGazelleRocks.Req req) { return serveOtherPage2((Req) req); } public Object serveOtherPage2(Req req) { { Object __31 = super.serveOtherPage2(req); if (__31 != null) return __31; } String uri = dropTrailingSlashIfNemptyAfterwards(req.uri); Matches m = new Matches(); if (swic_notSame(uri, "/beaCRUD/", m)) return renderBEAObjectTable(req, urldecode(m.rest())); if (eq(uri, "/inputs")) return renderBEAObjectTable(req, "input"); if (eq(uri, "/syntacticMatchesTable")) return hrefresh(baseLink + "/matchesTable?syntacticOnly=1"); if (eq(uri, "/matchesTable")) { boolean syntacticOnly = eq("1", req.get("syntacticOnly")); List list = new ArrayList(); for (BEAObject match : beaList("Match")) { BEAObject input = cgetOpt(BEAObject.class, match, "input"); BEAObject pat = cgetOpt(BEAObject.class, match, "pattern"); if (syntacticOnly && !calculations.isSyntacticPattern(pat)) continue; { if (calculations.patternAlwaysMatches(pat)) continue; } Map mapping = match.mapping(); if (input == null || pat == null || mapping == null) continue; list.add(match); } list = sortedByCalculatedFieldDesc(list, match -> conceptID(cgetBEA("input", match))); HTMLPaginator paginator = new HTMLPaginator(); paginator.processParams(req.params()); paginator.baseLink = addParamsToURL(baseLink, filterKeys(req.params(), p -> eq(p, "syntacticOnly"))); paginator.max = l(list); req.framer.add(divUnlessEmpty(paginator.renderNav())); list = subList(list, paginator.visibleRange()); List data = new ArrayList(); for (BEAObject match : list) { BEAObject input = cgetOpt(BEAObject.class, match, "input"); BEAObject pat = cgetOpt(BEAObject.class, match, "pattern"); Map mapping = match.mapping(); String patText = calculations.patternTextWithAngleBracketVars(pat); List tok = javaTokWithAngleBrackets(patText); BitSet bs = new BitSet(); tok = replaceAngleBracketVars(tok, mapping, bs); for (Pair __26 : bitSetStreaksAndNonStreaks(bs, l(tok))) { IntRange r = pairA(__26); boolean b = pairB(__26); String t = joinSubList(tok, r); replaceTokens(tok, r, b ? formatSubInput(input, t, "obj" + match.id) : htmlEncode2(t)); } String boldenedInput = join(tok); data.add(litorderedmap("Input", aname("obj" + match.id, joinWithBR(ahref(beaURL(input), htmlEncode2_str(call(input, "text"))), boldenedInput)), "Pattern", ahref(beaURL(pat), htmlEncode2(pat.text())), "DB object", beaHTML_justID(match), "Feedback", joinNemptiesWithSpace(calculations.feedbackHTML(match), addCommentHTML(match, "defaultComment", "good match", "redirectAfterSave", req.uriWithParams(), "text", "+")))); } req.framer.title = syntacticOnly ? "Syntactic matches table" : "Matches table"; req.framer.add(p()); req.framer.add(htmlTable2_noHtmlEncode(data)); return completeFrame(req); } if (eq(uri, "/rewritesTable")) { List data = new ArrayList(); for (BEAObject input : beaList("Input")) for (BEAObject r : beaBackRefs(input, "Rewrite")) data.add(litorderedmap("Input", input.text(), "Rewrite", tok_dropCurlyBrackets(r.text()), "Rewrite Type", getOpt("rewriteType", r))); req.framer.title = "Rewrites table"; req.framer.add(p()); req.framer.add(htmlTable2(data)); return completeFrame(req); } if (eq(uri, "/patternRewritesTable")) { List data = new ArrayList(); for (BEAObject pat : beaListAny("Pattern", "Syntactic Pattern")) for (BEAObject r : beaBackRefs(pat, "Rewrite")) if (cget("isRewriteOf", r) == pat) { Pair example = calculations.exampleForPatternRewrite(pat, r); data.add(litorderedmap("Pattern", ahref(beaURL(pat), htmlEncode2(pat.text())), "Rewrite", ahref(beaURL(r), htmlEncode2(tok_dropCurlyBrackets(r.text()))), "Example", joinWithBR(htmlEncode2(example.a), htmlEncode2("=> " + example.b)), "Rewrite Type", htmlEncode2_str(getOpt("rewriteType", r)), "Cmds", hPopDownButton(targetBlank(conceptEditLink(r), "Edit")))); } req.framer.title = "Pattern rewrites table"; req.framer.add(p()); req.framer.add(htmlTable2_noHtmlEncode(data)); return completeFrame(req); } if (eq(uri, "/syntacticPatternsWithoutRewrites")) { HCRUD crud = makeBEATypeCrud(req, "Syntactic Pattern"); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); IF1 prev = data.customFilter; data.customFilter = list -> { list = filter(list, c -> empty(beaBackRefs(c, "Rewrite"))); return postProcess(prev, list); }; crud.customTitle = "Syntactic patterns without rewrites"; return serveCRUD(req, BEAObject.class, crud); } if (eq(uri, "/inputsWithoutRewrites")) { HCRUD crud = makeBEATypeCrud(req, "input"); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); IF1 prev = data.customFilter; data.customFilter = list -> { list = filter(list, c -> empty(beaBackRefs(c, "Rewrite"))); return postProcess(prev, list); }; crud.customTitle = "Inputs without rewrites"; return serveCRUD(req, BEAObject.class, crud); } if (eq(uri, "/inputsWithRewrites")) { HCRUD crud = makeBEATypeCrud(req, "input"); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); IF1 prev = data.customFilter; data.customFilter = list -> { list = filter(list, c -> nempty(beaBackRefs(c, "Rewrite"))); return postProcess(prev, list); }; crud.customTitle = "Inputs with rewrites"; return serveCRUD(req, BEAObject.class, crud); } if (eq(uri, "/inputsWithoutMatches")) { HCRUD crud = makeBEATypeCrud(req, "input"); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); IF1 prev = data.customFilter; data.customFilter = list -> { list = filter(list, c -> empty(beaBackRefs(c, "Match"))); return postProcess(prev, list); }; crud.customTitle = "Inputs without matches"; return serveCRUD(req, BEAObject.class, crud); } if (eq(uri, "/patterns")) return renderBEAObjectTable(req, "pattern"); if (eq(uri, "/syntacticPatterns")) return renderBEAObjectTable(req, "Syntactic Pattern"); if (eq(uri, "/matches")) return renderBEAObjectTable(req, "match"); if (eq(uri, "/rewrites")) return renderBEAObjectTable(req, "rewrite"); if (eq(uri, "/aiTasks")) return renderBEAObjectTable(req, "AI Task"); if (eq(uri, "/query")) return calculations.serveQueryPage(req); if (eq(uri, "/queryHome")) return calculations.serveQueryPage(req, true); if (eq(uri, "/saveInput")) { if (userAgentIsBot(currentUserAgent())) return "You're a bot"; String text = trim(req.get("text")); String info = trim(req.get("info")); String uncleanedText = trim(req.get("uncleanedText")); if (empty(text)) return subBot_serve500("Input empty"); if (l(text) > maxInputLength) return subBot_serve500("Input too long"); BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text, "createdBy", user(req)); saveUserAgent(input); if (nempty(info) || nempty(uncleanedText)) cnew(BEAObject.class, "type", "Input Source", "input", input, "source", info, "uncleanedText", uncleanedText); return hrefresh(or2(req.get("redirect"), baseLink + "/")); } if (eq(uri, "/markUseful")) { BEAObject o = beaGet("objectID", req); if (o == null) return subBot_serve500("Object not found"); uniqCI(BEAObject.class, "type", "Useful", "object", o, "createdBy", user(req)); return hrefresh(or2(req.get("redirect"), baseLink + "/")); } if (eq(uri, "/markBad")) { BEAObject o = beaGet("objectID", req); if (o == null) return subBot_serve500("Object not found"); uniqCI(BEAObject.class, "type", "Bad", "object", o, "createdBy", user(req)); return hrefresh(or2(req.get("redirect"), baseLink + "/")); } if (eq(uri, "/saveAnswer")) { String text = trim(req.get("text")); String rewriteType = or2(trim(req.get("rewriteType")), "Suggested Answer"); long inputID = toLong(req.get("inputID")); BEAObject input = beaGet(inputID); if (input == null) return subBot_serve500("Input not found"); if (empty(text)) return subBot_serve500("Text empty"); if (l(text) > maxInputLength) return subBot_serve500("Text too long"); uniqCI(BEAObject.class, "type", "Rewrite", "text", text, "isRewriteOf", input, "rewriteType", rewriteType, "createdBy", user(req)); return hrefresh(or2(req.get("redirect"), baseLink + "/")); } if (eq(uri, "/javaSource")) { BEAObject o = beaGet("id", req); return serveText(loadTextFile(javaSourceFileForObject(o))); } if (startsWith(uri, "/beaHTML/", m)) { String rest = m.rest(); int i = smartIndexOf(rest, "/"); BEAObject o = beaGet(takeFirst(i, rest)); String subURI = substring(rest, i + 1); return serveBEAHTML(req, o, subURI); } if (eq(uri, "/is-a-gazelle")) return "yes"; if (eq(uri, "/gazelle-server-id")) return gazelleServerGlobalID; if (eq(uri, "/get-field")) { BEAObject obj = beaGet("obj", req); String field = req.get("field"); String value = str(cget(field, obj)); if (eqic(req.get("enhance"), "JavaX")) { JavaXHyperlinker hl = new JavaXHyperlinker(); hl.targetBlank = true; hl.addExplainer(ph -> { if (eq(ph.token, "from") && isInteger(ph.next)) ph.link(ph.cIdx + 2, beaURL(parseLong(ph.next))); }); String html = hl.codeToHTML(value); return htitle_h1(beaHTML(obj) + "." + htmlEncode2(field)) + div(sourceCodeToHTML_noEncode(html), "style", hstyle_sourceCodeLikeInRepo()); } return serveText(value); } if (sourceIsPublic || masterAuthed(req)) if (eqicOneOf(uri, "/source", "/sources", "/src", "sourceCode", "/code")) return "You will be redirected to my source code..." + hrefresh(3.0, snippetURL(programID())); BEAForward forward = findBEAShortURL(uri); if (forward != null) return serveBEAHTML(req, forward.object, forward.subURI); if (exportUsersGlobally && eq(uri, "/lookup-user")) { String name = req == null ? null : req.get("name"); String passwordMD5 = req == null ? null : req.get("passwordMD5"); String salt = req == null ? null : req.get("salt"); print("lookup-user called from " + req.webRequest.clientIP() + ", name: " + name); if (!eq(salt, passwordSalt())) return serveJSON(litorderedmap("error", "Bad salt")); if (empty(name)) return serveJSON(litorderedmap("error", "No name")); User user = conceptWhereCI(User.class, "name", name); if (user == null) return serveJSON(litorderedmap("error", "User not found")); if (!eq(getVar(user.passwordMD5), passwordMD5)) return serveJSON(litorderedmap("error", "Bad pw")); return serveJSON(litorderedmap("userID", user.id, "contact", getString("contact", user), "isMaster", getBoolOpt("isMaster", user))); } if (!inMasterMode(req)) return null; if (eq(uri, "/uploadInputs")) return serveUploadTexts(req, "Input"); if (eq(uri, "/uploadPatterns")) return serveUploadTexts(req, "Pattern"); if (eq(uri, "/analyzeInput")) return calculations.serveAnalyzeInput(req); if (eq(uri, "/allBEATypes")) { return h2_title("All object types") + ul(renderObjectTypes()); } if (eq(uri, "/storeMatch")) { BEAObject pattern = beaGet(req.get("pattern")); BEAObject input = beaGet(req.get("input")); String label = req.get("label"); BEAObject match = calculations.reactInputWithPattern(input, pattern); if (match == null) return "Couldn't match"; cset(match, "label", label); return hrefresh(or2(req.get("redirect"), beaObjectURL(match))); } if (eq(uri, "/saveSyntacticPattern") || eq(uri, "/savePattern")) { String type = cic(uri, "syntactic") ? "Syntactic Pattern" : "Pattern"; String text = req.get("text"); BEAObject fromInput = beaGet(req.get("fromInput")); BEAObject pat = uniqCI(BEAObject.class, "type", type, "text", text, "createdBy", user(req)); csetIfUnset(pat, "fromInput", fromInput); if (fromInput != null) calculations.reactInputWithPattern(fromInput, pat); return hrefresh(or2(req.get("redirect"), baseLink + "/")); } if (eq(uri, "/runInstruction")) { BEAObject o = beaGet(req.get("instruction")); runInstruction(o); return hrefresh(beaObjectURL(o)); } if (eq(uri, "/convertResultToInput")) { BEAObject result = beaGet(req.get("result")); if (result == null) return subBot_serve500("Object not found"); String text = unquote(getString("result", result)); if (l(text) > maxInputLength) return subBot_serve500("Input too long"); BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text); uniqCI(BEAObject.class, "type", "Input Source", "input", input, "source", result); return hrefresh(beaShortURL(input)); } if (eq(uri, "/setWordType")) { BEAObject r = beaGet(req.get("resultID")); String wordType = assertNempty(req.get("wordType")); List result = assertStringList(cget("result", r)); for (String s : result) uniqCI(BEAObject.class, "type", "Word type", "word", s, "wordType", wordType); return "OK"; } if (eq(uri, "/reload")) { dm_reloadModuleIn(3); return "Reloading module in 3"; } if (eq(uri, "/performAutoRuns")) { BEAObject o = beaGet(req.get("onObject")); if (o == null) return "Object not found"; rstAutoRuns.add(o); return hrefresh(beaURL(o)); } if (eq(uri, "/reactAllInputsWithAllSyntacticPatterns")) { return str(returnTimed(new Runnable() { public void run() { try { calculations.reactAllInputsWithAllSyntacticPatterns(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "calculations.reactAllInputsWithAllSyntacticPatterns();"; } })); } if (eq(uri, "/reactAllInputsWithPattern")) { BEAObject pat = beaGet(req.get("patternID")); if (pat == null) return "Pattern not found"; return str(returnTimed(new Runnable() { public void run() { try { calculations.reactAllInputsWithPattern(pat); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "calculations.reactAllInputsWithPattern(pat);"; } })); } if (eq(uri, "/storeSubInput")) { BEAObject input = beaGet(req.get("input")); if (input == null) return "Input not found"; String text = req.get("text"); String type = eqic(req.get("label"), "good") ? "Sub-Input" : "Bad Sub-Input"; BEAObject o = uniqCI(BEAObject.class, "type", type, "input", input, "text", text, "createdBy", currentUser()); return hrefresh(or2(req.get("redirect"), beaURL(o))); } if (eq(uri, "/performAutoRunOnAllObjects")) { BEAObject autoRun = beaGet("autoRun", req); performAutoRunOnAllObjects(autoRun); return "OK"; } if (eq(uri, "/autoMigrate")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; String url = beaURL(o); return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(autoMigrateToCustomClass(o)) + hrefresh(1.0, url); } if (eq(uri, "/migrateToBase")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; String url = beaURL(o); return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(autoMigrateToBase(o)) + hrefresh(1.0, url); } if (eq(uri, "/convertSyntacticToSemanticMatches")) { BEAObject match = beaGet("matchID", req); if (match == null) return "Match not found"; return ul_htmlEncode2(calculations.convertSyntacticToSemanticMatches(match)); } if (eq(uri, "/convertSyntacticToSemanticMatchesForWholePattern")) { BEAObject pat = beaGet("patternID", req); if (pat == null) return "Pattern not found"; return ul_htmlEncode2(calculations.convertSyntacticToSemanticMatchesForWholePattern(pat)); } if (eq(uri, "/createPatternListFromUsefulSyntacticPatterns")) return hrefresh(beaURL(calc.createPatternListFromUsefulSyntacticPatterns())); if (eq(uri, "/createConceptShadows")) return createConceptShadows(); if (eq(uri, "/compareConceptShadows")) { if (conceptShadows == null) return createConceptShadows(); List newShadows = allConceptShadows(); List> diff = diffConceptShadows(conceptShadows, newShadows); return subBot_serveText(nDiffs(diff) + ":\n\n" + pnlToString(diff)); } if (eq(uri, "/includeScript")) { String snippetID = req.get("id"); Object wired = hotwire(snippetID); return "Wired: " + wired; } if (eq(uri, "/dependents")) { BEAObject o = beaGet("id", req); return ul(lmap(__59 -> htmlEncode2_str(__59), objectWithDependents(o))); } if (eq(uri, "/prototypeUsers")) { BEAObject o = beaGet("id", req); return ul(lmap(__60 -> htmlEncode2_str(__60), prototypeUsers(o))); } if (eq(uri, "/activateObject")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; cset(o, "meta_shouldActivate", true); callActivate(o); return "Object activated." + hrefresh(1.0, beaURL(o)); } if (eq(uri, "/deactivateObject")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; cset(o, "meta_shouldActivate", false); callDeactivate(o); return "Object deactivated." + hrefresh(1.0, beaURL(o)); } if (eq(uri, "/reactivateDynamicObject")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; long id = o.id; reactivateAndMigratePrototypeUsers(o); return "OK" + hrefresh(1.0, beaURL(id)); } if (eq(uri, "/activateDynamicObject")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; compileAndLoadObject(o); o = beaGet("id", req); String url = or2(req.get("redirect"), beaURL(o)); return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(o) + hrefresh(1.0, url); } if (eq(uri, "/callAnyMethod")) { BEAObject o = beaGet("id", req); if (o == null) return "Object not found"; String name = req.get("name"); boolean showPrints = eq("1", req.get("showPrints")); List args = new ArrayList(); for (Map.Entry __27 : _entrySet(req.params())) { String key = __27.getKey(); String val = __27.getValue(); List groups = regexpExtractGroups("^(arg|conceptArg)(\\d+)$", key); if (groups != null) { int idx = parseInt(second(groups)); String type = first(groups); Object arg = eq(type, "conceptArg") ? getConcept(parseLong(val)) : val; listSet(args, idx - 1, arg); } } String arg = req.get("arg"); if (arg != null) listSet(args, 0, arg); String result = hijackPrintPlusResult_text(() -> { try { return call(o, name, toObjectArray(args)); } catch (Throwable e) { printStackTrace(e); return null; } }); return serveText("Result of " + o + " . " + name + "(" + joinWithComma(args) + "):\n" + result); } if (eq(uri, "/download")) return subBot_serveFileWithName("gazelle-database." + ymd_minus_hms() + ".gz", conceptsFile()); if (eq(uri, "/errorSource")) return subBot_serveText(loadTextFile(transpilerErrorSourceFile())); if (eq(uri, "/changeUserPassword")) { String name = req.get("name"), newPW = req.get("newPW"); if (empty(name)) return "Need 'name' parameter (user name)"; if (empty(newPW)) return "Need 'newPW' parameter"; User user = conceptWhereCI(User.class, "name", name); cset(user, "passwordMD5", new SecretValue(hashPW(newPW))); return "Password for " + htmlEncode2(user) + " updated!"; } return null; } public class BEAForward implements IFieldsToList { public BEAObject object; public String subURI; public BEAForward() { } public BEAForward(BEAObject object, String subURI) { this.subURI = subURI; this.object = object; } public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + object + ", " + subURI + ")"; } public Object[] _fieldsToList() { return new Object[] { object, subURI }; } } public Collection beaShortURLObjects() { return filter(__61 -> createdByMasterUser(__61), beaList("BEA Short URL")); } public Collection masterObjects(Collection l) { return filter(__62 -> createdByMasterUser(__62), l); } public boolean isBEAShortURLObject(BEAObject o) { return o != null && o.typeIs("BEA Short URL") && createdByMasterUser(o); } public BEAForward findBEAShortURL(String uri) { Matches m = new Matches(); String uriWithSlash = addSlashSuffix(uri); for (BEAObject o : beaShortURLObjects()) { try { String uriToTest = getStringOpt("uri", o); if (startsWith_addingSlash(uriWithSlash, uriToTest, m)) { BEAObject o2 = (BEAObject) (cget("object", o)); if (o2 != null) { String subURI = m.rest(); if (l(uriWithSlash) > l(uri)) subURI = dropSlashSuffix(subURI); return new BEAForward(o2, subURI); } } } catch (Throwable __e) { printStackTrace(__e); } } return null; } transient public List conceptShadows; public Object createConceptShadows() { long _startTime_28 = sysNow(); String profile = profileThisThreadToString(new Runnable() { public void run() { try { conceptShadows = allConceptShadows(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "conceptShadows = allConceptShadows();"; } }); done2_always("Make shadows", _startTime_28); return subBot_serveText(n2(conceptShadows, "shadow") + " made in " + lastTiming_formatted() + "\n\n" + profile); } public HCRUD makeBEATypeCrud(Req req, String type) { return makeBEATypeCrud(req, type, req.framer); } public HCRUD makeBEATypeCrud(Req req, String type, HTMLFramer1 framer) { HCRUD crud = makeCRUDBase(BEAObject.class, req, framer); crud.baseLink = req.uri(); HCRUD_Concepts data = (HCRUD_Concepts) (crud.data); data.itemName = () -> firstToUpper(type); data.addCIFilter("type", eqic(type, "(no type)") ? null : type); if (eqicOneOf(type, "Input", "Pattern", "AI Task")) { IF0> prev = data.emptyObject; data.emptyObject = () -> { Map item = data.emptyObject_fallback(prev); item.put("text", ""); return item; }; } optimizeBEACrud(crud); return crud; } public Object renderBEAObjectTable(Req req, String type) { HCRUD crud = makeBEATypeCrud(req, type); return serveCRUD(req, BEAObject.class, crud); } public Object serveUploadTexts(Req req, String type) { String inputs = req.get("text"); List output = new ArrayList(); if (nempty(inputs)) { for (String text : tlft(inputs)) { Pair p = uniqCI2_sync(BEAObject.class, "type", type, "text", text); if (cget("uploadedBy", p.a) == null) cset(p.a, "uploadedBy", req.auth.user); output.add(type + " " + (p.b ? "added" : "exists") + " (ID " + p.a.id + "): " + text); } } return h2("Upload " + plural(type)) + hpostform(p(plural(type) + " (one per line):") + p(htextarea(inputs, "name", "text")) + pIfNempty(htmlEncode_nlToBR(lines(output))) + hsubmit("Upload " + plural(type))); } public Collection beaObjectsOfType(String type) { return conceptsWhereCI(BEAObject.class, "type", type); } public void reactAllInputsWithSomePatterns() { calculations.reactAllInputsWithSomePatterns(); } transient public IF0 navDiv; public String navDiv() { return navDiv != null ? navDiv.get() : navDiv_base(); } final public String navDiv_fallback(IF0 _f) { return _f != null ? _f.get() : navDiv_base(); } public String navDiv_base() { return div_vbar(newNavLinks(), "style", "margin-bottom: 0.5em"); } transient public IF0> newNavLinks; public List newNavLinks() { return newNavLinks != null ? newNavLinks.get() : newNavLinks_base(); } final public List newNavLinks_fallback(IF0> _f) { return _f != null ? _f.get() : newNavLinks_base(); } public List newNavLinks_base() { Req req = currentReq(); HCRUD crud = makeCRUD(BEAObject.class, req); String allObjectTypesLink = ahref(baseLink + "/allBEATypes", "All object types"); BEAHTMLFramer framer = (BEAHTMLFramer) (req.framer); framer.unnamedPopDownButton.addAll(ahref(baseLink + "/stats", "Stats"), !isMasterAuthed() ? null : ahref(baseLink + "/download", "DB download"), targetBlank(getProgramURL(), "Source code"), !isMasterAuthed() ? null : ahref(baseLink + "/refchecker", "Reference checker"), ahref(baseLink + "/inputsWithRewrites", "Inputs with rewrites"), ahref(baseLink + "/rewritesTable", "Rewrites table"), ahref(baseLink + "/patternRewritesTable", "Pattern rewrites table"), ahref(baseLink + "/matchesTable", "Matches table"), ahref(baseLink + "/matchesTable?syntacticOnly=1", "Syntactic matches table")); List items = new ArrayList(); if (showInputAndPatternNavItems) addAll(items, ahref(baseLink + "/query", "Query"), ahref(baseLink + "/newSearch", span_title("New BEA-based searched in development", "New Search (dev.)")), beaNavLink("Input", crud), beaNavLink("Pattern", crud), beaNavLink("Syntactic Pattern", crud), ahref(baseLink + "/syntacticPatternsWithoutRewrites", (showInputCounts ? n2(syntacticPatternsWithoutRewrites.get()) + " " : "") + "Syntactic patterns w/o rewrites"), beaNavLink("Match", crud), beaNavLink("Rewrite", crud), beaNavLink("AI Task", crud), ahref(baseLink + "/inputsWithoutMatches", (showInputCounts ? n2(inputsWithoutMatches.get()) + " " : "") + "Inputs w/o matches"), ahref(baseLink + "/inputsWithoutRewrites", (showInputCounts ? n2(inputsWithoutRewrites.get()) + " " : "") + "Inputs w/o rewrites")); addAll(items, inlineSwappable("navDiv_allObjectTypes", this, () -> allObjectTypesLink + " " + hPopDownButton(listPlus(renderObjectTypes(10), allObjectTypesLink))), framer.unnamedPopDownButton.width(350).height(500).html()); return items; } public String beaNavLink(String type, HCRUD crud) { return beaNavLink(type, crud, beaCount(type)); } public String beaNavLink(String type, HCRUD crud, int count) { String plural = firstToLower(plural(type)); String link = baseLink + "/" + camelCase(plural); return ahref(link, n2(count) + " " + firstToUpper(plural)) + (!crud.actuallyAllowCreate() ? "" : " " + ahref(addParamToURL(link, "cmd", "new"), "+")); } public String beaObjectURL(BEAObject o) { return conceptLink(o, currentReq()); } public String matchDescHTML(BEAObject m) { try { BEAObject pat = (BEAObject) (cget("pattern", m)); Map mapping = (Map) (cget("mapping", m)); return ahref_undecorated(crudLink(m), htmlEncode2(quote(getString("text", pat))) + "
  with " + renderEqualsCommaProperties(mapping)); } catch (Throwable __e) { printStackTrace(__e); } return htmlEncode2(str(m)); } public Collection beaList() { return list(BEAObject.class); } public Collection beaList(String type, Object... params) { return conceptsWhereCI(BEAObject.class, paramsPlus_inFront(params, "type", type)); } public Collection beaListAny(String... types) { return concatLists(lmap(__63 -> beaList(__63), litciset(types))); } public Collection beaListAny(Collection types) { return concatLists(lmap(__64 -> beaList(__64), asCISet(types))); } public BEAObject beaGet(long id) { return getConceptOpt(BEAObject.class, id); } public BEAObject beaGet(String id) { return beaGet(parseFirstLong(id)); } public boolean beaTypeIs(BEAObject o, String type) { return o != null && o.typeIs(type); } public BEAObject beaGet(String key, Req req) { return beaGet(req.get(key)); } final public BEAObject beaGet(String field, BEAObject o) { return cgetBEA(field, o); } public BEAObject cgetBEA(String field, BEAObject o) { return (BEAObject) cget(field, o); } final public BEAObject beaGet(BEAObject o, String field) { return cgetBEA(o, field); } public BEAObject cgetBEA(BEAObject o, String field) { return cgetBEA(field, o); } final public String beaToHTML(BEAObject o) { return beaLinkHTML(o); } final public String beaHTML(BEAObject o) { return beaLinkHTML(o); } public String beaLinkHTML(BEAObject o) { return beaLinkHTML(o, false); } final public String beaToHTML(BEAObject o, boolean targetBlank) { return beaLinkHTML(o, targetBlank); } final public String beaHTML(BEAObject o, boolean targetBlank) { return beaLinkHTML(o, targetBlank); } public String beaLinkHTML(BEAObject o, boolean targetBlank) { return o == null ? null : ahref_targetBlankIf(targetBlank, conceptLink(o), htmlEncode2_nlToBr(str(o))); } public String beaHTML_targetBlank(BEAObject o) { return o == null ? null : targetBlank(conceptLink(o), htmlEncode2_nlToBr(str(o))); } public String beaHTML_justID(BEAObject o) { return o == null ? null : ahref(beaShortURL(o), o.id); } public String beaFullURL(BEAObject o) { return o == null ? null : mainDomainWithProtocol + beaURL(o); } public String beaURL(long id) { return baseLink + "/" + id; } final public String beaURL(BEAObject o) { return beaShortURL(o); } public String beaShortURL(BEAObject o) { return o == null ? null : baseLink + "/" + o.id; } public Collection beaBackRefs(BEAObject o, String type) { return objectsWhereCI(findBackRefs(BEAObject.class, o), "type", type); } public Collection beaBackRefs(BEAObject o) { return findBackRefs(BEAObject.class, o); } transient public IF1 serveDefaultPage; @Override public Object serveDefaultPage(DynGazelleRocks.Req req) { return serveDefaultPage != null ? serveDefaultPage.get(req) : serveDefaultPage_base(req); } final public Object serveDefaultPage_fallback(IF1 _f, DynGazelleRocks.Req req) { return _f != null ? _f.get(req) : serveDefaultPage_base(req); } public Object serveDefaultPage_base(DynGazelleRocks.Req req) { HTMLFramer1 framer = req.framer; framer.add(centerGazelleLogo()); return completeFrame(req); } public String centerGazelleLogo() { return hcenter3(hsnippetimg_scaleToWidth(200, "#1102967", 200, 110, "title", "Gazelle"), "style", "margin-top: 100px"); } public String html_loggedIn() { return html_loggedIn(true); } public String html_loggedIn(boolean offerLogInLink) { User user = user(currentReq()); return user == null ? (offerLogInLink ? ahref(baseLink + "/login", "Log in") : "Not logged in") : "Logged in as " + htmlEncode2(user.name); } transient public IVF1 distributeNewObject_impl; public void distributeNewObject_impl(BEAObject o) { if (distributeNewObject_impl != null) distributeNewObject_impl.get(o); else distributeNewObject_impl_base(o); } final public void distributeNewObject_impl_fallback(IVF1 _f, BEAObject o) { if (_f != null) _f.get(o); else distributeNewObject_impl_base(o); } public void distributeNewObject_impl_base(BEAObject o) { if (newObjectIsWorthNotification(o)) distributeNewObject_impl_noCheck(o); } transient public IF1 newObjectIsWorthNotification; public boolean newObjectIsWorthNotification(BEAObject o) { return newObjectIsWorthNotification != null ? newObjectIsWorthNotification.get(o) : newObjectIsWorthNotification_base(o); } final public boolean newObjectIsWorthNotification_fallback(IF1 _f, BEAObject o) { return _f != null ? _f.get(o) : newObjectIsWorthNotification_base(o); } public boolean newObjectIsWorthNotification_base(BEAObject o) { return o.id != 0 && !o.typeIsOneOf("Match", "Live WebSocket"); } transient public IVF1 distributeNewObject_impl_noCheck; public void distributeNewObject_impl_noCheck(BEAObject o) { if (distributeNewObject_impl_noCheck != null) distributeNewObject_impl_noCheck.get(o); else distributeNewObject_impl_noCheck_base(o); } final public void distributeNewObject_impl_noCheck_fallback(IVF1 _f, BEAObject o) { if (_f != null) _f.get(o); else distributeNewObject_impl_noCheck_base(o); } public void distributeNewObject_impl_noCheck_base(BEAObject o) { distributeNotification("New object: " + o); } public void performAutoRuns(BEAObject o) { AutoCloseable __34 = enter(); try { for (BEAObject autoRun : beaList("Auto Run")) { if (!isTrue(getOpt("enabled", autoRun))) { print("Not enabled: " + autoRun); continue; } performAutoRunOnObject(autoRun, o); } } finally { _close(__34); } } public void performAutoRunOnAllObjects(BEAObject autoRun) { for (BEAObject o : list(BEAObject.class)) performAutoRunOnObject(autoRun, o); } public void performAutoRunOnObject(BEAObject autoRun, BEAObject o) { ping(); String type = getString("onChangedObjectOfType", autoRun); if (!o.typeIs(type)) return; print("Running " + autoRun); BEAObject procedure = (BEAObject) (cget("procedure", autoRun)); String internalCode = getString("internalCode", procedure); printVars_str("internalCode", internalCode, "o", o); if (eqic(internalCode, "convertInputToPattern")) { String text = o.text(); if (!containsAngleBracketVars(text)) { print("No angle bracket vars"); return; } BEAObject p = uniqCI_returnIfNew(BEAObject.class, "type", "Pattern", "text", text); cset(p, "fromInput", o, "byProcedure", procedure, "byAutoRun", autoRun); print("p", p); } else if (eqic(internalCode, "convertInputToSyntacticPattern")) { String text = o.text(); if (!containsStars(text)) { print("No stars"); return; } BEAObject p = uniqCI_returnIfNew(BEAObject.class, "type", "Syntactic Pattern", "text", text); cset(p, "fromInput", o, "byProcedure", procedure, "byAutoRun", autoRun); print("p", p); } else if (eqic(internalCode, "dropPunctuationFromPattern")) { String text = o.text(); String text2 = dropPunctuation(text); if (eq(text, text2)) return; BEAObject p = uniqCI(BEAObject.class, "type", o.type(), "text", text2); cset(o, "withoutPunctuation", p); } else if (eqic(internalCode, "makeSyntacticPattern")) { print("sp", calculations.makeSyntacticPattern(o)); } else if (eqic(internalCode, "runFunctionOnInput")) { print("runFunctionOnInput"); BEAObject function = beaGet(o, "function"); BEAObject input = beaGet(o, "input"); if (function == null || input == null) { print("Missing parameters"); return; } if (cget("result", o) != null) { print("Has result"); return; } BEAObject result = calculations.reactFunctionWithInput(calculations.new BackEndAlgorithm(), function, input); print("result", result); if (result != null) { cset(result, "request", o); cset(o, "result", result); } } else print("Unknown internal code"); } public BEAObject findInput(String text) { return conceptWhereIC(BEAObject.class, "type", "Input", "text", text); } public String addRewriteHTML(BEAObject o) { return ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Rewrite", "f_type", "Rewrite", "f_text", getStringOpt("text", o), "f_isRewriteOf", o.id, "metaInfo_isRewriteOf", "concept"), "Add Rewrite"); } @Override public Object serveIntegerLink(DynGazelleRocks.Req req, long id) { BEAObject o = getConceptOpt(BEAObject.class, id); if (o != null) return htitle(str(o)) + hrefresh(conceptLink_long(o)); return super.serveIntegerLink(req, id); } public void distributeTestNotification() { distributeNotification("It is " + localTimeWithSeconds()); } public void distributeNotification(String text) { notificationQ.add(new Runnable() { public void run() { try { String jsCode = "window.createNotification({ theme: 'success', showDuration: 3000 })(" + jsonEncodeMap("message", text) + ");"; sendJavaScriptToAllWebSockets(jsCode); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "/*for (User user)\r\n if (nemptyAfterTrim(user.notificationSetting))\r\n ..."; } }); } public void sendJavaScriptToAllWebSockets(String jsCode) { for (Pair p : syncMapToPairs(webSockets)) { pcall(p.a, "send", jsonEncodeMap("eval", jsCode)); } } public void runInstruction(BEAObject o) { if (o == null) return; try { BEAObject instruction = o; if (o.typeIs("Step in script")) instruction = (BEAObject) cget(o, "instruction"); if (instruction.typeIs("Instruction | List objects by type")) { saveInstructionResult(o, beaList(getString("typeToList", instruction))); return; } if (instruction.typeIs("Instruction | List object types")) { saveInstructionResult(o, distinctCIFieldValuesOfConcepts(BEAObject.class, "type")); return; } if (instruction.typeIs("Instruction | Filter list by text starting with")) { BEAObject scriptRun = cgetBEA("scriptRun", o); if (scriptRun == null) throw fail("Need to be run as part of script"); List steps = scriptRunSteps(scriptRun); int idx = indexOf(steps, o); if (idx < 0) throw fail("Step not found in script run"); List list = firstNotNull(map(reversed(takeFirst(steps, idx)), step -> optCast(List.class, cget("data", cgetBEA("result", step))))); String prefix = getString("prefix", instruction); List filtered = filter(list, obj -> swic(obj.text(), prefix)); saveInstructionResult(o, filtered); return; } if (instruction.typeIs("Script")) { BEAObject script = instruction; BEAObject scriptRun = cnew(BEAObject.class, "type", "Script Run", "script", script); int i = 0; List steps = new ArrayList(); while ((instruction = (BEAObject) cget(instruction, "step" + (++i))) != null) { BEAObject step = cnew(BEAObject.class, "type", "Step in script", "step", i, "scriptRun", scriptRun, "instruction", instruction); steps.add(step); } cset(scriptRun, "steps", steps); return; } cnew(BEAObject.class, "type", "Instruction Error", "instruction", o, "error", "Unknown instruction type"); } catch (Throwable e) { cnew(BEAObject.class, "type", "Instruction Error", "instruction", o, "error", getStackTrace(e)); } } public BEAObject saveInstructionResult(BEAObject instruction, Object data) { BEAObject result = cnew(BEAObject.class, "type", "Instruction Result", "instruction", instruction, "data", data); cset(instruction, "result", result); return result; } public List scriptRunSteps(BEAObject scriptRun) { return (List) cget("steps", scriptRun); } public String addCommentHTML(BEAObject o, Object... __) { String redirectAfterSave = (String) (optPar("redirectAfterSave", __)); String defaultComment = (String) (optPar("defaultComment", __)); String text = optPar("text", __, "Add comment"); return ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Comment", "f_type", "Comment", "f_on", o.id, "f_text", unnull(defaultComment), "redirectAfterSave", redirectAfterSave, "autofocus", "f_text", "metaInfo_on", "concept"), text); } public String formatSubInput(BEAObject input, String text, String anchor) { String redirect = addAnchorToURL(currentReq.get().uriWithParams(), anchor); int goodCount = countConceptsCI(BEAObject.class, "type", "Sub-Input", "input", input, "text", text); int badCount = countConceptsCI(BEAObject.class, "type", "Bad Sub-Input", "input", input, "text", text); return calculations.bestInputHTML(text) + " " + small(joinNemptiesWithSpace(ahref_noFollow(addParamsToURL(baseLink + "/storeSubInput", "label", "good", "text", text, "input", input.id, "redirect", redirect), unicode_thumbsUp()), goodCount == 0 ? "" : n2(goodCount), ahref_noFollow(addParamsToURL(baseLink + "/storeSubInput", "label", "bad", "text", text, "input", input.id, "redirect", redirect), unicode_thumbsDown()), badCount == 0 ? "" : n2(badCount))); } public List renderObjectTypes() { return renderObjectTypes(Integer.MAX_VALUE); } public List renderObjectTypes(int max) { MultiSet ms = distinctCIFieldValuesOfConcepts_multiSet(BEAObject.class, "type"); return mapPairs(takeFirst(max, multiSetToPairsByPopularity(ms)), (type, count) -> { String _type = or2(type, "(no type)"); return n2(count) + " " + ahref(baseLink + "/beaCRUD/" + urlencode(_type), htmlEncode2(_type)); }); } public BEAObject autoMigrateToBase(BEAObject o) { return migrateToClass(o, BEAObject.class); } public BEAObject autoMigrateToCustomClass(BEAObject o) { return migrateToClass(o, defaultCustomClass(o)); } public BEAObject migrateToClass(BEAObject o, Class targetClass) { if (o == null || o._concepts != db_mainConcepts()) return null; if (targetClass != null && targetClass != _getClass(o)) { BEAObject newObject = unlistedCopyToClass_withConverter_pcall(targetClass, o); callOpt(newObject, "_fixAfterMigration", o); return replaceConceptAndUpdateRefs(o, newObject); } return o; } public void setCodeState(BEAObject o, long timestamp, String codeHash, Object state) { if (empty(state)) state = null; cset(o, "meta_codeState", state); } public String codeForObject(BEAObject o) { return getStringOpt("meta_code", o); } public String actualCodeHash(BEAObject o) { return md5OrNull(codeForObject(o)); } public boolean codeHashUpToDate(BEAObject o) { return eq(actualCodeHash(o), getStringOpt("meta_codeHash", o)); } public boolean compileErrorInObject(BEAObject o) { return swic(getStringOpt("meta_codeState", o), "error."); } public boolean isDependentOn(BEAObject a, BEAObject b) { return contains(optCast(Concept.RefL.class, getOpt("meta_dependsOnCode", a)), b); } public Collection objectWithDependents(BEAObject o) { return stepAllAndGet(new TransitiveHull<>(x -> filter(y -> isDependentOn(y, x), list(BEAObject.class)), o)); } public BEAObject compileAndLoadObject(BEAObject o) { dm_mediumRefreshTranspiler(); Collection withDependents = objectWithDependents(o); withDependents = filter(withDependents, x -> x == o || !isFalse(getBoolOpt("meta_shouldActivate", x))); print("Dependents for " + o + ": " + withDependents); for (BEAObject x : withDependents) compileAndLoadObject_withoutDependents(x); return (BEAObject) getMigration(o); } static public class UseClassDecl implements IFieldsToList { static final public String _fieldOrder = "objID innerClassName"; public long objID; public String innerClassName; public UseClassDecl() { } public UseClassDecl(long objID, String innerClassName) { this.innerClassName = innerClassName; this.objID = objID; } public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + objID + ", " + innerClassName + ")"; } public boolean equals(Object o) { if (!(o instanceof UseClassDecl)) return false; UseClassDecl __46 = (UseClassDecl) o; return objID == __46.objID && eq(innerClassName, __46.innerClassName); } public int hashCode() { int h = 1216910491; h = boostHashCombine(h, _hashCode(objID)); h = boostHashCombine(h, _hashCode(innerClassName)); return h; } public Object[] _fieldsToList() { return new Object[] { objID, innerClassName }; } } public UseClassDecl parseUseClassDecl(String useClass) { List tok = javaTokC(useClass); if (l(tok) == 3 && eqGet(tok, 1, ".") && isIdentifier(tok.get(2)) && isIntegerOrIdentifier(tok.get(0))) { String innerClassName = tok.get(2); long objID = trailingLong_regexp(first(tok)); return new UseClassDecl(objID, innerClassName); } return null; } public Class protoClass(BEAObject o) { BEAObject proto = (BEAObject) (cget("meta_prototype", o)); String useClass = (String) (cget("meta_useClass", o)); if (nempty(useClass)) { UseClassDecl uc = parseUseClassDecl(useClass); if (uc != null) { String innerClassName = uc.innerClassName; long objID = uc.objID; proto = beaGet(objID); if (proto == null) throw fail("useClass invalid reference: " + objID + " not found"); if (!usesLiveCustomCode(proto)) throw fail("Prototype is not custom or not loaded: " + proto); Class protoClass = proto.getClass(); Class outerClass = getOuterClass(protoClass, _defaultClassFinder()); printVars("id", o.id, "useClass", useClass, "innerClassName", innerClassName, "protoClass", protoClass, "outerClass", outerClass); Class innerClass = getInnerClass(outerClass, innerClassName, _defaultClassFinder()); printVars("innerClass", innerClass); if (innerClass == null) throw fail("Inner class not found: " + outerClass + " . " + innerClassName); cset(o, "meta_dependsOnCode", ll(proto)); return innerClass; } else throw fail("meta_useClass has invalid syntax: " + useClass); } Class protoClass = null; if (proto != null) { if (!usesLiveCustomCode(proto)) throw fail("Prototype is not custom or not loaded: " + proto); protoClass = proto.getClass(); } return protoClass; } public String setCodeHash(BEAObject o) { String code = codeForObject(o); String codeHash = empty(code) ? null : md5(code); cset(o, "meta_codeHash", codeHash); return codeHash; } public void compileAndLoadObject_withoutDependents(BEAObject o) { try { print("compileAndLoadObject_withoutDependents", o); assertSame(db_mainConcepts(), o._concepts); ClassLoader cl = dm_moduleClassLoader(); long timestamp = now(); setCodeState(o, timestamp, null, "Compiling"); String codeHash = null; transpileAndCompileForHotwiring_src.set(null); try { Class protoClass = protoClass(o); codeHash = setCodeHash(o); String code = codeForObject(o); if (empty(code)) { if (protoClass != null) { o = migrateToClass(o, protoClass); setCodeState(o, timestamp, null, "Migrated to proto class " + shortClassName(protoClass)); callActivate(o); } else { o = autoMigrateToBase(o); setCodeState(o, timestamp, null, null); } return; } actualCompile(o); reactivateAndMigratePrototypeUsers(o); print("Done compiling"); } catch (Throwable e) { cset(o, "meta_javaClass", null); setCodeState(o, timestamp, codeHash, "Error. " + exceptionToStringShort(e)); throw rethrow(e); } } catch (Exception __e) { throw rethrow(__e); } } public void setCodeHashAndActualCompile(BEAObject o) { setCodeHash(o); actualCompile(o); } public void actualCompile(BEAObject o) { Class protoClass = protoClass(o); cset(o, "meta_codeSafety", null); DynClassName dcn = new DynClassName(o.id, aGlobalID(), o.id); cset(o, "meta_javaClass", dcn.fullClassName()); String code = codeForObject(o); List tok = javaTok(code); String baseClass = "BEAObject"; List implementedInterfaces = new ArrayList(); for (int i : jfindAll(tok, "implements", (_tok, nIdx) -> { String left = get(_tok, nIdx - 1); return !(isIdentifier(left) || eq(left, ">")); })) { int iSemi = tok_findEndOfStatement(tok, i) - 1; List tokWhat = subList(tok, i + 1, iSemi); String className; if (nCodeTokens(tokWhat) == 3 && eq(tokWhat.get(3), "from")) { className = tokWhat.get(1); className = "B" + tokWhat.get(5) + "." + className; } else className = join(dropFirstAndLast(tokWhat)); className = expandShortClassRef(className); implementedInterfaces.add(className); clearTokens(tok, i, iSemi + 2); } int tokIdx; if ((tokIdx = jfind_any(tok, "extends ;", "extends .;", "extends .;", "extends ..;")) > 0) { int j = indexOf(tok, ";", tokIdx); baseClass = joinSubList(tok, tokIdx + 2, j - 1); baseClass = expandShortClassRef(baseClass); clearTokens(tok, tokIdx, j + 2); } jreplace(tok, "extends <.>", "extends $2<" + dcn.middleClassName() + ".$5>"); if ((tokIdx = jfind_any(tok, "extends from *;", "extends <> from *;", "extends <.> from *;")) > 0) { int iFrom = indexOf(tok, tokIdx, "from"); String className = joinSubList(tok, tokIdx + 2, iFrom - 1); baseClass = expandShortClassRef("B" + parseFirstLong_regexp(tok.get(iFrom + 2)) + "." + className); int j = indexOf(tok, ";", iFrom); clearTokens(tok, tokIdx, j + 2); } List imports = new ArrayList(); while ((tokIdx = jfind_any(tok, "import from ;", "import from ;", "import static from ;", "import static from ;")) > 0) { int i = tokIdx + 2; if (eqGet(tok, i, "static")) i += 2; int iStart = i; String className = tok.get(i); String bClass = addPrefix("B", tok.get(i += 4)); String name = expandShortClassRef(bClass + "." + className); imports.add(joinSubList(tok, tokIdx, iStart - 1) + " " + name + ";"); int j = indexOf(tok, ";", tokIdx); clearTokens(tok, tokIdx, j + 2); } String global = getGlobalCode(tok); code = join(tok); String src = lines(imports) + "mainPackage " + dcn.makePackageName() + "\n" + "mainClassName " + dcn.makeMainClassName() + "\n" + "concept " + dcn.makeBEAClassName() + " extends " + (protoClass == null ? baseClass : protoClass.getName().replace("$", ".")) + (empty(implementedInterfaces) ? "" : " implements " + joinWithComma(implementedInterfaces)) + " {\n" + code + "\n}\n" + global + "\n" + customCodePostlude(); ClassLoader cl = dm_moduleClassLoader(); var files = concatLists(filesFromClassLoader(cl), filesFromClassLoader(getVirtualParent(cl))); print("Compiling with " + n2(files, "byte code path")); javaCompileToJar_localLibraries.set(files); File bytecode; List libs = new ArrayList(); try { bytecode = transpileAndCompileForHotwiring(src, libs); libs.remove(str(parseSnippetID(mainLibID))); print("libs", libs); } finally { String javaSrc = transpileAndCompileForHotwiring_src.get(); saveTextFile(javaSourceFileForObject(o), javaSrc); LinkedHashSet dependencies = new LinkedHashSet(); for (String id : tok_identifiers(javaTok(javaSrc))) { long objID = regexpToLongIC("^b_?(\\d+)", id); if (objID != 0 && objID != o.id) dependencies.add(getConceptOrMarkMissingObject(BEAObject.class, objID)); } cset(o, "meta_libraries", nullIfEmpty(joinWithSpace(libs))); cset(o, "meta_dependsOnCode", nullIfEmpty(asList(dependencies))); } renameFileVerbose(bytecode, dcn.byteCodeFile()); cset(o, "meta_javaClass", dcn.fullClassName()); } public void reactivateAndMigratePrototypeUsers(BEAObject o) { var p = reactivateDynamicObject(o); if (p == null) throw fail("Activation of " + o.id + " failed. " + getOpt("meta_codeState", o)); File deadPath = byteCodePathForClass(o); print("New dead class path: " + deadPath + " (total: " + n2(deadClassPaths) + ")"); deadClassPaths.add(deadPath); o = p.a; assertNotNull("Activated object", o); String codeHash = getStringOpt("meta_codeHash", o); long timestamp = now(); setCodeState(o, timestamp, codeHash, "Custom code loaded"); print("Custom code loaded"); migratePrototypeUsers(o); } public String expandShortClassRef(String name) { List groups = regexpGroups("^B?(\\d+)(\\..+)$", name); if (groups != null) { long baseID = parseLong(first(groups)); BEAObject baseObj = beaGet(baseID); name = mainClassNameForObject(baseObj) + second(groups); if (empty(name)) throw fail("Referenced object doesn't have a Java class: " + baseID); } return name; } public void migratePrototypeUsers(BEAObject o) { for (BEAObject derivative : prototypeUsers(o)) { try { print("Migrating prototype user " + derivative + " of " + o + " to new base class " + o.getClass()); migrateToClass(derivative, o.getClass()); } catch (Throwable __e) { printStackTrace(__e); } } } public Collection prototypeUsers(BEAObject o) { TransitiveHull th = new TransitiveHull<>(x -> filter(conceptsWhere(BEAObject.class, "meta_prototype", x), d -> empty(codeForObject(d))), o); return setMinus_inPlace(stepAllAndGet(th), o); } public Pair reactivateDynamicObject(BEAObject o) { try { return reactivateDynamicObject_impl(o); } catch (Throwable e) { printStackTrace(e); cset(o, "meta_javaClass", null); cset(o, "meta_codeState", exceptionToStringShort(e)); return null; } } public boolean usesLiveCustomCode(BEAObject o) { return startsWith(className(o), packagePrefix()); } public Pair reactivateDynamicObject_impl(BEAObject o) { try { assertNotNull(o); assertSame(db_mainConcepts(), o._concepts); DynClassName dcn = dcnForObject(o); if (dcn == null) { cset(o, "meta_codeState", null); return pair(o, false); } File byteCode = dcn.byteCodeFile(); loadObjectsLibraries(o); dm_addByteCodePathToModuleClassLoader(byteCode); String fullName = dcn.fullClassNameForVM(); print("fullName", fullName); ClassLoader cl = dm_moduleClassLoader(); Class targetClass = cl.loadClass(fullName); print("targetClass", targetClass); assertNotNull("Class not found: " + fullName, targetClass); o = migrateToClass(o, targetClass); assertNotNull("autoMigrated", o); callActivate(o); cset(o, "meta_codeState", "[" + formatGMTWithMilliseconds_24() + "] " + "Custom code reloaded"); return pair(o, true); } catch (Exception __e) { throw rethrow(__e); } } public File javaSourceFileForObject(BEAObject o) { return programFile("BEA Java Sources/" + o.id + ".java"); } public File byteCodeFile(DynClassName name) { return name == null ? null : programFile("Object ByteCode/" + name.objectID + "-" + name.globalID + ".jar"); } public DynClassName dcnForObject(BEAObject o) { String javaClassName = getString("meta_javaClass", o); return DynClassName_parse(javaClassName); } public File byteCodeFileForObject(BEAObject o) { DynClassName dcn = dcnForObject(o); return dcn == null ? null : dcn.byteCodeFile(); } public BEAObject autoMigrateUnlistedOrKeep(BEAObject o) { return canAutoMigrate(o) ? unlistedCopyToClass_withConverter(defaultCustomClass(o), o) : o; } public boolean canAutoMigrate(BEAObject o) { return o != null && !eqOneOf(defaultCustomClass(o), _getClass(o), null); } public Class defaultCustomClass(BEAObject o) { if (o == null) return null; BEAObject entry = conceptWhereCI(BEAObject.class, "type", "Auto Custom Class", "forType", o.type()); if (entry == null) return null; String className = getString("toClassName", entry); Class c = findClassThroughDefaultClassFinder(className); return c; } public String queryLink(String algorithm, String q) { return addParamsToURL(baseLink + "/query", "algorithm", algorithm, "q", q); } public String currentUserAgent() { return userAgent(currentReq()); } public String userAgent(Req req) { if (req == null) return null; return mapGet(req.webRequest.headers(), "user-agent"); } public void saveUserAgent(BEAObject input) { String userAgent = currentUserAgent(); if (nempty(userAgent) && !userAgentIsBot(userAgent)) uniqCI2(BEAObject.class, "type", "Input Source", "input", input, "userAgent", userAgent); } public boolean isObjectWithCode(BEAObject o) { return o != null && o.hasCustomCode(); } public boolean createdByMasterUser(BEAObject o) { User user = optCast(User.class, cget("createdBy", o)); return user != null && user.isMaster; } public void autoActivateDynamicObject(BEAObject o) { if (!autoActivateDynamicObjects) return; String code = codeForObject(o); if (empty(code)) return; if (!createdByMasterUser(o)) return; String codeState = getString("meta_codeState", o); String time = leadingAngleBracketStuff(codeState); long timestamp = empty(time) ? 0 : parseDateWithMillisecondsGMT(time); if (o._modified <= timestamp) return; String hash = getString("meta_codeHash", o); if (eq(hash, md5(code))) return; print("Auto-activating dynamic object: " + o); compileAndLoadObject(o); sleepSeconds(1); } public String customCodePostlude() { return "!include early #1031282\n\n"; } public String makeJavaClassName(BEAObject o) { return aGlobalID(); } public String packagePrefix() { return "dyn.b_"; } public String makePackageName(BEAObject o) { return packagePrefix() + o.id; } public BEAObject websiteEnhancersObject() { Collection l = beaList("Live Website Enhancers"); if (l(l) > 1) warn("Multiple Live Website Enhancers: " + l); return first(l); } public BEAObject getWebsiteEnhancer(String key) { return beaGet(websiteEnhancersObject(), key); } public String newLinkForCRUD(HCRUD crud, Class c) { if (c == User.class) return baseLink + "/register"; else return super.newLinkForCRUD(crud, c); } public String callHTMLFixer(Object caller, String html) { BEAObject fixer = beaGet("htmlFixer", websiteEnhancersObject()); return or((String) callOpt(fixer, "fixHTML", html, caller), html); } @Override public Object html3(DynGazelleRocks.Req req) { return html3((Req) req); } public Object html3(Req req) { assertSame(realMC(), mc()); assertSame(main.beaMod(), me()); vmBus_send("logMethodCall", this, "html3", req); vmBus_send("html3", this, req); BHTTPRequest reified = null; if (reifyHTTPRequests()) reified = cnew(BHTTPRequest.class, "type", "Live HTTP Request", "req", req, "uri", req.uri(), "ip", req.webRequest.clientIP(), "user", user(req)); long time = sysNow(); try { return html4(req); } finally { time = sysNow() - time; if (reified != null) cset(reified, "type", "Past HTTP Request", "processingTime", time); } } public Object html4(Req req) { if (saveAllQsAsInput && !cic(req.uri(), "/live") && user(req) != null) { String text = trim(req.get("q")); if (nempty(text)) { BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text); uniqCI(BEAObject.class, "type", "Input Source", "input", input, "source", "Web Request (q parameter)"); } } Object response = html5(req); if (response instanceof String) response = routeThroughAll(pagePostProcessors, ((String) response)); return response; } transient public List> pagePostProcessors = syncL(); public Object html5(Req req) { String uri = req.uri(); for (BEAObject rewrite : filter(__65 -> createdByMasterUser(__65), beaList("Live URL Rewrite"))) { try { String input = getString("input", rewrite); boolean ci = isTrueOpt("caseInsensitive", rewrite); vmBus_send("testingURLRewrite", rewrite, uri); if (eqOrEqic(ci, uri, input)) { vmBus_send("applyingURLRewrite", rewrite, uri); String output = getString("output", rewrite); return hrefresh(appendParamsToURL(output, req.params())); } } catch (Throwable __e) { printStackTrace(__e); } } return super.html3(req); } @Override public Object serveOtherPage(DynGazelleRocks.Req req) { return serveOtherPage((Req) req); } public Object serveOtherPage(Req req) { if (eq(req.uri, "/login")) return serveAuthForm(null); if (startsWith_addingSlash(req.uri, "/myLoginData")) return serveMyLoginData(req); return super.serveOtherPage(req); } public void cleanMeUp_deactivateBEAObjects() { Collection objects = filter(beaList(), o -> hasMethod(o, "_deactivate")); print("Deactivating " + nObjects(objects) + " for shutdown"); for (BEAObject bea : objects) callDeactivate(bea); if (nempty(objects)) print("Done"); } public DynClassName DynClassName_parse(String className) { className = replace(className, "$", "."); List groups = regexpFirstGroups("^dyn\\.b_(\\d+)_([a-z]+)\\.B(\\d+)\\$?(.*)", className); if (verboseClassLoading) printVars("DynClassName_parse", "className", className, "groups", groups); if (groups != null) return new DynClassName(parseLong(first(groups)), second(groups), parseLong(third(groups)), fourth(groups)); return DynClassName_parseOther(className); } public DynClassName DynClassName_parseOther(String className) { className = replace(className, "$", "."); List groups = regexpFirstGroups("^dyn\\.b_(\\d+)_([a-z]+)\\.(.*)", className); if (verboseClassLoading) printVars("DynClassName_parseOther", "className", className, "groups", groups); if (groups != null) return new DynClassName(parseLong(first(groups)), second(groups), 0, third(groups)); return null; } public String DynClassName_mainPrefix() { return "dyn."; } public String DynClassName_mainPrefixForVM() { return "dyn."; } public class DynClassName { public long compileBaseObjectID; public String globalID; public long objectID; public String innerClass; public DynClassName(long compileBaseObjectID, String globalID, long objectID) { this.objectID = objectID; this.globalID = globalID; this.compileBaseObjectID = compileBaseObjectID; } public DynClassName(long compileBaseObjectID, String globalID, long objectID, String innerClass) { this.innerClass = innerClass; this.objectID = objectID; this.globalID = globalID; this.compileBaseObjectID = compileBaseObjectID; } public String middleClassName() { return objectID == 0 ? "" : "B" + objectID; } public String makePackageName() { return dropDotSuffix(DynClassName_mainPrefix()); } public String makeMainClassName() { return "b_" + compileBaseObjectID + "_" + globalID; } public String makeBEAClassName() { return joinNempties("$", middleClassName(), innerClass); } public String fullClassName() { return joinWithDot(makePackageName(), makeMainClassName(), makeBEAClassName()); } public String fullClassNameForVM() { return makePackageName() + "." + makeMainClassName() + "$" + makeBEAClassName(); } public File byteCodeFile() { return programFile("Object ByteCode/" + baseSystemVersion + "/" + compileBaseObjectID + "/" + globalID + ".jar"); } } public String mainClassNameForObject(BEAObject o) { if (o == null) return null; String fullBaseClass = getString("meta_javaClass", o); return takeFirst(fullBaseClass, lastIndexOf(fullBaseClass, ".")); } public void loadObjectsLibraries(BEAObject o) { List libs = splitAtSpace_trim(getString("meta_libraries", o)); if (addLibrariesToClassLoader(dm_moduleClassLoader(), libs)) print("Loaded libs for " + o + ": " + libs); } public void callActivate(BEAObject bea) { if (getBoolOpt("meta_shouldActivate", bea, true)) { loadObjectsLibraries(bea); pcallOpt(bea, "_activate"); } } public void callDeactivate(BEAObject bea) { pcallOpt(bea, "_deactivate"); } public void onNewWebSocket(WebSocketInfo ws) { super.onNewWebSocket(ws); Req req = (Req) (ws.req); String uri = ws.uri; BEAObject reifiedWebSocket = null; if (webSocketsToBEA()) { long _startTime_29 = sysNow(); var webRequest = req == null ? null : req.webRequest; var cookie = cookieFromWebRequest(webRequest); User user = user(req); reifiedWebSocket = cnew(webSocketClass, "webSocketInfo", ws, "type", "Live WebSocket", "uri", uri, "user", user); ws.dbRepresentation = reifiedWebSocket; ws.eval(replaceDollarVars("if (typeof $ !== \"undefined\") $(\".webSocketPlaceholder\").html($html);", "html", jsQuote(beaHTML(reifiedWebSocket)))); done2_always("Reify WebSocket", _startTime_29); } onNewWebSocket2(ws); BEAForward forward = null; if (eq(uri, "/")) { BEAObject o = beaGet(beaHomePageID); if (o != null) forward = new BEAForward(o, dropLeadingSlash(uri)); } if (forward == null) { Matches m = new Matches(); if (startsWith(uri, "/beaHTML/", m)) { BEAObject handler = beaGet(m.rest()); if (handler != null) forward = new BEAForward(handler, afterSlash(m.rest())); } else forward = findBEAShortURL(uri); } printVars("onNewWebSocket", "uri", uri, "forward", forward); if (forward != null) { var handler = forward.object; req.subURI = forward.subURI; print("Have WebSocket " + reifiedWebSocket + "/" + ws + " at " + uri + " for " + handler); if (!handler._isAlive()) { print("HAndler not alive!?"); return; } cset(reifiedWebSocket, "handler", handler); beaPcall(handler, "useWebSocket", ws); } } transient public IVF1 onNewWebSocket2; public void onNewWebSocket2(WebSocketInfo ws) { if (onNewWebSocket2 != null) onNewWebSocket2.get(ws); else onNewWebSocket2_base(ws); } final public void onNewWebSocket2_fallback(IVF1 _f, WebSocketInfo ws) { if (_f != null) _f.get(ws); else onNewWebSocket2_base(ws); } public void onNewWebSocket2_base(WebSocketInfo ws) { } transient public Class webSocketClass = BWebSocket.class; public void onWebSocketClose(WebSocketInfo ws) { AutoCloseable __35 = enter(); try { super.onWebSocketClose(ws); retireReifiedWebSocket((BWebSocket) ws.dbRepresentation); } finally { _close(__35); } } public void retireReifiedWebSocket(BWebSocket ws) { if (!keepReifiedWebSockets()) cdelete(ws); else cset(ws, "type", "Closed WebSocket"); } transient public TimedCache webSocketsToBEA_cache = new TimedCache<>(10.0, () -> webSocketsToBEA_load()); public boolean webSocketsToBEA() { return webSocketsToBEA_cache.get(); } public Boolean webSocketsToBEA_load() { return getBoolOpt("webSocketsToBEA", liveGazelleSettings()); } transient public TimedCache keepReifiedWebSockets_cache = new TimedCache<>(10.0, () -> keepReifiedWebSockets_load()); public boolean keepReifiedWebSockets() { return keepReifiedWebSockets_cache.get(); } public Boolean keepReifiedWebSockets_load() { return getBoolOpt("keepReifiedWebSockets", liveGazelleSettings()); } transient public TimedCache reifyHTTPRequests_cache = new TimedCache<>(10.0, () -> reifyHTTPRequests_load()); public boolean reifyHTTPRequests() { return reifyHTTPRequests_cache.get(); } public Boolean reifyHTTPRequests_load() { return getBoolOpt("reifyHTTPRequests", liveGazelleSettings()); } public BSettings gazelleSettings() { return conceptWhere(BSettings.class); } public BEAObject liveGazelleSettings() { return first(filter(__66 -> createdByMasterUser(__66), beaList("Live Gazelle Settings"))); } final public Object withFrame(String html) { return serveWithNavigation(html); } public Object serveWithNavigation(String html) { var framer = framer(); framer.add(html); return completeFrame(); } @Override public Object completeFrame_base(DynGazelleRocks.Req req) { ((Req) req).framer.addNavItems(pageBy_navItems(((Req) req).makers)); return super.completeFrame_base(((Req) req)); } public List pageBy_navItems(Object... makers) { return pageBy_navItems(asList(makers)); } public List pageBy_navItems(Collection makers) { makers = nonNulls(makers); if (empty(makers)) return ll(); List beas = instancesOf(BEAObject.class, makers); List nonBEAs = nonInstancesOf(BEAObject.class, makers); return concatLists(map(beas, o -> targetBlank(beaURL(o), repS(2, html_gazelle_madeByIcon()), "title", "Page made by: " + o)), empty(nonBEAs) ? ll() : ll(new HPopDownButton(empty(beas) ? "Page by" : "Page also by", map(makers, o -> { if (o instanceof BEAObject) return beaHTML_targetBlank((BEAObject) o); return htmlEncode2(shortenStr(o, 40)); })).html())); } public List> renderStats_base() { return listPlusItems_inPlace(super.renderStats_base(), ll("Live / dead class paths", n2(classLoaderPathsCount(dm_moduleClassLoader())) + " / " + n2(deadClassPaths))); } transient public IVF2 makeNavItems; @Override public void makeNavItems(DynGazelleRocks.Req req, HTMLFramer1 framer) { if (makeNavItems != null) makeNavItems.get(req, framer); else makeNavItems_base(req, framer); } final public void makeNavItems_fallback(IVF2 _f, DynGazelleRocks.Req req, HTMLFramer1 framer) { if (_f != null) _f.get(req, framer); else makeNavItems_base(req, framer); } public void makeNavItems_base(DynGazelleRocks.Req req, HTMLFramer1 framer) { super.makeNavItems(req, framer); String webSocketPlaceholder = span("", "class", "webSocketPlaceholder"); if (moveNavItemsToMisc) { var navItems = cloneList(framer.navItems); framer.clearNavItems(); framer.addNavItem(hPopDownButtonWithText("Misc", map(navItems, ni -> framer.renderNavItem(ni))) + " " + webSocketPlaceholder); } else framer.addNavItem(webSocketPlaceholder); if (findConcept(CMissingObject.class) != null) framer.addNavItem(makeClassNavItem(CMissingObject.class, req)); } transient public int showMoreThreshold = 500; transient public int showMoreHeight = 250; transient public IF1 addShowMoreButton; public String addShowMoreButton(String html) { return addShowMoreButton != null ? addShowMoreButton.get(html) : addShowMoreButton_base(html); } final public String addShowMoreButton_fallback(IF1 _f, String html) { return _f != null ? _f.get(html) : addShowMoreButton_base(html); } public String addShowMoreButton_base(String html) { if (l(html) < showMoreThreshold) return html; return new HDivWithVerticalExpandButton(showMoreHeight, html).html(); } public boolean deleteQsWhenEmpty() { BSettings settings = gazelleSettings(); return settings != null && settings.deleteQsWhenEmpty; } public Set activateOnlyTheseIDs() { if (empty(activateOnlyTheseIDs)) return null; return mapToLinkedHashSet(__67 -> parseLong(__67), tok_integers(activateOnlyTheseIDs)); } public Set dontActivateTheseIDs() { if (empty(dontActivateTheseIDs)) return null; return mapToLinkedHashSet(__68 -> parseLong(__68), tok_integers(dontActivateTheseIDs)); } public GazelleBEA beaMod() { return this; } public Object beaCall(BEAObject c, String method, Object... args) { return cCall(c, method, args); } public Object beaCallOpt(BEAObject c, String method, Object... args) { return cCallOpt(c, method, args); } public Object beaPcall(BEAObject c, String method, Object... args) { return cPcall(c, method, args); } public Object beaCall(Concept.Ref ref, String method, Object... args) { return cCall(ref, method, args); } public Object beaPcall(Concept.Ref ref, String method, Object... args) { return cPcall(ref, method, args); } public Object beaCall(long id, String method, Object... args) { return cCall(beaMod().beaGet(id), method, args); } public Object beaPcall(long id, String method, Object... args) { return cPcall(beaMod().beaGet(id), method, args); } public Object beaCallOpt(long id, String method, Object... args) { return cCallOpt(beaMod().beaGet(id), method, args); } public
A beaGet(Class c, String key, GazelleBEA.Req req) { return optCast(c, beaGet(key, req)); } public String beaHTMLURL(BEAObject o) { return o == null ? null : o.myURI(); } public String beaHTML(Object o) { if (o instanceof BEAObject) return beaHTML((BEAObject) o); return htmlEncode2(o); } public BEAObject beaGetOpt(long id) { return getConceptOpt(BEAObject.class, id); } static public Collection beaDeleteType(String type) { return deleteConceptsWhereIC(BEAObject.class, "type", type); } public int beaCount(String type) { return countConceptsWhereCI(BEAObject.class, "type", type); } public BEAObject beaNew(Object... __) { __ = prependParamIfOddCount("type", __); return cnew(BEAObject.class, __); } public String getGlobalCode(List tok) { String global = ""; int idx; while ((idx = jfind_any(tok, "global {", "exports {")) >= 0) { int j = findEndOfBracketPart(tok, idx + 2); global = joinSubList(tok, idx + 3, j - 1); clearTokens(tok, idx, j + 1); } return global; } public String getGlobalCode(BEAObject o) { return getGlobalCode(javaTok(codeForObject(o))); } public AutoCloseable beaEnter(BEAObject o) { if (o == null) return null; return combineAutoCloseables(tempSetTL(beaThreadOwner, o), enter()); } public JComponent visualize() { JComponent _c = super.visualize(); addControls(); return _c; } public void addControls() { } transient public IF1 beaObjectToString_long; public String beaObjectToString_long(BEAObject o) { return beaObjectToString_long != null ? beaObjectToString_long.get(o) : beaObjectToString_long_base(o); } final public String beaObjectToString_long_fallback(IF1 _f, BEAObject o) { return _f != null ? _f.get(o) : beaObjectToString_long_base(o); } public String beaObjectToString_long_base(BEAObject o) { return beaObjectToString_long_static(o); } static public String beaObjectToString_long_static(BEAObject o) { if (o == null) return "null"; String type = strOrNull(o.typeForToString()); String s = or2(type, "(no type)"); s += " " + o.id; s += appendBracketed(strOrNull(getOpt("label", o))); if (eqic(type, "Match")) s += " " + getOpt("mapping", o); boolean enabled = eq(true, getOpt("enabled", o)); if (enabled) s += " [enabled]"; String purpose = getStringOpt("purpose", o); if (nempty(purpose)) s += " " + quote(purpose); String text = or2(o.text(), getStringOpt("name", o), getStringOpt("internalCode", o)); if (text != null) s += " " + quote(text); Object fc = getOpt("functionCalled", o); if (fc != null) s += " " + fc; Object result = getOpt("result", o); if (result != null) s += " = " + shorten_str(result); return s; } public boolean useErrorHandling() { return false; } public User findOrCreateUserForLogin(String name, String pw) { { User u = super.findOrCreateUserForLogin(name, pw); if (u != null) return u; } if (empty(grabUsersFromDomain)) return null; try { var passwordMD5 = new SecretValue(hashPW(pw)); String url = addSlashSuffix(grabUsersFromDomain) + "lookup-user"; Map map = jsonDecodeMap(postPage(url, "name", name, "passwordMD5", passwordMD5, "salt", passwordSalt())); print("Got map? " + (map != null)); String error = (String) (mapGet(map, "error")); if (nempty(error)) { print("error", error); return null; } if (map != null) return cnew(User.class, "name", name, "contact", (String) map.get("contact"), "passwordMD5", passwordMD5, "isMaster", isTrue(map.get("isMaster")), "copiedFromMainDB", true); } catch (Throwable __e) { printStackTrace(__e); } return null; } public String conceptLink(Concept c) { if (c instanceof BEAObject) return beaShortURL((BEAObject) c); return super.conceptLink(c); } public String conceptLink_long(Concept c) { return super.conceptLink(c); } public String conceptToHTML_targetBlank(Concept c) { return c == null ? "" : targetBlank(conceptLink(c), htmlEncode2(c)); } public Req newReq() { return new Req(); } public class Req extends DynGazelleRocks.Req { public Set makers = syncCompactSet(); public Timestamp started = new Timestamp(); public void add(Object html) { framer.add(html); } public boolean debug() { return eq(get("debug"), "1"); } public BEAHTMLFramer framer() { return (BEAHTMLFramer) framer; } } transient public IF0 serveHomePage; @Override public Object serveHomePage() { return serveHomePage != null ? serveHomePage.get() : serveHomePage_base(); } final public Object serveHomePage_fallback(IF0 _f) { return _f != null ? _f.get() : serveHomePage_base(); } public Object serveHomePage_base() { BEAObject o = beaGet(beaHomePageID); if (o != null) { Req req = currentReq(); return serveBEAHTML(req, o, dropLeadingSlash(req.uri())); } return super.serveHomePage(); } public Req currentReq() { return (Req) super.currentReq(); } public void cleanReifiedWebSockets() { AutoCloseable __36 = enter(); try { for (BWebSocket o : instancesOf(BWebSocket.class, cloneList(beaList("Live WebSocket")))) if (o.webSocket() == null) retireReifiedWebSocket(o); } finally { _close(__36); } } public Class defaultCRUDClass() { return BEAObject.class; } public Object serveFavIcon() { Object response = super.serveFavIcon(); print("serveFavIcon: " + response); return response; } public boolean alwaysShowLogInLink() { return true; } public String logInLink() { return baseLink + "/login"; } public String defaultRedirectAfterLogin() { return baseLink + "/crud/BEAObject"; } @Override public void fillReqAuthFromCookie(DynGazelleRocks.Req req, String cookie, AuthedDialogID auth) { super.fillReqAuthFromCookie(req, cookie, auth); if (makeAnonymousUsers && auth != null && auth.user.get() == null) { String pw = aGlobalID(); User userObj = cnew(User.class, "passwordMD5", new SecretValue(hashPW(pw)), "password", new SecretValue(pw)); cset(userObj, "name", "guest" + userObj.id); cset(auth, "user", userObj); vmBus_send("userCreated", userObj); } } public boolean userHasData(User user) { Collection refs = allBackRefs(user); refs = withoutInstancesOf(AuthedDialogID.class, refs); refs = withoutInstancesOf(BWebSocket.class, refs); pnl("USERDATA", refs); return nempty(refs); } public boolean anonymousUserWarning(Req req, HTMLFramer1 framer) { User user = user(req); if (print("confirm", empty(req.get("confirmLogout"))) && print("isAnonymousUser", isAnonymousUser(user)) && print("userHasData", userHasData(user))) { framer.add(h2("Anonymous User Warning")); framer.add(p("You are currently logged in as anonymous user " + b(htmlEncode2(user)) + " and seem to have some data stored on the server. Do you want to download your login data before logging out?")); framer.add(p(joinWithSpace(hlinkButton(baseLink + "/myLoginData", "Download Login Data"), hlinkButton(baseLink + req.uri + "?logout=1&confirmLogout=1", "Just log me out")))); return true; } return false; } @Override public Object handleLogout(DynGazelleRocks.Req req) { print("handleLogout " + user(((Req) req))); if (anonymousUserWarning(((Req) req), framer(((Req) req)))) return completeFrame(((Req) req)); print("Actual logout"); return super.handleLogout(((Req) req)); } public boolean isAnonymousUser(User user) { return cget("password", user) != null; } public Object serveMyLoginData(Req req) { User user = user(req); SecretValue pw = (SecretValue) (cget("password", user)); boolean isAnon = pw != null; if (!isAnon) { req.framer.add(p("You are not an anonymous user. Only anonymous users can download their login data.")); return beaMod().completeFrame(req); } if (eq(req.uri(), "/myLoginData/download")) { String host = mapGet(req.headers(), "host"); String text = jsonEncode_breakAtLevel1(litorderedmap("site", host, "user", user.name, "password", pw.get(), "date", dateWithSecondsUTC(), "ip", getClientIPFromHeaders(req.headers()))); String filename = "my-login-at-" + host + ".txt"; return subBot_noCacheHeaders(addFilenameHeader(filename, subBot_serveWithContentType(text, binaryMimeType()))); } req.framer.add(hcenter(linesLL(h1(req.framer.htmlTitle("Download Login Data")), p("You are currently logged in as an anonymous user and are able to upload data to the site. In order to access, modify or delete this data later, you should definitely download your login data now. Otherwise you risk losing this data and/or being unable to delete it."), p(hbuttonLink(baseLink + "/myLoginData/download", "Download my login data"))))); return completeFrame(req); } public HTMLFramer1 framer(Req req) { if (req.framer == null) makeFramer(req); return req.framer; } public boolean userCanSeeObject(User user, Object o) { if (user == null) return false; if (user.isMaster) return true; o = derefRef(o); if (user == o) return true; if (o instanceof Concept) { if (cget("createdBy", (Concept) o) == user) return true; if (isTrueOpt("isPublic", (Concept) o)) return true; } return false; } @Override public File uploadsBaseDir() { return programFile("uploads"); } public class BEAHTMLFramer extends HTMLFramer1 { public HTMLPopDownButton unnamedPopDownButton = new HTMLPopDownButton(); } public String makeAbsoluteURL(Req req, String url) { return loadableUtils.utils.makeAbsoluteURL((req.isHttps() ? "https://" : "http://") + req.domain(), url); } public Object serveBEAHTML(Req req, BEAObject o, String subURI) { req.noSpam(); req.subURI = subURI; req.makers.add(o); framer(req).title = str(o); IF0 result = call_optional(o, "html", req); if (result != null) return result.get(); result = call_optional(o, "html", req.webRequest); if (result != null) return result.get(); return call(o, "html"); } public String optBeaHTML(Object o) { return optBeaHTML(o, false); } public String optBeaHTML(Object o, boolean targetBlank) { if (o instanceof BEAObject) return beaHTML(((BEAObject) o), targetBlank); return htmlEncode2(str(o)); } public String beaHTML_preferRendered(BEAObject o) { return beaHTML_preferRendered(o, false); } public String beaHTML_preferRendered(BEAObject o, boolean targetBlank) { if (o != null && o.canRenderHTML()) return targetBlankIf(targetBlank, o.myUri(), htmlEncode2_nlToBr(str(o))); return beaHTML(o, targetBlank); } public boolean checkCookie(String cookie, String domain) { print("checkCookie " + takeFirst(4, cookie)); AuthedDialogID auth = authObject(cookie); if (auth == null) return false; Req req = new Req(); fillReqAuthFromCookie(req, cookie, auth); return masterAuthed(req); } public boolean masterAuthed(WebSocketInfo ws) { return masterAuthed(ws == null ? null : ws.req); } public String redirectToLoginURL(Req req) { return addParamsToURL(baseLink + "/login", "redirect", req.uri()); } public Object redirectToLogin(Req req) { return subBot_serveRedirect(redirectToLoginURL(req)); } public String redirectUnlessMasterAuthed(WebSocketInfo ws) { if (masterAuthed(ws)) return null; return hrefresh(redirectToLoginURL((Req) ws.req)); } public String redirectToLogin_hrefresh(Req req) { return hrefresh(addParamsToURL(baseLink + "/login", "redirect", req.uri())); } @Override public Object html(IWebRequest request) { AutoCloseable __37 = enter(); try { boolean profile = eq(request.get("_profile"), "1"); if (profile) { return subBot_serveText(profileThisThreadToString(() -> { super.html(request); })); } return super.html(request); } finally { _close(__37); } } public A findService(Class type) { if (type == null) return null; String name = shortClassName(type); return (A) findService(name); } public BEAObject findService(String name) { if (empty(name)) return null; var services = cloneList(serviceIndex.getAll(name)); if (l(services) > 1) warn("Duplicate service " + name + ": " + joinWithSlash(services)); return first(services); } public String beaAttribution(BEAObject o) { return o == null ? null : html_gazelle_madeByIcon(beaURL(o)); } public File beaDataDir(BEAObject o) { if (o == null) return null; long id = o.id; return id == 0 ? null : programFile("BEA Data " + id); } public String beaTypeCRUDURL(String type) { return baseLink + "/beaCRUD/" + urlencode(type); } @Override public Object serveCRUD(DynNewBot2.Req req) { if (eq(req.uri(), "/crud/BEA")) return hrefresh(baseLink + "/crud/BEAObject"); return super.serveCRUD(req); } } static public class BEAObject extends ConceptWithGlobalID { public UserPost mirrorPost() { return (UserPost) cget("mirrorPost", this); } public void change() { super.change(); var mod = beaMod(); if (mod != null) { mod.rstUpdateBEAMirrors.add(this); if (mod.autoActivateDynamicObjects) mod.rstAutoActivateDynamicObjects.add(this); } } public void delete() { cdelete(mirrorPost()); pcallOpt(this, "_deactivate"); super.delete(); } public void updateMirrorPost() { GazelleBEA mod = beaMod(); if (isDeleted() || !mod.mirrorBEAObjects) return; if (mirrorPost() == null) cset(this, "mirrorPost", cnew(UserPost.class, "type", "BEA Object", "creator", mod.internalUser(), "botInfo", "BEA Mirror Bot")); String text = structureString(); cset(mirrorPost(), "title", str(this), "text", text); } public String structureString() { String text = "Error"; try { structure_Data data = new structure_Data() { public structure_ClassInfo newClass(Class c) { structure_ClassInfo info = super.newClass(c); if (c == Concept.Ref.class) { info.special = true; info.serializeObject = o -> { Concept cc = (Concept) (deref((Concept.Ref) o)); if (cc != null) append("CRef(id=" + cc.id + ", c=" + quote(dynShortClassName(cc)) + ")", 6); else append("CRef", 1); }; } return info; } public void setFields(structure_ClassInfo info, List fields) { if (isSubclassOf(info.c, BEAObject.class)) { removeAll(fields, getField(BEAObject.class, "refs"), getField(BEAObject.class, "backRefs")); } super.setFields(info, fields); } }; String struct = structure(this, data); struct = structure_convertTokenMarkersToExplicit(struct); struct = dropLoadableUtilsPackageFromStruct(struct); text = indentStructureString_firstLevels(1, struct); } catch (Throwable __e) { printStackTrace(__e); } return text; } public String toString() { return shorten(toString_long()); } public String toString_long() { var mod = beaMod(); if (mod != null) return mod.beaObjectToString_long(this); return "[NO MODULE] " + mod.beaObjectToString_long_static(this); } final public boolean _isAlive() { return isAlive(); } public boolean isAlive() { return !_conceptsDefunctOrUnregistered(); } public boolean hasCustomCode() { return cget("meta_code", this) != null || cget("meta_prototype", this) != null || cget("meta_useClass", this) != null; } public boolean customCodeLoaded() { String className = getStringOpt("meta_javaClass", this); if (className != null) return eq(replace(className(this), "$", "."), className); String useClass = getStringOpt("meta_useClass", this); GazelleBEA.UseClassDecl uc = beaMod().parseUseClassDecl(useClass); if (uc != null) return eq(shortClassName(this), uc.innerClassName); return false; } public String type() { return getStringOpt("type", this); } public boolean typeIs(String type) { return eqic(type(), type); } final public boolean typeIsAny(String... types) { return typeIsOneOf(types); } public boolean typeIsOneOf(String... types) { return eqicOneOf(type(), types); } public String text() { return getStringOpt("text", this); } public BEAObject input() { return (BEAObject) cget("input", this); } public BEAObject isRewriteOf() { return (BEAObject) cget("isRewriteOf", this); } public String inputText() { BEAObject input = or(input(), isRewriteOf()); return input == null ? null : input.text(); } public Map mapping() { return keysAndValuesToString(cgetOpt(Map.class, this, "mapping")); } public List directCmds() { return ll(); } public Collection allObjects() { return list(_concepts, BEAObject.class); } public String baseLink() { return beaMod().baseLink; } public BEAObject beaGet(String field, BEAObject o) { return beaMod().beaGet(field, o); } public BEAObject beaGet(long id) { return beaMod().beaGet(id); } public BEAObject beaGet(String field) { return beaMod().beaGet(field, this); } public Object beaCall(BEAObject c, String method, Object... args) { return cCall(c, method, args); } public Object beaCallOpt(BEAObject c, String method, Object... args) { return cCallOpt(c, method, args); } public Object beaPcall(BEAObject c, String method, Object... args) { return cPcall(c, method, args); } public Object beaCall(Concept.Ref ref, String method, Object... args) { return cCall(ref, method, args); } public Object beaPcall(Concept.Ref ref, String method, Object... args) { return cPcall(ref, method, args); } public Object beaCall(long id, String method, Object... args) { return cCall(beaMod().beaGet(id), method, args); } public Object beaPcall(long id, String method, Object... args) { return cPcall(beaMod().beaGet(id), method, args); } public Object beaCallOpt(long id, String method, Object... args) { return cCallOpt(beaMod().beaGet(id), method, args); } public A beaGet(Class c, String key, GazelleBEA.Req req) { return optCast(c, beaGet(key, req)); } public String beaHTMLURL(BEAObject o) { return o == null ? null : o.myURI(); } public String beaHTML(Object o) { if (o instanceof BEAObject) return beaHTML((BEAObject) o); return htmlEncode2(o); } public BEAObject beaGetOpt(long id) { return getConceptOpt(BEAObject.class, id); } static public Collection beaDeleteType(String type) { return deleteConceptsWhereIC(BEAObject.class, "type", type); } public int beaCount(String type) { return countConceptsWhereCI(BEAObject.class, "type", type); } public BEAObject beaNew(Object... __) { __ = prependParamIfOddCount("type", __); return cnew(BEAObject.class, __); } public gazelle.main.GazelleBEA beaMod() { return _concepts == null ? main.beaMod() : (GazelleBEA) _concepts.miscMapGet(DynNewBot2.class); } final public Collection beaAll() { return beaList(); } public Collection beaList() { return beaMod().beaList(); } public Collection beaListAny(String... types) { return beaMod().beaListAny(types); } public Collection beaList(String type, Object... params) { return beaMod().beaList(type, params); } public String beaHTML(BEAObject o) { return beaHTML(o, false); } public String beaHTML(BEAObject o, boolean targetBlank) { return beaMod().beaHTML(o, targetBlank); } final public String beaURL(BEAObject o) { return beaShortURL(o); } public String beaShortURL(BEAObject o) { return beaMod().beaURL(o); } final public String fixHtml(String html) { return fixHTML(html); } final public String htmlFixer(String html) { return fixHTML(html); } final public String htmlFix(String html) { return fixHTML(html); } public String fixHTML(String html) { return beaMod().callHTMLFixer(this, html); } public boolean createdByMasterUser(BEAObject o) { return beaMod().createdByMasterUser(o); } final public String myUri() { return myURI(); } public String myURI() { String shortURI = first(myShortURLs()); if (shortURI != null) return beaMod().baseLink + shortURI; return beaMod().baseLink + "/beaHTML/" + id; } public void massageItemMapForList(Map map) { } public BEAObject beaGet(String key, GazelleBEA.Req req) { return beaMod().beaGet(key, req); } public BEAObject me() { return this; } public Object completeFrame(GazelleBEA.Req req) { return beaMod().completeFrame(req); } public String typeForToString() { return strOrEmpty(cget("type", this)); } public boolean masterAuthed(GazelleBEA.Req req) { return beaMod().masterAuthed(req); } public GazelleBEA.BEAHTMLFramer framer(GazelleBEA.Req req) { return (GazelleBEA.BEAHTMLFramer) beaMod().framer(req); } public User user(GazelleBEA.Req req) { return beaMod().user(req); } public GazelleBEA.Req currentReq() { return beaMod().currentReq(); } public boolean isHomePage() { return beaMod().beaHomePageID == id; } public String optBeaHTML(Object o) { return optBeaHTML(o, false); } public String optBeaHTML(Object o, boolean targetBlank) { return beaMod().optBeaHTML(o, targetBlank); } public boolean haveShortURL(String uri) { var forward = beaMod().findBEAShortURL(uri); return forward != null && forward.object == this; } public Collection myShortURLs() { return collectStrings("uri", filter(findBackRefs(BEAObject.class, this), o -> beaMod().isBEAShortURLObject(o))); } public boolean canRenderHTML() { return hasMethodNamed(this, "html"); } public String beaAttribution(BEAObject o) { return beaMod().beaAttribution(o); } public String madeByMeStamp() { return beaAttribution(this); } public A findService(Class type) { return beaMod().findService(type); } public BEAObject findService(String name) { return beaMod().findService(name); } public Collection masterObjects(Collection l) { return beaMod().masterObjects(l); } public String redirectUnlessMasterAuthed(GazelleBEA.WebSocketInfo ws) { return beaMod().redirectUnlessMasterAuthed(ws); } public boolean masterAuthed(GazelleBEA.WebSocketInfo ws) { return beaMod().masterAuthed(ws); } public File myDataDir() { return assertNotNull(beaMod().beaDataDir(this)); } } static public class BEARegExp extends BEAObject { static final public String _fieldOrder = "text caseInsensitive"; public String text; public boolean caseInsensitive = true; public boolean valid() { return nempty(text); } public java.util.regex.Pattern compile() { return compileRegexpPossiblyIC_unicodeCase(text, caseInsensitive); } } static public class BEARegExpReplacement extends BEARegExp { public String replacement; public String apply(String text) { try { return regexpReplace_directWithRefs(compile().matcher(text), unnull(replacement)); } catch (Throwable e) { throw fail(format_quoted("Was searching * in * ", this.text, text)); } } public List directCmds() { return listPlus(super.directCmds(), !valid() ? "Note: not valid" : targetBlank(beaMod().queryLink("Apply regular expression replacement to all inputs", str(id)), "Apply to all inputs")); } } static public class BEAPatternList extends BEAObject { public RefL patterns = new RefL(); public String toString() { return super.toString() + ": " + nPatterns(patterns); } } static public GazelleBEA beaMod() { return (GazelleBEA) dm_current_mandatory(); } static public JavaXClassLoader hotwire_makeClassLoader(List files) { ClassLoader cl = myClassLoader(); return new JavaXClassLoaderWithParent2(null, files, cl, ll()); } static public class BWebSocket extends BEAObject { static final public String _fieldOrder = "webSocketInfo screenShot onScreenShotChanged"; transient public GazelleBEA.WebSocketInfo webSocketInfo; transient public WithTimestamp screenShot; transient public Set onScreenShotChanged = syncLinkedHashSet(); public Object webSocket() { return getWeakRef(webSocketInfo == null ? null : webSocketInfo.webSocket); } public void sendJavaScript(String js) { if (empty(js)) return; Object ws = webSocket(); call(ws, "send", jsonEncode(litorderedmap("eval", js))); } public void setScreenShot(WithTimestamp screenShot) { this.screenShot = screenShot; vmBus_send("screenShotChanged", this, screenShot); print("Listeners: " + cloneList(onScreenShotChanged)); pcallFAll(onScreenShotChanged); } } static public class BWithResources extends BEAObject { static final public String _fieldOrder = "resources q log activated meta_shouldActivate"; transient public CloseablesHolder resources = new CloseablesHolder(); transient public Q q = startQ(); public List> log; transient public boolean activated = false; public boolean meta_shouldActivate = true; public AutoCloseable enter() { return beaMod().beaEnter(this); } public void beaPrintVars(Object... __) { beaPrint(renderVars(__)); } public void _handleException(Throwable e) { beaPrint(getStackTrace(e)); } public boolean _active() { return activated; } final public void _activate() { addToQ(new Runnable() { public void run() { try { if (activated) return; activated = true; _activateImpl(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "if (activated) return;\r\n activated = true;\r\n _activateImpl();"; } }); } public void _activateImpl() { } public void _deactivate() { addToQ(new Runnable() { public void run() { try { _deactivateImpl(); resources.close(); activated = false; } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "_deactivateImpl();\r\n resources.close();\r\n activated = false;"; } }); } public void _deactivateImpl() { } public void delete() { _deactivate(); waitForQToEmpty(q()); super.delete(); } final public void ownResource(AutoCloseable r) { addResource(r); } public void addResource(AutoCloseable r) { resources.add(r); } public void clearBEAPrintLog() { inQ(new Runnable() { public void run() { try { log = null; change(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "log = null;\r\n change();"; } }); } public int maxBeaPrintLength() { return 10000; } public A beaPrintAndReturn(A a) { return beaPrintAndReturn("", a); } public A beaPrintAndReturn(String s, A a) { beaPrint(s, a); return a; } public void beaPrint(Object o) { beaPrint("", o); } public void beaPrint(String s, Object o) { AutoCloseable __38 = enter(); try { inQ(new Runnable() { public void run() { try { String text = combinePrintParameters(s, o); text = shorten(maxBeaPrintLength(), text); if (log == null) log = new ArrayList(); synchronized (log) { truncateListFromStart(log, maxLogSize() - 1); printIndent(id + "|", text); log.add(new WithTimestamp(text)); } change(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "String text = combinePrintParameters(s, o);\r\n text = shorten(maxBeaPrint..."; } }); } finally { _close(__38); } } public int maxLogSize() { return getIntOpt("maxLogSize", this, 10); } public BWithResources me() { return this; } public void inQ(Runnable r) { if (r == null) return; if (isInQ(q)) r.run(); else addToQ(r); } public void addToQ(Runnable r) { if (r == null) return; getQ().add(new Runnable() { public void run() { try { AutoCloseable __39 = enter(); try { try { r.run(); } catch (Throwable e) { beaPrint(getStackTrace(e)); } } finally { _close(__39); } } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "temp enter(); \r\n try {\r\n r.run();\r\n } catch (Throwable e) {\r..."; } }); } final public Q q() { return getQ(); } public Q getQ() { return q; } public void useWebSocket(GazelleBEA.WebSocketInfo ws) { } } static public class BSettings extends Concept { public boolean deleteQsWhenEmpty = false; } static public class BHTTPRequest extends BEAObject { transient public GazelleBEA.Req req; } static public class WebSocketSet { public Set set = syncWeakSet(); transient public List onCountChanged; public WebSocketSet onCountChanged(Runnable r) { onCountChanged = syncAddOrCreate(onCountChanged, r); return this; } public void countChanged() { pcallFAll(onCountChanged); } transient public List> onWsAdded; public WebSocketSet onWsAdded(IVF1 f) { onWsAdded = syncAddOrCreate(onWsAdded, f); return this; } public void wsAdded(GazelleBEA.WebSocketInfo ws) { pcallFAll(onWsAdded, ws); } transient public List> onWsRemoved; public WebSocketSet onWsRemoved(IVF1 f) { onWsRemoved = syncAddOrCreate(onWsRemoved, f); return this; } public void wsRemoved(GazelleBEA.WebSocketInfo ws) { pcallFAll(onWsRemoved, ws); } public void add(GazelleBEA.WebSocketInfo ws) { if (ws == null) return; ws.onClose(() -> remove(ws)); if (set.add(ws)) { wsAdded(ws); countChanged(); } } public void remove(GazelleBEA.WebSocketInfo ws) { if (set.remove(ws)) { wsRemoved(ws); countChanged(); } } public int size() { return l(set); } public boolean empty() { return size() == 0; } public boolean nempty() { return size() != 0; } public List getList() { return cloneList(set); } public void eval(String js, Object... __) { broadcast(jsonEvalMsg(js, __)); } public void broadcast(String data) { broadcast(data, null); } public void broadcast(String data, GazelleBEA.WebSocketInfo excludeSender) { var sockets = cloneList(set); for (GazelleBEA.WebSocketInfo ws : sockets) { try { if (ws == excludeSender) continue; try { ws.send(data); } catch (Throwable e) { remove(ws); ws.close(); } } catch (Throwable __e) { printStackTrace(__e); } } } } static public class BWithWebSockets extends BWithResources { static final public String _fieldOrder = "webSockets timer updateFrequency"; transient public WebSocketSet webSockets = new WebSocketSet(); transient public FlexibleRateTimer timer = new FlexibleRateTimer(); public double updateFrequency = 0.5; { webSockets.onCountChanged(new Runnable() { public void run() { try { inQ(new Runnable() { public void run() { try { webSocketCountChanged(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "webSocketCountChanged();"; } }); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "inQ(r webSocketCountChanged)"; } }); webSockets.onWsAdded(__44 -> wsAdded(__44)); webSockets.onWsRemoved(__45 -> wsRemoved(__45)); } public void webSocketCountChanged() { } public void wsAdded(GazelleBEA.WebSocketInfo ws) { } public void wsRemoved(GazelleBEA.WebSocketInfo ws) { } @Override public void useWebSocket(GazelleBEA.WebSocketInfo ws) { if (acceptWebSocket(ws)) webSockets.add(ws); else ws.send(jsonEncodeMap("webSocketAccepted", false)); } public boolean acceptWebSocket(GazelleBEA.WebSocketInfo ws) { return true; } } static public class BByWebSocket extends BWithResources { public class Rendered implements IFieldsToList { public String html; public Runnable afterSent; public Rendered() { } public Rendered(String html, Runnable afterSent) { this.afterSent = afterSent; this.html = html; } public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + html + ", " + afterSent + ")"; } public Object[] _fieldsToList() { return new Object[] { html, afterSent }; } public Rendered(String html) { this.html = html; } } public Object html(GazelleBEA.Req req) { HInitWebSocket iws = new HInitWebSocket(); iws.autoOpen = false; if (req.isPost()) iws.params.put("_hasPostData", "1"); iws.reconnectParams = "reconnect=1"; return hhtml(linesLL(hhead(nemptyLinesLL(hmobilefix(), iws.get(), !eq(req.get("wsVerbose"), "1") ? null : hjs("wsVerbose = true;"), !req.isPost() ? null : hjs_escapedDollarVars("\r\n var _postParams = $params;\r\n wsOnOpen(function() { wsSend(JSON.stringify({\"postData\": _postParams})); });\r\n ", "params", req.params()), hsansserif(), hjs(js_nodeScriptReplace2()))), hbody(hnoscript(noScriptContent()) + loadingContent() + hjs("\r\n var lc = document.getElementById(\"loading-content\");\r\n if (lc) lc.style.display = \"table\";\r\n console.log(\"Opening WebSocket\"); ws.open();\r\n ")))); } public String loadingContent() { return hcss("body { background-color: #ecf0f1; #loading-content { display: none; }") + hfullcenter(hsnippetimg("#1102948", "title", "Initializing WebSocket") + hnoscript(noScriptContent()), "id", "loading-content"); } public String noScriptContent() { return "Please enable JavaScript to see this page."; } public Rendered htmlX(GazelleBEA.WebSocketInfo ws) { return new Rendered(html(ws)); } public String html(GazelleBEA.WebSocketInfo ws) { return hhead(linesLL(htitle("Hello world"), hsansserif()) + hbody(hfullcenter(span("Actual contents!", "style", "font-size: 30px")))); } public Rendered htmlX_safe(GazelleBEA.WebSocketInfo ws) { try { return htmlX(ws); } catch (Throwable e) { printStackTrace(e); return new Rendered("Error: " + e); } } public boolean isReconnected(GazelleBEA.WebSocketInfo ws) { return ws != null && eq(ws.get("reconnect"), "1"); } public void handleReconnect(GazelleBEA.WebSocketInfo ws) { } public void useWebSocket(GazelleBEA.WebSocketInfo ws) { try { boolean re = isReconnected(ws); beaPrint("Have " + stringIf(re, "reconnected ") + " websocket: " + ws); if (re) { handleReconnect(ws); } else { double delay = min(10.0, parseDouble(ws.get("_wsDelay"))); sleepSeconds(delay); Rendered html = htmlX_safe(ws); if (html != null && html.html != null) { sendHTML(ws, html.html); callF(html.afterSent); } } } catch (Throwable e) { beaPrint(e); } } public void sendHTML(GazelleBEA.WebSocketInfo ws, String html) { { if (ws != null) ws.eval(js_replaceHTML(html)); } } public Rendered renderedIfNempty(String html) { return empty(html) ? null : new Rendered(html); } } static public String mainLibID; static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) { return print_byThread().get() == null ? tempInterceptPrint(f) : null; } static volatile public Concepts mainConcepts; static public Concepts db_mainConcepts() { if (mainConcepts == null) mainConcepts = newConceptsWithClassFinder(getDBProgramID()); return mainConcepts; } static public void cleanMeUp_concepts() { if (db_mainConcepts() != null) db_mainConcepts().cleanMeUp(); } static public String hjs_autoExpandingTextAreas() { return hjs_autoExpandingTextAreas(false); } static public String hjs_autoExpandingTextAreas(boolean verbose) { return hcss("\r\n .auto-expand {\r\n max-height: 30em; vertical-align: top;\r\n }\r\n ") + hjs(replaceDollarVars("\r\n var autoExpandVerbose = $verbose;\r\n \r\n var autoExpandTextArea = function (ta) {\r\n ta.style.height = \"1px\";\r\n \r\n // Get the computed styles for the element\r\n var computed = window.getComputedStyle(ta);\r\n \r\n var h = ta.scrollHeight\r\n + parseInt(computed.getPropertyValue('border-top-width'))\r\n + parseInt(computed.getPropertyValue('border-bottom-width'));\r\n \r\n if (autoExpandVerbose)\r\n console.log(\"Calculated auto-expand height \" + h + \" for \" + ta);\r\n ta.style.height = h + 'px';\r\n };\r\n \r\n document.addEventListener('input', function (event) {\r\n if (!event.target.classList.contains(\"auto-expand\")) return;\r\n autoExpandTextArea(event.target);\r\n }, false);\r\n \r\n //$(document).ready(function() {\r\n document.addEventListener(\"DOMContentLoaded\", function(event) { \r\n $(\".auto-expand\").each(function() { autoExpandTextArea(this); });\r\n });\r\n ", "verbose", verbose)); } static public void db() { conceptsAndBot(); } static public void db(Integer autoSaveInterval) { conceptsAndBot(autoSaveInterval); } static public Object _defaultClassFinder_value = defaultDefaultClassFinder(); static public Object _defaultClassFinder() { return _defaultClassFinder_value; } static public String mcName() { return mc().getName(); } static public Object defaultDefaultClassFinder() { return new F1() { public Class get(String name) { Class c = get2(name); return c; } public Class get2(String name) { if (eq(name, "
")) return mc(); { Class c = findClass_fullName(name); if (c != null) return c; } if (startsWithAny(name, "loadableUtils.utils$", "main$", mcDollar())) for (String pkg : ll("loadableUtils.utils$", mcDollar())) { String newName = pkg + afterDollar(name); { Class c = findClass_fullName(newName); if (c != null) return c; } } return null; } }; } static public String mcDollar() { return mcName() + "$"; } static public ConceptFieldIndexDesc indexConceptFieldDesc_v2(Class c, String field) { return indexConceptFieldDesc_v2(db_mainConcepts(), c, field); } static public ConceptFieldIndexDesc indexConceptFieldDesc_v2(Concepts cc, Class c, String field) { var idx = (ConceptFieldIndexDesc) getConceptFieldIndex(cc, c, field); return idx != null ? idx : new ConceptFieldIndexDesc(cc, c, field); } static public String dropSlashSuffix(String s) { return dropTrailingSlash(s); } static public String ahref_targetBlankIf(String link, Object contents, boolean targetBlank, Object... params) { return ahref_possiblyTargetBlank(link, contents, targetBlank, params); } static public String ahref_targetBlankIf(boolean targetBlank, String link, Object contents, Object... params) { return ahref_possiblyTargetBlank(targetBlank, link, contents, params); } static public ClassLoader getVirtualParent(ClassLoader cl) { return (ClassLoader) rcallOpt("getVirtualParent", cl); } static public Class findClassThroughDefaultClassFinder(String shortName) { return shortName == null ? null : (Class) callF(_defaultClassFinder(), "main$" + shortName); } static public Class mc() { return main.class; } static public String afterSlash(String s) { return substring(s, smartIndexOf(s, '/') + 1); } static public List nonInstancesOf(Iterable i, Class c) { return withoutInstancesOf(i, c); } static public List nonInstancesOf(Class c, Iterable i) { return withoutInstancesOf(c, i); } static public String repS(String s, int n) { return repeatString(s, n); } static public String repS(IF0 f, int n) { return join(repF(f, n)); } static public String repS(int n, String s) { return repS(s, n); } static public String html_gazelle_madeByIcon() { return html_gazelle_madeByIcon(""); } static public String html_gazelle_madeByIcon(String link) { return html_gazelle_madeByIcon(link, ""); } static public String html_gazelle_madeByIcon(String link, String description) { return targetBlank(link, himgsnippet("#1103033", "style", "width: .8em; height: .8em", "title", "Object that created this" + (empty(description) ? "" : ": " + description))); } static public String targetBlankIf(String link, Object contents, boolean targetBlank, Object... params) { return ahref_possiblyTargetBlank(link, contents, targetBlank, params); } static public String targetBlankIf(boolean targetBlank, String link, Object contents, Object... params) { return ahref_possiblyTargetBlank(targetBlank, link, contents, params); } static public String joinWithSlash(Iterable l) { return join("/", l); } static public String joinWithSlash(A... l) { return joinWithSlash(asList(l)); } static public List collectStrings(Iterable c, String field) { return stringsOnly(collect(c, field)); } static public List collectStrings(String field, Iterable c) { return collectStrings(c, field); } static public URI uri(String uri) { try { return new URI(uri); } catch (Exception __e) { throw rethrow(__e); } } static public Set syncWeakSet() { return synchroWeakHashSet(); } static public List getList(Map map, Object key) { return map == null ? null : (List) map.get(key); } static public List getList(List l, int idx) { return (List) get(l, idx); } static public List getList(Object o, Object key) { if (o instanceof Map) return getList((Map) o, key); if (key instanceof String) return (List) getOpt(o, (String) key); throw fail("Not a string key: " + getClassName(key)); } static public List getList(String name, Object o) { return getList(o, name); } static public String jsonEvalMsg(String code, Object... __) { return jsonEncodeMap("eval", jsDollarVars(code, __)); } static public String hjs_escapedDollarVars(String s, Object... __) { return hjs(replaceDollarVars_js(s, __)); } static public String js_nodeScriptReplace2() { return linesLL(js_executeScriptElements(), "var nodeScriptReplace = executeScriptElements;"); } static public String hnoscript(Object contents) { return hfulltag("noscript", contents); } static public String html(Object contents) { return fixHTML(contents); } static public String js_replaceHTML(String html) { return replaceDollarVars_js("\r\n (function() {\r\n var target = document.querySelector(\"html\");\r\n target.innerHTML = $html;\r\n nodeScriptReplace(target);\r\n })(); ", "html", unnull(html)); } static public Concepts newConceptsWithClassFinder(String progID) { Concepts cc = new Concepts(progID); cc.classFinder = _defaultClassFinder(); return cc; } volatile static public boolean conceptsAndBot_running = false; static public boolean conceptsAndBot_thinOnStart = true; static public void conceptsAndBot() { conceptsAndBot(null); } static public void conceptsAndBot(Integer autoSaveInterval) { if (conceptsAndBot_running) return; conceptsAndBot_running = true; Concepts cc = db_mainConcepts(); try { if (cc.useFileLock) { if (!cc.fileLock().tryToLock()) { ensureDBNotRunning(dbBotStandardName()); cc.fileLock().forceLock(); } } else ensureDBNotRunning(dbBotStandardName()); } catch (Throwable _e) { cc.dontSave = true; throw rethrow(_e); } cc.persist(autoSaveInterval); dbBot(false); if (conceptsAndBot_thinOnStart) { try { thinAProgramsBackups(getDBProgramID(), true); } catch (Throwable __e) { printStackTrace(__e); } } } static public HashMap findClass_fullName_cache = new HashMap(); static public Class findClass_fullName(String name) { synchronized (findClass_fullName_cache) { if (findClass_fullName_cache.containsKey(name)) return findClass_fullName_cache.get(name); Class c; try { c = Class.forName(name); } catch (ClassNotFoundException e) { c = null; } findClass_fullName_cache.put(name, c); return c; } } static public IFieldIndex getConceptFieldIndex(Class c, String field) { return getConceptFieldIndex(db_mainConcepts(), c, field); } static public IFieldIndex getConceptFieldIndex(Concepts cc, Class c, String field) { return cc.getFieldIndex(c, field); } static public String repeatString(String s, int n) { StringBuilder buf = new StringBuilder(l(s) * n); for (int i = 0; i < n; i++) buf.append(s); return str(buf); } static public List repF(int n, Object f, Object... args) { List l = new ArrayList(); for (int i = 0; i < n; i++) l.add(callF(f, args)); return l; } static public List repF(Object f, int n) { return repF(n, f); } static public List repF(int n, IF0 f) { return repF(f, n); } static public List stringsOnly(Iterable it) { List out = new ArrayList(); for (Object o : unnullForIteration(it)) if (o instanceof String) out.add((String) o); return out; } static public String jsDollarVars(String s, Object... __) { return replaceDollarVars_js(s, __); } static public String replaceDollarVars_js(String s, Object... __) { Map vars = paramsToMap_withNulls(__); if (empty(vars)) return s; var vars2 = mapKeys(__75 -> dropDollarPrefix(__75), vars); return replaceDollarVars_dyn(s, var -> { if (!vars2.containsKey(var)) return null; Object value = vars2.get(var); return jsonEncode_extended(value); }); } static public String js_executeScriptElements() { return "\r\n function executeScriptElements(containerElement) {\r\n const scriptElements = containerElement.querySelectorAll(\"script\");\r\n \r\n Array.from(scriptElements).forEach((scriptElement) => {\r\n const clonedElement = document.createElement(\"script\");\r\n \r\n Array.from(scriptElement.attributes).forEach((attribute) => {\r\n clonedElement.setAttribute(attribute.name, attribute.value);\r\n });\r\n \r\n clonedElement.text = scriptElement.text;\r\n \r\n scriptElement.parentNode.replaceChild(clonedElement, scriptElement);\r\n });\r\n}\r\n "; } static public Map paramsToMap_withNulls(Object... params) { int n = l(params); if (l(params) == 1 && params[0] instanceof Map) return (Map) params[0]; LinkedHashMap map = new LinkedHashMap(); for (int i = 0; i + 1 < n; i += 2) map.put(params[i], params[i + 1]); return map; } static public String jsonEncode_extended(Object o) { StringBuilder buf = new StringBuilder(); jsonEncode_extended(o, buf); return str(buf); } static public void jsonEncode_extended(Object o, StringBuilder buf) { if (o == null) buf.append("null"); else if (o instanceof JS) buf.append(((JS) o).get()); else if (o instanceof String) buf.append(quote((String) o)); else if (o instanceof Number || o instanceof Boolean) buf.append(o); else if (o instanceof Map) { Map map = (Map) o; buf.append("{"); boolean first = true; for (Object key : keys(map)) { if (first) first = false; else buf.append(","); buf.append(quote((String) key)); buf.append(":"); jsonEncode_extended(map.get(key), buf); } buf.append("}"); } else if (o instanceof Collection) { Collection l = (Collection) o; buf.append("["); boolean first = true; for (Object element : l) { if (first) first = false; else buf.append(","); jsonEncode_extended(element, buf); } buf.append("]"); } else throw fail("Unknown object for JSON encoding: " + className(o)); } static public class HInitWebSocket { public String wsVar = "ws"; public String readyMsg = "WebSocket ready!"; public boolean handleEvals = true; public boolean wsVerbose = true; public boolean autoOpen = true; public Map params = new HashMap(); public String reconnectParams = "reconnect=1"; public HInitWebSocket() { } public HInitWebSocket(IWebRequest req) { if (req != null && eq(req.get("wsVerbose"), "1")) wsVerbose = true; } final public String get() { return headStuff(); } public String headStuff() { return hreconnectingWebSockets() + hscript(js()); } public List dependencies() { return ll(hjssnippet(hreconnectingWebSockets_snippetID(), "data-comment", "ReconnectingWebSocket")); } public String js() { return jsDollarVars("\r\n var wsReady = false;\r\n var wsInitialMsgs = [];\r\n var wsMsgListeners = [];\r\n var wsOpenListeners = [];\r\n var wsWillReconnectListeners = [];\r\n var wsVerbose = $wsVerbose;\r\n var wsConnectionCount = 0;\r\n var wsAugmentURL = function(url) { return url; };\r\n var wsURL = ((window.location.protocol === \"https:\") ? \"wss://\" : \"ws://\") + window.location.host\r\n + window.location.pathname + window.location.search;\r\n if ($params != \"\")\r\n wsURL += (wsURL.match(/\\?/) ? \"&\" : \"?\") + $params;\r\n \r\n var $wsVar = new ReconnectingWebSocket(wsURL, null, $options);\r\n \r\n $wsVar.onopen = function(event) {\r\n wsReady = true;\r\n console.log($readyMsg + \" \" + ws.url);\r\n \r\n if (++wsConnectionCount == 1)\r\n if ($reconnectParams != \"\") {\r\n wsURL += (wsURL.match(/\\?/) ? \"&\" : \"?\") + $reconnectParams;\r\n ws.url = wsAugmentURL(wsURL);\r\n }\r\n\r\n wsOpenListeners.forEach(function(f) { f(); });\r\n\r\n ws.onmessage = function(event) {\r\n if (wsVerbose) console.log(\"Got msg: \" + event.data.substring(0, 200));\r\n wsMsgListeners.forEach(function(listener) {\r\n listener(event);\r\n });\r\n };\r\n \r\n ws.onclose = function(event) {\r\n if (wsVerbose) console.log(\"WebSocket closed\");\r\n wsReady = false;\r\n };\r\n\r\n wsInitialMsgs.forEach(function(msg) {\r\n if (wsVerbose) console.log(\"Sending initial msg: \" + msg);\r\n ws.send(msg);\r\n });\r\n wsInitialMsgs = [];\r\n if (wsVerbose) console.log(\"Cleared initial msgs\");\r\n };\r\n \r\n // send it now if ws is open already or when ws was opened\r\n function wsSend(msg) {\r\n if (wsReady) {\r\n if (wsVerbose) console.log(\"Sending msg: \" + msg);\r\n ws.send(msg); // TODO: wsReady = false on failed send?\r\n return;\r\n } else {\r\n if (wsVerbose) console.log(\"Scheduling msg: \" + msg);\r\n wsInitialMsgs.push(msg);\r\n }\r\n }\r\n \r\n function wsOnOpen(f) {\r\n wsOpenListeners.push(f); \r\n }\r\n \r\n function wsOnMessage(f) {\r\n wsMsgListeners.push(f); \r\n }\r\n \r\n function wsSetAugmentURL(f) {\r\n wsAugmentURL = f;\r\n if (ws) ws.url = wsAugmentURL(wsURL);\r\n }\r\n \r\n ", "wsVar", new JS(wsVar), "wsVerbose", wsVerbose, "readyMsg", readyMsg, "params", makePostData(params), "reconnectParams", unnull(reconnectParams), "options", options()) + (!handleEvals ? "" : "wsOnMessage(" + js_evalOnWebSocketMessage() + ");\n"); } public Map options() { return litorderedmap("automaticOpen", autoOpen ? null : false); } } static public class FlexibleRateTimer implements AutoCloseable { public double hertz; transient public Runnable action; transient public double timestamp; transient public DoLater doLater; transient public Flag started = new Flag(); transient volatile public boolean disposed = false; transient public long delay; transient public List onFrequencyChanged; transient public boolean verbose = false; static public double minHertz = 0, actualMinHertz = 1e-8, maxHertz = 1000; public FlexibleRateTimer() { } public FlexibleRateTimer(double hertz) { this.hertz = hertz; } public FlexibleRateTimer(double hertz, Runnable action) { this.action = action; this.hertz = hertz; } public void start() { if (!started.raise()) return; if (verbose) print("Starting timer with " + hertz + " Hz"); vmBus_timerStarted(this); _kaboom(); } synchronized public void _kaboom() { try { if (verbose) print(disposed ? "Timer kaboom (disposed)" : "Timer kaboom"); if (disposed) return; { cleanUp(doLater); doLater = null; } if (hertz <= actualMinHertz) { timestamp = 0; return; } if (timestamp == 0) timestamp = sysNow(); timestamp += 1000 / getFrequency(); long _timestamp = lround(timestamp); doLater = new DoLater(_timestamp, new Runnable() { public void run() { try { delay = sysNow() - _timestamp; if (verbose) print("Timer action"); pcallF(action); _kaboom(); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "delay = sysNow()-_timestamp;\r\n if (verbose) print(\"Timer action\");\r\n ..."; } }); if (verbose) print("Timer scheduled for: " + (_timestamp - sysNow())); doLater.enable(); } catch (Throwable __e) { printStackTrace(__e); } } public void cancel() { close(); } public synchronized void close() { disposed = true; { cleanUp(doLater); doLater = null; } } public void setRunnableAndStart(Runnable action) { this.action = action; start(); } public void setFrequency(double hertz) { synchronized (this) { if (disposed) return; hertz = clamp(hertz, minHertz, maxHertz); if (hertz == this.hertz) return; this.hertz = hertz; } pcallFAll(onFrequencyChanged); } public void setFrequencyImmediately(double hertz) { synchronized (this) { if (disposed) return; hertz = clamp(hertz, minHertz, maxHertz); if (hertz == this.hertz) return; this.hertz = hertz; if (!started.isUp()) return; if (verbose) print("Timer setFreq doLater=" + doLater); boolean b = doLater == null || doLater.cancel(); print("Timer cancel result: " + b + " (" + this.hertz + " -> " + hertz + ")"); timestamp = sysNow(); if (b) _kaboom(); } pcallFAll(onFrequencyChanged); } synchronized public double getFrequency() { return hertz; } public long currentDelay() { return delay; } synchronized public void onFrequencyChanged(Runnable r) { onFrequencyChanged = addOrCreate(onFrequencyChanged, r); } public void onFrequencyChangedAndNow(Runnable r) { onFrequencyChanged(runAndReturn(r)); } } static public class HPopDownButton { public String labelHTML; public String buttonHTML = htmlEncode2(unicode_smallDownPointingTriangle()); public List entries = new ArrayList(); public String id = "dropdown-" + aGlobalID(), outerID = "outer-" + id; public String style = "position: relative; display: inline-block; cursor: context-menu"; public String menuStyle = ""; public HPopDownButton() { } public HPopDownButton(String labelHTML, List entries) { this.labelHTML = labelHTML; addAll(this.entries, entries); } public String onclick() { return replaceDollarVars("\r\n var x = document.getElementById($id);\r\n x.style.display = window.getComputedStyle(x).display === \"none\" ? \"block\" : \"none\";\r\n console.log(\"popup \" + id + \" display: \" + x.style.display);\r\n ", "id", jsQuote(id)); } public String html() { return hstyle(replaceDollarVars("\r\n #$id ul {\r\n list-style-type: none;\r\n margin: 0;\r\n padding: 0;\r\n width: 200px;\r\n background-color: #f1f1f1;\r\n }\r\n \r\n #$id {\r\n position: absolute;\r\n display:none;\r\n background-color: #f9f9f9;\r\n width:auto;\r\n height:200px;\r\n overflow: auto;\r\n \r\n min-width: 160px;\r\n box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);\r\n \r\n z-index: 99;\r\n }\r\n \r\n #$id li a {\r\n text-decoration: none;\r\n color: #000;\r\n }\r\n \r\n #$id li { \r\n display: block;\r\n border-bottom: 1px solid #555;\r\n padding: 8px 16px;\r\n color: #000;\r\n }\r\n \r\n #$id li:hover, #$id li:hover > a {\r\n background-color: #3399ff;\r\n color: white;\r\n }\r\n ", "id", id)) + hdiv(buttonHTMLWithOnClick() + hdiv(ul(entries), "id", id, "style", menuStyle), "style", style, "id", outerID) + hscript(replaceDollarVars("\r\n if (typeof $ !== 'undefined')\r\n $('body').click(function(e) {\r\n if (!$(e.target).closest('#$outerID').length) {\r\n $(\"#$id\").hide();\r\n }\r\n });\r\n ", "id", id, "outerID", outerID)); } transient public IF0 buttonHTMLWithOnClick; public String buttonHTMLWithOnClick() { return buttonHTMLWithOnClick != null ? buttonHTMLWithOnClick.get() : buttonHTMLWithOnClick_base(); } final public String buttonHTMLWithOnClick_fallback(IF0 _f) { return _f != null ? _f.get() : buttonHTMLWithOnClick_base(); } public String buttonHTMLWithOnClick_base() { return span(joinNemptiesWithSpace(labelHTML, buttonHTML), "onclick", onclick()); } } static public class JavaXHyperlinker { public boolean targetBlank = false; abstract static public class PeepHole { public List tok; public int cIdx; public String prevPrev, prev, token, next; public void explain(String text) { explain(cIdx, text); } abstract public void explain(int i, String text); public void link(String url) { link(cIdx, url); } abstract public void link(int i, String url); } public Map shortFor = litmap("BigInt", "BigInteger", "$1", "m.unq(0)", "$2", "m.unq(1)", "$3", "m.unq(2)", "LS", "List", "sclass", "static class", "asclass", "abstract static class", "svoid", "static void", "SS", "Map", "S", "String", "ret", "return", "L", "List", "Cl", "Collection", "O", "Object", "sO", "static Object", "sS", "static String", "fO", "final Object", "fS", "final String", "sS", "static String", "sbool", "static boolean", "fbool", "final boolean", "bool", "boolean", "Int", "Integer", "cast", "casting to the type required on the left-hand side", "°", "()", "ItIt", "IterableIterator", "ES", "Ext (string plus extended information)", "CloseableItIt", "CloseableIterableIterator", "LPairS", "List>", "ISegmenter", "IF1>"); public String explFunc = "anonymous function declaration (similar to Java 8 lambdas)"; public String explPNoconsole = "Main program including Substance L&F, started in non-AWT thread, hiding the console"; public Map tokenExplanations = litmap("cm", "cm summons the last version of a module in Stefan's OS (cm originally stood for 'compact module')", "~.", "short for accessing a field or calling a method by reflection", "beaConcept", "a BEA concept is just a concept (database-enabled Java class) derived from BEAObject (the AGI base class)", "== null ?:", "short for: == null ? null :", "p-exp {", "main program with automatic upgrade", "mapLike", "a function that takes a global function name as first argument and can be called like this: (...)", "mapMethodLike", "a function that takes a method or field name as first argument and can be called like this: (...)", "func(", explFunc, "func{", explFunc, "voidfunc", "anonymous function declaration without return value (similar to Java 8 lambdas)", "ctex", "ctex rethrows exceptions as RuntimeExceptions so you don't have to declare them", "p {", "short for: public static void main(String[] args)", "p-experiment {", "Main program with a nice big console & auto-restart", "p-substance {", "Main program including Substance L&F, started in AWT thread", "p-subst {", "Main program including Substance L&F, started in non-AWT thread", "p-noconsole {", explPNoconsole, "pn {", explPNoconsole, "answer {", "Answer function - static S answer(S s) { new Matches m; ...; null; }", "time {", "Run the code block and print how long it took", "cprint {", "A module with default class name derived from DynPrintLog", "semiauto {", "In a semiauto block, JavaX automatically adds a ; to (almost) every line", "autosemi {", "In an autosemi block, JavaX automatically adds a ; to (almost) every line", "Clusters", "Clusters is short for Map>", "temp", "temp is like try (...) extending to the end of the current block", "pcall {", "protected call - try { ... } catch { print exception }", "r {", "r { ... } is short for: new Runnable() { public void run() { ... } }", "runnable {", "runnable { ... } is short for: new Runnable() { public void run() { ... } }", "pcall-short {", "protected call, shorter output - try { ... } catch { printShortException }", "LPair<", "LPair<...> is short for: L>", "visualize {", "Visualisation method for an OS module; returns a Swing component", "visualize as", "define a visualization for the module", "enhanceFrame {", "Method that changes properties of an OS module's frame", "run {", "short for: public void run()", "start {", "Method that is run when an OS module is loaded", "enter {", "Methods in a module should be marked 'enter' for bookkeeping", "vf<", "reference to function as voidfunc", "compact module", "try to save memory by reusing code between modules", "cmodule", "cmodule = compact module for Stefan's OS. compact = try to save memory by reusing code between modules", "cmodule2", "cmodule2 = compact module for Stefan's OS (newer version). compact = try to save memory by reusing code between modules", "rThread {", "Runnable in a new thread", "shit(", "short for: return with print", "shit:", "short for: return with print", ":=", "the := operator translates to a simple comma, but converts an identifier on its left-hand side into a string", "noeq", "don't auto-generate equals+hashCode methods", "for single (", "for single is for ping + singletonUnlessNull", "selfType", "selfType is replaced with the enclosing class's name", "runnable class", "short for: class X implementing Runnable { run { ... }}", "aka", "In JavaX, methods can have multiple names"); public Map sc, sf; public StringTree2 tokenExplanationsTree; public List> explainers = new ArrayList(); public JavaXHyperlinker() { clearCaches(); tokenExplanationsTree = stringTree2_javaTok(tokenExplanations); } public String codeToHTML(String code) { return codeToHTML(code, true); } public String codeToHTML(String code, boolean real) { List tok = javaTok(code); Map links = new HashMap(); Map explanations = new HashMap(); putMultipleKeys(explanations, allPlus(4, jfindAll(tok, "void q {")), "Function will execute in module's queue"); Map styles = new HashMap(); tokensToColors(tok, styles); Matches m = new Matches(); for (int i = 1; i < l(tok); i += 2) { String t = tok.get(i); String prev = get(tok, i - 2), prevPrev = get(tok, i - 4); String next = get(tok, i + 2); String sfID = sf.get(t); PeepHole ph = new PeepHole() { public void explain(int i, String text) { explanations.put(i, text); } public void link(int i, String url) { links.put(i, url); } }; ph.tok = tok; ph.cIdx = i; ph.prevPrev = prevPrev; ph.prev = prev; ph.token = t; ph.next = next; pcallFAll(explainers, ph); if (startsWith(t, "lambda", m) && isInteger(m.rest()) && isIdentifier(next)) explanations.put(i, ("lambda reference to a " + (m.rest()) + "-argument function")); if (eq(t, "is") && isIdentifier(next)) explanations.put(i, "synonym of 'implements'"); if (eq(t, "methodLambda0") && isIdentifier(next)) explanations.put(i, ("short for: x -> x." + next + "() (with a fresh variable instead of x)")); if (eq(t, "swappable") && isIdentifier(next)) explanations.put(i, "swappable functions can be exchanged per object instance"); if (eq(t, "main") && isIdentifier(next)) explanations.put(i, "reference to the current 'main' class (where all the standard functions are held, not always called 'main')"); if (eq(t, "autoDispose") && isIdentifier(next)) explanations.put(i, "autoDispose adds a cleanMeUp method that properly disposes of this variable"); if (eq(t, "macro") && isIdentifier(next)) explanations.put(i, "define a macro called '" + next + "', visible until the end of the enclosing block (or until redefined)"); if (eq(t, "virtual") && isIdentifier(next)) explanations.put(i, "\"virtual\" represents a type that is not visible in this realm, so it is transpiled to just Object"); if (eq(t, "concept") && isIdentifier(next)) explanations.put(i, "A concept is like a Java class, but persistable"); if (eq(t, "flexeq") && isIdentifier(next)) explanations.put(i, "flexeq is a fix for records inside parameterized classes"); if (eq(t, "switchable") && isIdentifier(next)) explanations.put(i, "A field that can be changed through the module's popup menu"); if (eq(t, "embedded") && isIdentifier(next)) explanations.put(i, "\"embedded\" allows you to put a function where they would not normally be allowed"); if (eq(t, "visual") && isIdentifier(next)) explanations.put(i, "short definition of the visualize() function"); if (eq(t, "dm_q") && isIdentifier(next)) explanations.put(i, "Function reference delegating to module queue"); if (eq(t, "!") && isIdentifier(prev) && neq(next, "=")) explanations.put(i, "! is short for .get()"); if (eq(t, "#") && isIdentifier(next)) explanations.put(i, "# makes an identifier local to the scope"); if (eq(t, "f") && isIdentifier(next)) explanations.put(i, "f references a static function in the main class"); if (eq(t, "r") && isIdentifier(next)) explanations.put(i, "short for: r { " + next + "() }"); if (eqOneOf(t, "rThread", "rThreadEnter") && isIdentifier(next)) explanations.put(i, "short for: " + t + " { " + next + "() }"); if (eq(t, "dispose") && isIdentifier(next)) explanations.put(i, "short for: cleanUp(" + next + "); " + next + " = null;"); if (eq(t, "*") && eq(next, "(")) explanations.put(i, "Short syntax for a constructor declaration"); if (eq(t, "thread") && eq(next, "{")) explanations.put(i, "Start a new thread with the following code"); if (eq(t, "module") && isIdentifier(next)) explanations.put(i, "A module is a class that can be loaded in Stefan's OS"); if (eq(t, "record") && isIdentifier(next)) explanations.put(i, "A record is a value-based class"); if (eq(t, "srecord") && isIdentifier(next)) explanations.put(i, "An srecord is a static value-based class"); if (eqOneOf(t, "cached", "simplyCached") && isIdentifier(next)) explanations.put(i, "A function that caches its return value"); if (eq(t, "thread") && isQuoted(next)) explanations.put(i, "Start a new thread with the following name & code"); if (eq(t, "if") && isQuoted(next)) { try { List tok2 = tok_subListWithoutBorderNTokens(tok, i, i + 3); tok_expandIfQuoted(tok2); explanations.put(i, "short for: " + join(tok2)); } catch (Throwable __e) { printStackTrace(__e); } } if (eq(t, "html") && eq(next, "{")) explanations.put(i, "short for: static Object html(String uri, final Map params) ctex {"); if (eq(t, "try") && eq(next, "answer")) doublePut(explanations, i, i + 2, "\"try answer\" returns the expression if it isn't null or empty"); if (isSingleQuoteIdentifier(t)) explanations.put(i, "string constant, " + quote(fromSingleQuoteIdentifier(t))); if (eq(t, "event") && isIdentifier(next)) explanations.put(i, "declare a function called " + next + "() plus helpers for adding listeners"); if (eqOneOf(t, "null", "false", "true", "this") && eq(next, ";") && tok_tokenBeforeLonelyReturnValue(tok, i - 2)) doublePut(explanations, i, i + 2, "short for: return " + t + ";"); String e = shortFor.get(t); if (e != null) mapPut(explanations, i, "short for: " + e); if (!explanations.containsKey(i) && sfID != null) { if (eqOneOf(prev, "f", "r", "rThread") || startsWith(prev, "lambda") || isIdentifier(next) && eqGet(tok, i + 4, "(") || eqOneOf(next, "(", "°") && (neq(prev, ".") || eq(prevPrev, "main") && neq(get(tok, i - 6), ".")) || eq(prev, "{") && eq(next, "}") && eq(prevPrev, "postProcess") || eq(prev, ":") && eq(prevPrev, ":")) links.put(i, sfID); } List fewTokens = codeTokens(subList(tok, i - 1, i + 2 * 5)); Pair p = stringTreeLeafValue2(tokenExplanationsTree, fewTokens); if (p != null) { int lastCodeToken = i + p.b * 2 - 2; if (eq(get(tok, lastCodeToken), "{")) lastCodeToken -= 2; mapPutInRange(explanations, i, lastCodeToken + 1, p.a); } if (isQuoted(t) && eq(prev, "(") && isIdentifier(prevPrev) && isMechFunction(prevPrev)) mapPut(links, i, neatMechListURL(unquote(t))); String id = sc.get(t); if (id != null) links.put(i, id); } StringBuilder out = new StringBuilder(); Map titles = getSnippetTitles(filter(__76 -> isSnippetID(__76), values(links))); for (int i = 0; i < l(tok); i++) { String t = tok.get(i); if (empty(t)) continue; String id = links.get(i), ex = explanations.get(i); String style = styles.get(i); if (t.startsWith("[[") && t.endsWith("]]")) { String explanation = "[[...]] denotes a multi-line string constant (as in Lua)"; out.append(dottedSpan("[[", explanation)); String inner = htmlencode(dropPrefix("[[", dropSuffix("]]", t))); out.append(span(inner, "style", "background-color: #77FF77")); out.append(dottedSpan("]]", explanation)); continue; } if (t.startsWith("[=[") && t.endsWith("]=]")) { String explanation = "[=[...]=] denotes a multi-line string constant (as in Lua)"; out.append(dottedSpan("[=[", explanation)); String inner = htmlencode(dropPrefix("[=[", dropSuffix("]=]", t))); out.append(span(inner, "style", "background-color: #77FF77")); out.append(dottedSpan("]=]", explanation)); continue; } String enc = htmlencode(t); out.append(id != null ? ahref(makeLink(real, id), enc, "title", isSnippetID(id) ? titles.get(fsI(id)) : ex, "style", "text-decoration: none; color: black; border-bottom: dotted 1px", "target", targetBlank ? "_blank" : null) : ex != null ? dottedSpan(enc, ex) : style != null ? span(enc, "style", style) : enc); } String html = str(out); html = dynamize_noEncode(html); return html; } public String makeLink(boolean real, String id) { if (isRelativeOrAbsoluteURL(id)) return id; if (real) return longSnippetLink(id); return "/" + psI(id); } public void clearCaches() { stdFunctions_clearCache(); sc = standardClassesMap(); sf = stdFunctions_cached(); } public boolean isMechFunction(String s) { return startsWithOneOf(s, "mech", "mL"); } public void tokensToColors(List tok, Map styles) { for (int i = 0; i < l(tok); i += 2) if (tok_whitespaceContainsJavaComments(tok.get(i))) styles.put(i, "color: #666666"); } public void addExplainer(IVF1 explainer) { explainers.add(explainer); } } static public class DoLater implements AutoCloseable { public long targetSysTime; volatile public Runnable action; transient public ISleeper sleeper; transient public Executor executor; transient public Flag enabled = new Flag(); transient public Flag cancelledOrExecuted = new Flag(); public DoLater() { } public DoLater(long targetSysTime, Runnable action) { this.action = action; this.targetSysTime = targetSysTime; } public void enable() { if (!enabled.raise()) return; if (sleeper == null) sleeper = defaultSleeper(); sleeper.doLater(targetSysTime, new Runnable() { public void run() { try { if (!cancelledOrExecuted.raise()) return; runWithExecutor(action, executor); } catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "if (!cancelledOrExecuted.raise()) return;\r\n runWithExecutor(action, exec..."; } }); } public boolean cancel() { if (!cancelledOrExecuted.raise()) return false; { close(); return true; } } public void close() { cancelledOrExecuted.raise(); { cleanUp(sleeper); sleeper = null; } } } static public interface ISleeper extends AutoCloseable { public void doLater(long targetSysTime, Runnable r); } static public String hjssnippet(String snippetID, Object... __) { return hjavascript_src_snippet(snippetID, __); } static public String hreconnectingWebSockets_snippetID() { return "#2000597"; } static public Concept options(List l) { return l(l) == 1 ? first(l) : new Options(l); } static public long lround(double d) { return Math.round(d); } static public long lround(Number n) { return lround(toDouble(n)); } static public List addOrCreate(List l, A a) { return addDyn(l, a); } static public Runnable runAndReturn(Runnable r) { callF(r); return r; } static public Explain explain(String input, String rules, String className) { Object parseResult = parse1(input, rules); List e = (List) (call(parseResult, "explain", className)); if (e == null) return null; return new Explain(parseResult, e); } static public boolean isRelativeOrAbsoluteURL(String s) { return isAbsoluteURL(s) || isRelativeURL(s); } static public Map stdFunctions_cached_map; static public Lock stdFunctions_cached_lock = lock(); static public Map stdFunctions_cached() { Lock __0 = stdFunctions_cached_lock; lock(__0); try { if (stdFunctions_cached_map == null) stdFunctions_cached_map = stdFunctions_uncached(); return stdFunctions_cached_map; } finally { unlock(__0); } } static synchronized public void stdFunctions_clearCache() { stdFunctions_cached_map = null; } static public boolean tok_whitespaceContainsJavaComments(String s) { int l = l(s) - 1; for (int j = 0; j < l; j++) if (s.charAt(j) == '/') { char d = s.charAt(j + 1); if (d == '*' || d == '/') return true; } return false; } static public ISleeper defaultSleeper() { return new ISleeper() { public java.util.Timer timer; public void doLater(long targetSysTime, Runnable r) { timer = loadableUtils.utils.doLater(max(0, targetSysTime - sysNow()), r); } public void close() { cancelTimer(timer); } }; } static public void runWithExecutor(Runnable r, Executor e) { if (e == null) r.run(); else e.execute(r); } static public List addDyn(List l, A a) { if (l == null) l = new ArrayList(); l.add(a); return l; } static public Object parse1_parser; static public Object parse1(String text, String rules) { return parse1(javaTok(text), rules); } static synchronized public Object parse1(List tok, String rules) { if (parse1_parser == null) parse1_parser = run_overBot("#1002719"); return call(parse1_parser, "parse", tok, rules); } static public boolean isAbsoluteURL(String s) { return isURL(s); } static public boolean isRelativeURL(String s) { return startsWithOneOf(s, "/", "./", "../"); } static public Class main() { return getMainClass(); } static public Class run_overBot(String progID) { Class main = hotwire_overBot(progID); callMain(main); return main; } static public Class hotwire_overBot(String src) { return hotwire(src); } static public class Options extends ConceptL { public Options() { } public Options(List l) { super(l); } public Options(Concept... l) { super(asList(l)); } } static public class Explain { static public List primitiveClasses = litlist("quoted", "identifier", "any", "int"); public Object parseResult; public List tok; public List e; public List subs = new ArrayList(); public List fullMatchClasses() { return (List) call(parseResult, "fullMatchClasses"); } static public boolean debug = false; public Explain(Object parseResult, List e) { this.e = e; this.parseResult = parseResult; tok = (List) get(parseResult, "tok"); _makeSubExplains(); } public void _makeSubExplains() { for (int i = 4; i < l(e); i++) { List sub = (List) (get(e, i)); int t1 = (int) get(sub, 0); int t2 = (int) get(sub, 1); String className = getString(sub, 2); List subE = sub; if (debug) print("subE first = " + sfu(subE)); if (!primitiveClasses.contains(className)) subE = (List) call(parseResult, "explainFull", t1, t2, className); if (debug) printF("Explaining for " + className() + ": * * * => *", t1, t2, className, subE); if (subE == null) subs.add(null); else subs.add(new Explain(parseResult, subE)); } } public String className() { return getString(e, 2); } public int fromToken() { return (int) get(e, 0); } public int toToken() { return (int) get(e, 1); } public List tok() { return concatLists(litlist(""), subList(tok, fromToken(), toToken() - 1), litlist("")); } public String string() { return join(subList(tok, fromToken(), toToken() - 1)); } public boolean containsToken(String t) { return main.containsToken(tok(), t); } public void findAll(String className, List out) { if (eq(className, className())) out.add(string()); else for (Explain e : subs) if (e != null) e.findAll(className, out); } public List findAll(String className) { List l = new ArrayList(); findAll(className, l); return l; } public Explain find(String className) { return findFirst(className); } public Explain findFirst(String className) { if (eq(className, className())) return this; return findFirstSub(className); } public Explain findFirstSub(String className) { for (Explain e : subs) if (e != null) { Explain result = e.findFirst(className); if (result != null) return result; } return null; } public boolean is(String className) { return eq(className(), className); } public boolean has(String className) { return findFirst(className) != null; } public boolean hasSub(String className) { return findFirstSub(className) != null; } public void findAll2(String className, List out) { if (is(className)) out.add(this); for (Explain e : subs) if (e != null) e.findAll2(className, out); } public List findAll2(String className) { List l = new ArrayList(); findAll2(className, l); return l; } public Explain prune(String className) { return pruneSubs(className); } public Explain pruneSubs(String className) { for (int i = 0; i < l(subs); ) { Explain e = sub(i); if (e == null) ++i; else if (eq(e.className(), className)) subs.remove(i); else { e.pruneSubs(className); ++i; } } return this; } public Explain sub(int i) { return get(subs, i); } public String str(int i) { List sub = (List) (get(e, 4 + i)); int t1 = (int) get(sub, 0); int t2 = (int) get(sub, 1); return join(subList(tok, t1, t2 - 1)); } public List subs() { return subs; } public boolean singleEqualChild() { if (l(subs) != 1 || first(subs) == null) return false; Explain e = first(subs); return fromToken() == e.fromToken() && toToken() == e.toToken(); } public String prettierAnalysis() { return (String) call(parseResult, "prettierAnalysis"); } } static public class ConceptL extends Concept implements Iterable { public RefL l = new RefL(); public ConceptL() { } public ConceptL(List l) { loadableUtils.utils.addAll(this.l, l); } public void addAll(List l) { this.l.addAll(l); } public Iterator iterator() { return l.iterator(); } public List getList() { return l; } } static public void printF(String s, Object... args) { printFormat(s, args); } static public boolean containsToken(List tok, String token) { return tok.contains(token); } static public String string(Object o) { return String.valueOf(o); } static public List findAll(JFrame f, Class theClass) { List l = new ArrayList(); scanForComponents(f, theClass, l); return l; } static public boolean is(String a, String b) { return false; } static public void printFormat(String s, Object... args) { print(format(s, args)); } static public String format(String pat, Object... args) { return format3(pat, args); } }