Builds the html of the body.<p>

@param segment the HTML segment (START / END)
@param className optional class attribute to add to the body tag
@param parameters optional parameters to add to the body tag
@return the html of the body
439135
public String pageBody(int segment, String className, String parameters) {

        if (segment == HTML_START) {
            StringBuffer result = new StringBuffer(128);
            result.append("</head>\n<body unselectable=\"on\"");
            if (className != null) {
                result.append(" class=\"");
                result.append(className);
                result.append("\"");
            }
            if (CmsStringUtil.isNotEmpty(parameters)) {
                result.append(" ");
                result.append(parameters);
            }
            result.append(">\n");
            return result.toString();
        } else {
            return "</body>";
        }
    }
601875
static ElementAttributes createElementAttributes(String tag) {
        // Parsing strings
        // <!--$includetemplate$aggregated2$templatewithparams.jsp$-->
        // or
        // <!--$includeblock$aggregated2$$(block)$myblock$-->
        // in order to retrieve driver, page and name attributes
        Pattern pattern = Pattern.compile("(?<=\\$)(?:[^\\$]|\\$\\()*(?=\\$)");
        Matcher matcher = pattern.matcher(tag);
        List<String> listparameters = new ArrayList<>();
        while (matcher.find()) {
            listparameters.add(matcher.group());
        }

        String[] parameters = listparameters.toArray(new String[listparameters.size()]);

        Driver driver;
        String page = "";
        String name = null;

        if (parameters.length > 1) {
            driver = DriverFactory.getInstance(parameters[1]);
        } else {
            driver = DriverFactory.getInstance();
        }

        if (parameters.length > 2) {
            page = parameters[2];
        }

        if (parameters.length > 3) {
            name = parameters[3];
        }
        return new ElementAttributes(driver, page, name);

    }
195871
@Override
    public CompletableFuture<Void> createSegment(String segmentName, Duration timeout) {
        return invokeExtension(segmentName,
                e -> e.createSegment(segmentName, timeout),
                "createSegment", segmentName);
    }
930605
private static void createElement(String apiName) {
        ClassWriter classWriter = generateClass(ELEMENT, JAVA_OBJECT, null, "<T::" + elementTypeDesc + "Z::" + elementTypeDesc + ">" + JAVA_OBJECT_DESC, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, apiName);

        MethodVisitor mVisitor = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "self", "()" + elementTypeDesc, "()TT;", null);
        mVisitor.visitEnd();
        mVisitor = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "getVisitor", "()" + elementVisitorTypeDesc, null, null);
        mVisitor.visitEnd();
        mVisitor = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "getName", "()" + JAVA_STRING_DESC, null, null);
        mVisitor.visitEnd();
        mVisitor = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "__", "()" + elementTypeDesc, "()TZ;", null);
        mVisitor.visitEnd();
        mVisitor = classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "getParent", "()" + elementTypeDesc, "()TZ;", null);
        mVisitor.visitEnd();

        writeClassToFile(ELEMENT, classWriter, apiName);
    }
562107
public static Part buildDataPart(final String name, final String data) {
		final ByteArrayContent content = new ByteArrayContent(null, data.getBytes());
		final Part part = new Part(content);
		final HttpHeaders headers = new HttpHeaders();
		final String disposition = String.format(Request.DATA_CONTENT_DISPOSITION, name);
		headers.set(Request.CONTENT_DISPOSITION, disposition);
		part.setHeaders(headers);
		return part;
	}
