private void traverseToLeaves( final PackageDependenciesNode treeNode, final StringBuffer denyRules, final StringBuffer allowRules) { final Enumeration enumeration = treeNode.breadthFirstEnumeration(); while (enumeration.hasMoreElements()) { PsiElement childPsiElement = ((PackageDependenciesNode) enumeration.nextElement()).getPsiElement(); if (myIllegalDependencies.containsKey(childPsiElement)) { final Map<DependencyRule, Set<PsiFile>> illegalDeps = myIllegalDependencies.get(childPsiElement); for (final DependencyRule rule : illegalDeps.keySet()) { if (rule.isDenyRule()) { if (denyRules.indexOf(rule.getDisplayText()) == -1) { denyRules.append(rule.getDisplayText()); denyRules.append("\n"); } } else { if (allowRules.indexOf(rule.getDisplayText()) == -1) { allowRules.append(rule.getDisplayText()); allowRules.append("\n"); } } } } } }
String replaceTimestamp(String strLine) { if (timestamp == null) return strLine; // no timestamp was specified at constructor. if (strLine.contains(TIMESTAMP_TAG) && tsIndex < ts.size()) { // ts is timestamp array, each next timestamp gets next value StringBuffer sb = new StringBuffer(strLine); String tsStr = ts.get(tsIndex++); int p1 = sb.indexOf("value=\"") + 7; int p2 = sb.indexOf("\"", p1); String strLine2 = sb.replace(p1, p2, "0x" + tsStr).toString(); System.out.println(">>> replaced Event-Timestamp : " + strLine + " => " + strLine2); return strLine2; } return strLine; // default }
// Serialize the bean using the specified namespace prefix & uri public String serialize(Object bean) throws IntrospectionException, IllegalAccessException { // Use the class name as the name of the root element String className = bean.getClass().getName(); String rootElementName = null; if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) { AnnotatedElement annotatedElement = bean.getClass(); ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class); rootElementName = aliasAnnotation.value(); } // Use the package name as the namespace URI Package pkg = bean.getClass().getPackage(); nsURI = pkg.getName(); // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array) className = StringUtils.deleteTrailingChar(className, ';'); StringBuffer sb = new StringBuffer(className); String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString(); domDocument = createDomDocument(objectName); document = domDocument.getDocument(); Element root = document.getDocumentElement(); // Parse the bean elements getBeanElements(root, rootElementName, className, bean); StringBuffer xml = new StringBuffer(); if (prettyPrint) xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog)); else xml.append(domDocument.serialize(includeXmlProlog)); if (!includeTypeInfo) { int index = xml.indexOf(root.getNodeName()); xml.delete(index - 1, index + root.getNodeName().length() + 2); xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length()); } return xml.toString(); }
/** * Given a string, replace all occurraces of 'newStr' with 'oldStr'. * * @param originalStr the string to modify. * @param oldStr the string to replace. * @param newStr the string to insert in place of the old string. */ public static String replaceText(String originalStr, String oldStr, String newStr) { if (oldStr == null || newStr == null || oldStr.equals(newStr)) { return originalStr; } StringBuffer result = new StringBuffer(originalStr); int startIndex = 0; while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) { result = result.replace(startIndex, startIndex + oldStr.length(), newStr); startIndex += newStr.length(); } return result.toString(); }
/** * Given a string, replace all tabs with the appropriate number of spaces. * * @param tabLength the length of each tab. * @param s the String to scan. */ public static void replaceTabs(int tabLength, StringBuffer s) { int index, col; StringBuffer whitespace; while ((index = s.indexOf("\t")) != -1) { whitespace = new StringBuffer(); col = index; do { whitespace.append(" "); col++; } while ((col % tabLength) != 0); s.replace(index, index + 1, whitespace.toString()); } }
String replaceCounterdef(String strLine) { final String COUNTERDEF_TAG = "<counterdef"; if (strLine.contains( COUNTERDEF_TAG)) { // ts is timestamp array, each next timestamp gets next value StringBuffer sb = new StringBuffer(strLine); int p1 = sb.indexOf("init=\"") + 6; int p2 = sb.indexOf("\">", p1); if (p1 > 0 && p2 > 0) { String strLine2 = sb.replace(p1, p2, counterdefInitValue).toString(); System.out.println(">>> replaced counterdef init : " + strLine + " => " + strLine2); // strLine = strLine2; return strLine2; } } return strLine; }
public int indexOf(String tag) { return m_template.indexOf(tag); }
/* PROTECTED METHODS */ protected void getBeanElements( Element parentElement, String objectName, String objectType, Object bean) throws IntrospectionException, IllegalAccessException { if (objectName == null) { // Get just the class name by lopping off the package name StringBuffer sb = new StringBuffer(bean.getClass().getName()); sb.delete(0, sb.lastIndexOf(".") + 1); objectName = sb.toString(); } // Check if the bean is a standard Java object type or a byte[] (encoded as a base 64 array) Element element = getStandardObjectElement(document, bean, objectName); // If the body element object is null then the bean is not a standard Java object type if (element != null) { if (includeNullValues || !element .getAttribute( NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + org.apache.axis.Constants.ATTR_TYPE) .equals("anyType")) { if (!includeTypeInfo) { element.removeAttribute( NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + org.apache.axis.Constants.ATTR_TYPE); element.removeAttribute(NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null"); } parentElement.appendChild(element); } } else { // Analyze the bean Class classOfBean = null; if (bean != null) classOfBean = bean.getClass(); // If the object is an array, then serialize each of the beans in the array. if ((classOfBean != null) && (classOfBean.isArray())) { String[] arrayInfo = getXsdSoapArrayInfo(classOfBean.getCanonicalName(), nsPrefix); int arrayLen = Array.getLength(bean); StringBuffer arrayType = new StringBuffer(arrayInfo[1]); arrayType.insert(arrayType.indexOf("[]") + 1, arrayLen); if (objectName.charAt(objectName.length() - 1) == ';') objectName = new StringBuffer(objectName).deleteCharAt(objectName.length() - 1).toString(); element = document.createElement(objectName); parentElement.appendChild(element); // Get the bean objects from the array and serialize each for (int i = 0; i < arrayLen; i++) { Object b = Array.get(bean, i); if (b != null) { String name = null; if (objectName.charAt(objectName.length() - 1) == 's') { name = formatName(objectName.substring(0, objectName.length() - 1)); } getBeanElements(element, name, b.getClass().getName(), b); } else { // Array element is null, so don't include it and decrement the # elements in the array int index = arrayType.indexOf("["); arrayType.replace(index + 1, index + 2, String.valueOf(--arrayLen)); } if (includeTypeInfo) { element.setAttributeNS( NamespaceConstants.NSURI_SCHEMA_XSI, NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE, NamespaceConstants.NSPREFIX_SOAP_ENCODING + ":Array"); element.setAttributeNS( NamespaceConstants.NSURI_SOAP_ENCODING, NamespaceConstants.NSPREFIX_SOAP_ENCODING + ":" + Constants.ATTR_ARRAY_TYPE, arrayInfo[0] + ":" + arrayType.toString()); } } } else { int beanType = 0; String beanName = null; if (classOfBean != null) { if (classOfBean == Vector.class) { beanType = 1; beanName = "Vector"; } else if (classOfBean == ArrayList.class) { beanType = 2; beanName = "ArrayList"; } else if (classOfBean == LinkedList.class) { beanType = 3; beanName = "LinkedList"; } else if (classOfBean == Hashtable.class) { beanType = 4; beanName = "Hashtable"; } else if (classOfBean == Properties.class) { beanType = 5; beanName = "Properties"; } else if ((classOfBean == HashMap.class) || (classOfBean == SortedMap.class)) { beanType = 6; beanName = "Map"; } } if (beanType > 0) { String prefix = null; if ((beanType == 1) || (beanType == 5)) prefix = NamespaceConstants.NSPREFIX_SOAP_ENCODING; if (beanType == 6) prefix = Constants.NS_PREFIX_XMLSOAP; else prefix = DEFAULT_NS_PREFIX; element = document.createElement(objectName); if (includeTypeInfo) { element.setAttributeNS( NamespaceConstants.NSURI_SCHEMA_XSI, NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE, prefix + ":" + beanName); if (bean == null) element.setAttributeNS( NamespaceConstants.NSURI_SCHEMA_XSI, NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null", "true"); } parentElement.appendChild(element); if ((beanType >= 1) && (beanType <= 3)) { AbstractCollection collection = (AbstractCollection) bean; // Get the bean objects from the vector and serialize each Iterator it = collection.iterator(); while (it.hasNext()) { Object b = it.next(); String name = null; if (b != null) { if (objectName.charAt(objectName.length() - 1) == 's') { name = formatName(objectName.substring(0, objectName.length() - 1)); } else name = "item"; } getBeanElements(element, name, b.getClass().getName(), b); } } else if ((beanType == 4) || (beanType == 5)) { Hashtable hashtable = (Hashtable) bean; // Get the bean objects from the hashtable or properties and serialize each Enumeration en = hashtable.keys(); while (en.hasMoreElements()) { Object key = en.nextElement(); String keyClassName = key.getClass().getName(); Object value = hashtable.get(key); String beanClassName = null; if (value != null) beanClassName = value.getClass().getName(); Element itemElement = document.createElement("item"); element.appendChild(itemElement); getBeanElements(itemElement, "key", keyClassName, key); getBeanElements(itemElement, "value", beanClassName, value); } } else if (beanType == 6) { Map map = null; if (classOfBean == HashMap.class) map = (HashMap) bean; else if (classOfBean == SortedMap.class) map = (SortedMap) bean; // Get the bean objects from the hashmap and serialize each Set set = map.keySet(); Iterator it = set.iterator(); while (it.hasNext()) { Object key = it.next(); String keyClassName = key.getClass().getName(); Object value = map.get(key); String beanClassName = null; if (value != null) beanClassName = value.getClass().getName(); Element itemElement = document.createElement("item"); element.appendChild(itemElement); getBeanElements(itemElement, "key", keyClassName, key); getBeanElements(itemElement, "value", beanClassName, value); } } } else { // Create a parent element for this bean's properties if (objectName.charAt(objectName.length() - 1) == ';') objectName = new StringBuffer(objectName).deleteCharAt(objectName.length() - 1).toString(); objectName = formatName(objectName); element = document.createElement(objectName); parentElement.appendChild(element); if (includeTypeInfo) { StringBuffer className = new StringBuffer(objectType); element.setAttributeNS( NamespaceConstants.NSURI_SCHEMA_XSI, NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE, nsPrefix + ":" + className.delete(0, className.lastIndexOf(".") + 1).toString()); } if (classOfBean != null) { // Get an array of property descriptors BeanInfo bi = Introspector.getBeanInfo(classOfBean); PropertyDescriptor[] pds = bi.getPropertyDescriptors(); // For each property of the bean, get a SOAPBodyElement that // represents the individual property. Append that SOAPBodyElement // to the class name element of the SOAP body. for (int i = 0; i < pds.length; i++) { PropertyDescriptor pd = pds[i]; getBeanElementProperties(element, bean, pd); } } else { if (includeTypeInfo) element.setAttributeNS( NamespaceConstants.NSURI_SCHEMA_XSI, NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null", "true"); } } } } }
public boolean searchAndReplace( @NotNull Editor editor, @NotNull LineRange range, @NotNull String excmd, String exarg) { boolean res = true; // Explicitly exit visual mode here, so that visual mode marks don't change when we move the // cursor to a match. if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) { VimPlugin.getMotion().exitVisual(editor); } CharPointer cmd = new CharPointer(new StringBuffer(exarg)); // sub_nsubs = 0; // sub_nlines = 0; int which_pat; if (excmd.equals("~")) { which_pat = RE_LAST; /* use last used regexp */ } else { which_pat = RE_SUBST; /* use last substitute regexp */ } CharPointer pat; CharPointer sub; char delimiter; /* new pattern and substitution */ if (excmd.charAt(0) == 's' && !cmd.isNul() && !Character.isWhitespace(cmd.charAt()) && "0123456789cegriIp|\"".indexOf(cmd.charAt()) == -1) { /* don't accept alphanumeric for separator */ if (CharacterClasses.isAlpha(cmd.charAt())) { VimPlugin.showMessage(MessageHelper.message(Msg.E146)); return false; } /* * undocumented vi feature: * "\/sub/" and "\?sub?" use last used search pattern (almost like * //sub/r). "\&sub&" use last substitute pattern (like //sub/). */ if (cmd.charAt() == '\\') { cmd.inc(); if ("/?&".indexOf(cmd.charAt()) == -1) { VimPlugin.showMessage(MessageHelper.message(Msg.e_backslash)); return false; } if (cmd.charAt() != '&') { which_pat = RE_SEARCH; /* use last '/' pattern */ } pat = new CharPointer(""); /* empty search pattern */ delimiter = cmd.charAt(); /* remember delimiter character */ cmd.inc(); } else /* find the end of the regexp */ { which_pat = RE_LAST; /* use last used regexp */ delimiter = cmd.charAt(); /* remember delimiter character */ cmd.inc(); pat = cmd.ref(0); /* remember start of search pat */ cmd = RegExp.skip_regexp(cmd, delimiter, true); if (cmd.charAt() == delimiter) /* end delimiter found */ { cmd.set('\u0000').inc(); /* replace it with a NUL */ } } /* * Small incompatibility: vi sees '\n' as end of the command, but in * Vim we want to use '\n' to find/substitute a NUL. */ sub = cmd.ref(0); /* remember the start of the substitution */ while (!cmd.isNul()) { if (cmd.charAt() == delimiter) /* end delimiter found */ { cmd.set('\u0000').inc(); /* replace it with a NUL */ break; } if (cmd.charAt(0) == '\\' && cmd.charAt(1) != 0) /* skip escaped characters */ { cmd.inc(); } cmd.inc(); } } else /* use previous pattern and substitution */ { if (lastReplace == null) /* there is no previous command */ { VimPlugin.showMessage(MessageHelper.message(Msg.e_nopresub)); return false; } pat = null; /* search_regcomp() will use previous pattern */ sub = new CharPointer(lastReplace); } /* * Find trailing options. When '&' is used, keep old options. */ if (cmd.charAt() == '&') { cmd.inc(); } else { do_all = Options.getInstance().isSet("gdefault"); do_ask = false; do_error = true; // do_print = false; do_ic = 0; } while (!cmd.isNul()) { /* * Note that 'g' and 'c' are always inverted, also when p_ed is off. * 'r' is never inverted. */ if (cmd.charAt() == 'g') { do_all = !do_all; } else if (cmd.charAt() == 'c') { do_ask = !do_ask; } else if (cmd.charAt() == 'e') { do_error = !do_error; } else if (cmd.charAt() == 'r') /* use last used regexp */ { which_pat = RE_LAST; } else if (cmd.charAt() == 'i') /* ignore case */ { do_ic = 'i'; } else if (cmd.charAt() == 'I') /* don't ignore case */ { do_ic = 'I'; } else if (cmd.charAt() != 'p') { break; } cmd.inc(); } int line1 = range.getStartLine(); int line2 = range.getEndLine(); /* * check for a trailing count */ cmd = CharHelper.skipwhite(cmd); if (CharacterClasses.isDigit(cmd.charAt())) { int i = CharHelper.getdigits(cmd); if (i <= 0 && do_error) { VimPlugin.showMessage(MessageHelper.message(Msg.e_zerocount)); return false; } line1 = line2; line2 = EditorHelper.normalizeLine(editor, line1 + i - 1); } /* * check for trailing command or garbage */ cmd = CharHelper.skipwhite(cmd); if (!cmd.isNul() && cmd.charAt() != '"') /* if not end-of-line or comment */ { VimPlugin.showMessage(MessageHelper.message(Msg.e_trailing)); return false; } String pattern = ""; if (pat == null || pat.isNul()) { switch (which_pat) { case RE_LAST: pattern = lastPattern; break; case RE_SEARCH: pattern = lastSearch; break; case RE_SUBST: pattern = lastSubstitute; break; } } else { pattern = pat.toString(); } lastSubstitute = pattern; if (pattern != null) { setLastPattern(editor, pattern); } // int start = editor.logicalPositionToOffset(new LogicalPosition(line1, 0)); // int end = editor.logicalPositionToOffset(new LogicalPosition(line2, // EditorHelper.getLineLength(editor, line2))); int start = editor.getDocument().getLineStartOffset(line1); int end = editor.getDocument().getLineEndOffset(line2); RegExp sp; RegExp.regmmatch_T regmatch = new RegExp.regmmatch_T(); sp = new RegExp(); regmatch.regprog = sp.vim_regcomp(pattern, 1); if (regmatch.regprog == null) { if (do_error) { VimPlugin.showMessage(MessageHelper.message(Msg.e_invcmd)); } return false; } /* the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase' */ if (do_ic == 'i') { regmatch.rmm_ic = true; } else if (do_ic == 'I') { regmatch.rmm_ic = false; } /* * ~ in the substitute pattern is replaced with the old pattern. * We do it here once to avoid it to be replaced over and over again. * But don't do it when it starts with "\=", then it's an expression. */ if (!(sub.charAt(0) == '\\' && sub.charAt(1) == '=') && lastReplace != null) { StringBuffer tmp = new StringBuffer(sub.toString()); int pos = 0; while ((pos = tmp.indexOf("~", pos)) != -1) { if (pos == 0 || tmp.charAt(pos - 1) != '\\') { tmp.replace(pos, pos + 1, lastReplace); pos += lastReplace.length(); } pos++; } sub = new CharPointer(tmp); } lastReplace = sub.toString(); searchHighlight(false); if (logger.isDebugEnabled()) { logger.debug("search range=[" + start + "," + end + "]"); logger.debug("pattern=" + pattern + ", replace=" + sub); } int lastMatch = -1; int lastLine = -1; int searchcol = 0; boolean firstMatch = true; boolean got_quit = false; int lcount = EditorHelper.getLineCount(editor); for (int lnum = line1; lnum <= line2 && !got_quit; ) { CharacterPosition newpos = null; int nmatch = sp.vim_regexec_multi(regmatch, editor, lcount, lnum, searchcol); if (nmatch > 0) { if (firstMatch) { VimPlugin.getMark().saveJumpLocation(editor); firstMatch = false; } String match = sp.vim_regsub_multi(regmatch, lnum, sub, 1, false); // logger.debug("found match[" + spos + "," + epos + "] - replace " + match); int line = lnum + regmatch.startpos[0].lnum; CharacterPosition startpos = new CharacterPosition(lnum + regmatch.startpos[0].lnum, regmatch.startpos[0].col); CharacterPosition endpos = new CharacterPosition(lnum + regmatch.endpos[0].lnum, regmatch.endpos[0].col); int startoff = EditorHelper.characterPositionToOffset(editor, startpos); int endoff = EditorHelper.characterPositionToOffset(editor, endpos); int newend = startoff + match.length(); if (do_all || line != lastLine) { boolean doReplace = true; if (do_ask) { // editor.getSelectionModel().setSelection(startoff, endoff); RangeHighlighter hl = highlightConfirm(editor, startoff, endoff); int choice = getConfirmChoice(match); // editor.getSelectionModel().removeSelection(); editor.getMarkupModel().removeHighlighter(hl); switch (choice) { case 0: // Yes doReplace = true; break; case 1: // No doReplace = false; break; case 2: // All do_ask = false; break; case JOptionPane.CLOSED_OPTION: case 3: // Quit doReplace = false; got_quit = true; break; case 4: // Last do_all = false; line2 = lnum; doReplace = true; break; } } if (doReplace) { editor.getDocument().replaceString(startoff, endoff, match); lastMatch = startoff; newpos = EditorHelper.offsetToCharacterPosition(editor, newend); lnum += newpos.line - endpos.line; line2 += newpos.line - endpos.line; } } lastLine = line; lnum += nmatch - 1; if (do_all && startoff != endoff) { if (newpos != null) { lnum = newpos.line; searchcol = newpos.column; } else { searchcol = endpos.column; } } else { searchcol = 0; lnum++; } } else { lnum++; searchcol = 0; } } if (lastMatch != -1) { MotionGroup.moveCaret( editor, VimPlugin.getMotion() .moveCaretToLineStartSkipLeading( editor, editor.offsetToLogicalPosition(lastMatch).line)); } else { VimPlugin.showMessage(MessageHelper.message(Msg.e_patnotf2, pattern)); } return res; }
public void reduce( Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException { List<String[]> _temp = new ArrayList<String[]>(); int count = 0; while (values.hasNext()) { Text _out = values.next(); String[] tokens = StringUtils.splitPreserveAllTokens(_out.toString(), TAB); _temp.add(tokens); if (count++ > 100000) break; } if (count > 10000) { Set<String> ipSet = new HashSet<String>(); for (int posI = 0; posI < _temp.size(); posI++) { String[] array = _temp.get(posI); if (array == null) continue; String mid = array[2]; String ip = array[3]; ipSet.add(ip); } output.collect( key, Utils.mergeKey(String.valueOf(ipSet.size()), StringUtils.join(ipSet, '|'))); return; } /** * ·Ö×éËã·¨ FOREACH ALL_DATA IF IN INDEX THEN UPDATE INDEX AND INSERT DATA ELSE FOREACH SUB_DATA * MAKE INDEX AND SET FIND'S DATA AS NULL */ // List<List<String[]>> dataList = new ArrayList<List<String[]>>(); List<StringBuffer> indexList = new ArrayList<StringBuffer>(); Set<String> ipSet = new HashSet<String>(); boolean muliHost = false; for (int posI = 0; posI < _temp.size(); posI++) { String[] array = _temp.get(posI); if (array == null) continue; String mid = array[2]; String ip = array[3]; ipSet.add(ip); boolean hasIndex = false; for (int i = 0; i < indexList.size(); i++) { StringBuffer index = indexList.get(i); if (index.indexOf("|" + mid + "|") >= 0 || index.indexOf("|" + ip + "|") >= 0) { if (index.indexOf("|" + mid + "|") < 0) { index.append('|').append(mid).append('|'); } if (index.indexOf("|" + ip + "|") < 0) { index.append('|').append(ip).append('|'); } // dataList.get(i).add(array); hasIndex = true; break; } } if (!hasIndex) { StringBuffer index = new StringBuffer("|" + mid + "|" + ip + "|"); // List<String[]> _tmp = new ArrayList<String[]>(); // _tmp.add(array); for (int k = posI + 1; k < _temp.size(); k++) { String[] _newArray = _temp.get(k); if (_newArray == null) { continue; } String _mid = _newArray[2]; String _ip = _newArray[3]; if (index.indexOf("|" + _mid + "|") >= 0 || index.indexOf("|" + _ip + "|") >= 0) { if (index.indexOf("|" + _mid + "|") < 0) { index.append('|').append(_mid).append('|'); } if (index.indexOf("|" + _ip + "|") < 0) { index.append('|').append(_ip).append('|'); } // _tmp.add(_newArray); _temp.set(k, null); } } indexList.add(index); // dataList.add(_tmp); } } // for(String[] _array : _temp){ // output.collect(key,Utils.mergeKey(_array[1],_array[2],_array[3],_array[4])); // } StringBuffer allIndex = new StringBuffer(); for (StringBuffer index : indexList) { allIndex.append(index).append(';'); } if (allIndex.length() > 0) { allIndex.deleteCharAt(allIndex.length() - 1); } output.collect( key, Utils.mergeKey(String.valueOf(indexList.size()), StringUtils.join(ipSet, '|'))); }