Author: doogie
Date: Mon Jun 29 17:36:54 2009 New Revision: 789391 URL: http://svn.apache.org/viewvc?rev=789391&view=rev Log: More string optimizations. Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=789391&r1=789390&r2=789391&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Mon Jun 29 17:36:54 2009 @@ -107,7 +107,9 @@ } public void appendContentUrl(Appendable writer, String location) throws IOException { - ContentUrlTag.appendContentPrefix(this.request, writer); + StringBuilder buffer = new StringBuilder(); + ContentUrlTag.appendContentPrefix(this.request, buffer); + writer.append(buffer.toString()); writer.append(location); } @@ -209,14 +211,11 @@ Map<String, Object> fieldMap = inPlaceEditor.getFieldMap(context); if (fieldMap != null) { url.append('?'); - Set<Entry<String, Object>> fieldSet = fieldMap.entrySet(); - Iterator<Entry<String, Object>> fieldIterator = fieldSet.iterator(); int count = 0; - while (fieldIterator.hasNext()) { + for (Entry<String, Object> field: fieldMap.entrySet()) { count++; - Entry<String, Object> field = fieldIterator.next(); url.append(field.getKey()).append('=').append(field.getValue()); - if (count < fieldSet.size()) { + if (count < fieldMap.size()) { url.append('&'); } } @@ -2332,19 +2331,21 @@ // Create separate url path String and request parameters String, // add viewIndex/viewSize parameters to request parameter String String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); - String prepLinkText = UtilHttp.getQueryStringFromTarget(targetService); - if (prepLinkText == null) { - prepLinkText = ""; - } - if (prepLinkText.indexOf("?") < 0) { - prepLinkText += "?"; - } else if (!prepLinkText.endsWith("?")) { - prepLinkText += "&"; + StringBuilder prepLinkBuffer = new StringBuilder(); + String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); + if (prepLinkQueryString != null) { + prepLinkBuffer.append(prepLinkQueryString); + } + if (prepLinkBuffer.indexOf("?") < 0) { + prepLinkBuffer.append("?"); + } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { + prepLinkBuffer.append("&"); } if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkText += queryString + "&"; + prepLinkBuffer.append(queryString).append("&"); } - prepLinkText += viewSizeParam + "=" + viewSize + "&" + viewIndexParam + "="; + prepLinkBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("="); + String prepLinkText = prepLinkBuffer.toString(); if (ajaxEnabled) { // Prepare params for prototype.js prepLinkText = prepLinkText.replace("?", ""); @@ -2366,7 +2367,7 @@ writer.append("javascript:ajaxUpdateAreas('").append(createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + 0 + anchor, context)).append( "')"); } else { linkText = prepLinkText + 0 + anchor; - appendOfbizUrl(writer, urlPath + linkText); + writer.append(rh.makeLink(this.request, this.response, urlPath + linkText)); } writer.append("\">").append(modelForm.getPaginateFirstLabel(context)).append("</a>"); } else { @@ -2384,7 +2385,7 @@ writer.append("javascript:ajaxUpdateAreas('").append(createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + (viewIndex - 1) + anchor, context)).append("')"); } else { linkText = prepLinkText + (viewIndex - 1) + anchor; - appendOfbizUrl(writer, urlPath + linkText); + writer.append(rh.makeLink(this.request, this.response, urlPath + linkText)); } writer.append("\">").append(modelForm.getPaginatePreviousLabel(context)).append("</a>"); } else { @@ -2404,9 +2405,7 @@ if (linkText.startsWith("/")) { linkText = linkText.substring(1); } - writer.append("location.href = '"); - appendOfbizUrl(writer, urlPath + linkText); - writer.append("' + this.value;"); + writer.append("location.href = '").append(rh.makeLink(this.request, this.response, urlPath + linkText)).append("' + this.value;"); } writer.append("\">"); // actual value @@ -2442,7 +2441,7 @@ writer.append("javascript:ajaxUpdateAreas('").append(createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + (viewIndex + 1) + anchor, context)).append("')"); } else { linkText = prepLinkText + (viewIndex + 1) + anchor; - appendOfbizUrl(writer, urlPath + linkText); + writer.append(rh.makeLink(this.request, this.response, urlPath + linkText)); } writer.append("\">").append(modelForm.getPaginateNextLabel(context)).append("</a>"); } else { @@ -2460,7 +2459,7 @@ writer.append("javascript:ajaxUpdateAreas('").append(createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + (listSize / viewSize) + anchor, context)).append("')"); } else { linkText = prepLinkText + (listSize / viewSize) + anchor; - appendOfbizUrl(writer, urlPath + linkText); + writer.append(rh.makeLink(this.request, this.response, urlPath + linkText)); } writer.append("\">").append(modelForm.getPaginateLastLabel(context)).append("</a>"); } else { @@ -2521,19 +2520,21 @@ paramName.add("sortField"); String queryString = UtilHttp.stripNamedParamsFromQueryString(str, paramName); String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); - String prepLinkText = UtilHttp.getQueryStringFromTarget(targetService); - if (prepLinkText == null) { - prepLinkText = ""; - } - if (prepLinkText.indexOf("?") < 0) { - prepLinkText += "?"; - } else if (!prepLinkText.endsWith("?")) { - prepLinkText += "&"; + StringBuilder prepLinkBuffer = new StringBuilder(); + String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); + if (prepLinkQueryString != null) { + prepLinkBuffer.append(prepLinkQueryString); + } + if (prepLinkBuffer.indexOf("?") < 0) { + prepLinkBuffer.append("?"); + } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { + prepLinkBuffer.append("&"); } if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkText += queryString + "&"; + prepLinkBuffer.append(queryString).append("&"); } - prepLinkText += "sortField" + "=" + newSortField; + prepLinkBuffer.append("sortField").append("=").append(newSortField); + String prepLinkText = prepLinkBuffer.toString(); if (ajaxEnabled) { prepLinkText = prepLinkText.replace("?", ""); prepLinkText = prepLinkText.replace("&", "&"); @@ -2550,7 +2551,7 @@ if (ajaxEnabled) { writer.append("javascript:ajaxUpdateAreas('").append(createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText, context)).append("')"); } else { - appendOfbizUrl(writer, urlPath + prepLinkText); + writer.append(rh.makeLink(this.request, this.response, urlPath + prepLinkText)); } writer.append("\">").append(titleText).append("</a>"); } @@ -2666,7 +2667,10 @@ String value = modelFormField.getEntry(context, imageField.getValue(context)); if (UtilValidate.isNotEmpty(value)) { writer.append(" src=\""); - appendContentUrl(writer, value); + StringBuilder buffer = new StringBuilder(); + ContentUrlTag.appendContentPrefix(request, buffer); + writer.append(buffer.toString()); + writer.append(value); writer.append('"'); } @@ -2903,11 +2907,7 @@ ajaxParams += extraParams; } ajaxUrl.append(updateArea.getAreaId()).append(","); - try { - appendOfbizUrl(ajaxUrl, UtilHttp.removeQueryStringFromTarget(targetUrl)); - } catch (IOException e) { - throw (InternalError) new InternalError(e.getMessage()).initCause(e); - } + ajaxUrl.append(this.rh.makeLink(this.request, this.response, UtilHttp.removeQueryStringFromTarget(targetUrl))); ajaxUrl.append(",").append(ajaxParams); } return ajaxUrl.toString(); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java?rev=789391&r1=789390&r2=789391&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java Mon Jun 29 17:36:54 2009 @@ -312,17 +312,17 @@ if (paginateAnchor != null) anchor = "#" + paginateAnchor; // preparing the link text, so that later in the code we can reuse this and just add the viewIndex - String prepLinkText = ""; - prepLinkText = targetService; - if (prepLinkText.indexOf("?") < 0) { - prepLinkText += "?"; - } else if (!prepLinkText.endsWith("?")) { - prepLinkText += "&"; + StringBuilder prepLinkTextBuffer = new StringBuilder(targetService); + if (prepLinkTextBuffer.indexOf("?") < 0) { + prepLinkTextBuffer.append("?"); + } else if (prepLinkTextBuffer.indexOf("?", prepLinkTextBuffer.length() - 1) > 0) { + prepLinkTextBuffer.append("&"); } if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkText += queryString + "&"; + prepLinkTextBuffer.append(queryString).append("&"); } - prepLinkText += viewSizeParam + "=" + viewSize + "&" + viewIndexParam + "="; + prepLinkTextBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("="); + String prepLinkText = prepLinkTextBuffer.toString(); String linkText; @@ -734,12 +734,7 @@ editRequest += "contentId=" + expandedContentId; ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - String urlString = rh.makeLink(request, response, editRequest, false, false, false); - writer.append("<a href=\""); - writer.append(rh.makeLink(request, response, editRequest, false, false, false)); - writer.append("\">"); - writer.append(editMode); - writer.append("</a>"); + writer.append("<a href=\"").append(rh.makeLink(request, response, editRequest, false, false, false)).append("\">").append(editMode).append("</a>"); } if (UtilValidate.isNotEmpty(editContainerStyle)) { writer.append("</div>"); @@ -871,9 +866,7 @@ */ ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - writer.append("<a href=\""); - writer.append(rh.makeLink(request, response, editRequest, false, false, false)); - writer.append("\">").append(editMode).append("</a>"); + writer.append("<a href=\"").append(rh.makeLink(request, response, editRequest, false, false, false)).append("\">").append(editMode).append("</a>"); } if (UtilValidate.isNotEmpty(editContainerStyle)) { writer.append("</div>"); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java?rev=789391&r1=789390&r2=789391&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java Mon Jun 29 17:36:54 2009 @@ -88,15 +88,15 @@ currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); expandCollapseLink.setStyle("collapsed"); expandCollapseLink.setText(" "); - String target = node.getModelTree().getExpandCollapseRequest(context); + StringBuilder target = new StringBuilder(node.getModelTree().getExpandCollapseRequest(context)); String trailName = node.getModelTree().getTrailName(context); if (target.indexOf("?") < 0) { - target += "?"; + target.append("?"); } else { - target += "&"; + target.append("&"); } - target += trailName + "=" + currentNodeTrailPiped; - expandCollapseLink.setTarget(target); + target.append(trailName).append("=").append(currentNodeTrailPiped); + expandCollapseLink.setTarget(target.toString()); } } else { context.put("processChildren", Boolean.TRUE); @@ -108,15 +108,15 @@ } expandCollapseLink.setStyle("expanded"); expandCollapseLink.setText(" "); - String target = node.getModelTree().getExpandCollapseRequest(context); + StringBuilder target = new StringBuilder(node.getModelTree().getExpandCollapseRequest(context)); String trailName = node.getModelTree().getTrailName(context); if (target.indexOf("?") < 0) { - target += "?"; + target.append("?"); } else { - target += "&"; + target.append("&"); } - target += trailName + "=" + currentNodeTrailPiped; - expandCollapseLink.setTarget(target); + target.append(trailName).append("=").append(currentNodeTrailPiped); + expandCollapseLink.setTarget(target.toString()); // add it so it can be remove in renderNodeEnd currentNodeTrail.add(lastContentId); } @@ -240,12 +240,13 @@ } else if ("inter-app".equalsIgnoreCase(urlMode) && req != null) { String externalLoginKey = (String) req.getAttribute("externalLoginKey"); if (UtilValidate.isNotEmpty(externalLoginKey)) { + writer.append(target); if (target.contains("?")) { - target += "&externalLoginKey=" + externalLoginKey; + writer.append("&externalLoginKey="); } else { - target += "?externalLoginKey=" + externalLoginKey; + writer.append("?externalLoginKey="); } - writer.append(target); + writer.append(externalLoginKey); } } else { writer.append(target); |
Free forum by Nabble | Edit this page |