public ArrayList<String> collectLinks(String p) { ArrayList<String> PageLinks = new ArrayList<String>(); try { URL url = new URL(p); BufferedReader br3 = new BufferedReader(new InputStreamReader(url.openStream())); String str = ""; while (null != (str = br3.readLine())) { Pattern link = Pattern.compile( "<a target=\"_top\" href=\"/m/.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher match = link.matcher(str); while (match.find()) { String tmp = match.group(); int start = tmp.indexOf('/'); tmp = tmp.substring(start + 1, tmp.indexOf('\"', start + 1)); if (Crawl.contains("http://www.rottentomatoes.com/" + tmp) || ToCrawl.contains("http://www.rottentomatoes.com/" + tmp) || PageLinks.contains("http://www.rottentomatoes.com/" + tmp)) continue; PageLinks.add("http://www.rottentomatoes.com/" + tmp); // bw4.write("http://www.rottentomatoes.com/"+tmp+"\r\n"); } } br3.close(); } catch (Exception ex) { ex.printStackTrace(); } return PageLinks; }
public ArrayList<String> parseXML() throws Exception { ArrayList<String> ret = new ArrayList<String>(); handshake(); URL url = new URL( "http://mangaonweb.com/page.do?cdn=" + cdn + "&cpn=book.xml&crcod=" + crcod + "&rid=" + (int) (Math.random() * 10000)); String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(page)); Document d = builder.parse(is); Element doc = d.getDocumentElement(); NodeList pages = doc.getElementsByTagName("page"); total = pages.getLength(); for (int i = 0; i < pages.getLength(); i++) { Element e = (Element) pages.item(i); ret.add(e.getAttribute("path")); } return (ret); }
// convert coordinates to relative coordinates with the top-left one as (0,0) public void convertToRelativePositions() { LayoutBox box = getExactLayoutBox(); // System.out.println("Box // ("+box.topleft.x+","+box.topleft.y+");("+(box.topleft.x+box.width)+","+(box.topleft.y+box.height)); Iterator<NodeLayout> e = nodes.iterator(); NodeLayout nl; while (e.hasNext()) { nl = e.next(); /* Debug code if(nl.x<box.topleft.x || nl.y<box.topleft.y || nl.x>(box.topleft.x+box.width) || nl.y>(box.topleft.y+box.height)){ System.out.println("Invalid node "+nl.x+","+nl.y); } //*/ nl.x = nl.x - box.topleft.x; nl.y = nl.y - box.topleft.y; } Iterator<EdgeLayout> e2 = edges.iterator(); EdgeLayout el; while (e2.hasNext()) { el = e2.next(); for (LayoutPoint lp : el.bends) { lp.x = lp.x - box.topleft.x; lp.y = lp.y - box.topleft.y; } } }
public void flipLayoutLeftRight() { LayoutBox box = getExactLayoutBox(); Iterator<NodeLayout> ne = nodes.iterator(); while (ne.hasNext()) { NodeLayout nl = ne.next(); if (nl.processID.equals("null")) { nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 60; // minus 60 which is the width of process node's box, since using upperleft // coor } else if (isSecondary(nl)) { nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 60; } else { nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 20; } } Iterator<EdgeLayout> e2 = edges.iterator(); EdgeLayout el; while (e2.hasNext()) { el = e2.next(); for (LayoutPoint lp : el.bends) { lp.x = box.topleft.x + (box.width - (lp.x - box.topleft.x)); } } }
public static Casella findCasella(String d) { for (int i = 0; i < caselle.size(); i++) { if (caselle.get(i).id.equalsIgnoreCase(d)) { return caselle.get(i); } } return null; }
private QueryResult gatherResultInfoForSelectQuery( String queryString, int queryNr, boolean sorted, Document doc, String[] rows) { Element root = doc.getRootElement(); // Get head information Element child = root.getChild("head", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#")); // Get result rows (<head>) List headChildren = child.getChildren( "variable", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#")); Iterator it = headChildren.iterator(); ArrayList<String> headList = new ArrayList<String>(); while (it.hasNext()) { headList.add(((Element) it.next()).getAttributeValue("name")); } List resultChildren = root.getChild("results", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#")) .getChildren( "result", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#")); int nrResults = resultChildren.size(); QueryResult queryResult = new QueryResult(queryNr, queryString, nrResults, sorted, headList); it = resultChildren.iterator(); while (it.hasNext()) { Element resultElement = (Element) it.next(); String result = ""; // get the row values and paste it together to one String for (int i = 0; i < rows.length; i++) { List bindings = resultElement.getChildren( "binding", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#")); String rowName = rows[i]; for (int j = 0; j < bindings.size(); j++) { Element binding = (Element) bindings.get(j); if (binding.getAttributeValue("name").equals(rowName)) if (result.equals("")) result += rowName + ": " + ((Element) binding.getChildren().get(0)).getTextNormalize(); else result += "\n" + rowName + ": " + ((Element) binding.getChildren().get(0)).getTextNormalize(); } } queryResult.addResult(result); } return queryResult; }
/** * @return exact rectangle box bounding all the center points of the nodes and all the bend * points. */ public LayoutBox getExactLayoutBox() { Iterator<NodeLayout> e = nodes.iterator(); double tlx = 0, tly = 0, brx = 0, bry = 0; // top left, bottom right NodeLayout nl; if (e.hasNext()) { nl = e.next(); tlx = nl.x; tly = nl.y; brx = nl.x; bry = nl.y; } while (e.hasNext()) { nl = e.next(); if (nl.x < tlx) { tlx = nl.x; } if (nl.x > brx) { brx = nl.x; } if (nl.y < tly) { tly = nl.y; } if (nl.y > bry) { bry = nl.y; } } Iterator<EdgeLayout> ee = edges.iterator(); Iterator<LayoutPoint> be; LayoutPoint lp; EdgeLayout el; while (ee.hasNext()) { el = ee.next(); be = el.bends.iterator(); while (be.hasNext()) { lp = be.next(); if (lp.x < tlx) { tlx = lp.x; } if (lp.x > brx) { brx = lp.x; } if (lp.y < tly) { tly = lp.y; } if (lp.y > bry) { bry = lp.y; } } } return new LayoutBox(tlx, tly, brx - tlx, bry - tly); }
public String toString() { if (isEmpty()) { return ""; } StringBuffer sb = new StringBuffer(); Iterator<NodeLayout> e = nodes.iterator(); while (e.hasNext()) sb.append((e.next()).toString()); sb.append("\n"); Iterator<EdgeLayout> ee = edges.iterator(); while (ee.hasNext()) sb.append((ee.next()).toString()); return sb.toString(); }
@Override public void transferListenersTo( IModelChangeProviderExtension target, IModelChangedListenerFilter filter) { ArrayList<IModelChangedListener> removed = new ArrayList<>(); for (int i = 0; i < fListeners.size(); i++) { IModelChangedListener listener = fListeners.get(i); if (filter == null || filter.accept(listener)) { target.addModelChangedListener(listener); removed.add(listener); } } fListeners.removeAll(removed); }
public static void parseDocumentFragment(Reader reader, XMLReceiver xmlReceiver) throws SAXException { try { final XMLReader xmlReader = newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getXMLReader(); xmlReader.setContentHandler(new XMLFragmentReceiver(xmlReceiver)); final ArrayList<Reader> readers = new ArrayList<Reader>(3); readers.add(new StringReader("<root>")); readers.add(reader); readers.add(new StringReader("</root>")); xmlReader.parse(new InputSource(new SequenceReader(readers.iterator()))); } catch (IOException e) { throw new OXFException(e); } }
/** Generates array of XContour from local contours and modules. Used for TTF building. */ private XContour[] toContours() { XContour[] retval; ArrayList<XContour> list = new ArrayList<>(); XContour[] contours = m_glyph.getBody().getContour(); for (int i = 0; i < contours.length; i++) { EContour contour = (EContour) contours[i]; list.add(contour.toQuadratic()); } // for i XModule[] modules = m_glyph.getBody().getModule(); for (int i = 0; i < modules.length; i++) { EModuleInvoke module = (EModuleInvoke) modules[i]; // push and pop happens inside toContour list.add(module.toContour(new AffineTransform())); } // for i if (list.size() == 0) return null; retval = new XContour[list.size()]; for (int i = 0; i < list.size(); i++) { retval[i] = list.get(i); } // for i return retval; }
public String toBeautifiedString() { StringBuffer sb = new StringBuffer(); Iterator<NodeLayout> e = nodes.iterator(); while (e.hasNext()) sb.append((e.next()).toBeautifiedString()); sb.append("\n"); Iterator<EdgeLayout> ee = edges.iterator(); while (ee.hasNext()) { sb.append((ee.next()).toBeautifiedString()); } sb.append("\n\nNumber of Nodes: "); sb.append(nodes.size()); sb.append("\nNumber of Edges: "); sb.append(edges.size() + "\n"); return sb.toString(); }
public TTGlyph toSimpleGlyph() { // convert the file into array of contours XContour[] contours = toContours(); if ((contours == null) && (!isRequiredGlyph())) { return null; } // if TTGlyph retval = new TTGlyph(); retval.setSimple(true); retval.setAdvanceWidth(getAdvanceWidth()); if (contours == null) { return retval; } // if ArrayList<EContourPoint> points = new ArrayList<>(); for (int i = 0; i < contours.length; i++) { XContour contour = contours[i]; XContourPoint[] contourPoints = contour.getContourPoint(); for (int j = 0; j < contourPoints.length; j++) { points.add((EContourPoint) contourPoints[j]); } // for j retval.addEndPoint(points.size() - 1); } // for i for (EContourPoint point : points) { loadContourPoint(retval, point); } // for point boolean hasGridfit = false; // I need int i here. for (int i = 0; i < points.size(); i++) { EContourPoint point = points.get(i); if (!point.isRounded()) { continue; } // if hasGridfit = true; loadGridfit(retval, point, i); } // for i if (hasGridfit) { retval.addInstruction(TTGlyph.IUP1); retval.addInstruction(TTGlyph.IUP0); } // if // I need int i here. for (int i = 0; i < points.size(); i++) { EContourPoint point = points.get(i); if (point.getHint().length == 0) { continue; } // if loadHint(retval, point, i); } // for i return retval; }
public boolean download(DownloadListener dl) throws Exception { // 1) get crcod, cdn, and cookies handshake(); // 2) get XML ArrayList<String> paths = parseXML(); dl.setTotal(getTotal()); // 3) get pages byte[] key = { 99, 49, 51, 53, 100, 54, 56, 56, 57, 57, 99, 56, 50, 54, 99, 101, 100, 55, 99, 52, 57, 98, 99, 55, 54, 97, 97, 57, 52, 56, 57, 48 }; BlowFishKey bfkey = new BlowFishKey(key); for (int i = 0; i < paths.size(); i++) { if (dl.isDownloadAborted()) return (true); // rid is just a random number from 0-9999 URL url = new URL( "http://mangaonweb.com/page.do?cdn=" + cdn + "&cpn=" + paths.get(i) + "&crcod=" + crcod + "&rid=" + (int) (Math.random() * 10000)); byte[] encrypted = downloadByteArray(url); bfkey.decrypt(encrypted, 0); RandomAccessFile output = new RandomAccessFile(dl.downloadPath(this, i), "rw"); output.write(encrypted); output.close(); dl.downloadIncrement(this); } dl.downloadFinished(this); return (true); }
public JSONObject describeClass(Class<?> clazz) throws Exception { JSONObject desc = new JSONObject(); desc.put("name", clazz.getName()); if (clazz.isEnum()) { @SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) clazz; ArrayList<String> enumNames = Lists.newArrayList(); for (Enum<?> e : enumClass.getEnumConstants()) { enumNames.add(e.name()); } desc.put("enum", enumNames); } UI_TYPE ui_type = UI_TYPE.getEnumFor(clazz); if (ui_type != null) { desc.put("uiType", ui_type.getName()); } desc.put("properties", getClassProperties(clazz, 0)); return desc; }
public EdgeLayout getEdgeLayouts(String spid, String sid, String tpid, String tid) { Iterator<EdgeLayout> ee = edges.iterator(); EdgeLayout el; while (ee.hasNext()) { el = ee.next(); if (el.sourceNode.equals(sid) && el.targetNode.equals(tid)) { return el; } } return null; } // */
public boolean addNodeLayout(String pid, String id, String c, double x, double y) { /*if(idToNode.containsKey(pid + id)){ return false; } */ NodeLayout newNode = new NodeLayout(pid, id, c, x, y); nodes.add(newNode); idToNode.put(pid + id, newNode); return true; }
// convert coordinates to shifted coordinates with the top-left one as (xs,ys) public void convertToShiftedPositions(double xs, double ys) { convertToRelativePositions(); Iterator<NodeLayout> e = nodes.iterator(); NodeLayout nl; while (e.hasNext()) { nl = e.next(); nl.x += xs; nl.y += ys; } Iterator<EdgeLayout> e2 = edges.iterator(); EdgeLayout el; while (e2.hasNext()) { el = e2.next(); for (LayoutPoint lp : el.bends) { lp.x += xs; lp.y += ys; } } }
public void filpLayoutUpDown() { LayoutBox box = getExactLayoutBox(); Iterator<NodeLayout> ne = nodes.iterator(); while (ne.hasNext()) { NodeLayout nl = ne.next(); if (nl.cofactor.equalsIgnoreCase("true")) { nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12; } else { nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20; } } Iterator<EdgeLayout> e2 = edges.iterator(); EdgeLayout el; while (e2.hasNext()) { el = e2.next(); for (LayoutPoint lp : el.bends) { lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y)); } } }
public void flipLayoutUpDown() { LayoutBox box = getExactLayoutBox(); Iterator<NodeLayout> ne = nodes.iterator(); while (ne.hasNext()) { NodeLayout nl = ne.next(); if (isSecondary(nl)) { nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12; } else { nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20; } } Iterator<EdgeLayout> e2 = edges.iterator(); EdgeLayout el; while (e2.hasNext()) { el = e2.next(); for (LayoutPoint lp : el.bends) { lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y)); } } }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append(sourcepid + "," + sourceNode + "," + targetpid + "," + targetNode + ","); Iterator<LayoutPoint> e = bends.iterator(); LayoutPoint b; while (e.hasNext()) { b = (LayoutPoint) e.next(); sb.append(b.x + "," + b.y + ","); } sb.append("\n"); return sb.toString(); }
public LayoutInfo copyOfThisLayoutInfo() { LayoutInfo copyI = new LayoutInfo(); for (NodeLayout nl : nodes) { copyI.addNodeLayout(nl.processID, nl.nodeID, nl.cofactor, nl.x, nl.y); } for (EdgeLayout el : edges) { ArrayList<LayoutPoint> copyBends = new ArrayList<LayoutPoint>(); for (LayoutPoint lp : el.bends) { copyBends.add(new LayoutPoint(lp.x, lp.y)); } copyI.addEdgeLayout( el.sourcepid, el.sourceNode, el.scofactor, el.targetpid, el.targetNode, el.tcofactor, copyBends); } return copyI; }
public List<ClassNode> getClasses() { ArrayList<ClassNode> classes = new ArrayList<ClassNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует приложению * application. Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега class для текущего тега application. */ NodeList classNodes = node.getChildNodes(); for (int i = 0; i < classNodes.getLength(); i++) { Node node = classNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление класса. */ ClassNode classNode = new ClassNode(node); classes.add(classNode); } } return classes; }
/** Возвращает список методов класса. */ public List<MethodNode> getMethods() { ArrayList<MethodNode> methods = new ArrayList<MethodNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует классу class. * Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега method для текущего тега class. */ NodeList methodNodes = node.getChildNodes(); for (int i = 0; i < methodNodes.getLength(); i++) { node = methodNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление метода. */ MethodNode methodNode = new MethodNode(node); methods.add(methodNode); } } return methods; }
public String toBeautifiedString() { StringBuffer sb = new StringBuffer(); sb.append("sourcePID: " + sourcepid); sb.append(" sourceNodeId: " + sourceNode + "\n"); sb.append(" targetPID: " + targetpid); sb.append(" targetNodeId: " + targetNode + "\n"); Iterator<LayoutPoint> e = bends.iterator(); LayoutPoint b; while (e.hasNext()) { b = (LayoutPoint) e.next(); sb.append(" Bend Points: " + b.x + "," + b.y + " "); } sb.append("\n\n"); return sb.toString(); }
/** * Populates LOCALES list with contents of xml. * * @param list the configuration list */ private static void parseLocales(NodeList list) { for (int i = 0; i < list.getLength(); ++i) { Node node = list.item(i); NamedNodeMap attributes = node.getAttributes(); String label = ((Attr) attributes.getNamedItem("label")).getValue(); String code = ((Attr) attributes.getNamedItem("isoCode")).getValue(); String dictLocation = ((Attr) attributes.getNamedItem("dictionaryUrl")).getValue(); try { LOCALES.add(new Locale(label, code, new URL(dictLocation))); } catch (MalformedURLException exc) { logger.warn( "Unable to parse dictionary location of " + label + " (" + dictLocation + ")", exc); } } }
public Command executeStep(Element stepRow) throws Exception { Command command = new Command(); NodeList stepFields = stepRow.getElementsByTagName("td"); String cmd = stepFields.item(0).getTextContent().trim(); command.cmd = cmd; ArrayList<String> argList = new ArrayList<String>(); if (stepFields.getLength() == 1) { // skip comments command.result = "OK"; return command; } for (int i = 1; i < stepFields.getLength(); i++) { String content = stepFields.item(i).getTextContent(); content = content.replaceAll(" +", " "); content = content.replace('\u00A0', ' '); content = content.trim(); argList.add(content); } String args[] = argList.toArray(new String[0]); command.args = args; if (this.verbose) { System.out.println(cmd + " " + Arrays.asList(args)); } try { command.result = this.commandProcessor.doCommand(cmd, args); command.error = false; } catch (Exception e) { command.result = e.getMessage(); command.error = true; } command.failure = command.error && !cmd.startsWith("verify"); if (this.verbose) { System.out.println(command.result); } return command; }
public void collega() { for (int i = 1; i < caselle.size(); i++) { String down = caselle.get(i).down; String up = caselle.get(i).up; String lat = caselle.get(i).laterale; caselle.get(i).setProssimaCasellaSensoAntiOrario(findCasella(down)); caselle.get(i).setProssimaCasellaSensoOrario(findCasella(up)); Casella c; if (lat.isEmpty()) c = null; else c = findCasella(lat); caselle.get(i).setCasellaLaterale(c); // null se non è un bivio } }
private boolean showDialog() { String[] types = {"RAW", "JPEG", "ZLIB"}; GenericDialog gd = new GenericDialog("Generate Bricks"); gd.addChoice("FileType", types, filetype); gd.addNumericField("JPEG quality", jpeg_quality, 0); gd.addNumericField("Max file size (MB)", bdsizelimit, 0); int[] wlist = WindowManager.getIDList(); if (wlist == null) return false; String[] titles = new String[wlist.length]; for (int i = 0; i < wlist.length; i++) titles[i] = ""; int tnum = 0; for (int i = 0; i < wlist.length; i++) { ImagePlus imp = WindowManager.getImage(wlist[i]); if (imp != null) { titles[tnum] = imp.getTitle(); tnum++; } } gd.addChoice("Source image: ", titles, titles[0]); gd.showDialog(); if (gd.wasCanceled()) return false; filetype = types[gd.getNextChoiceIndex()]; jpeg_quality = (int) gd.getNextNumber(); if (jpeg_quality > 100) jpeg_quality = 100; if (jpeg_quality < 0) jpeg_quality = 0; bdsizelimit = (int) gd.getNextNumber(); int id = gd.getNextChoiceIndex(); lvImgTitle = new ArrayList<String>(); lvImgTitle.add(titles[id]); Prefs.set("filetype.string", filetype); Prefs.set("jpeg_quality.int", jpeg_quality); Prefs.set("bdsizelimit.int", bdsizelimit); return true; }
// Return the shared nodes(with the same node id) with the other LayoutInfo public LinkedHashMap<NodeLayout, NodeLayout> sharedNodes(LayoutInfo info2) { LinkedHashMap<NodeLayout, NodeLayout> shared = new LinkedHashMap<NodeLayout, NodeLayout>(); Iterator<NodeLayout> e = nodes.iterator(); while (e.hasNext()) { NodeLayout nl = e.next(); if (nl.cofactor.equalsIgnoreCase("true")) { continue; } NodeLayout nl2; Iterator<NodeLayout> e2 = info2.nodes.iterator(); while (e2.hasNext()) { nl2 = e2.next(); if (nl2.cofactor.equalsIgnoreCase("true")) { continue; } if (nl.nodeID.equals(nl2.nodeID)) { shared.put(nl, nl2); } } } return shared; }