/** * Deletes a meeting from the database * * <p>- Requires a cookie for the session user - Requires a meetingId request parameter for the * HTTP GET * * @param req The HTTP Request * @param res The HTTP Response */ public void deletemeetingAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; if (req.getMethod() == HttpMethod.Get) { // Get the meeting int meetingId = Integer.parseInt(req.getParameter("meetingId")); MeetingManager meetingMan = new MeetingManager(); Meeting meeting = meetingMan.get(meetingId); meetingMan.deleteMeeting(meetingId); // Update the User Session to remove meeting HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); List<Meeting> adminMeetings = userSession.getUser().getMeetings(); for (int i = 0; i < adminMeetings.size(); i++) { Meeting m = adminMeetings.get(i); if (m.getId() == meeting.getId()) { adminMeetings.remove(i); break; } } redirectToLocal(req, res, "/home/dashboard"); return; } else if (req.getMethod() == HttpMethod.Post) { httpNotFound(req, res); } }
/** * This method should setup the flags/switches for the java command which will determine the * actual command to be executed. * * <p>Sets up flags like : * * <ul> * <li>-Dem.home * <li>-Dprocess.name * </ul> * * <br> * add computes the classpath. */ protected void updateFlags(ServerCommand serverCmd) { String bootDir = System.getProperty("em.home"); String appType = System.getProperty("appType"); String appInst = System.getProperty("appInst"); String javaClasspath = serverCmd.getClasspath(); String processName = getProcessNameForLog(); List jvmFlags = serverCmd.getJVMFlags(); int cpToken = -1; for (int i = 0; i < jvmFlags.size(); i++) { String token = (String) jvmFlags.get(i); if (token.startsWith("-classpath")) { cpToken = i; javaClasspath = null; } else if (token.startsWith("-Dem.home")) { bootDir = null; } else if (token.startsWith("-Dprocess.name")) { processName = null; } } List addonJVMFlags = new LinkedList(); if (bootDir != null) { addonJVMFlags.add("-Dem.home=" + bootDir); } if (processName != null) { addonJVMFlags.add("-Dprocess.name=" + processName); } if (!(appType == null || appType.trim().equals(""))) { addonJVMFlags.add("-DappType=" + appType); } if (!(appInst == null || appInst.trim().equals(""))) { addonJVMFlags.add("-DappInst=" + appInst); } if (cpToken != -1) { jvmFlags.remove(cpToken); String str = (String) jvmFlags.remove(cpToken); serverCmd.setClasspath(str); } jvmFlags.addAll(addonJVMFlags); }
boolean load(Object[] props, int offset) { if (_values.size() > 0) { int p = _values.size() - 1; while (_index[p] > _values.get(p).size() - 1 && p > 0) { _index[p] = 0; --p; ++_index[p]; } if (_index[p] > _values.get(p).size() - 1) { return false; } // System.err.print("\t TypedValueGroup.load{"); for (int i = 0; i < _values.size(); ++i) { props[i + offset] = _values.get(i).get(_index[i]).data; // System.err.print("[" + _index[i] + "](" + props[i+offset].getClass().getSimpleName() + // ')'); } // System.err.println("}"); ++_index[_values.size() - 1]; return true; } else { return false; } }
/* hack TODO do not know how to get int status back from Windows * Stick in code that handles particular commands that we can figure out * the status. */ private int determineStatus(List<String> args) { if (args == null) throw new NullPointerException(); if (args.size() < 2) return 0; String instanceName = args.get(args.size() - 1); if (isCommand(args, "_delete-instance-filesystem")) { try { String dir = Paths.getInstanceDirPath(node, instanceName); WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir); return instanceDir.exists() ? 1 : 0; } catch (WindowsException ex) { return 0; } } else if (isCommand(args, "_create-instance-filesystem")) { try { String dir = Paths.getDasPropsPath(node); WindowsRemoteFile dasProps = new WindowsRemoteFile(dcomInfo.getCredentials(), dir); if (dasProps.exists()) return 0; // uh-oh. Wipe out the instance directory that was created dir = Paths.getInstanceDirPath(node, instanceName); WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir); instanceDir.delete(); return 1; } catch (WindowsException ex) { return 1; } } return 0; }
protected static int processGet() throws NimbitsException { final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities(); log.info("Processing " + points.size() + " potentially idle points"); for (final Entity p : points) { try { checkIdle((Point) p); } catch (NimbitsException e) { LogHelper.logException(IdlePointCron.class, e); } } return points.size(); }
/** * Returns the String array of the specified property, or null in case the returned property * string array had zero length. * * @param propertyName the name of the property that is being queried. * @param regex the delimiting regular expression * @return the array of strings computed by splitting the specified property value around matches * of the given regular expression */ public static String[] getStringArray(String propertyName, String regex) { String str = getString(propertyName); if (str == null) return null; String[] parts = str.split(regex); // Remove mal-formatted entries. List<String> res = new ArrayList<String>(); for (String s : parts) if (s != null && s.trim().length() != 0) res.add(s); if (res.size() == 0) return null; return res.toArray(new String[res.size()]); }
@Override public void processingInstruction(String target, String data) throws SAXException { _logger.fine("Processing Instruction " + target); _logger.fine("Processing Instruction data: " + data); if (target.equals("assemble")) { if (!_stack.isEmpty()) { ElementInfo element = _stack.get(_stack.size() - 1); Matcher matcher = PROCESSING_INSTRUCTION.matcher(data); while (matcher.find()) { if (matcher.groupCount() == 2) { String name = matcher.group(1); if (name.charAt(0) == '@') { element.inst.put(name, matcher.group(2)); } else { element.args.add(guessUntypedValue(name, matcher.group(2))); } _logger.fine( "Processing Instruction for " + element.data.getClass() + "\n\ttarget = " + target + "\n\t" + name + "=" + matcher.group(2)); } } } } }
/** * Find the periods in a calendar year it need not be a standard period (used in MRP) * * @param C_Year_ID Year * @param periodType Period Type * @param ctx context * @param trx trx * @return MPeriod[] */ public static MPeriod[] getAllPeriodsInYear(int C_Year_ID, String periodType, Ctx ctx, Trx trx) { List<MPeriod> periods = new ArrayList<MPeriod>(); String sql = "SELECT * FROM C_Period WHERE IsActive='Y'"; sql = sql + " AND C_Year_ID = ?"; if (periodType != null) sql = sql + " AND PeriodType = ? "; sql = sql + " order by StartDate "; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, C_Year_ID); if (periodType != null) pstmt.setString(2, periodType); rs = pstmt.executeQuery(); while (rs.next()) periods.add(new MPeriod(ctx, rs, trx)); } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MPeriod[] retValue = new MPeriod[periods.size()]; periods.toArray(retValue); return retValue; }
/** * Find all the year records in a Calendar, it need not be a standard period (used in MRP) * * @param C_Calendar_ID calendar * @param ctx context * @param trx trx * @return MYear[] */ public static MYear[] getAllYearsInCalendar(int C_Calendar_ID, Ctx ctx, Trx trx) { List<MYear> years = new ArrayList<MYear>(); String sql = "SELECT * FROM C_Year WHERE " + "IsActive='Y' AND C_Calendar_ID = ? "; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, C_Calendar_ID); rs = pstmt.executeQuery(); while (rs.next()) years.add(new MYear(ctx, rs, trx)); } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MYear[] retValue = new MYear[years.size()]; years.toArray(retValue); return retValue; }
/** * Stores the value for the given field associated to last inserted symbol. If no symbol has been * inserted yet, an exception occurs. */ public void putValue(final Field field, final double val) { final String symbol = symbols.get(symbols.size() - 1); Map<Field, Double> vs = values.get(symbol); if (vs == null) vs = new HashMap<Field, Double>(); vs.put(field, val); this.values.put(symbol, vs); }
/** * @param sourceFile File to read from * @return List of String objects with the shas */ public static FileRequestFileContent readRequestFile(final File sourceFile) { if (!sourceFile.isFile() || !(sourceFile.length() > 0)) { return null; } Document d = null; try { d = XMLTools.parseXmlFile(sourceFile.getPath()); } catch (final Throwable t) { logger.log(Level.SEVERE, "Exception in readRequestFile, during XML parsing", t); return null; } if (d == null) { logger.log(Level.SEVERE, "Could'nt parse the request file"); return null; } final Element rootNode = d.getDocumentElement(); if (rootNode.getTagName().equals(TAG_FrostFileRequestFile) == false) { logger.severe( "Error: xml request file does not contain the root tag '" + TAG_FrostFileRequestFile + "'"); return null; } final String timeStampStr = XMLTools.getChildElementsTextValue(rootNode, TAG_timestamp); if (timeStampStr == null) { logger.severe("Error: xml file does not contain the tag '" + TAG_timestamp + "'"); return null; } final long timestamp = Long.parseLong(timeStampStr); final List<Element> nodelist = XMLTools.getChildElementsByTagName(rootNode, TAG_shaList); if (nodelist.size() != 1) { logger.severe("Error: xml request files must contain only one element '" + TAG_shaList + "'"); return null; } final Element rootShaNode = nodelist.get(0); final List<String> shaList = new LinkedList<String>(); final List<Element> xmlKeys = XMLTools.getChildElementsByTagName(rootShaNode, TAG_sha); for (final Element el : xmlKeys) { final Text txtname = (Text) el.getFirstChild(); if (txtname == null) { continue; } final String sha = txtname.getData(); shaList.add(sha); } final FileRequestFileContent content = new FileRequestFileContent(timestamp, shaList); return content; }
private static String[] splitLibDirPaths(String libDirPathsString) { List<String> libDirPathList = new ArrayList<String>(8); StringTokenizer stringTokenizer = new StringTokenizer(libDirPathsString, File.pathSeparator); while (stringTokenizer.hasMoreElements()) { String libDirPath = (String) stringTokenizer.nextElement(); libDirPathList.add(libDirPath); } return libDirPathList.toArray(new String[libDirPathList.size()]); }
/** * Returns all supported capture sizes. * * @return an array of capture sizes, in bytes, never <code>null</code>. */ public Integer[] getCaptureSizes() { final String rawValue = this.properties.get(DEVICE_CAPTURESIZES); final String[] values = rawValue.split(",\\s*"); final List<Integer> result = new ArrayList<Integer>(); for (String value : values) { result.add(Integer.valueOf(value.trim())); } Collections.sort( result, NumberUtils.<Integer>createNumberComparator(false /* aSortAscending */)); return result.toArray(new Integer[result.size()]); }
private static ServerAddress _checkAddress(List<ServerAddress> addrs) { if (addrs == null) throw new NullPointerException("addresses can't be null"); if (addrs.size() == 0) throw new IllegalArgumentException("need to specify at least 1 address"); return addrs.get(0); }
/** * List version * * @param * @return */ public static String joinNelementsPerLine( List<String> vnl, int divisor, String sp, boolean quote, String qm, String lnsp) { String[] vn = (String[]) vnl.toArray(new String[vnl.size()]); return joinNelementsPerLine(vn, divisor, sp, quote, qm, lnsp); }
// List version public static String joinNelementsPerLine(List<String> vnl, boolean quote) { return joinNelementsPerLine(vnl, vnl.size(), ", ", quote, "'", null); }
TypedValueGroup complete() { _index = new int[_values.size()]; return this; }
int size() { return _values.size(); }
/** Receive notification of the start of an element. */ @Override public void startElement(String uri, String l, String q, Attributes a) { /* * 1. Load a class that matches the element name. * 2. If no class found, assume the element maps to a String. * 3. Otherwise, construct a new object of the class with element attributes. */ _logger.fine( S.fine(_logger) ? "Consider element " + l + "\n uri " + uri + "\n q " + q : null); ElementInfo info = new ElementInfo(); // Record java packages defined on this element as xmlns for (int i = 0; i < a.getLength(); ++i) { _logger.fine( S.fine(_logger) ? " attr " + a.getQName(i) + "=" + a.getValue(i) + "\n " + a.getQName(i) + ":" + a.getURI(i) : null); if (a.getQName(i).startsWith("xmlns:") && a.getValue(i).startsWith("java://")) { info.pkgs.put(a.getQName(i).substring(6), a.getValue(i).substring(7)); } } // Resolve the package name of this element, which could be empty (default package) int colon = q.indexOf(':'); if (colon > 0) { String xmlns = q.substring(0, colon); // is it defined right here? info.jpkg = info.pkgs.get(xmlns); // find a matching namespace from ancesters if (info.jpkg == null && !_stack.isEmpty()) { for (int i = _stack.size() - 1; i >= 0; --i) { info.jpkg = _stack.get(i).pkgs.get(xmlns); if (info.jpkg != null) { break; } } } } else if (isPrimitiveType(q)) { info.jpkg = "java.lang"; } else if (!_stack.isEmpty()) { info.jpkg = _stack.get(_stack.size() - 1).jpkg; } else { info.jpkg = _jpkg; } _logger.fine("to create element with package = " + info.jpkg); try { info.name = (info.jpkg != null) ? info.jpkg + '.' + Strings.toCamelCase(l) : Strings.toCamelCase(l); try { if (info.name.endsWith("...")) { // Array construction info.type = Class.forName(info.name.substring(0, info.name.length() - 3)); info.data = new ArrayList<Object>(); } else { // Non-array construction int size = a.getLength(); TypedValueGroup arguments = new TypedValueGroup(); for (int i = 0; i < size; ++i) { if (!a.getQName(i).startsWith("xmlns:") && !a.getQName(i).equals("xmlns")) { arguments.add(guessUntypedValue(a.getQName(i), a.getValue(i))); } } arguments.complete(); _logger.fine(S.fine(_logger) ? "arguments=" + arguments : null); if (arguments.size() > 0) { if (arguments.size() == 1 && "java.lang".equals(info.jpkg)) { info.inst.put( "@as", Strings.toCamelCase( arguments.get(0).name, '-', false)); // respect original spelling info.data = arguments.get(0).get(0).data; info.type = arguments.get(0).get(0).type; } else { Exception last = null; Object[] args = new Object[arguments.size()]; while (arguments.load(args, 0)) { try { _logger.fine( S.fine(_logger) ? "to create " + info.name + " with args: " + args.length + args(args) : null); info.data = _factory.create(info.name, args); info.type = info.data.getClass(); break; } catch (InvocationTargetException x) { throw x; } catch (Exception x) { last = x; _logger.fine( "failure in creating " + info.name + ": probing for other constructors"); } } if (info.data == null) { throw last; } } } else { _logger.fine("Create " + info.name + " with the default constructor"); info.data = _factory.create(info.name); info.type = info.data.getClass(); } } } catch (ClassNotFoundException x) { // no class by the element name is found, assumed String if (!_lenient) { throw new BeanAssemblyException("No class associated with element " + q); } else { _logger.log(Level.WARNING, "can't find class " + info.name, x); } } _stack.add(info); // _logger.fine(">>ElementInfo: " + info.type.getName() + " in " + info); // all other exceptions indicate mismatches between the beans and the XML schema } catch (Exception x) { if (!_lenient) { throw new BeanAssemblyException("Failed to assemble bean from element " + q, x); } else { _logger.log(Level.SEVERE, "can't create object for this element", x); } } }
public void actionPerformed(ActionEvent ae) { if (paths != null && paths.size() > 0) { dialog = new LockDialog(getView(), paths, false, remote); GUIUtils.center(getView(), dialog); dialog.setVisible(true); final CommitData data = dialog.getData(); if (data == null) { return; // null means user canceled } if (getUsername() == null) { verifyLogin(data.getPaths() == null ? null : data.getPaths().get(0)); if (isCanceled()) { return; } } data.setUsername(getUsername()); data.setPassword(getPassword()); data.setOut(new ConsolePrintStream(getView())); getView().getDockableWindowManager().showDockableWindow("subversion"); final OutputPanel panel = SVNPlugin.getOutputPanel(getView()); panel.showConsole(); final Logger logger = panel.getLogger(); logger.log(Level.INFO, jEdit.getProperty("ips.Unlocking_...", "Unlocking ...")); for (Handler handler : logger.getHandlers()) { handler.flush(); } class Runner extends SwingWorker<LockResults, Object> { @Override public LockResults doInBackground() { try { Lock lock = new Lock(); return lock.unlock(data); } catch (Exception e) { data.getOut().printError(e.getMessage()); } finally { data.getOut().close(); } return null; } @Override public boolean cancel(boolean mayInterruptIfRunning) { boolean cancelled = super.cancel(mayInterruptIfRunning); if (cancelled) { data.getOut().printError("Stopped 'Unlock' action."); data.getOut().close(); } else { data.getOut().printError("Unable to stop 'Unlock' action."); } return cancelled; } @Override protected void done() { if (isCancelled()) { return; } try { JPanel results_panel = new AddResultsPanel( get(), AddResultsPanel.UNLOCK, getView(), getUsername(), getPassword()); panel.addTab(jEdit.getProperty("ips.Unlocked", "Unlocked"), results_panel); } catch (Exception e) { // NOPMD // ignored } } } Runner runner = new Runner(); panel.addWorker("Unlock", runner); runner.execute(); } }
/** Receive notification of the end of an element. */ @Override public void endElement(String uri, String l, String q) { /* * 1. If current element is a String, update its value from the string buffer. * 2. Add the element to parent. */ ElementInfo element = _stack.remove(_stack.size() - 1); _logger.fine("endElement " + element); if (element.type == null) { _logger.warning("Element " + element.name + " not created "); return; } else if (_chars.length() > 0) { try { injectProperty(element.data, String.class, _chars.toString(), null, null); } catch (Exception x) { if (!_lenient) { throw new BeanAssemblyException( "Failed to set characters to object " + element.type.getName(), x); } else { _logger.warning("Failed to set characters to parent " + element.data); } } } _chars.setLength(0); _logger.fine( "<<ElementInfo: " + element.type.getName() + " in " + element + "\n @as is " + element.inst.get("@as") + "\n @id is " + element.inst.get("@id")); if (List.class.isAssignableFrom(element.data.getClass()) && element.name.endsWith("...")) { List<?> list = (List<?>) element.data; Object array = Array.newInstance(element.type, list.size()); for (int i = 0; i < list.size(); ++i) { Array.set(array, i, list.get(i)); } element.data = array; } String id = element.inst.get("@id"); if (id != null) { // locally stored object - not added to the parent _local.put(id, element); } else if (!_stack.isEmpty()) { // inject into the parent as a property ElementInfo parent = _stack.get(_stack.size() - 1); _logger.fine("Parent is " + parent.data.getClass().getName()); try { String as = element.inst.get("@as"); if (as != null) { injectProperty( parent.data, element.type, element.data, Strings.toCamelCase(as, '-', false), element.args.complete()); } else { injectProperty(parent.data, element.type, element.data, null, element.args.complete()); } } catch (Exception x) { if (!_lenient) { throw new BeanAssemblyException( "Failed to set value " + element.data + " to parent " + parent.data, x); } else { _logger.log( Level.WARNING, "Failed to set value " + element.data + " to parent " + parent.data, x); } } } _top = element.data; }
/** * Gets the number of <tt>Candidate</tt>s harvested for {@link #hostCandidate} during this * harvest. * * @return the number of <tt>Candidate</tt>s harvested for {@link #hostCandidate} during this * harvest */ int getCandidateCount() { return candidates.size(); }