/** * @param section * @param index * @return * @throws IOException */ final String getStringFromSection(final Section section, final int index) throws IOException { if (index > section.getSize()) { return ""; } final StringBuffer str = new StringBuffer(); // Most string symbols will be less than 50 bytes in size final byte[] tmp = new byte[50]; this.efile.seek(section.getFileOffset() + index); while (true) { int len = this.efile.read(tmp); for (int i = 0; i < len; i++) { if (tmp[i] == 0) { len = 0; break; } str.append((char) tmp[i]); } if (len <= 0) { break; } } return str.toString(); }
/** Converts the Message to a String. */ public String toString() { StringBuffer sb = new StringBuffer(); OPTRecord opt = getOPT(); if (opt != null) sb.append(header.toStringWithRcode(getRcode()) + "\n"); else sb.append(header + "\n"); if (isSigned()) { sb.append(";; TSIG "); if (isVerified()) sb.append("ok"); else sb.append("invalid"); sb.append('\n'); } if (opt != null) { sb.append(";; OPT PSEUDOSECTION:\n"); sb.append("; EDNS: version: "); sb.append(opt.getVersion()); sb.append(", flags:"); if ((opt.getFlags() & ExtendedFlags.DO) != 0) { sb.append(" do"); } sb.append("; udp: "); sb.append(opt.getPayloadSize()); sb.append("\n"); } for (int i = 0; i < 4; i++) { if (header.getOpcode() != Opcode.UPDATE) sb.append(";; " + Section.longString(i) + ":\n"); else sb.append(";; " + Section.updString(i) + ":\n"); sb.append(sectionToString(i) + "\n"); } sb.append(";; Message size: " + numBytes() + " bytes"); return sb.toString(); }
/////////// // Methods// /////////// public void createServerFile( HashMap<String, DataObj> dataObjsMap, HashMap<String, PageObj> pageObjsMap) { // Copy files over try { FileUtils.copyFile(sourceConfig, new File("Output/config.js")); } catch (IOException e) { System.out.println("Error copying over config file for"); System.out.println(e); } out.write(genDbConnection()); // For each data object, get object by ID Iterator it = dataObjsMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry one = (Map.Entry) it.next(); DataObj curDataObj = (DataObj) one.getValue(); String name = curDataObj.getName(); out.write("\n /* " + name + ": CRUD GET, DELETE, UPDATE, POST BY ID*/\n"); out.write(genGetById(curDataObj)); out.write(genDelById(curDataObj)); out.write(genUpdateById(curDataObj)); out.write(genAdd(curDataObj)); } // Hack to get a necessary API call for OAuth stuff out.write( genGetByPageParam( null, new Section( "View", new ArrayList<String>(Arrays.asList(new String[] {"OAuthID"})), new ArrayList<String>(Arrays.asList(new String[] {"User"}))), dataObjsMap)); // For each page, generate the calls necessery to make // the view/create params work it = pageObjsMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry one = (Map.Entry) it.next(); PageObj curPageObj = (PageObj) one.getValue(); String name = curPageObj.getName(); out.write("\n /* " + name + ": CRUD GET,DELETE,UPDATE,POST *NOT* BY ID */\n"); List<Section> sections = curPageObj.getSections(); for (Section section : sections) { switch ((Section.Type) section.getType()) { case VIEW: out.write(genGetByPageParam(curPageObj, section, dataObjsMap)); break; case CREATE: // out.write(genPostByPageParam(curPageObj, section)); break; case MODIFY: break; case DELETE: break; } } } out.write(genServerListen()); }
/** * @param name * @return * @throws IOException */ public Section getSectionByName(final String name) throws IOException { final Section[] secs = getSections(); for (Section section : secs) { if (name.equals(section.getName())) { return section; } } return null; }
/** * Writes this instance in INI format to an output stream writer. * * @param streamWriter where to write * @throws IOException at an I/O problem */ public void save(OutputStreamWriter streamWriter) throws IOException { Iterator<String> it = this.sectionOrder.iterator(); PrintWriter writer = new PrintWriter(streamWriter, true); while (it.hasNext()) { Section sect = getSection(it.next()); writer.println(sect.header()); sect.save(writer); } }
/** * @param type * @return * @throws IOException */ public Section[] getSections(final int type) throws IOException { final ArrayList<Section> result = new ArrayList<Section>(); final Section[] secs = getSections(); for (Section section : secs) { if (type == section.getType()) { result.add(section); } } return result.toArray(new Section[result.size()]); }
/** * Returns the value of a given option in a given section or null if either the section or the * option don't exist. If a common section was defined options are also looked up there if they're * not present in the specific section. * * @param section the section's name * @param option the option's name * @return the option's value * @throws NullPointerException any of the arguments is <code>null</code> */ public String get(String section, String option) { if (hasSection(section)) { Section sect = getSection(section); if (sect.hasOption(option)) { return sect.get(option); } if (this.commonName != null) { return getSection(this.commonName).get(option); } } return null; }
/** * Adds a section if it doesn't exist yet. * * @param name the name of the section * @return <code>true</code> if the section didn't already exist * @throws IllegalArgumentException the name is illegal, ie contains one of the characters '[' and * ']' or consists only of white space */ public boolean addSection(String name) { String normName = normSection(name); if (!hasSection(normName)) { // Section constructor might throw IllegalArgumentException Section section = new Section(normName, this.commentDelims, this.isCaseSensitive); section.setOptionFormat(this.optionFormat); this.sections.put(normName, section); this.sectionOrder.add(normName); return true; } else { return false; } }
@Override public Void visit(Section s) { for (Statement stat : s.getBody()) { stat.accept(this); } return null; }
public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException { Vgroup vgroup = (Vgroup) v2.getSPobject(); Range scanRange = section.getRange(0); Range radialRange = section.getRange(1); Range gateRange = section.getRange(2); Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape()); IndexIterator ii = data.getIndexIterator(); for (int i = scanRange.first(); i <= scanRange.last(); i += scanRange.stride()) { Cinrad2Record[] mapScan = vgroup.map[i]; readOneScan(mapScan, radialRange, gateRange, vgroup.datatype, ii); } return data; }
/** Converts the Message to a String. */ public String toString() { StringBuffer sb = new StringBuffer(); OPTRecord opt = getOPT(); if (opt != null) sb.append(header.toStringWithRcode(getRcode()) + "\n"); else sb.append(header + "\n"); if (isSigned()) { sb.append(";; TSIG "); if (isVerified()) sb.append("ok"); else sb.append("invalid"); sb.append('\n'); } for (int i = 0; i < 4; i++) { if (header.getOpcode() != Opcode.UPDATE) sb.append(";; " + Section.longString(i) + ":\n"); else sb.append(";; " + Section.updString(i) + ":\n"); sb.append(sectionToString(i) + "\n"); } sb.append(";; Message size: " + numBytes() + " bytes"); return sb.toString(); }
/** * Loads INI formatted input from a stream reader into this instance. Everything in the stream * before the first section header is ignored. * * @param streamReader where to read from * @throws IOException at an I/O problem */ public void load(InputStreamReader streamReader) throws IOException { BufferedReader reader = new BufferedReader(streamReader); String curSection = null; String line = null; while (reader.ready()) { line = reader.readLine().trim(); if (line.length() > 0 && line.charAt(0) == Section.HEADER_START) { int endIndex = line.indexOf(Section.HEADER_END); if (endIndex >= 0) { curSection = line.substring(1, endIndex); addSection(curSection); } } if (curSection != null) { Section sect = getSection(curSection); sect.load(reader); } } }
/** * @return * @throws IOException */ public Section[] getSections() throws IOException { if (this.sections == null) { this.sections = Section.create(this, this.ehdr, this.efile); for (int i = 0; i < this.sections.length; i++) { if (this.sections[i].getType() == Section.SHT_SYMTAB) { this.syms = i; } if ((this.syms == 0) && (this.sections[i].getType() == Section.SHT_DYNSYM)) { this.syms = i; } } } return this.sections; }
/** * @param aSection * @return * @throws IOException */ private Symbol[] loadSymbolsBySection(final Section aSection) throws IOException { if (aSection == null) { return new Symbol[0]; } return aSection.loadSymbols(this.ehdr, this.efile); }
// Generates the get request for items that the config 'page' section // requests to be shown given a certain param public String genGetByPageParam( PageObj pageObj, Section section, HashMap<String, DataObj> dataObjsMap) { StringBuilder s = new StringBuilder(1024); List<String> showObjs = section.getShow(); List<String> pageParams = section.getParams(); StringBuilder paramQuery = new StringBuilder(256); // create the end of the url for (String param : pageParams) { paramQuery.append("/find/" + param + "/:" + param); } for (String tableName : showObjs) { DataObj dataObj = dataObjsMap.get(tableName); String whereParams = parsePageParam(dataObj, pageParams); String reqParams = makeReqParams(dataObj, pageParams); s.append("app.get('/" + tableName + paramQuery.toString() + "', function(req,res) {\n"); // know when to return response s.append(returnTab(1) + "totalCount = 0;\n"); s.append(returnTab(1) + "count = 0;\n"); // generates the BASIC select * from table where id = ? s.append( returnTab(1) + "var query = \"" + selectProperties(dataObj) + " from " + tableName + " as " + tableName + " where " + whereParams + "\";\n"); s.append(returnTab(1) + "con.query(query," + reqParams + ", function(err, rows0,fields) {\n"); s.append(returnTab(2) + "if(err) throw err;\n"); // once the BASIC info is returned, each foreign key needs to be // expanded. this is done recursively with evaluateFK() tabDepth = 0; queryNo = 0; queryNoNext = 1; String fks = evaluateFK(dataObj, 0, "", "", "row.ID"); s.append(fks); if (fks.length() > 0) { s.append(returnTab(tabDepth + 2) + "count += 1;\n"); } s.append(returnTab(tabDepth + 2) + "if (count == totalCount) {\n"); s.append(returnTab(tabDepth + 3) + "res.jsonp(rows0);\n"); s.append(returnTab(tabDepth + 2) + "}\n"); // adds all of the closing brackets while (tabDepth + 2 > 0) { s.append(returnTab(1 + tabDepth) + "});\n"); if (tabDepth == 1) { s.append(returnTab(1 + tabDepth) + "if (rows0.length == 0) {\n"); s.append(returnTab(2 + tabDepth) + "res.jsonp([])\n"); s.append(returnTab(1 + tabDepth) + "}\n"); } tabDepth -= 1; } s.append("\n"); } return s.toString(); }