708246
@Override
    public String rewriteUrl(final String url, final String sessionId) {
        if ((url == null) || (sessionId == null))
            return (url);

        String path = url;
        String query = "";
        String anchor = "";
        String fragment = "";
        int question = url.indexOf('?');
        if (question >= 0) {
            path = url.substring(0, question);
            query = url.substring(question);
        }
        int pound = path.indexOf('#');
        if (pound >= 0) {
            anchor = path.substring(pound);
            path = path.substring(0, pound);
        }
        int fragmentIndex = path.lastIndexOf(';');
        if(fragmentIndex >= 0) {
            fragment = path.substring(fragmentIndex);
            path = path.substring(0, fragmentIndex);
        }

        StringBuilder sb = new StringBuilder(path);
        if (sb.length() > 0) { // jsessionid can't be first.
            if(fragmentIndex > 0) {
                if(fragment.contains(name)) {
                    //this does not necessarily mean that this parameter is present. It could be part of the value, or the
                    //name could be a substring of a larger key name
                    sb.append(';'); //we make sure we append the fragment portion
                    String key = null;
                    StringBuilder paramBuilder = new StringBuilder();
                    for (int i = 1; i < fragment.length(); ++i) {
                        char c = fragment.charAt(i);
                        if (key == null) {
                            if (c == '&' || c == '=') {
                                key = paramBuilder.toString();
                                paramBuilder.setLength(0);
                                if (c == '&') {
                                    if (!key.equals(name)) { //we don't append if it matches the name
                                        sb.append(key);
                                        sb.append('&');
                                    }
                                    key = null;
                                }
                            } else {
                                paramBuilder.append(c);
                            }
                        } else {
                            if (c == '&') {
                                String value = paramBuilder.toString();
                                paramBuilder.setLength(0);
                                if (!key.equals(name)) { //we don't append if it matches the name
                                    sb.append(key);
                                    sb.append('=');
                                    sb.append(value);
                                    sb.append('&');
                                }
                                key = null;
                            } else {
                                paramBuilder.append(c);
                            }
                        }
                    }
                    if(paramBuilder.length() > 0) {
                        if(key == null) {
                            key = paramBuilder.toString();
                            if (!key.equals(name)) { //we don't append if it matches the name
                                sb.append(key);
                                sb.append('&');
                            }
                        } else {
                            String value = paramBuilder.toString();
                            if (!key.equals(name)) { //we don't append if it matches the name
                                sb.append(key);
                                sb.append('=');
                                sb.append(value);
                                sb.append('&');
                            }
                        }
                    }
                } else {
                    sb.append(fragment);
                    sb.append("&");
                }
            } else {
                sb.append(';');
            }
            sb.append(name);
            sb.append('=');
            sb.append(sessionId);
        }
        sb.append(anchor);
        sb.append(query);
        UndertowLogger.SESSION_LOGGER.tracef("Rewrote URL from %s to %s", url, sessionId);
        return (sb.toString());
    }
978537
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
        FormEncodingBuilder formBuilder  = new FormEncodingBuilder();
        for (Entry<String, Object> param : formParams.entrySet()) {
            formBuilder.add(param.getKey(), parameterToString(param.getValue()));
        }
        return formBuilder.build();
    }
99893
public static Document parseBodyFragment(String bodyHtml, String baseUri) {
        return Parser.parseBodyFragment(bodyHtml, baseUri);
    }
947637
public String classToUrl(String className) {
	ClassDoc classDoc = rootClassdocs.get(className);
	if (classDoc != null) {
	    String docRoot = optionProvider.getGlobalOptions().apiDocRoot;
	    if (docRoot == null)
		return null;
	    return new StringBuilder(docRoot.length() + className.length() + 10).append(docRoot) //
		    .append(classDoc.containingPackage().name().replace('.', '/')) //
		    .append('/').append(classDoc.name()).append(".html").toString();
	}
	String docRoot = optionProvider.getGlobalOptions().getApiDocRoot(className);
	    if (docRoot == null)
		return null;
	int split = splitPackageClass(className);
	StringBuilder buf = new StringBuilder(docRoot.length() + className.length() + 10).append(docRoot);
	if (split > 0) // Avoid -1, and the extra slash then.
	    buf.append(className.substring(0, split).replace('.', '/')).append('/');
	return buf.append(className, Math.min(split + 1, className.length()), className.length()) //
		.append(".html").toString();
    }
1043546
public static <E extends HTMLElement> HtmlContentBuilder<E> htmlElement(String tag, Class<E> type) {
        return new HtmlContentBuilder<>(createElement(tag, type));
    }
1371370
protected void addConstructedGuardToMethodBody(final ClassMethod classMethod, String className) {
        if (!useConstructedFlag()) {
            return;
        }
        // now create the conditional
        final CodeAttribute cond = classMethod.getCodeAttribute();
        cond.aload(0);
        cond.getfield(classMethod.getClassFile().getName(), CONSTRUCTED_FLAG_NAME, BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR);

        // jump if the proxy constructor has finished
        BranchEnd jumpMarker = cond.ifne();
        // generate the invokespecial call to the super class method
        // this is run when the proxy is being constructed
        cond.aload(0);
        cond.loadMethodParameters();
        cond.invokespecial(className, classMethod.getName(), classMethod.getDescriptor());
        cond.returnInstruction();
        cond.branchEnd(jumpMarker);
    }
