Example usage for java.util Stack peek

List of usage examples for java.util Stack peek

Introduction

In this page you can find the example usage for java.util Stack peek.

Prototype

public synchronized E peek() 

Source Link

Document

Looks at the object at the top of this stack without removing it from the stack.

Usage

From source file:com.jsmartframework.web.tag.LinkTagHandler.java

@SuppressWarnings("unchecked")
private StringBuilder getFunction(String url) {
    Ajax jsonAjax = new Ajax();
    jsonAjax.setId(id);//w w  w .j  a  va 2s  .c o  m
    jsonAjax.setTimeout(timeout);
    jsonAjax.setValidate(!skipValidation);
    jsonAjax.setForm((String) getTagValue(onForm));
    jsonAjax.setTag("link");

    // Params must be considered regardless the action for rest purpose
    for (String name : params.keySet()) {
        jsonAjax.addParam(new Param(name, params.get(name)));
    }

    if (action != null) {
        jsonAjax.setMethod("post");
        jsonAjax.setAction(getTagName(J_SBMT, action));

        if (!args.isEmpty()) {
            String argName = getTagName(J_SBMT_ARGS, action);
            for (Object arg : args.keySet()) {
                jsonAjax.addArg(new Param(argName, arg, args.get(arg)));
            }
        }

        if (update == null && onError == null && onSuccess == null && onComplete == null) {
            jsonAjax.setUrl(url);
        }
    } else if (update != null) {
        jsonAjax.setMethod("get");
    }
    if (update != null) {
        jsonAjax.setUpdate((String) getTagValue(update.trim()));
    }
    if (beforeSend != null) {
        jsonAjax.setBefore((String) getTagValue(beforeSend.trim()));
    }
    if (onError != null) {
        jsonAjax.setError((String) getTagValue(onError.trim()));
    }
    if (onSuccess != null) {
        jsonAjax.setSuccess((String) getTagValue(onSuccess.trim()));
    }
    if (onComplete != null) {
        jsonAjax.setComplete((String) getTagValue(onComplete.trim()));
    }

    // It means that the ajax is inside some iterator tag, so the
    // ajax actions will be set by iterator tag and the event bind
    // will use the id as tag attribute
    Stack<RefAction> actionStack = (Stack<RefAction>) getMappedValue(DELEGATE_TAG_PARENT);
    if (actionStack != null) {
        actionStack.peek().addRef(id, Event.CLICK.name(), jsonAjax);

    } else {
        StringBuilder builder = new StringBuilder();
        builder.append(JSMART_AJAX.format(getJsonValue(jsonAjax)));
        return getBindFunction(id, Event.CLICK.name(), builder);
    }

    return null;
}

From source file:uk.ac.cam.caret.sakai.rwiki.component.model.impl.RWikiEntityImpl.java

/**
 * {@inheritDoc}/*from  w  ww .jav  a2 s.co m*/
 */
public Element toXml(Document doc, Stack stack) {
    if (rwo == null)
        throw new RuntimeException(" Cant serialise containers at the moment ");
    Element wikipage = doc.createElement(SchemaNames.EL_WIKIPAGE);

    if (stack.isEmpty()) {
        doc.appendChild(wikipage);
    } else {
        ((Element) stack.peek()).appendChild(wikipage);
    }

    stack.push(wikipage);

    wikipage.setAttribute(SchemaNames.ATTR_ID, rwo.getId());
    wikipage.setAttribute(SchemaNames.ATTR_PAGE_NAME, rwo.getName());
    wikipage.setAttribute(SchemaNames.ATTR_REVISION, String.valueOf(rwo.getRevision()));
    wikipage.setAttribute(SchemaNames.ATTR_USER, rwo.getUser());
    wikipage.setAttribute(SchemaNames.ATTR_OWNER, rwo.getOwner());

    // I would like to be able to render this, but we cant... because its a
    // pojo !
    getProperties().toXml(doc, stack);
    Element content = doc.createElement(SchemaNames.EL_WIKICONTENT);
    stack.push(content);
    wikipage.appendChild(content);
    content.setAttribute("enc", "BASE64");
    try {
        String b64Content = Base64.encode(rwo.getContent().getBytes("UTF-8"));
        CDATASection t = doc.createCDATASection(b64Content);
        stack.push(t);
        content.appendChild(t);
        stack.pop();
    } catch (UnsupportedEncodingException usex) {
        // if UTF-8 isnt available, we are in big trouble !
        throw new IllegalStateException("Cannot find Encoding UTF-8");
    }
    stack.pop();

    stack.pop();

    return wikipage;
}

From source file:de.codesourcery.jasm16.compiler.Main.java

