Repository: incubator-ranger Updated Branches: refs/heads/master 246d53690 -> d9a661cfe
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/common/util/StrUtils.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/common/util/StrUtils.java b/ranger_solrj/src/main/java/org/apache/solr/common/util/StrUtils.java deleted file mode 100644 index 8ac87d7..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/common/util/StrUtils.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.solr.common.util; - -import java.util.List; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Locale; -import java.io.IOException; - -import org.apache.solr.common.SolrException; - -/** - * - */ -public class StrUtils { - public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', - '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - - /** - * Split a string based on a separator, but don't split if it's inside - * a string. Assume '\' escapes the next char both inside and - * outside strings. - */ - public static List<String> splitSmart(String s, char separator) { - ArrayList<String> lst = new ArrayList<>(4); - int pos=0, start=0, end=s.length(); - char inString=0; - char ch=0; - while (pos < end) { - char prevChar=ch; - ch = s.charAt(pos++); - if (ch=='\\') { // skip escaped chars - pos++; - } else if (inString != 0 && ch==inString) { - inString=0; - } else if (ch=='\'' || ch=='"') { - // If char is directly preceeded by a number or letter - // then don't treat it as the start of a string. - // Examples: 50" TV, or can't - if (!Character.isLetterOrDigit(prevChar)) { - inString=ch; - } - } else if (ch==separator && inString==0) { - lst.add(s.substring(start,pos-1)); - start=pos; - } - } - if (start < end) { - lst.add(s.substring(start,end)); - } - - /*** - if (SolrCore.log.isLoggable(Level.FINEST)) { - SolrCore.log.trace("splitCommand=" + lst); - } - ***/ - - return lst; - } - - /** Splits a backslash escaped string on the separator. - * <p> - * Current backslash escaping supported: - * <br> \n \t \r \b \f are escaped the same as a Java String - * <br> Other characters following a backslash are produced verbatim (\c => c) - * - * @param s the string to split - * @param separator the separator to split on - * @param decode decode backslash escaping - */ - public static List<String> splitSmart(String s, String separator, boolean decode) { - ArrayList<String> lst = new ArrayList<>(2); - StringBuilder sb = new StringBuilder(); - int pos=0, end=s.length(); - while (pos < end) { - if (s.startsWith(separator,pos)) { - if (sb.length() > 0) { - lst.add(sb.toString()); - sb=new StringBuilder(); - } - pos+=separator.length(); - continue; - } - - char ch = s.charAt(pos++); - if (ch=='\\') { - if (!decode) sb.append(ch); - if (pos>=end) break; // ERROR, or let it go? - ch = s.charAt(pos++); - if (decode) { - switch(ch) { - case 'n' : ch='\n'; break; - case 't' : ch='\t'; break; - case 'r' : ch='\r'; break; - case 'b' : ch='\b'; break; - case 'f' : ch='\f'; break; - } - } - } - - sb.append(ch); - } - - if (sb.length() > 0) { - lst.add(sb.toString()); - } - - return lst; - } - - /** - * Splits file names separated by comma character. - * File names can contain comma characters escaped by backslash '\' - * - * @param fileNames the string containing file names - * @return a list of file names with the escaping backslashed removed - */ - public static List<String> splitFileNames(String fileNames) { - if (fileNames == null) - return Collections.<String>emptyList(); - - List<String> result = new ArrayList<>(); - for (String file : fileNames.split("(?<!\\\\),")) { - result.add(file.replaceAll("\\\\(?=,)", "")); - } - - return result; - } - - /** - * Creates a backslash escaped string, joining all the items. - * @see #escapeTextWithSeparator - */ - public static String join(List<?> items, char separator) { - StringBuilder sb = new StringBuilder(items.size() << 3); - boolean first=true; - for (Object o : items) { - String item = o.toString(); - if (first) { - first = false; - } else { - sb.append(separator); - } - appendEscapedTextToBuilder(sb, item, separator); - } - return sb.toString(); - } - - - - public static List<String> splitWS(String s, boolean decode) { - ArrayList<String> lst = new ArrayList<>(2); - StringBuilder sb = new StringBuilder(); - int pos=0, end=s.length(); - while (pos < end) { - char ch = s.charAt(pos++); - if (Character.isWhitespace(ch)) { - if (sb.length() > 0) { - lst.add(sb.toString()); - sb=new StringBuilder(); - } - continue; - } - - if (ch=='\\') { - if (!decode) sb.append(ch); - if (pos>=end) break; // ERROR, or let it go? - ch = s.charAt(pos++); - if (decode) { - switch(ch) { - case 'n' : ch='\n'; break; - case 't' : ch='\t'; break; - case 'r' : ch='\r'; break; - case 'b' : ch='\b'; break; - case 'f' : ch='\f'; break; - } - } - } - - sb.append(ch); - } - - if (sb.length() > 0) { - lst.add(sb.toString()); - } - - return lst; - } - - public static List<String> toLower(List<String> strings) { - ArrayList<String> ret = new ArrayList<>(strings.size()); - for (String str : strings) { - ret.add(str.toLowerCase(Locale.ROOT)); - } - return ret; - } - - - - /** Return if a string starts with '1', 't', or 'T' - * and return false otherwise. - */ - public static boolean parseBoolean(String s) { - char ch = s.length()>0 ? s.charAt(0) : 0; - return (ch=='1' || ch=='t' || ch=='T'); - } - - /** how to transform a String into a boolean... more flexible than - * Boolean.parseBoolean() to enable easier integration with html forms. - */ - public static boolean parseBool(String s) { - if( s != null ) { - if( s.startsWith("true") || s.startsWith("on") || s.startsWith("yes") ) { - return true; - } - if( s.startsWith("false") || s.startsWith("off") || s.equals("no") ) { - return false; - } - } - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "invalid boolean value: "+s ); - } - - /** - * {@link NullPointerException} and {@link SolrException} free version of {@link #parseBool(String)} - * @return parsed boolean value (or def, if s is null or invalid) - */ - public static boolean parseBool(String s, boolean def) { - if( s != null ) { - if( s.startsWith("true") || s.startsWith("on") || s.startsWith("yes") ) { - return true; - } - if( s.startsWith("false") || s.startsWith("off") || s.equals("no") ) { - return false; - } - } - return def; - } - - /** - * URLEncodes a value, replacing only enough chars so that - * the URL may be unambiguously pasted back into a browser. - * <p> - * Characters with a numeric value less than 32 are encoded. - * &,=,%,+,space are encoded. - */ - public static void partialURLEncodeVal(Appendable dest, String val) throws IOException { - for (int i=0; i<val.length(); i++) { - char ch = val.charAt(i); - if (ch < 32) { - dest.append('%'); - if (ch < 0x10) dest.append('0'); - dest.append(Integer.toHexString(ch)); - } else { - switch (ch) { - case ' ': dest.append('+'); break; - case '&': dest.append("%26"); break; - case '%': dest.append("%25"); break; - case '=': dest.append("%3D"); break; - case '+': dest.append("%2B"); break; - default : dest.append(ch); break; - } - } - } - } - - /** - * Creates a new copy of the string with the separator backslash escaped. - * @see #join - */ - public static String escapeTextWithSeparator(String item, char separator) { - StringBuilder sb = new StringBuilder(item.length() * 2); - appendEscapedTextToBuilder(sb, item, separator); - return sb.toString(); - } - - /** - * writes chars from item to out, backslash escaping as needed based on separator -- - * but does not append the seperator itself - */ - public static void appendEscapedTextToBuilder(StringBuilder out, - String item, - char separator) { - for (int i = 0; i < item.length(); i++) { - char ch = item.charAt(i); - if (ch == '\\' || ch == separator) { - out.append('\\'); - } - out.append(ch); - } - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/common/util/URLUtil.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/common/util/URLUtil.java b/ranger_solrj/src/main/java/org/apache/solr/common/util/URLUtil.java deleted file mode 100644 index 6d273ec..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/common/util/URLUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.solr.common.util; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class URLUtil { - - public final static Pattern URL_PREFIX = Pattern.compile("^([a-z]*?://).*"); - - public static String removeScheme(String url) { - Matcher matcher = URL_PREFIX.matcher(url); - if (matcher.matches()) { - return url.substring(matcher.group(1).length()); - } - - return url; - } - - public static boolean hasScheme(String url) { - Matcher matcher = URL_PREFIX.matcher(url); - return matcher.matches(); - } - - public static String getScheme(String url) { - Matcher matcher = URL_PREFIX.matcher(url); - if (matcher.matches()) { - return matcher.group(1); - } - - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/common/util/XML.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/common/util/XML.java b/ranger_solrj/src/main/java/org/apache/solr/common/util/XML.java deleted file mode 100644 index 50a6da2..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/common/util/XML.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.solr.common.util; - -import java.io.Writer; -import java.io.IOException; -import java.util.Map; - -/** - * - */ -public class XML { - - // - // copied from some of my personal code... -YCS - // table created from python script. - // only have to escape quotes in attribute values, and don't really have to escape '>' - // many chars less than 0x20 are *not* valid XML, even when escaped! - // for example, <foo>�<foo> is invalid XML. - private static final String[] chardata_escapes= - {"#0;","#1;","#2;","#3;","#4;","#5;","#6;","#7;","#8;",null,null,"#11;","#12;",null,"#14;","#15;","#16;","#17;","#18;","#19;","#20;","#21;","#22;","#23;","#24;","#25;","#26;","#27;","#28;","#29;","#30;","#31;",null,null,null,null,null,null,"&",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"<",null,">"}; - - private static final String[] attribute_escapes= - {"#0;","#1;","#2;","#3;","#4;","#5;","#6;","#7;","#8;",null,null,"#11;","#12;",null,"#14;","#15;","#16;","#17;","#18;","#19;","#20;","#21;","#22;","#23;","#24;","#25;","#26;","#27;","#28;","#29;","#30;","#31;",null,null,""",null,null,null,"&",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"<"}; - - - - /***************************************** - #Simple python script used to generate the escape table above. -YCS - # - #use individual char arrays or one big char array for better efficiency - # or byte array? - #other={'&':'amp', '<':'lt', '>':'gt', "'":'apos', '"':'quot'} - # - other={'&':'amp', '<':'lt'} - - maxi=ord(max(other.keys()))+1 - table=[None] * maxi - #NOTE: invalid XML chars are "escaped" as #nn; *not* &#nn; because - #a real XML escape would cause many strict XML parsers to choke. - for i in range(0x20): table[i]='#%d;' % i - for i in '\n\r\t ': table[ord(i)]=None - for k,v in other.items(): - table[ord(k)]='&%s;' % v - - result="" - for i in range(maxi): - val=table[i] - if not val: val='null' - else: val='"%s"' % val - result += val + ',' - - print result - ****************************************/ - - -/********* - * - * @throws IOException If there is a low-level I/O error. - */ - public static void escapeCharData(String str, Writer out) throws IOException { - escape(str, out, chardata_escapes); - } - - public static void escapeAttributeValue(String str, Writer out) throws IOException { - escape(str, out, attribute_escapes); - } - - public static void escapeAttributeValue(char [] chars, int start, int length, Writer out) throws IOException { - escape(chars, start, length, out, attribute_escapes); - } - - - public final static void writeXML(Writer out, String tag, String val) throws IOException { - out.write('<'); - out.write(tag); - if (val == null) { - out.write('/'); - out.write('>'); - } else { - out.write('>'); - escapeCharData(val,out); - out.write('<'); - out.write('/'); - out.write(tag); - out.write('>'); - } - } - - /** does NOT escape character data in val, must already be valid XML */ - public final static void writeUnescapedXML(Writer out, String tag, String val, Object... attrs) throws IOException { - out.write('<'); - out.write(tag); - for (int i=0; i<attrs.length; i++) { - out.write(' '); - out.write(attrs[i++].toString()); - out.write('='); - out.write('"'); - out.write(attrs[i].toString()); - out.write('"'); - } - if (val == null) { - out.write('/'); - out.write('>'); - } else { - out.write('>'); - out.write(val); - out.write('<'); - out.write('/'); - out.write(tag); - out.write('>'); - } - } - - /** escapes character data in val */ - public final static void writeXML(Writer out, String tag, String val, Object... attrs) throws IOException { - out.write('<'); - out.write(tag); - for (int i=0; i<attrs.length; i++) { - out.write(' '); - out.write(attrs[i++].toString()); - out.write('='); - out.write('"'); - escapeAttributeValue(attrs[i].toString(), out); - out.write('"'); - } - if (val == null) { - out.write('/'); - out.write('>'); - } else { - out.write('>'); - escapeCharData(val,out); - out.write('<'); - out.write('/'); - out.write(tag); - out.write('>'); - } - } - - /** escapes character data in val */ - public static void writeXML(Writer out, String tag, String val, Map<String, String> attrs) throws IOException { - out.write('<'); - out.write(tag); - for (Map.Entry<String, String> entry : attrs.entrySet()) { - out.write(' '); - out.write(entry.getKey()); - out.write('='); - out.write('"'); - escapeAttributeValue(entry.getValue(), out); - out.write('"'); - } - if (val == null) { - out.write('/'); - out.write('>'); - } else { - out.write('>'); - escapeCharData(val,out); - out.write('<'); - out.write('/'); - out.write(tag); - out.write('>'); - } - } - - private static void escape(char [] chars, int offset, int length, Writer out, String [] escapes) throws IOException{ - for (int i=offset; i<length; i++) { - char ch = chars[i]; - if (ch<escapes.length) { - String replacement = escapes[ch]; - if (replacement != null) { - out.write(replacement); - continue; - } - } - out.write(ch); - } - } - - private static void escape(String str, Writer out, String[] escapes) throws IOException { - for (int i=0; i<str.length(); i++) { - char ch = str.charAt(i); - if (ch<escapes.length) { - String replacement = escapes[ch]; - if (replacement != null) { - out.write(replacement); - continue; - } - } - out.write(ch); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/common/util/XMLErrorLogger.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/common/util/XMLErrorLogger.java b/ranger_solrj/src/main/java/org/apache/solr/common/util/XMLErrorLogger.java deleted file mode 100644 index 7f45ff9..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/common/util/XMLErrorLogger.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.solr.common.util; - -import org.slf4j.Logger; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.TransformerException; -import javax.xml.stream.Location; -import javax.xml.stream.XMLReporter; - -public final class XMLErrorLogger implements ErrorHandler,ErrorListener,XMLReporter { - - private final Logger log; - - public XMLErrorLogger(Logger log) { - this.log = log; - } - - // ErrorHandler - - @Override - public void warning(SAXParseException e) { - log.warn("XML parse warning in \""+e.getSystemId()+"\", line "+e.getLineNumber()+", column "+e.getColumnNumber()+": "+e.getMessage()); - } - - @Override - public void error(SAXParseException e) throws SAXException { - throw e; - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } - - // ErrorListener - - @Override - public void warning(TransformerException e) { - log.warn(e.getMessageAndLocation()); - } - - @Override - public void error(TransformerException e) throws TransformerException { - throw e; - } - - @Override - public void fatalError(TransformerException e) throws TransformerException { - throw e; - } - - // XMLReporter - - @Override - public void report(String message, String errorType, Object relatedInformation, Location loc) { - final StringBuilder sb = new StringBuilder("XML parser reported ").append(errorType); - if (loc != null) { - sb.append(" in \"").append(loc.getSystemId()).append("\", line ") - .append(loc.getLineNumber()).append(", column ").append(loc.getColumnNumber()); - } - log.warn(sb.append(": ").append(message).toString()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/common/util/package-info.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/common/util/package-info.java b/ranger_solrj/src/main/java/org/apache/solr/common/util/package-info.java deleted file mode 100644 index 1da825f..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/common/util/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Common utility classes reused on both clients & server. - */ -package org.apache.solr.common.util; - - http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/overview.html ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/overview.html b/ranger_solrj/src/main/java/overview.html deleted file mode 100644 index 7a534ed..0000000 --- a/ranger_solrj/src/main/java/overview.html +++ /dev/null @@ -1,21 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<html> -<body> -Apache Solr Search Server: Solr-j -</body> -</html>
