List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:com.openerp.support.listview.OEListViewAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { viewRow = convertView;//from w w w . jav a2 s.com parentView = parent; LayoutInflater inflater = ((MainActivity) context).getLayoutInflater(); if (viewRow == null) { viewRow = inflater.inflate(this.resource_id, parent, false); } row = this.rows.get(position); rowdata = row.getRow_data(); for (final Integer control_id : controlClickHandler.keySet()) { viewRow.findViewById(control_id).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { controlClickHandler.get(control_id).controlClicked(position, rows.get(position), viewRow); } }); } for (int i = 0; i < this.to.length; i++) { final String key = from[i]; if (booleanEvents.contains(from[i])) { handleBinaryBackground(row.getRow_id(), key, to[i], viewRow, position); } else if (backgroundChange.containsKey(key)) { String backFlag = rowdata.get(key).toString(); if (!backFlag.equals("false")) { backFlag = "true"; } int color = backgroundChange.get(key).get(backFlag); viewRow.findViewById(this.to[i]).setBackgroundColor(color); continue; } else if (imageCols.contains(from[i])) { String data = rowdata.get(from[i]).toString(); if (!data.equals("false")) { ImageView imgView = (ImageView) viewRow.findViewById(this.to[i]); imgView.setImageBitmap(Base64Helper.getBitmapImage(context, data)); } } else { TextView txvObj = null; WebView webview = null; if (!webViewControls.containsKey(this.from[i])) { txvObj = (TextView) viewRow.findViewById(this.to[i]); } else { if (webViewControls.get(this.from[i])) { webview = (WebView) viewRow.findViewById(this.to[i]); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); } else { txvObj = (TextView) viewRow.findViewById(this.to[i]); } } String key_col = this.from[i]; String alt_key_col = key_col; if (key_col.contains("|")) { String[] splits = key_col.split("\\|"); key_col = splits[0]; alt_key_col = splits[1]; } String data = rowdata.get(key_col).toString(); if (data.equals("false") || TextUtils.isEmpty(data)) { data = rowdata.get(alt_key_col).toString(); } if (this.cleanColumn.contains(key_col)) { data = HTMLHelper.htmlToString(data); } if (datecols.contains(key_col)) { if (date_format != null) { data = OEDate.getDate(data, TimeZone.getDefault().getID(), date_format); } else { data = OEDate.getDate(data, TimeZone.getDefault().getID()); } } if (!data.equals("false")) { try { StringBuffer inputdata = new StringBuffer(); JSONArray tmpData = new JSONArray(data); for (int k = 0; k < tmpData.length(); k++) { if (tmpData.get(k) instanceof JSONArray) { if (tmpData.getJSONArray(k).length() == 2) { inputdata.append(tmpData.getJSONArray(k).getString(1)); inputdata.append(","); } } else { inputdata.append(tmpData.getString(0)); inputdata.append(","); } } int index = inputdata.lastIndexOf(","); if (index > 0) { inputdata.deleteCharAt(index); } txvObj.setText(inputdata.toString()); } catch (Exception e) { if (this.toHtml.contains(key_col)) { if (webViewControls.get(this.from[i])) { String customHtml = data; webview.loadData(customHtml, "text/html", "UTF-8"); } else { txvObj.setText(HTMLHelper.stringToHtml(data)); } } else { txvObj.setText(data); } } } else { txvObj.setText(""); } } } if (this.canChangeBackground && !viewRow.isSelected()) { boolean flag = Boolean.parseBoolean(rowdata.get(conditionKey).toString()); if (flag) { viewRow.setBackgroundResource(colors[1]); } else { viewRow.setBackgroundResource(colors[0]); } } if (viewListener != null) { viewRow = viewListener.listViewOnCreateListener(position, viewRow, this.rows.get(position)); } return viewRow; }
From source file:wicket.markup.Markup.java
/** * Based on the tag and its current tag path create a cache entry and update * the tag path again depending on the tag * //from w ww . j av a 2 s . c o m * @param tagPath * The current tag path in the markup * @param tag * The current tag * @param tagIndex * The index of the tag within the markup * @return Updated tag path for the next ComponentTag in the markup */ private StringBuffer setComponentPathForTag(final StringBuffer tagPath, final ComponentTag tag, final int tagIndex) { // Only if the tag has wicket:id="xx" and open or open-close if ((tag.isOpen() || tag.isOpenClose()) && tag.getAttributes().containsKey(wicketId)) { int size = tagPath.length(); if (size > 0) { tagPath.append(TAG_PATH_SEPARATOR); } tagPath.append(tag.getId()); this.componentMap.put(tagPath.toString(), new Integer(tagIndex)); // With open-close the path does not change. It can/will not have // children. The same is true for HTML tags like <br> or <img> // which might not have close tags. if (tag.isOpenClose() || tag.hasNoCloseTag()) { tagPath.setLength(size); } } else if (tag.isClose() && (tagPath != null)) { // For example <wicket:message> does not have an id if ((tag.getOpenTag() == null) || tag.getOpenTag().getAttributes().containsKey(wicketId)) { // Remove the last element from the component path final int index = tagPath.lastIndexOf(String.valueOf(TAG_PATH_SEPARATOR)); if (index != -1) { tagPath.setLength(index); } else { tagPath.setLength(0); } } } return tagPath; }
From source file:com.krawler.spring.crm.common.crmManagerDAOImpl.java
public StringBuffer recursiveManagerUsers(String userid) throws ServiceException { StringBuffer usersList = new StringBuffer(); try {// ww w . j a v a 2 s .c o m List appendList = new ArrayList(); List appendUserList = new ArrayList(); recursiveManagerUsers(userid, usersList, appendUserList, appendList, 0, ""); if (usersList.length() > 0) usersList = usersList.deleteCharAt(usersList.lastIndexOf(",")); // usersList.append("'" + userid + "'"); } catch (Exception e) { throw ServiceException.FAILURE("crmManagerDAOImpl.recursiveManagerUsers", e); } return usersList; }
From source file:net.yacy.http.servlets.YaCyDefaultServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo;//from w w w.j a v a 2 s.c o m Enumeration<String> reqRanges = null; boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; if (included) { pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo == null) { pathInfo = request.getPathInfo(); } } else { pathInfo = request.getPathInfo(); // Is this a Range request? reqRanges = request.getHeaders(HeaderFramework.RANGE); if (!hasDefinedRange(reqRanges)) { reqRanges = null; } } String pathInContext = pathInfo == null ? "/" : pathInfo; // this is the path of the resource in _resourceBase (= path within htroot respective htDocs) boolean endsWithSlash = pathInContext.endsWith(URIUtil.SLASH); // Find the resource Resource resource = null; try { // Look for a class resource boolean hasClass = false; if (reqRanges == null && !endsWithSlash) { final int p = pathInContext.lastIndexOf('.'); if (p >= 0) { String pathofClass = pathInContext.substring(0, p) + ".class"; Resource classresource = _resourceBase.addPath(pathofClass); // Does a class resource exist? if (classresource != null && classresource.exists() && !classresource.isDirectory()) { hasClass = true; } } } // find resource resource = getResource(pathInContext); if (!hasClass && (resource == null || !resource.exists()) && !pathInContext.contains("..")) { // try to get this in the alternative htDocsPath resource = Resource.newResource(new File(_htDocsPath, pathInContext)); } if (ConcurrentLog.isFine("FILEHANDLER")) { ConcurrentLog.fine("FILEHANDLER", "YaCyDefaultServlet: uri=" + request.getRequestURI() + " resource=" + resource); } // Handle resource if (!hasClass && (resource == null || !resource.exists())) { if (included) { throw new FileNotFoundException("!" + pathInContext); } response.sendError(HttpServletResponse.SC_NOT_FOUND); } else if (!resource.isDirectory()) { if (endsWithSlash && pathInContext.length() > 1) { String q = request.getQueryString(); pathInContext = pathInContext.substring(0, pathInContext.length() - 1); if (q != null && q.length() != 0) { pathInContext += "?" + q; } response.sendRedirect(response .encodeRedirectURL(URIUtil.addPaths(_servletContext.getContextPath(), pathInContext))); } else { if (hasClass) { // this is a YaCy servlet, handle the template handleTemplate(pathInfo, request, response); } else { if (included || passConditionalHeaders(request, response, resource)) { sendData(request, response, included, resource, reqRanges); } } } } else { // resource is directory String welcome; if (!endsWithSlash) { StringBuffer buf = request.getRequestURL(); synchronized (buf) { int param = buf.lastIndexOf(";"); if (param < 0) { buf.append('/'); } else { buf.insert(param, '/'); } String q = request.getQueryString(); if (q != null && q.length() != 0) { buf.append('?'); buf.append(q); } response.setContentLength(0); response.sendRedirect(response.encodeRedirectURL(buf.toString())); } } // else look for a welcome file else if (null != (welcome = getWelcomeFile(pathInContext))) { ConcurrentLog.fine("FILEHANDLER", "welcome={}" + welcome); // Forward to the index RequestDispatcher dispatcher = request.getRequestDispatcher(welcome); if (dispatcher != null) { if (included) { dispatcher.include(request, response); } else { dispatcher.forward(request, response); } } } else { if (included || passConditionalHeaders(request, response, resource)) { sendDirectory(request, response, resource, pathInContext); } } } } catch (IllegalArgumentException e) { ConcurrentLog.logException(e); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } finally { if (resource != null) { resource.close(); } } }
From source file:org.etudes.component.app.melete.SectionDB.java
private String getAllDeleteSectionIds(List<Integer> delSections) { StringBuffer allIds = new StringBuffer("( "); String a = null;/* w w w . j ava2 s. c om*/ for (Integer s : delSections) { allIds.append(Integer.toString(s) + ","); } if (allIds.lastIndexOf(",") != -1) a = allIds.substring(0, allIds.lastIndexOf(",")) + " )"; return a; }
From source file:org.medici.bia.controller.search.AjaxController.java
/** * // w ww . j a va 2 s . c o m * @param simpleSearchPerimeter * @param uuid * @param sortingColumnNumber * @param sortingDirection * @param firstRecord * @param length * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = "/src/ExpandResultsAdvancedSearch.json", method = RequestMethod.GET) public ModelAndView expandResultsAdvancedSearch(HttpSession httpSession, @RequestParam(value = "simpleSearchPerimeter") SimpleSearchPerimeter simpleSearchPerimeter, @RequestParam(value = "sSearch") String uuid, @RequestParam(value = "iSortCol_0", required = false) Integer sortingColumnNumber, @RequestParam(value = "sSortDir_0", required = false) String sortingDirection, @RequestParam(value = "iDisplayStart") Integer firstRecord, @RequestParam(value = "iDisplayLength") Integer length) { Map<String, Object> model = new HashMap<String, Object>(0); Map<String, SearchFilter> searchFilterMap = (Map<String, SearchFilter>) httpSession .getAttribute("searchFilterMap"); SearchFilter searchFilter = searchFilterMap.get(uuid); PaginationFilter paginationFilter = new PaginationFilter(firstRecord, length, sortingColumnNumber, sortingDirection, simpleSearchPerimeter); Page page = null; try { page = getSearchService().searchAdvancedDocuments(searchFilter.getFilterData(), paginationFilter); } catch (ApplicationThrowable aex) { page = new Page(paginationFilter); } List resultList = new ArrayList(); for (Document currentDocument : (List<Document>) page.getList()) { List singleRow = new ArrayList(); if (currentDocument.getSenderPeople() != null) { if (!currentDocument.getSenderPeople().getMapNameLf() .equals("Person Name Lost, Not Indicated or Unidentifiable")) singleRow.add(currentDocument.getSenderPeople().getMapNameLf()); else singleRow.add("Person Name Lost"); } else singleRow.add(""); if (currentDocument.getRecipientPeople() != null) { if (!currentDocument.getRecipientPeople().getMapNameLf() .equals("Person Name Lost, Not Indicated or Unidentifiable")) singleRow.add(currentDocument.getRecipientPeople().getMapNameLf()); else singleRow.add("Person Name Lost"); } else singleRow.add(""); if (currentDocument.getYearModern() != null) { singleRow.add(DateUtils.getStringDateHTMLForTable(currentDocument.getYearModern(), currentDocument.getDocMonthNum(), currentDocument.getDocDay())); } else { singleRow.add(DateUtils.getStringDateHTMLForTable(currentDocument.getDocYear(), currentDocument.getDocMonthNum(), currentDocument.getDocDay())); } if (currentDocument.getSenderPlace() != null) { if (!currentDocument.getSenderPlace().getPlaceName() .equals("Place Name Lost, Not Indicated or Unidentifable")) singleRow.add(currentDocument.getSenderPlace().getPlaceName()); else singleRow.add("Place Name Lost"); } else singleRow.add(""); if (currentDocument.getRecipientPlace() != null) { if (!currentDocument.getRecipientPlace().getPlaceName() .equals("Place Name Lost, Not Indicated or Unidentifable")) singleRow.add(currentDocument.getRecipientPlace().getPlaceName()); else singleRow.add("Place Name Lost"); } else singleRow.add(""); String lastColumn = getLastColumn(currentDocument, new StringBuilder()); singleRow.add(lastColumn); AdvancedSearchDocument advancedSearchDocument = (AdvancedSearchDocument) searchFilter.getFilterData(); StringBuffer yourSearch = new StringBuffer(); if (simpleSearchPerimeter.equals(SimpleSearchPerimeter.EXTRACT)) { if (advancedSearchDocument.getExtract() != null) { for (String currentExtract : advancedSearchDocument.getExtract()) { if (StringUtils.countMatches(currentExtract, "\"") % 2 != 0) { StringBuffer tempString = new StringBuffer(currentExtract); tempString.setCharAt(tempString.lastIndexOf("\""), ' '); currentExtract = tempString.toString(); } //This code is for highlight the correct words if (currentExtract.contains("\"")) { StringTokenizer stringTokenizer = new StringTokenizer(currentExtract.replace('"', ' '), " "); while (stringTokenizer.hasMoreTokens()) { String currentToken = stringTokenizer.nextToken(); if (currentToken.length() > 0 && currentToken != "") { if (yourSearch.toString().length() > 0) yourSearch.append(" " + currentToken); else yourSearch.append(currentToken); } } } else { if (yourSearch.toString().length() > 0) yourSearch.append(" " + currentExtract); else yourSearch.append(currentExtract); } } } if (currentDocument.getSynExtract().getDocExtract() != null) { if (yourSearch.length() != 0) { String text = DocumentUtils.searchTextResultExpand( currentDocument.getSynExtract().getDocExtract(), yourSearch.toString()); singleRow.add(HtmlUtils.highlightText(text, yourSearch.toString())); } else { if (currentDocument.getSynExtract().getDocExtract().length() > 200) { String text = currentDocument.getSynExtract().getDocExtract().substring(0, 197); singleRow.add(text.substring(0, text.lastIndexOf(" ")) + " ..."); } else { singleRow.add(currentDocument.getSynExtract().getDocExtract()); } } } else singleRow.add(""); } else if (simpleSearchPerimeter.equals(SimpleSearchPerimeter.SYNOPSIS)) { if (advancedSearchDocument.getSynopsis() != null) { for (String currentSynopsis : advancedSearchDocument.getSynopsis()) { if (StringUtils.countMatches(currentSynopsis, "\"") % 2 != 0) { StringBuffer tempString = new StringBuffer(currentSynopsis); tempString.setCharAt(tempString.lastIndexOf("\""), ' '); currentSynopsis = tempString.toString(); } //This code is for highlight the correct words if (currentSynopsis.contains("\"")) { StringTokenizer stringTokenizer = new StringTokenizer(currentSynopsis.replace('"', ' '), " "); while (stringTokenizer.hasMoreTokens()) { String currentToken = stringTokenizer.nextToken(); if (currentToken.length() > 0 && currentToken != "") { if (yourSearch.toString().length() > 0) yourSearch.append(" " + currentToken); else yourSearch.append(currentToken); } } } else { if (yourSearch.toString().length() > 0) yourSearch.append(" " + currentSynopsis); else yourSearch.append(currentSynopsis); } } } if (currentDocument.getSynExtract().getSynopsis() != null) { if (yourSearch.length() != 0) { String text = DocumentUtils.searchTextResultExpand( currentDocument.getSynExtract().getSynopsis(), yourSearch.toString()); singleRow.add(HtmlUtils.highlightText(text, yourSearch.toString())); } else { if (currentDocument.getSynExtract().getSynopsis().length() > 200) { String text = currentDocument.getSynExtract().getSynopsis().substring(0, 197); singleRow.add(text.substring(0, text.lastIndexOf(" ")) + " ..."); } else { singleRow.add(currentDocument.getSynExtract().getSynopsis()); } } } else singleRow.add(""); } else singleRow.add(""); resultList.add(HtmlUtils.showDocumentExpand(singleRow, currentDocument.getEntryId())); } model.put("iEcho", "1"); model.put("iTotalDisplayRecords", page.getTotal()); model.put("iTotalRecords", page.getTotal()); model.put("aaData", resultList); return new ModelAndView("responseOK", model); }
From source file:org.pentaho.platform.web.http.api.resources.RepositoryResource.java
/** * Takes a pathId to a file and generates a URI that represents the URL to call to generate content from that file. * * <p><b>Example Request:</b><br /> * GET pentaho/api/repos/public:steel%20wheels:Invoice%20(report).prpt/default * </p>// w ww . j ava 2 s .c o m * * @param pathId @param pathId * * @return URI that represents a forwarding URL to execute to generate content from the file {pathId}. * * <p><b>Example Response:</b></p> * <pre function="syntax.xml"> * This response does not contain data. * </pre> */ @GET @Path("{pathId : .+}/default") @Produces({ WILDCARD }) @StatusCodes({ @ResponseCode(code = 303, condition = "Successfully get the resource."), @ResponseCode(code = 404, condition = "Failed to find the resource.") }) public Response doExecuteDefault(@PathParam("pathId") String pathId) throws FileNotFoundException, MalformedURLException, URISyntaxException { String perspective = null; StringBuffer buffer = null; String url = null; String path = FileResource.idToPath(pathId); String extension = path.substring(path.lastIndexOf('.') + 1); IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession()); IContentInfo info = pluginManager.getContentTypeInfo(extension); for (IPluginOperation operation : info.getOperations()) { if (operation.getId().equalsIgnoreCase("RUN")) { //$NON-NLS-1$ perspective = operation.getPerspective(); break; } } if (perspective == null) { perspective = GENERATED_CONTENT_PERSPECTIVE; } buffer = httpServletRequest.getRequestURL(); String queryString = httpServletRequest.getQueryString(); url = buffer.substring(0, buffer.lastIndexOf("/") + 1) + perspective + //$NON-NLS-1$ ((queryString != null && queryString.length() > 0) ? "?" + httpServletRequest.getQueryString() : ""); return Response.seeOther((new URL(url)).toURI()).build(); }
From source file:com.openerp.orm.ORM.java
/** * Creates the statement.// ww w .java 2s . c o m * * @param table * the table * @param fields * the fields * @return the sQL statement */ private SQLStatement createStatement(String table, List<Fields> fields) { SQLStatement statement = new SQLStatement(); StringBuffer sql = new StringBuffer(); sql.append("CREATE TABLE IF NOT EXISTS "); sql.append(table); sql.append(" ("); for (Fields field : fields) { try { sql.append(field.getName()); sql.append(" "); sql.append(field.getType()); sql.append(", "); } catch (Exception e) { } } sql.deleteCharAt(sql.lastIndexOf(",")); sql.append(")"); statement.setTable_name(table); statement.setType("create"); statement.setStatement(sql.toString()); return statement; }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
private String getCompleteRelativeFileName(String relativeFileName) { if (Utility.FILE_SEPARATOR.equalsIgnoreCase("\\")) { // Convert '/' to Windows file separator relativeFileName = relativeFileName.replaceAll("/", "\\\\"); }/*from ww w .j a v a 2 s .c om*/ String completeRelativeFileName = relativeFileName; // Check if this is a URL first try { new URL(relativeFileName); // This is a URL. Do not process return completeRelativeFileName; } catch (MalformedURLException ex) { // Not a URL. Continue processing } if (this.currentRelativeFilename != null) { // if relativeFileName starts with './' or '../' complete it: // Get directory of currently processed filename // Do directory update. For example: // topDir/dir1/file1.wsdl // topDir/dir2/file2.wsdl // file2.wsdl has import to ../dir1/file1.wsdl // Do following: // 1. Calculate directory of file doing the importing // In this example, file2.wsdl does import, its dir is: /topDir/dir2/ // 2. Append relative import to file1.wsdl to file2.wsdl's directory: // topDir/dir2/../dir1/file1.wsdl // 3. Resolve relative path to file1.wsdl // Replace the '../' and the directory above it. // topDir/dir2/../dir1/file1.wsdl -> topDir/dir1/file1.wsdl // Note, the algorithm will handle any number of '../' in the path int index = currentRelativeFilename.lastIndexOf(Utility.FILE_SEPARATOR); String currentRelativeDir = ""; if (index != -1) { currentRelativeDir = currentRelativeFilename.substring(0, index + 1); } String relativeDir = ""; int index2 = relativeFileName.lastIndexOf(Utility.FILE_SEPARATOR); if (index2 != -1) { relativeDir = relativeFileName.substring(0, index2 + 1); } if (!currentRelativeDir.equalsIgnoreCase(relativeDir)) { // In other words, if you do not have the same directory path to // both files, continue below String fullRelativePath = currentRelativeDir + relativeFileName; String[] dirs = null; if (Utility.FILE_SEPARATOR.equalsIgnoreCase("\\")) { // Handle Windows dir separator dirs = fullRelativePath.split("\\\\"); } else { dirs = fullRelativePath.split(Utility.FILE_SEPARATOR); } StringBuffer completeRelativePath = new StringBuffer(); for (int i = 0; i < dirs.length; i++) { int completeRelativePathLength = completeRelativePath.length(); if (dirs[i].equalsIgnoreCase("..")) { // delete the previously appended dir if (i > 0) { if (completeRelativePathLength > 0) { int lastDirIndex = completeRelativePath.lastIndexOf(Utility.FILE_SEPARATOR); if (lastDirIndex == -1) { lastDirIndex = 0; } completeRelativePath = completeRelativePath.delete(lastDirIndex, completeRelativePathLength); } } } else if (i < dirs.length - 1 && dirs[i].equalsIgnoreCase(".")) { continue; } else { if (i > 0 && completeRelativePathLength > 0) { completeRelativePath.append(Utility.FILE_SEPARATOR); } completeRelativePath.append(dirs[i]); } } completeRelativeFileName = completeRelativePath.toString(); } } return completeRelativeFileName; }
From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java
/** * Format HTML text to fit into one or more vertically aligned text views. * Parses the given text and removes {@code <code> </code>} tags. If the code * text is of multiple lines a new {@link android.widget.TextView TextView} is * created and added to the view container else the code text is added to * already created {@link android.widget.TextView TextView}. * /* ww w. jav a2 s . c om*/ * @param context * @param markdownText * @return */ public static ArrayList<View> parse(Context context, String markdownText) { if (context != null && markdownText != null) { ArrayList<View> views = new ArrayList<View>(); try { markdownText = clean(markdownText); XmlPullParserFactory xmlPullParserFactory = XmlPullParserFactory.newInstance(); XmlPullParser xmlPullParser = xmlPullParserFactory.newPullParser(); xmlPullParser.setInput(new StringReader(markdownText)); int eventType = xmlPullParser.getEventType(); StringBuffer buffer = new StringBuffer(); StringBuffer code = new StringBuffer(); boolean codeFound = false; boolean oneLineCode = false; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { } else if (eventType == XmlPullParser.START_TAG) { if (xmlPullParser.getName().equals(Tags.CODE)) codeFound = true; else if (xmlPullParser.getName().equals(Tags.IMG)) { addSimpleTextToView(context, views, buffer, params); String attributeValue = xmlPullParser.getAttributeValue(null, Attributes.SRC); addImgLinkText(context, views, attributeValue, params); } else { buffer.append("<" + xmlPullParser.getName()); for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { buffer.append(" " + xmlPullParser.getAttributeName(i) + "=\"" + xmlPullParser.getAttributeValue(i) + "\""); } buffer.append(">"); } } else if (eventType == XmlPullParser.END_TAG) { if (xmlPullParser.getName().equals(Tags.CODE)) { codeFound = false; if (oneLineCode) oneLineCode = false; else { addSimpleTextToView(context, views, buffer, params); views.add(getTextViewForCode(context, code.toString())); code.delete(0, code.length()); } } else if (xmlPullParser.getName().equals(Tags.IMG)) { LogWrapper.v(TAG, "Ignore img tag"); } else { buffer.append("</" + xmlPullParser.getName() + ">"); } } else if (eventType == XmlPullParser.TEXT) { String text = xmlPullParser.getText(); if (codeFound) { if (!text.contains(NEW_LINE)) { if (buffer.length() > 0 && buffer.lastIndexOf(NEW_LINE) == buffer.length() - 1) buffer.setCharAt(buffer.length() - 1, ' '); buffer.append(text); oneLineCode = true; } else { code.append(text); } } else { text = text.replace(NEW_LINE, " ").replace(CR, " "); buffer.append(text); } } eventType = xmlPullParser.next(); } addSimpleTextToView(context, views, buffer, params); } catch (XmlPullParserException e) { LogWrapper.e(TAG, "Error parsing: " + e); } catch (IOException e) { LogWrapper.e(TAG, "Error parsing: " + e); } return views; } return null; }