List of usage examples for java.util Stack push
public E push(E item)
From source file:com.ephesoft.dcma.util.FileUtils.java
/** * List the contents of directory.//from w ww . j a v a2s . c om * @param directory {@link File} * @param includingDirectory boolean * @return List<String> * @throws IOException in case of error */ public static List<String> listDirectory(File directory, boolean includingDirectory) throws IOException { Stack<String> stack = new Stack<String>(); List<String> list = new ArrayList<String>(); // If it's a file, just return itself if (directory.isFile()) { if (directory.canRead()) { list.add(directory.getName()); } } else { // Traverse the directory in width-first manner, no-recursively String root = directory.getParent(); stack.push(directory.getName()); while (!stack.empty()) { String current = (String) stack.pop(); File curDir = new File(root, current); String[] fileList = curDir.list(); if (fileList != null) { for (String entry : fileList) { File file = new File(curDir, entry); if (file.isFile()) { if (file.canRead()) { list.add(current + File.separator + entry); } else { throw new IOException("Can't read file: " + file.getPath()); } } else if (file.isDirectory()) { if (includingDirectory) { list.add(current + File.separator + entry); } stack.push(current + File.separator + file.getName()); } else { throw new IOException("Unknown entry: " + file.getPath()); } } } } } return list; }
From source file:org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.java
/** * @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map) *//* w w w.ja v a2s . com*/ @Override public ResourceResolver getResourceResolver(final Map<String, Object> passedAuthenticationInfo) throws LoginException { if (!isActive.get()) { throw new LoginException("ResourceResolverFactory is deactivated."); } // create a copy of the passed authentication info as we modify the map final Map<String, Object> authenticationInfo = new HashMap<String, Object>(); if (passedAuthenticationInfo != null) { authenticationInfo.putAll(passedAuthenticationInfo); // make sure there is no leaking of service bundle and info props authenticationInfo.remove(ResourceProvider.AUTH_SERVICE_BUNDLE); authenticationInfo.remove(SUBSERVICE); } final ResourceResolver result = getResourceResolverInternal(authenticationInfo, false); Stack<WeakReference<ResourceResolver>> resolverStack = resolverStackHolder.get(); if (resolverStack == null) { resolverStack = new Stack<WeakReference<ResourceResolver>>(); resolverStackHolder.set(resolverStack); } resolverStack.push(new WeakReference<ResourceResolver>(result)); return result; }
From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilder.java
@Nullable private Criteria buildCriteria(Object bean, MarklogicPersistentEntity<?> entity) { Stack<Criteria> stack = new Stack<>(); PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(bean); entity.doWithProperties((PropertyHandler<MarklogicPersistentProperty>) property -> { Object value = propertyAccessor.getProperty(property); if (hasContent(value)) { if (stack.empty()) { stack.push(buildCriteria(property, value)); } else { Criteria criteria = stack.peek(); if (criteria.getOperator() == null) { Criteria andCriteria = new Criteria(Criteria.Operator.and, new ArrayList<>(Arrays.asList(criteria, buildCriteria(property, value)))); stack.pop();//from w ww .j a va 2 s .com stack.push(andCriteria); } else { Criteria subCriteria = buildCriteria(property, value); if (subCriteria != null) { criteria.add(subCriteria); } } } } }); return stack.empty() ? null : stack.peek(); }
From source file:com.usefullc.platform.common.filter.WebCommonFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; // String url = req.getRequestURL().toString(); String url = req.getRequestURI(); if (canExcute) { Stack<ActionHandlerInterceptor> actionStack = new Stack<ActionHandlerInterceptor>(); ActionHandler actionHandler = new ActionHandler(req, res); for (ActionHandlerInterceptor interceptor : interceptorList) { String urlPattern = interceptor.getUrlPattern(); // ?url Boolean state = PatternMatchUtils.simpleMatch(urlPattern, url); if (!state) { continue; }//from ww w . j a va2 s . c om interceptor.beforeHandler(actionHandler); // actionStack.push(interceptor); } boolean actionState = false; try { chain.doFilter(request, response); actionState = true; } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter print = new PrintWriter(sw); e.printStackTrace(print); actionHandler.setErrMsg(sw.toString()); } finally { // actionHandler.setState(actionState); while (!actionStack.isEmpty()) { ActionHandlerInterceptor interceptor = actionStack.pop(); interceptor.afterHandler(actionHandler); } } } else { chain.doFilter(request, response); } }
From source file:com.intel.ssg.dcst.panthera.parse.sql.SqlParseDriver.java
/** * A pre-parse stage to convert the characters in query command (exclude * those in quotes) to lower-case, as our SQL Parser does not recognize * upper-case keywords. It does no harm to Hive as Hive is case-insensitive. * * @param command/* w ww. j a va2 s . c o m*/ * input query command * @return the command with all chars turned to lower case except * those in quotes */ protected String preparse(String command) { Character tag = '\''; Stack<Character> singleQuotes = new Stack<Character>(); Stack<Character> doubleQuotes = new Stack<Character>(); char[] chars = filterDot(command).toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '\'' && (i > 0 ? chars[i - 1] != '\\' : true)) { singleQuotes.push(tag); } else if (c == '\"' && (i > 0 ? chars[i - 1] != '\\' : true)) { doubleQuotes.push(tag); } if (singleQuotes.size() % 2 == 0 && doubleQuotes.size() % 2 == 0) { // if not inside quotes, convert to lower case chars[i] = Character.toLowerCase(c); } } return new String(chars); }
From source file:org.apache.hadoop.util.ConfTest.java
private static List<NodeInfo> parseConf(InputStream in) throws XMLStreamException { QName configuration = new QName("configuration"); QName property = new QName("property"); List<NodeInfo> nodes = new ArrayList<NodeInfo>(); Stack<NodeInfo> parsed = new Stack<NodeInfo>(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLEventReader reader = factory.createXMLEventReader(in); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { StartElement currentElement = event.asStartElement(); NodeInfo currentNode = new NodeInfo(currentElement); if (parsed.isEmpty()) { if (!currentElement.getName().equals(configuration)) { return null; }/*from www . ja v a 2 s . com*/ } else { NodeInfo parentNode = parsed.peek(); QName parentName = parentNode.getStartElement().getName(); if (parentName.equals(configuration) && currentNode.getStartElement().getName().equals(property)) { @SuppressWarnings("unchecked") Iterator<Attribute> it = currentElement.getAttributes(); while (it.hasNext()) { currentNode.addAttribute(it.next()); } } else if (parentName.equals(property)) { parentNode.addElement(currentElement); } } parsed.push(currentNode); } else if (event.isEndElement()) { NodeInfo node = parsed.pop(); if (parsed.size() == 1) { nodes.add(node); } } else if (event.isCharacters()) { if (2 < parsed.size()) { NodeInfo parentNode = parsed.pop(); StartElement parentElement = parentNode.getStartElement(); NodeInfo grandparentNode = parsed.peek(); if (grandparentNode.getElement(parentElement) == null) { grandparentNode.setElement(parentElement, event.asCharacters()); } parsed.push(parentNode); } } } return nodes; }
From source file:com.mirth.connect.connectors.file.FileReceiver.java
@Override protected void poll() { eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.POLLING)); try {//from w w w .ja v a 2 s. c o m String channelId = getChannelId(); String channelName = getChannel().getName(); URI uri = fileConnector .getEndpointURI(replacer.replaceValues(connectorProperties.getHost(), channelId, channelName)); String readDir = fileConnector.getPathPart(uri); String username = replacer.replaceValues(connectorProperties.getUsername(), channelId, channelName); String password = replacer.replaceValues(connectorProperties.getPassword(), channelId, channelName); filenamePattern = replacer.replaceValues(connectorProperties.getFileFilter(), channelId, channelName); SftpSchemeProperties sftpProperties = null; SchemeProperties schemeProperties = connectorProperties.getSchemeProperties(); if (schemeProperties instanceof SftpSchemeProperties) { sftpProperties = (SftpSchemeProperties) schemeProperties.clone(); sftpProperties .setKeyFile(replacer.replaceValues(sftpProperties.getKeyFile(), channelId, channelName)); sftpProperties.setPassPhrase( replacer.replaceValues(sftpProperties.getPassPhrase(), channelId, channelName)); sftpProperties.setKnownHostsFile( replacer.replaceValues(sftpProperties.getKnownHostsFile(), channelId, channelName)); } fileSystemOptions = new FileSystemConnectionOptions(uri, username, password, sftpProperties); if (connectorProperties.isDirectoryRecursion()) { Set<String> visitedDirectories = new HashSet<String>(); Stack<String> directoryStack = new Stack<String>(); directoryStack.push(readDir); FileInfo[] files; while ((files = listFilesRecursively(visitedDirectories, directoryStack)) != null) { processFiles(files); } } else { processFiles(listFiles(readDir)); } } catch (Throwable t) { eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), null, ErrorEventType.SOURCE_CONNECTOR, getSourceName(), connectorProperties.getName(), null, t)); logger.error("Error polling in channel: " + getChannelId(), t); } finally { eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.IDLE)); } }
From source file:com.amalto.core.history.UniqueIdTransformer.java
private void _addIds(org.w3c.dom.Document document, Element element, Stack<Integer> levels) { NamedNodeMap attributes = element.getAttributes(); Attr id = document.createAttribute(ID_ATTRIBUTE_NAME); int thisElementId = levels.pop() + 1; StringBuilder builder;/*ww w . j a v a 2 s. com*/ { builder = new StringBuilder(); for (Integer level : levels) { builder.append(level); } } String prefix = builder.toString().isEmpty() ? StringUtils.EMPTY : builder.toString() + '-'; id.setValue(prefix + element.getNodeName() + '-' + thisElementId); attributes.setNamedItem(id); levels.push(thisElementId); { levels.push(0); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element child = (Element) children.item(i); _addIds(document, child, levels); } } levels.pop(); } }
From source file:EditorPaneTest.java
public EditorPaneFrame() { setTitle("EditorPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane = new JEditorPane(); final JTextField url = new JTextField(30); // set up hyperlink listener editorPane.setEditable(false);/*w ww. j av a 2s . c o m*/ editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); add(new JScrollPane(editorPane), BorderLayout.CENTER); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(new JLabel("Editable")); panel.add(editable); add(panel, BorderLayout.SOUTH); }
From source file:com.bstek.dorado.view.output.DataOutputter.java
@SuppressWarnings("rawtypes") private void internalOutputData(Object object, OutputContext context) throws Exception { JsonBuilder json = context.getJsonBuilder(); Stack<Object> dataObjectStack = context.getDataObjectStack(); if (dataObjectStack.contains(object)) { Exception e = new IllegalArgumentException( resourceManager.getString("dorado.common/circuitReferenceError", object.toString())); logger.error(e, e);//from ww w. j av a2 s .c o m json.value(null); return; } dataObjectStack.push(object); try { if (object instanceof Collection<?>) { outputDataTypeIfNecessary(context, object); if (object instanceof PagingList) { outputPagingList((PagingList) object, context); } else { json.array(); for (Object e : (Collection<?>) object) { outputData(e, context); } json.endArray(); } } else if (object instanceof Page<?>) { outputPage((Page<?>) object, context); } else { outputEntity(object, context); } } finally { dataObjectStack.pop(); } }