protected void handleTagStart( List<BBCodeItem> bbCodeItems, Stack<String> tags, BBCodeToken bbCodeToken) { String startTag = bbCodeToken.getStartTag(); if (_blockElements.contains(startTag)) { String currentTag = null; while (!tags.isEmpty() && ((currentTag = tags.lastElement()) != null) && _inlineElements.contains(currentTag)) { BBCodeToken currentTagBBCodeToken = new BBCodeToken(currentTag); handleTagEnd(bbCodeItems, tags, currentTagBBCodeToken); } } if (_selfCloseElements.contains(startTag) && startTag.equals(tags.lastElement())) { BBCodeToken tagBBCodeToken = new BBCodeToken(startTag); handleTagEnd(bbCodeItems, tags, tagBBCodeToken); } tags.push(startTag); BBCodeItem bbCodeItem = new BBCodeItem(TYPE_TAG_START, bbCodeToken.getAttribute(), startTag); bbCodeItems.add(bbCodeItem); }
@Override public void onBackPressed() { if (fragmentStack.size() > 1) { fragmentCount.pop(); fragmentStack.pop().onPause(); setItemCheck(fragmentCount.lastElement()); Fragment fragment = fragmentStack.lastElement(); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); } else { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_exit); dialog.setTitle("Exit app ?"); Button button_exit = (Button) dialog.findViewById(R.id.button_exit); Button button_cancel = (Button) dialog.findViewById(R.id.button_cancle); dialog.show(); button_exit.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); finish(); } }); button_cancel.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } }
@Override protected void onResume() { super.onResume(); if (!isLoad) { Log.e("Load from Resume", "run"); LoadData(); isLoad = true; if (fragmentCount.lastElement() == 0) onNavigationDrawerItemSelected(0); else if (fragmentCount.lastElement() == 5) onNavigationDrawerItemSelected(5); } }
@Override public void onItemCulinaryPage(int id) { // TODO Auto-generated method stub FragmentTransaction ft = fragmentManager.beginTransaction(); detailDiscover = new DetailDiscover(); ft.add(R.id.content_frame, detailDiscover); fragmentStack.lastElement().onPause(); ft.hide(fragmentStack.lastElement()); fragmentStack.push(detailDiscover); ft.commit(); }
private int recursive( Transaction txn, final String endProt, Stack<String> path, int bestDepth, final int maxDepth) { DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); StringBinding.stringToEntry(path.lastElement(), key); if (this.database.get(txn, key, data, null) == OperationStatus.SUCCESS) { Set<String> partners = this.bindingSet.entryToObject(data); for (String prot2 : partners) { int depth = -1; if (prot2.equals(endProt)) { depth = path.size() - 1; } else if (path.size() < maxDepth && !path.contains(prot2)) { path.push(prot2); depth = recursive(txn, endProt, path, bestDepth, maxDepth); path.pop(); } if (depth != -1 && (bestDepth == -1 || bestDepth > depth)) { bestDepth = depth; } } } return bestDepth; }
/** 获取当前Activity(栈顶Activity) */ public BaseActivity currentActivity() { if (activityStack == null || activityStack.isEmpty()) { return null; } BaseActivity activity = activityStack.lastElement(); return activity; }
/** ����ǰActivity����ջ�����һ��ѹ��ģ� */ public void finishActivity() { Activity activity = activityStack.lastElement(); if (activity != null) { activity.finish(); activity = null; } }
/** 获得当前栈顶Activity */ public Activity currentActivity() { // lastElement()获取最后个子元素,这里是栈顶的Activity if (mActivityStack == null || mActivityStack.size() == 0) { return null; } Activity activity = mActivityStack.lastElement(); return activity; }
public Activity currentActivity() { if (activityStack.size() > 0) { Activity activity = activityStack.lastElement(); return activity; } else { return null; } }
@Override public void onBackPressed() { // TODO Auto-generated method stub Stack<Fragment> fragmStack = fragmentStack; if (fragmStack.size() != 1) { FragmentTransaction ft = fragmentManager.beginTransaction(); fragmentStack.lastElement().onPause(); ft.remove(fragmentStack.pop()); fragmentStack.lastElement().onResume(); ft.show(fragmentStack.lastElement()); ft.commit(); } else { super.onBackPressed(); } }
void endElement() { String localName = atts.getName(); if (idRecordingStack.size() > 0) { IdRecording ir = idRecordingStack.lastElement(); ir.sb.append("</"); ir.sb.append(localName); ir.sb.append(">"); ir.level--; if (ir.level == 0) { String xml = ir.sb.toString(); // Log.d(TAG, "Added element with id " + ir.id + " and content: " + xml); idXml.put(ir.id, xml); idRecordingStack.pop(); if (idRecordingStack.size() > 0) { idRecordingStack.lastElement().sb.append(xml); } Log.w(TAG, xml); } } }
void startElement() { String localName = atts.getName(); String id = ParseUtil.getStringAttr("id", atts); if (id != null) { IdRecording ir = new IdRecording(id); idRecordingStack.push(ir); } if (idRecordingStack.size() > 0) { IdRecording ir = idRecordingStack.lastElement(); ir.level++; // appendElementString(ir.sb, atts.getNamespace(), localName, atts.getName(), atts); appendElementString(ir.sb, localName, atts); } }
private static String _fixCssMarkupIfNeeded(String cssText) { Pattern p = Pattern.compile("(\\{([^\\{\\}]*)\\;([^\\{\\}\\@\\;]*)\\{)"); Matcher m = p.matcher(cssText); while (m.find()) { String[] strToRepl = m.group().split(";"); if (strToRepl.length < 1) { continue; } strToRepl[strToRepl.length - 1] = "}" + strToRepl[strToRepl.length - 1]; StringBuilder sb = new StringBuilder(); for (String s : strToRepl) { sb.append(s); sb.append(";"); } String replacement = sb.toString(); cssText = cssText.replace(m.group(), replacement); } Stack<Character> stack = new Stack(); StringBuilder sb = new StringBuilder(cssText); Character tmp; for (int i = 0; i < sb.length(); i++) { tmp = sb.charAt(i); if (tmp == '{') { stack.push(tmp); } if (tmp == '}' && !stack.empty() && stack.lastElement() == '{') { stack.pop(); } else if (tmp == '}' && stack.empty()) { sb.setCharAt(i, ' '); } } return sb.toString(); }
private void Searching(int current) { if (isFinal(current)) { isFound = true; return; } else { if (!ifContainsUnvisitedChildren(current)) { stack.pop(); if (stack.isEmpty()) return; else Searching((int) stack.lastElement()); } else { int next = getFirstUnvisitedChild(current); stack.push(next); visited.add(next); Searching(next); } } }
/** * @param obj * @param key * @todo refactor - move me - generating PLists from a stack of objets is not part of being a * PList. */ public PListObject popStack() { if (stack.isEmpty()) { return null; } PListObject ret = stack.pop(); stackCtxNestedDepth--; if (!stack.isEmpty()) { switch (stack.lastElement().getType()) { case DICT: stackCtxInArray = false; stackCtxInDict = true; break; case ARRAY: stackCtxInArray = true; stackCtxInDict = false; break; } } else { stackCtxInArray = false; stackCtxInDict = false; } return ret; }
public static void include_once(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException { String functionName = "include_once"; int argsCount = args.length; if (argsCount != 1) { HostObjectUtil.invalidNumberOfArgs( CommonManager.HOST_OBJECT_NAME, functionName, argsCount, false); } if (!(args[0] instanceof String)) { HostObjectUtil.invalidArgsError( CommonManager.HOST_OBJECT_NAME, functionName, "1", "string", args[0], false); } JaggeryContext jaggeryContext = CommonManager.getJaggeryContext(); Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext); String parent = includesCallstack.lastElement(); String fileURL = (String) args[0]; if (CommonManager.isHTTP(fileURL) || CommonManager.isHTTP(parent)) { CommonManager.include_once(cx, thisObj, args, funObj); return; } executeScript(jaggeryContext, jaggeryContext.getScope(), fileURL, false, false, true); }
/** ��ȡ��ǰActivity����ջ�����һ��ѹ��ģ� */ public Activity currentActivity() { Activity activity = activityStack.lastElement(); return activity; }
public void finishActivity() { Activity activity = activityStack.lastElement(); if (activity != null) { finishActivity(activity); } }
private static ScriptableObject executeScript( JaggeryContext jaggeryContext, ScriptableObject scope, String fileURL, final boolean isJSON, boolean isBuilt, boolean isIncludeOnce) throws ScriptException { Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext); Map<String, Boolean> includedScripts = CommonManager.getIncludes(jaggeryContext); ServletContext context = (ServletContext) jaggeryContext.getProperty(Constants.SERVLET_CONTEXT); String parent = includesCallstack.lastElement(); String keys[] = WebAppManager.getKeys(context.getContextPath(), parent, fileURL); fileURL = getNormalizedScriptPath(keys); if (includesCallstack.search(fileURL) != -1) { return scope; } if (isIncludeOnce && includedScripts.get(fileURL) != null) { return scope; } ScriptReader source; RhinoEngine engine = jaggeryContext.getEngine(); if (isBuilt) { source = new ScriptReader(context.getResourceAsStream(fileURL)) { @Override protected void build() throws IOException { try { if (isJSON) { sourceReader = new StringReader("(" + HostObjectUtil.streamToString(sourceIn) + ")"); } else { sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn)); } } catch (ScriptException e) { throw new IOException(e); } } }; } else { source = new ScriptReader(context.getResourceAsStream(fileURL)); } ScriptCachingContext sctx = new ScriptCachingContext(jaggeryContext.getTenantId(), keys[0], keys[1], keys[2]); sctx.setSecurityDomain(new JaggerySecurityDomain(fileURL, context)); long lastModified = WebAppManager.getScriptLastModified(context, fileURL); sctx.setSourceModifiedTime(lastModified); includedScripts.put(fileURL, true); includesCallstack.push(fileURL); if (isJSON) { scope = (ScriptableObject) engine.eval(source, scope, sctx); } else { engine.exec(source, scope, sctx); } includesCallstack.pop(); return scope; }
/** 结束当前Activity(堆栈中最后一个压入的) */ public void finishActivity() { Activity activity = activityStack.lastElement(); finishActivity(activity); }
public static Context getFrontMostActivity() { if (activityStack.size() == 0) { return getContext(); } return activityStack.lastElement(); }
/** Finish current activity */ public void finishCurrentActivity() { Activity currentActivity = activityStack.lastElement(); finishActivity(currentActivity); }
public static void include(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException { String functionName = "include"; int argsCount = args.length; if (argsCount != 1 && argsCount != 2) { HostObjectUtil.invalidNumberOfArgs(HOST_OBJECT_NAME, functionName, argsCount, false); } if (!(args[0] instanceof String)) { HostObjectUtil.invalidArgsError( HOST_OBJECT_NAME, functionName, "1", "string", args[0], false); } if (argsCount == 2 && !(args[1] instanceof ScriptableObject)) { HostObjectUtil.invalidArgsError( HOST_OBJECT_NAME, functionName, "2", "Object", args[1], false); } JaggeryContext jaggeryContext = getJaggeryContext(); RhinoEngine engine = jaggeryContext.getEngine(); if (engine == null) { log.error("Rhino Engine in Jaggery context is null"); throw new ScriptException("Rhino Engine in Jaggery context is null"); } Stack<String> includesCallstack = getCallstack(jaggeryContext); Map<String, Boolean> includedScripts = getIncludes(jaggeryContext); String parent = includesCallstack.lastElement(); String fileURL = (String) args[0]; if (isHTTP(fileURL) || isHTTP(parent)) { if (!isHTTP(fileURL)) { fileURL = parent + fileURL; } if (includesCallstack.search(fileURL) != -1) { return; } ScriptReader source; ScriptableObject scope; if (argsCount == 2) { scope = (ScriptableObject) args[1]; } else { scope = jaggeryContext.getScope(); } // this is a remote file url try { URL url = new URL(fileURL); url.openConnection(); source = new ScriptReader(url.openStream()); includedScripts.put(fileURL, true); includesCallstack.push(fileURL); engine.exec(source, scope, null); includesCallstack.pop(); } catch (MalformedURLException e) { String msg = "Malformed URL. function : import, url : " + fileURL; log.warn(msg, e); throw new ScriptException(msg, e); } catch (IOException e) { String msg = "IO exception while importing content from url : " + fileURL; log.warn(msg, e); throw new ScriptException(msg, e); } } else { String msg = "Unsupported file include : " + fileURL; throw new ScriptException(msg); } }