1221533
private MimePart createHtmlMimePart() throws MessagingException {
		MimePart bodyPart = new MimeBodyPart();
		bodyPart.setContent(htmlPart, "text/html; charset=utf-8");
		return bodyPart;
	}
319859
public static String addQueryStringFragment(String url, String fragment) {
        StringBuilder newUrl = new StringBuilder(url);

        if (fragment.startsWith("?") || fragment.startsWith("&")) {
            fragment = fragment.substring(1);
        }

        if (!url.endsWith("?") && !url.endsWith("&")) {
            if (url.contains("?")) {
                newUrl.append('&');
            } else {
                newUrl.append('?');
            }
        }

        return newUrl.append(fragment).toString();
    }
2617
private UpdateableSegmentMetadata createSegmentMetadata(String segmentName, long segmentId) {
        UpdateableSegmentMetadata metadata = new StreamSegmentMetadata(segmentName, segmentId, this.containerId);
        this.newSegments.put(metadata.getId(), metadata);
        this.newSegmentNames.put(metadata.getName(), metadata.getId());
        return metadata;
    }
673917
private String formatElement(final Object element, final Map classMap) {
        StringBuffer buf = new StringBuffer("\tat ");
        buf.append(element);
        try {
            String className = getClassNameMethod.invoke(element, (Object[])null).toString();
            Object classDetails = classMap.get(className);
            if (classDetails != null) {
                buf.append(classDetails);
            } else {
                Class cls = findClass(className);
                int detailStart = buf.length();
                buf.append('[');
                String mavenCoordinates = MavenCoordHelper.getMavenCoordinates(cls);
                if (!Objects.isBlank(mavenCoordinates)) {
                    buf.append(mavenCoordinates);
                } else {
                    try {
                        CodeSource source = cls.getProtectionDomain().getCodeSource();
                        if (source != null) {
                            URL locationURL = source.getLocation();
                            if (locationURL != null) {
                                //
                                //   if a file: URL
                                //
                                if ("file".equals(locationURL.getProtocol())) {
                                    String path = locationURL.getPath();
                                    if (path != null) {
                                        //
                                        //  find the last file separator character
                                        //
                                        int lastSlash = path.lastIndexOf('/');
                                        int lastBack = path.lastIndexOf(File.separatorChar);
                                        if (lastBack > lastSlash) {
                                            lastSlash = lastBack;
                                        }
                                        //
                                        //  if no separator or ends with separator (a directory)
                                        //     then output the URL, otherwise just the file name.
                                        //
                                        if (lastSlash <= 0 || lastSlash == path.length() - 1) {
                                            buf.append(locationURL);
                                        } else {
                                            buf.append(path.substring(lastSlash + 1));
                                        }
                                    }
                                } else {
                                    buf.append(locationURL);
                                }
                            }
                        }
                    } catch (SecurityException ex) {
                    }
                    buf.append(':');
                    Package pkg = cls.getPackage();
                    if (pkg != null) {
                        String implVersion = pkg.getImplementationVersion();
                        if (implVersion != null) {
                            buf.append(implVersion);
                        }
                    }
                }
                buf.append(']');
                classMap.put(className, buf.substring(detailStart));
            }
        } catch (Exception ex) {
        }
        return buf.toString();
    }
1073563
public String buildHtmlHelpEnd() {

        StringBuffer result = new StringBuffer(4);
        result.append("</body>\n");
        result.append("</html>");
        return result.toString();
    }
254997
public static Document parseBodyFragment(String bodyHtml, String baseUri) {
        Document doc = Document.createShell(baseUri);
        Element body = doc.body();
        List<Node> nodeList = parseFragment(bodyHtml, body, baseUri);
        Node[] nodes = nodeList.toArray(new Node[0]); // the node list gets modified when re-parented
        for (int i = nodes.length - 1; i > 0; i--) {
            nodes[i].remove();
        }
        for (Node node : nodes) {
            body.appendChild(node);
        }
        return doc;
    }