private int run(String[] args) throws Exception {
    final List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();

    final Stack<String> arguments = new Stack<String>();
    for (String arg : args) {
        arguments.push(arg);// w w  w.  j a va2 s  .c om
    }
    Collections.reverse(arguments);

    while (!arguments.isEmpty()) {
        final String arg = arguments.peek();
        if (arg.startsWith("-") || arg.startsWith("--")) {
            try {
                handleCommandlineOption(arg, arguments);
            } catch (NoSuchElementException e) {
                printError("Invalid command line, option " + arg + " lacks argument.");
                return 1;
            }
        } else {
            units.add(createCompilationUnit(arguments.pop()));
        }
    }

    if (verboseOutput) {
        printVersionInfo();
    }

    if (units.isEmpty()) {
        printError("No input files.");
        return 1;
    }

    setupCompiler(units);

    final ICompilationListener listener;
    if (printDebugStats || verboseOutput) {
        listener = new DebugCompilationListener(printDebugStats);
    } else {
        listener = new CompilationListener();
    }

    if (printSourceCode) {
        compiler.insertCompilerPhaseAfter(new CompilerPhase("format-code") {
            @Override
            protected void run(ICompilationUnit unit, ICompilationContext context) throws IOException {
                if (unit.getAST() != null) {
                    ASTUtils.visitInOrder(unit.getAST(), new FormattingVisitor(context));
                }
            };

        }, ICompilerPhase.PHASE_GENERATE_CODE);
    }

    // invoke compiler
    compiler.compile(units, listener);

    boolean hasErrors = false;
    for (ICompilationUnit unit : units) {
        if (unit.hasErrors()) {
            Misc.printCompilationErrors(unit, Misc.readSource(unit), printStackTraces);
            hasErrors = true;
        }
    }

    if (dumpObjectCode) {
        dumpObjectCode();
    }
    return hasErrors ? 1 : 0;
}

From source file:org.sakaiproject.site.impl.BaseToolConfiguration.java

/**
 * {@inheritDoc}/*ww w  .ja  va2 s  .c  om*/
 */
public Element toXml(Document doc, Stack stack) {
    Element element = doc.createElement("tool");
    ((Element) stack.peek()).appendChild(element);
    stack.push(element);

    element.setAttribute("id", getId());
    String toolId = getToolId();
    if (toolId != null) {
        element.setAttribute("toolId", toolId);
    }
    if (m_title != null) {
        element.setAttribute("title", m_title);
    }
    if (m_layoutHints != null) {
        element.setAttribute("layoutHints", m_layoutHints);
    }

    // properties
    Xml.propertiesToXml(getPlacementConfig(), doc, stack);

    stack.pop();

    return (Element) element;
}

From source file:org.sakaiproject.poll.model.Poll.java

public Element toXml(Document doc, Stack stack) {
    Element poll = doc.createElement("poll");

    if (stack.isEmpty()) {
        doc.appendChild(poll);/*from ww  w  . j  a v a  2s .  c om*/
    } else {
        ((Element) stack.peek()).appendChild(poll);
    }

    stack.push(poll);

    poll.setAttribute(ID, getId());
    poll.setAttribute(POLL_ID, getPollId().toString());
    poll.setAttribute(POLL_TEXT, getText());
    poll.setAttribute(MIN_OPTIONS, (new Integer(getMinOptions()).toString()));
    poll.setAttribute(MAX_OPTIONS, (new Integer(getMaxOptions()).toString()));

    if (description != null)
        poll.setAttribute(DESCRIPTION, description);

    DateFormat dformat = getDateFormatForXML();
    poll.setAttribute(VOTE_OPEN, dformat.format(this.voteOpen));
    poll.setAttribute(VOTE_CLOSE, dformat.format(this.voteClose));
    poll.setAttribute(LIMIT_VOTING, Boolean.valueOf(limitVoting).toString());
    // properties
    //getProperties().toXml(doc, stack);
    //apppend the options as chidren

    stack.pop();

    return poll;
}

From source file:com.baidu.rigel.biplatform.parser.CompileSection.java

private void sectionProcess(Stack<Node> nodes, Node tokenNode, CalculateNode calcNode) {
    if (nodes.isEmpty()) {
        if (calcNode == null) {
            nodes.push(tokenNode);//from w w w. j  a  va  2s .c o m
        } else {
            calcNode.setLeft(tokenNode);
            nodes.push(calcNode);
        }
    } else {
        // ?
        if (!nodes.peek().getNodeType().equals(NodeType.Calculate)) {
            // ??
            throw new NotAllowedOperationException("not allowed");
        }
        CalculateNode node = (CalculateNode) nodes.peek();
        if (calcNode == null) {
            node.setRight(tokenNode);
            return;
        }
        if (node.getOperation().getPriority() >= calcNode.getOperation().getPriority()) {
            node.setRight(tokenNode);
            calcNode.setLeft(node);
            // 
            nodes.pop();
        } else {
            calcNode.setLeft(tokenNode);
        }
        nodes.push(calcNode);
    }
}

From source file:org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.java

/**
 * @see org.apache.sling.api.resource.ResourceResolverFactory#getThreadResourceResolver()
 *///  w w  w . j  ava 2  s.co m
