⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accreditgroupmodel.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			// get the list of all aliases
			String aliasesString = (String) masterUser.elementAt(this.ALIASES);

			// remove the selected alias
			String newAliases = removeAliasFromList((String) alias
					.elementAt(this.GROUP_NAME), aliasesString);

			// save the new list of aliases
			masterUser.setElementAt(newAliases, this.ALIASES);

			// write back the the user file with the new alias list
			writeBackGroupAt(masterIndex, false, false); // aliases should not
			// affect cpl and cl
		}

		// always delete the alias from the server, even if the master was not
		// found

		// delete the alias file from the server
		psInterface.deleteAliasFile((String) alias.elementAt(this.GROUP_NAME));

		// now update the vector of all user and all aliases stored in this
		// table
		// to not include the deleted alias
		aliases.remove(alias);

		return true;
	}

	private boolean deleteUser(Vector user) throws VPPNoSuchFileException {

		// delete the user xml file from the server
		psInterface.deleteUser((String) user.elementAt(this.GROUP_NAME));

		// now delete all the alias files as well
		String aliasStr = (String) user.elementAt(this.ALIASES);
		StringTokenizer tokenizer = new StringTokenizer(aliasStr, ";");
		String alias;

		while (tokenizer.hasMoreTokens()) {
			alias = tokenizer.nextToken();

			try {
				psInterface.deleteAliasFile(alias);
			} catch (VPPNoSuchFileException ex) {

				// This should never really happen. It means the data on the
				// server is
				// corrupted or inconsistent. But just in case it happens ....
				ex.printStackTrace();
				JOptionPane
						.showMessageDialog(
								null,
								"The alias "
										+ alias
										+ " for this user file does not exist.\n\nYour user data is probably corrupted.",
								"ERROR", JOptionPane.ERROR_MESSAGE);
			}

			// Even if the alias file did not really exist on the server, for
			// some
			// strange reason, it may still be in the vector of all aliases.
			// It should be removed in that case (and in the regular case).

			// delete the alias from the vector of all aliases
			for (int i = 0; i < aliases.size(); i++) {
				Vector aliasVector = (Vector) aliases.elementAt(i);

				if (aliasVector.elementAt(GROUP_NAME).equals(alias)) {
					aliases.remove(aliasVector);

					if (data.contains(aliasVector)) {
						data.remove(aliasVector);
					}

					break;
				}
			}
		}

		return true;
	}

	public boolean aliasExists(String alias) {
		try {
			psInterface.getAliasNamed(alias);
		} catch (VPPNoSuchFileException e) {
			return false;
		}

		return true;
	}

	public boolean groupExists(String groupName) {
		Document doc;

		try {
			doc = psInterface.getGroupNamed(groupName);
		} catch (VPPNoSuchFileException e) {
			return false;
		} catch (IOException e) {

			// the file could not be read but probably does not necessarily mean
			// it
			// does not exist. Ummmm ... say it doesn't exist anyway
			return false;
		} catch (SAXException e) {

			// the file exists but could not be parsed. If its corrupted, say it
			// doesn't exist
			return false;
		} catch (VPPException ex) {
			return false;
		}

		if (doc == null) {
			return false;
		}

		return true;
	}

	public static String removeAliasFromList(String alias, String list) {
		int index = list.indexOf(alias); // position where alias starts

		if (index != -1) {
			String newList;

			newList = list.substring(0, index)
					+ list.substring(index + alias.length() + 1);
			list = newList;
		}

		return list;
	}

	

	public void writeBackGroupAt(int row, boolean generateCpl, boolean generateCl)
			throws NoSuchNodeException, NotTextNodeException, SAXException,
			IOException {
		Exception error = null;

		// If the user data loaded from the server did not contain an entry for
		// the
		// caller id blocking group, this contacts the provisioning server,
		// determines the list of all known caller id blocking groups and
		// defaults the value for this user to the first group on the list.
		try {
			if (getValueAt(row, this.CALLER_ID_BLOCKING_GROUP).equals(
					"not loaded from xml")) {
				String[] groups = psInterface
						.getFeatureGroups("CallerIdBlocking");

				if (groups != null) {
					if (groups.length > 0) {
						setValueAt(groups[0], row, CALLER_ID_BLOCKING_GROUP);
					}
				}
			}
		} catch (Exception e) {

			// quietly suppress this exception
			e.printStackTrace();
		}

		String groupName = (String) getValueAt(row, GROUP_NAME);

		// generate the alias files in the Aliases directory
		

		

		Document doc = convertUserAtToDocument(row);

		if (generateCpl) {
			CplGenerator cplGen = new CplGenerator(psInterface.getConnection());
			String cpl = "";

			if (getValueAt(row, this.FORWARD_ALL_USER_SET).equals("ON")) {
				System.out.println("---TRACE---cfa set by user");
				System.out
						.println("---TRACE---Building cpl for cfa with destination="
								+ getValueAt(row, FORWARD_ALL_DESTINATION));

				try {
					cpl = cplGen.buildCfaXML((String) getValueAt(row,
							FORWARD_ALL_DESTINATION));

					writeCpl((String) getValueAt(row, FORWARD_ALL_GROUP),
							(String) getValueAt(row, GROUP_NAME), cpl);
				} catch (Exception ex) {

					// catch the exception, save it and throw it only once an
					// attempt
					// has been made to generate each of the cpl scripts
					error = ex;
				}
			}

			// call return
			System.out.println("---TRACE--- generating call return cpl");

			// the setfeat sould have been set to on in the
			// convertUserToDocument function
			if (getValueAt(row, this.CALL_RETURN_ADMIN_ENABLED).equals("true")) {
				String calledCpl = cplGen.buildCallReturnUserXML();

				String callingCpl = cplGen.buildCallReturnUserCallingXML();

				writeCallingAndCalledCpls((String) getValueAt(row,
						this.CALL_RETURN_GROUP), (String) getValueAt(row,
						this.GROUP_NAME), callingCpl, calledCpl);
			}

			// caller id blocking
			System.out.println("---TRACE--- generating caller id blocking cpl");

			if (getValueAt(row, this.CALLER_ID_BLOCKING_USER_SET).equals("ON")) {

				// only write cpl if feature is set on
				cpl = cplGen.buildCallerIdBlockingXML();

				writeCpl(
						(String) getValueAt(row, this.CALLER_ID_BLOCKING_GROUP),
						(String) getValueAt(row, this.GROUP_NAME), cpl);
			}

			// generate call blocking cpl
			boolean block900 = false;
			boolean blockLongDist = false;

			if (getValueAt(row, BLOCK_900_ADMIN_ENABLED).equals("true")) {
				System.out.println("---TRACE---900 calls blocked by admin");

				block900 = true;
			} else {
				if (getValueAt(row, BLOCK_900_USER_SET).equals("true")) {
					System.out.println("---TRACE---900 calls blocked by user");

					block900 = true;
				}
			}

			if (getValueAt(row, BLOCK_LONG_DISTANCE_ADMIN_ENABLED).equals(
					"true")) {
				System.out
						.println("---TRACE---long distance calls blocked by admin");

				blockLongDist = true;
			} else {
				if (getValueAt(row, BLOCK_LONG_DISTANCE_USER_SET)
						.equals("true")) {
					System.out
							.println("---TRACE---long distance calls blocked by user");

					blockLongDist = true;
				}
			}

			if (block900 || blockLongDist) {
				System.out.println("Building cpl for clbl with block900="
						+ block900 + " and blockLongDist=" + blockLongDist);

				try {
					cpl = cplGen.buildClblXML(block900, blockLongDist,
							(String) getValueAt(row,
									AccreditGroupModel.CALL_BLOCK_PREFIX));

					writeCpl((String) getValueAt(row, CALL_BLOCK_GROUP),
							(String) getValueAt(row, GROUP_NAME), cpl);
				} catch (Exception ex) {
					error = ex;
				}
			}

			// generate call screening cpl
			// The setfeat field for this feature is not actually in the vector
			// used
			// to display the table. So we need to get it from the dom which was
			// created

			NodeList css = dom.getElementsByTagName("cs");

			if (css.getLength() > 0) {
				Element cs = (Element) css.item(0);
				NodeList setfeats = cs.getElementsByTagName("setfeat");

				if (setfeats.getLength() > 0) {
					Element setfeat = (Element) setfeats.item(0);

					if (setfeat.hasChildNodes()) {
						if (setfeat.getFirstChild().getNodeValue().equals("ON")) {
							System.out.println("Building cpl for cs");

							try {
								cpl = cplGen
										.buildCsXML(convertUserAtToDocument(row));

								writeCpl((String) getValueAt(row,
										CALL_SCREEN_GROUP),
										(String) getValueAt(row, GROUP_NAME),
										cpl);
							} catch (Exception ex) {
								error = ex;
							}
						}
					}
				}
			}

			boolean fna = false;

			if (getValueAt(row, this.FORWARD_UNANSWERED_USER_SET)
					.equals("true")) {
				System.out.println("---TRACE---forward no answer set by user");

				fna = true;
			}

			boolean fb = false;

			if (getValueAt(row, this.FORWARD_BUSY_USER_SET).equals("true")) {
				System.out.println("---TRACE---forward busy set by user");

				fb = true;
			}

			if (fna || fb) {

				// write forward no answer, blocking cpl
				String fnaDestination = (String) getValueAt(row,
						this.FORWARD_UNANSWERED_DESTINATION);
				String fbDestination = (String) getValueAt(row,
						this.FORWARD_BUSY_DESTINATION);
				String failureCause = (String) getValueAt(row,
						this.FAILURE_CASE);

				System.out.println("Building cpl for fnab with username="
						+ groupName + ", fna=" + fna + ", fnaDestination="
						+ fnaDestination + ", fb=" + fb + ", fbDestination= "
						+ fbDestination + "failureCause=" + failureCause);

				try {
					cpl = cplGen.buildFnabXML(groupName, fna, fnaDestination,
							fb, fbDestination, failureCause);

					writeCpl((String) getValueAt(row, this.FORWARD_BUSY_GROUP),
							(String) getValueAt(row, GROUP_NAME), cpl);
				} catch (Exception ex) {
					error = ex;
				}
			}
		} // end if generate cpl

		
		// write back the group xml
		psInterface.saveGroup(groupName, doc);

		if (error != null) {
			if (NoSuchNodeException.class.isInstance(error)) {
				throw (NoSuchNodeException) error;
			} else if (NotTextNodeException.class.isInstance(error)) {
				throw (NotTextNodeException) error;
			} else if (SAXException.class.isInstance(error)) {
				throw (SAXException) error;
			} else if (IOException.class.isInstance(error)) {
				throw (IOException) error;
			}
		}
	}

	private void writeCpl(String group, String userName, String cpl) {
		String[] paths = cplGen.getAddressArray(group);

		if (paths == null) {
			System.out
					.println("---ERROR--- Could not get cpl destination paths for group "
							+ group
							+ "\n---ERROR--- Probably, the group does not exist in the ListOfFeatureServers"
							+ "\n---ERROR--- Or there is no server configured for this feature.");

			return;
		}

		String filename = userName + ".cpl";
		String filegroup;

		for (int i = 1; i < paths.length; i++) {
			filegroup = paths[i];

			psInterface.put(filegroup, filename, cpl);
		}
	}

	/**
	 * Write a user's calling and called CPL scripts of a Feature Group. For
	 * now, we assume the feature is a called feature, so we need to substitue
	 * "called" with "calling" in the file path when we write the calling CPL.
	 */
	private void writeCallingAndCalledCpls(String group, String userName,
			String callingCpl, String calledCpl) {
		String[] calledPaths = cplGen.getAddressArray(group);

		if (calledPaths == null) {
			System.out

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -