use of java.util.StringTokenizer in project sonarqube by SonarSource.
the class ValidatorPlugIn method initResources.
/**
* Initialize the validator resources for this module.
*
* @throws IOException if an input/output error is encountered
* @throws ServletException if we cannot initialize these resources
*/
protected void initResources() throws IOException, ServletException {
if ((pathnames == null) || (pathnames.length() <= 0)) {
return;
}
StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);
List urlList = new ArrayList();
try {
while (st.hasMoreTokens()) {
String validatorRules = st.nextToken().trim();
if (log.isInfoEnabled()) {
log.info("Loading validation rules file from '" + validatorRules + "'");
}
URL input = servlet.getServletContext().getResource(validatorRules);
// loader which allows the config files to be stored in a jar
if (input == null) {
input = getClass().getResource(validatorRules);
}
if (input != null) {
urlList.add(input);
} else {
throw new ServletException("Skipping validation rules file from '" + validatorRules + "'. No url could be located.");
}
}
int urlSize = urlList.size();
URL[] urlArray = new URL[urlSize];
for (int urlIndex = 0; urlIndex < urlSize; urlIndex++) {
urlArray[urlIndex] = (URL) urlList.get(urlIndex);
}
this.resources = new ValidatorResources(urlArray);
} catch (SAXException sex) {
log.error("Skipping all validation", sex);
throw new ServletException(sex);
}
}
use of java.util.StringTokenizer in project sonarqube by SonarSource.
the class PresentTag method condition.
/**
* Evaluate the condition that is being tested by this particular tag, and
* return <code>true</code> if the nested body content of this tag should
* be evaluated, or <code>false</code> if it should be skipped. This
* method must be implemented by concrete subclasses.
*
* @param desired Desired outcome for a true result
* @throws JspException if a JSP exception occurs
*/
protected boolean condition(boolean desired) throws JspException {
// Evaluate the presence of the specified value
boolean present = false;
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
if (cookie != null) {
present = this.isCookiePresent(request);
} else if (header != null) {
String value = request.getHeader(header);
present = (value != null);
} else if (name != null) {
present = this.isBeanPresent();
} else if (parameter != null) {
String value = request.getParameter(parameter);
present = (value != null);
} else if (role != null) {
StringTokenizer st = new StringTokenizer(role, ROLE_DELIMITER, false);
while (!present && st.hasMoreTokens()) {
present = request.isUserInRole(st.nextToken());
}
} else if (user != null) {
Principal principal = request.getUserPrincipal();
present = (principal != null) && user.equals(principal.getName());
} else {
JspException e = new JspException(messages.getMessage("logic.selector"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
return (present == desired);
}
use of java.util.StringTokenizer in project sonarqube by SonarSource.
the class NestedPropertyHelper method calculateRelativeProperty.
/* This property, providing the property to be appended, and the parent tag
* to append the property to, will calculate the stepping of the property
* and return the qualified nested property
*
* @param property the property which is to be appended nesting style
* @param parent the "dot notated" string representing the structure
* @return qualified nested property that the property param is to the parent
*/
private static String calculateRelativeProperty(String property, String parent) {
if (parent == null) {
parent = "";
}
if (property == null) {
property = "";
}
/* Special case... reference my parent's nested property.
Otherwise impossible for things like indexed properties */
if ("./".equals(property) || "this/".equals(property)) {
return parent;
}
/* remove the stepping from the property */
String stepping;
/* isolate a parent reference */
if (property.endsWith("/")) {
stepping = property;
property = "";
} else {
stepping = property.substring(0, property.lastIndexOf('/') + 1);
/* isolate the property */
property = property.substring(property.lastIndexOf('/') + 1, property.length());
}
if (stepping.startsWith("/")) {
/* return from root */
return property;
} else {
/* tokenize the nested property */
StringTokenizer proT = new StringTokenizer(parent, ".");
int propCount = proT.countTokens();
/* tokenize the stepping */
StringTokenizer strT = new StringTokenizer(stepping, "/");
int count = strT.countTokens();
if (count >= propCount) {
/* return from root */
return property;
} else {
/* append the tokens up to the token difference */
count = propCount - count;
StringBuffer result = new StringBuffer();
for (int i = 0; i < count; i++) {
result.append(proT.nextToken());
result.append('.');
}
result.append(property);
/* parent reference will have a dot on the end. Leave it off */
if (result.charAt(result.length() - 1) == '.') {
return result.substring(0, result.length() - 1);
} else {
return result.toString();
}
}
}
}
use of java.util.StringTokenizer in project sonarqube by SonarSource.
the class JavascriptValidatorTag method escapeQuotes.
private String escapeQuotes(String in) {
if ((in == null) || (in.indexOf("\"") == -1)) {
return in;
}
StringBuffer buffer = new StringBuffer();
StringTokenizer tokenizer = new StringTokenizer(in, "\"", true);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (token.equals("\"")) {
buffer.append("\\");
}
buffer.append(token);
}
return buffer.toString();
}
use of java.util.StringTokenizer in project android_frameworks_base by ParanoidAndroid.
the class NetworkManagementService method getInterfaceConfig.
@Override
public InterfaceConfiguration getInterfaceConfig(String iface) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
final NativeDaemonEvent event;
try {
event = mConnector.execute("interface", "getcfg", iface);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
}
event.checkCode(InterfaceGetCfgResult);
// Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
final StringTokenizer st = new StringTokenizer(event.getMessage());
InterfaceConfiguration cfg;
try {
cfg = new InterfaceConfiguration();
cfg.setHardwareAddress(st.nextToken(" "));
InetAddress addr = null;
int prefixLength = 0;
try {
addr = NetworkUtils.numericToInetAddress(st.nextToken());
} catch (IllegalArgumentException iae) {
Slog.e(TAG, "Failed to parse ipaddr", iae);
}
try {
prefixLength = Integer.parseInt(st.nextToken());
} catch (NumberFormatException nfe) {
Slog.e(TAG, "Failed to parse prefixLength", nfe);
}
cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
while (st.hasMoreTokens()) {
cfg.setFlag(st.nextToken());
}
} catch (NoSuchElementException nsee) {
throw new IllegalStateException("Invalid response from daemon: " + event);
}
return cfg;
}
Aggregations