@Override
public ResourceResolver getThreadResourceResolver() {
    if (!isActive.get()) {
        return null;
    }

    ResourceResolver result = null;
    final Stack<WeakReference<ResourceResolver>> resolverStack = resolverStackHolder.get();
    if (resolverStack != null) {
        while (result == null && !resolverStack.isEmpty()) {
            result = resolverStack.peek().get();
            if (result == null) {
                resolverStack.pop();
            }
        }
    }
    return result;
}

From source file:com.jsmartframework.web.tag.ButtonTagHandler.java

@SuppressWarnings("unchecked")
private StringBuilder getFunction(String id, String action, Map<String, Object> params) {
    Ajax jsonAjax = new Ajax();
    jsonAjax.setId(id);/*from  w w  w .  jav a  2  s. co  m*/
    jsonAjax.setForm((String) getTagValue(onForm));
    jsonAjax.setTimeout(timeout);
    jsonAjax.setValidate(!skipValidation);
    jsonAjax.setTag("button");

    // Params must be considered regardless the action for rest purpose
    for (String name : params.keySet()) {
        jsonAjax.addParam(new Param(name, params.get(name)));
    }

    if (action != null) {
        jsonAjax.setMethod("post");
        jsonAjax.setAction(getTagName(J_SBMT, action));

        if (!args.isEmpty()) {
            String argName = getTagName(J_SBMT_ARGS, action);
            for (Object arg : args.keySet()) {
                jsonAjax.addArg(new Param(argName, arg, args.get(arg)));
            }
        }
    } else if (update != null) {
        jsonAjax.setMethod("get");
    }
    if (update != null) {
        jsonAjax.setUpdate((String) getTagValue(update.trim()));
    }
    if (beforeSend != null) {
        jsonAjax.setBefore((String) getTagValue(beforeSend.trim()));
    }
    if (onError != null) {
        jsonAjax.setError((String) getTagValue(onError.trim()));
    }
    if (onSuccess != null) {
        jsonAjax.setSuccess((String) getTagValue(onSuccess.trim()));
    }
    if (onComplete != null) {
        jsonAjax.setComplete((String) getTagValue(onComplete.trim()));
    }

    // It means that the ajax is inside some iterator tag, so the
    // ajax actions will be set by iterator tag and the event bind
    // will use the id as tag attribute
    Stack<RefAction> actionStack = (Stack<RefAction>) getMappedValue(DELEGATE_TAG_PARENT);
    if (actionStack != null) {
        actionStack.peek().addRef(id, Event.CLICK.name(), jsonAjax);

    } else {
        StringBuilder builder = new StringBuilder();
        builder.append(JSMART_AJAX.format(getJsonValue(jsonAjax)));
        return getBindFunction(id, Event.CLICK.name(), builder);
    }

    return null;
}

From source file:com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.java

/**
 * Gets the scriptable used at starting scope for the execution of current script.
 * @return the scope as defined in {@link JavaScriptEngine#callFunction}
 * or {@link JavaScriptEngine#execute}./*w w w  .j av  a 2 s . c o m*/
 */
protected Scriptable getStartingScope() {
    @SuppressWarnings("unchecked")
    final Stack<Scriptable> stack = (Stack<Scriptable>) Context.getCurrentContext()
            .getThreadLocal(JavaScriptEngine.KEY_STARTING_SCOPE);
    if (null == stack) {
        return null;
    }
    return stack.peek();
}

From source file:org.dhatim.cdr.extension.MapToResourceConfigFromParentConfig.java

public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException {
    Stack<SmooksResourceConfiguration> resourceStack = ExtensionContext.getExtensionContext(executionContext)
            .getResourceStack();//from  ww w  .j  av a  2  s  .  c o m
    SmooksResourceConfiguration currentConfig;
    SmooksResourceConfiguration parentConfig;
    String value;

    String actualMapTo = mapTo;

    //If no mapTo is set then the mapFrom value becomes the mapTo value
    if (actualMapTo == null) {
        actualMapTo = mapFrom;
    }

    // Get the current Config...
    try {
        currentConfig = resourceStack.peek();
    } catch (EmptyStackException e) {
        throw new SmooksException(
                "No SmooksResourceConfiguration available in ExtensionContext stack.  Unable to set SmooksResourceConfiguration property '"
                        + actualMapTo + "' with element text value.");
    }

    // Get the parent Config...
    try {
        parentConfig = resourceStack.get(resourceStack.size() - 1 + parentRelIndex);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new SmooksException(
                "No Parent SmooksResourceConfiguration available in ExtensionContext stack at relative index '"
                        + parentRelIndex + "'.  Unable to set SmooksResourceConfiguration property '"
                        + actualMapTo + "' with value of '" + mapFrom + "' from parent configuration.");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Mapping property '" + mapFrom + "' on parent resource configuration to property'"
                + actualMapTo + "'.");
    }
    ResourceConfigUtil.mapProperty(parentConfig, mapFrom, currentConfig, actualMapTo, defaultValue,
            executionContext);
}