List of usage examples for java.util Stack Stack
public Stack()
From source file:com.consol.citrus.mail.server.MailServer.java
/** * Split mail message into several messages. Each body and each attachment results in separate message * invoked on message handler. Mail message response if any should be sent only once within test case. * However latest mail response sent by test case is returned, others are ignored. * * @param bodyPart/*from w ww.j a v a 2s. c o m*/ * @param messageHeaders */ private org.springframework.integration.Message<?> split(BodyPart bodyPart, Map<String, String> messageHeaders) { MailMessage mailMessage = createMailMessage(messageHeaders); mailMessage.setBody(new BodyPart(bodyPart.getContent(), bodyPart.getContentType())); Stack<org.springframework.integration.Message<?>> responseStack = new Stack<org.springframework.integration.Message<?>>(); if (bodyPart instanceof AttachmentPart) { fillStack(getEndpointAdapter().handleMessage(org.springframework.integration.support.MessageBuilder .withPayload(mailMessageMapper.toXML(mailMessage)).copyHeaders(messageHeaders) .setHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType()) .setHeader(CitrusMailMessageHeaders.MAIL_FILENAME, ((AttachmentPart) bodyPart).getFileName()) .build()), responseStack); } else { fillStack(getEndpointAdapter().handleMessage(org.springframework.integration.support.MessageBuilder .withPayload(mailMessageMapper.toXML(mailMessage)).copyHeaders(messageHeaders) .setHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType()).build()), responseStack); } if (bodyPart.hasAttachments()) { for (AttachmentPart attachmentPart : bodyPart.getAttachments()) { fillStack(split(attachmentPart, messageHeaders), responseStack); } } return responseStack.isEmpty() ? null : responseStack.pop(); }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java
/** * This is the main loop of the RTF parser. *//*from w ww. ja v a2 s . c om*/ //CSOFF: @Override protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws CoreException { RTFDocument rtfDocument = (RTFDocument) document; StringBuilder text = new StringBuilder(); Map<String, Integer> currentTags = new HashMap<String, Integer>(); currentTags.put(UNICOUNT, 1); Stack<Map<String, Integer>> state = new Stack<Map<String, Integer>>(); state.push(currentTags); try { int c = contentStream.read(); while (c != -1) { char ch = (char) c; if (ch == BACKSLASH) { ParserPair pair = handleControl(contentStream, safeState(state)); handleControlCommand(pair.fString, text, safeState(state), rtfDocument); c = pair.fChar; } else if (ch == LEFT_BRACE) { ParserPair pair = handleGroup(contentStream, state, text, rtfDocument); c = pair.fChar; } else if (ch == RIGHT_BRACE) { handleEndGroup(contentStream, state, text, rtfDocument); c = contentStream.read(); } else { if (!in(ch, SPACES)) { text.append(ch); } else if (equal(ch, SPACE_CHAR)) { text.append(ch); } c = contentStream.read(); } } } catch (Exception e) { gLogger.error("Error while parsing a rtf file.", e); //$NON-NLS-1$ } rtfDocument.set(text.toString()); }
From source file:org.apache.sling.testing.tools.sling.SlingClient.java
/** Create path and all its parent folders, using MKCOL */ public void mkdirs(String path) throws IOException { // Call mkdir on all parent paths, starting at the topmost one final Stack<String> parents = new Stack<String>(); path = getParentPath(path);//w w w . j a v a 2 s .c o m while (path.length() > 0 && !exists(path)) { parents.push(path); path = getParentPath(path); } while (!parents.isEmpty()) { mkdir(parents.pop()); } }
From source file:gov.nih.nci.cagrid.sdk4query.processor.PublicDataCQL2ParameterizedHQL.java
/** * Processes the target object of a CQL query * * @param target//from ww w . java 2 s. c om * The target of a CQL query * @param hql * The hql string builder to append to * @param parameters * The list of positional parameter values * @param avoidSubclasses * A flag to indicate the target has subclasses, which we should * not return * @throws QueryProcessingException */ private void processTarget(Object target, StringBuilder hql, List<java.lang.Object> parameters, boolean avoidSubclasses) throws QueryProcessingException { LOG.debug("Processing target " + target.getName()); // the stack of associations processed at the current depth of the query Stack<Association> associationStack = new Stack<Association>(); // start the query hql.append("From ").append(target.getName()).append(" as ").append(TARGET_ALIAS).append(' '); if (target.getAssociation() != null) { hql.append("where "); processAssociation(target.getAssociation(), hql, parameters, associationStack, target, TARGET_ALIAS); } if (target.getAttribute() != null) { hql.append("where "); processAttribute(target.getAttribute(), hql, parameters, target, TARGET_ALIAS); } if (target.getGroup() != null) { hql.append("where "); processGroup(target.getGroup(), hql, parameters, associationStack, target, TARGET_ALIAS); } if (avoidSubclasses) { boolean mustAddWhereClause = target.getAssociation() == null && target.getAttribute() == null && target.getGroup() == null; if (mustAddWhereClause) { hql.append(" where "); } else { hql.append(" and "); } hql.append(TARGET_ALIAS).append(".class = ?"); // 0 is the targeted class, 1 is the first subclass, 2 is the // next... parameters.add(Integer.valueOf(0)); } }
From source file:com.amalto.core.storage.StorageMetadataUtils.java
/** * <p>/*from w ww .j av a 2 s . co m*/ * Find <b>all</b> paths from type <code>origin</code> to field <code>target</code>. * </p> * <p> * This is a rather expensive operation, so use this method only when needed. When you need only <b>a</b> path to * field <code>target</code>, prefer usage of * {@link #path(org.talend.mdm.commmon.metadata.ComplexTypeMetadata, org.talend.mdm.commmon.metadata.FieldMetadata)} * . * </p> * <p> * This method follows references to other type <b>only</b> when type is not instantiable (see * {@link org.talend.mdm.commmon.metadata.TypeMetadata#isInstantiable()}). * </p> * * @param type Point of entry in the metadata graph. * @param target Field to look for as end of path. * @return A path from type <code>origin</code> to field <code>target</code>. Returns empty list if no path could be * found. * @throws IllegalArgumentException If either <code>origin</code> or <code>path</code> is null. * @see #path(org.talend.mdm.commmon.metadata.ComplexTypeMetadata, org.talend.mdm.commmon.metadata.FieldMetadata) */ public static Set<List<FieldMetadata>> paths(ComplexTypeMetadata type, FieldMetadata target) { Stack<FieldMetadata> path = new Stack<FieldMetadata>(); HashSet<List<FieldMetadata>> foundPaths = new HashSet<List<FieldMetadata>>(); _paths(type, target, path, foundPaths, new HashSet<TypeMetadata>()); return foundPaths; }
From source file:com.inmobi.conduit.distcp.tools.SimpleCopyListing.java
private void traverseNonEmptyDirectory(SequenceFile.Writer fileListWriter, FileStatus sourceStatus, Path sourcePathRoot, boolean localFile, DistCpOptions options) throws IOException { FileSystem sourceFS = sourcePathRoot.getFileSystem(getConf()); Stack<FileStatus> pathStack = new Stack<FileStatus>(); pathStack.push(sourceStatus);/*from w w w. ja v a 2s .c o m*/ while (!pathStack.isEmpty()) { for (FileStatus child : getChildren(sourceFS, pathStack.pop())) { if (LOG.isDebugEnabled()) LOG.debug("Recording source-path: " + sourceStatus.getPath() + " for copy."); writeToFileListing(fileListWriter, child, sourcePathRoot, localFile, options); if (isDirectoryAndNotEmpty(sourceFS, child)) { if (LOG.isDebugEnabled()) LOG.debug("Traversing non-empty source dir: " + sourceStatus.getPath()); pathStack.push(child); } } } }
From source file:fr.openwide.talendalfresco.alfresco.importer.ViewParserBase.java
public void parse(Reader viewReader, Importer importer) { try {/*from w ww . j av a2 s. c om*/ XmlPullParser xpp = factory.newPullParser(); xpp.setInput(viewReader); ParserContext parserContext = new ParserContext(); parserContext.importer = importer; parserContext.dictionaryService = dictionaryService; parserContext.elementStack = new Stack<ElementContext>(); try { for (int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp .next()) { switch (eventType) { case XmlPullParser.START_TAG: { if (xpp.getDepth() == 1) { processRoot(xpp, parserContext); } else { processStartElement(xpp, parserContext); } break; } case XmlPullParser.END_TAG: { processEndElement(xpp, parserContext); break; } } } } catch (Exception e) { throw new ImporterException("Failed to import package at line " + xpp.getLineNumber() + "; column " + xpp.getColumnNumber() + " due to error: " + e.getMessage(), e); } } catch (XmlPullParserException e) { throw new ImporterException("Failed to parse view", e); } }
From source file:forestry.core.gui.GuiAlyzer.java
protected final void drawAnalyticsPageClassification(IIndividual individual) { startPage();/*www.j a va 2 s. c om*/ drawLine(StringUtil.localize("gui.alyzer.classification") + ":", 12); newLine(); Stack<IClassification> hierarchy = new Stack<IClassification>(); IClassification classification = individual.getGenome().getPrimary().getBranch(); while (classification != null) { if (classification.getScientific() != null && !classification.getScientific().isEmpty()) hierarchy.push(classification); classification = classification.getParent(); } boolean overcrowded = hierarchy.size() > 5; int x = 12; IClassification group = null; while (!hierarchy.isEmpty()) { group = hierarchy.pop(); if (overcrowded && group.getLevel().isDroppable()) continue; drawLine(group.getScientific(), x, group.getLevel().getColour()); drawLine(group.getLevel().name(), 155, group.getLevel().getColour()); newLine(); x += 10; } // Add the species name String binomial = individual.getGenome().getPrimary().getBinomial(); if (group != null && group.getLevel() == EnumClassLevel.GENUS) binomial = group.getScientific().substring(0, 1) + ". " + binomial.toLowerCase(Locale.ENGLISH); drawLine(binomial, x, 0xebae85); drawLine("SPECIES", 155, 0xebae85); newLine(); newLine(); drawLine(StringUtil.localize("gui.alyzer.authority") + ": " + individual.getGenome().getPrimary().getAuthority(), 12); if (AlleleManager.alleleRegistry.isBlacklisted(individual.getIdent())) { String extinct = ">> " + StringUtil.localize("gui.alyzer.extinct").toUpperCase() + " <<"; fontRendererObj.drawStringWithShadow(extinct, adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth(extinct), adjustToFactor(guiTop + getLineY()), fontColor.get("gui.beealyzer.dominant")); } newLine(); String description = individual.getGenome().getPrimary().getDescription(); if (StringUtils.isBlank(description) || description.startsWith("for.description.")) drawSplitLine(StringUtil.localize("gui.alyzer.nodescription"), 12, 208, 0x666666); else { String tokens[] = description.split("\\|"); drawSplitLine(tokens[0], 12, 208, 0x666666); if (tokens.length > 1) fontRendererObj.drawStringWithShadow("- " + tokens[1], adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth("- " + tokens[1]), adjustToFactor(guiTop + 145 - 14), 0x99cc32); } endPage(); }
From source file:com.opengamma.master.portfolio.ManageablePortfolioNode.java
/** * Finds the stack of nodes from the tree below this node by identifier. * This performs a recursive scan of the child nodes returning all the nodes * in the hierarchy from the root node to the specified node. * The specified node is at the top of the stack. * /*w w w. java2s . c om*/ * @param nodeObjectId the node object identifier, not null * @return the node stack, empty if not found, not null */ public Stack<ManageablePortfolioNode> findNodeStackByObjectId(final ObjectIdentifiable nodeObjectId) { ArgumentChecker.notNull(nodeObjectId, "nodeObjectId"); Stack<ManageablePortfolioNode> stack = new Stack<ManageablePortfolioNode>(); Stack<ManageablePortfolioNode> result = findNodeStackByObjectId0(stack, nodeObjectId.getObjectId()); return result == null ? stack : result; }
From source file:com.aipo.container.gadgets.parse.AipoNekoSimplifiedHtmlParser.java
private void fixNekoWeirdness(Document document) { // Neko as of versions > 1.9.13 stuffs all leading <script> nodes into // <head>. // This breaks all sorts of assumptions in gadgets, notably the existence of // document.body. // We can't tell Neko to avoid putting <script> into <head> however, since // gadgets/* w w w . j a va 2 s . c om*/ // like <Content><script>...</script><style>...</style> will break due to // both // <script> and <style> ending up in <body> -- at which point Neko // unceremoniously // drops the <style> (and <link>) elements. // Therefore we just search for <script> elements in <head> and stuff them // all into // the top of <body>. // This method assumes a normalized document as input. Node html = DomUtil.getFirstNamedChildNode(document, "html"); if (html.getNextSibling() != null && html.getNextSibling().getNodeName().equalsIgnoreCase("html")) { // if a doctype is specified, then the desired root <html> node is wrapped // by an <HTML> node // Pull out the <html> root. html = html.getNextSibling(); } Node head = DomUtil.getFirstNamedChildNode(html, "head"); if (head == null) { head = document.createElement("head"); html.insertBefore(head, html.getFirstChild()); } NodeList headNodes = head.getChildNodes(); Stack<Node> headScripts = new Stack<Node>(); for (int i = 0; i < headNodes.getLength(); ++i) { Node headChild = headNodes.item(i); if (headChild.getNodeName().equalsIgnoreCase("script")) { headScripts.add(headChild); } } // Remove from head, add to top of <body> in <head> order. Node body = DomUtil.getFirstNamedChildNode(html, "body"); if (body == null) { body = document.createElement("body"); html.insertBefore(body, head.getNextSibling()); } Node bodyFirst = body.getFirstChild(); while (!headScripts.isEmpty()) { Node headScript = headScripts.pop(); head.removeChild(headScript); body.insertBefore(headScript, bodyFirst); bodyFirst = headScript; } }