/** * Append XML content into root element * * @param hrefValue href of the topicref * @param parentResult XML content to insert into * @param tmpContent XML content to insert */ private void insertAfter(String hrefValue, StringBuffer parentResult, CharSequence tmpContent) { int insertpoint = parentResult.lastIndexOf("</"); final int end = parentResult.indexOf(">", insertpoint); if (insertpoint == -1 || end == -1) { logger.error(MessageUtils.getInstance().getMessage("DOTJ033E", hrefValue).toString()); } else { if (ELEMENT_NAME_DITA.equals(parentResult.substring(insertpoint, end).trim())) { insertpoint = parentResult.lastIndexOf("</", insertpoint - 1); } parentResult.insert(insertpoint, tmpContent); } }
public int lastIndexOf(String tag) { return m_template.lastIndexOf(tag); }
public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException { if (args.length != 2) { System.out.println("Usage: FeatureMatching ID <inputName.jpeg/inputName.jpg>"); System.exit(1); } SimpleDateFormat sdf = new SimpleDateFormat("", Locale.US); sdf.applyPattern("yyyy-MM-dd_HH-mm-ss"); String time = sdf.format(new Date()); Job job = Job.getInstance(); ID = "/" + args[0]; String filename = args[1]; filename = filename.toLowerCase(); System.out.println("current filename:" + filename); // Detect illegal username (if the username dir doesn't exist) File userPath = new File(LOCAL_USER_DIR + ID); if (!userPath.exists()) { System.out.println("Unauthorized username!!!\nExiting......"); System.exit(1); } // Preprocess the input image.jpg from local dir: /local.../user/ID/input/image.jpg // Save the features to local dir: hdfs://.../user/ID/input/image.jpg extractQueryFeatures2HDFS(filename, job); // Add the feature file to the hdfs cache String featureFileName = filename.substring(0, filename.lastIndexOf(".")) + ".json"; // job.addCacheFile(new Path(HDFS_HOME + USER + ID + INPUT + "/" + // featureFileName).toUri()); job.getConfiguration() .set("featureFilePath", HDFS_HOME + USER + ID + INPUT + "/" + featureFileName); // Check the file type. Only support jpeg/jpg type images String type = filename.substring(args[1].lastIndexOf(".")); if (!(type.equals(".jpg") || type.equals(".jpeg"))) { System.out.println("Image type not supported!!!\nExiting"); System.exit(1); } // Input: hdfs://.../features/ // The feature dir is a location of all features extracted from the database String inputPathStr = HDFS_HOME + FEATURES; // Output: hdfs://.../user/ID/output/ String outputPathStr = HDFS_HOME + USER + ID + OUTPUT + "/" + time; job.setInputFormatClass(KeyValueTextInputFormat.class); // job.setOutputFormatClass(TextOutputFormat.class); // Get the lists of all feature files: /.../features/data/part-* FileSystem fs = FileSystem.get(job.getConfiguration()); FileStatus[] statuses = fs.listStatus(new Path(inputPathStr)); StringBuffer sb = new StringBuffer(); for (FileStatus fileStatus : statuses) { sb.append(fileStatus.getPath() + ","); } sb.deleteCharAt(sb.lastIndexOf(",")); job.setJarByClass(FeatureMatching.class); job.setMapperClass(FeatureMatchMapper.class); job.setReducerClass(FeatureMatchReducer.class); // only need one reducer to collect the result job.setNumReduceTasks(1); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(DoubleWritable.class); // Input a directory, so need the recursive input FileInputFormat.setInputDirRecursive(job, true); // Set the PathFilter, to omit _SUCCESS files // (This is not working correctly, as the PathFilter class is an interface rather than a class. // But the 2nd arg asks me to extend the PathFilter) // FileInputFormat.setInputPathFilter(job, MyPathFilter.class); // // FileInputFormat.setInputPaths(job, new Path(inputPathStr)); FileInputFormat.setInputPaths(job, sb.toString()); FileOutputFormat.setOutputPath(job, new Path(outputPathStr)); boolean success = job.waitForCompletion(true); return success ? 0 : 1; }
/** Reads the file, and sets the label and the values in the hashmap. */ protected void setHM(String strPath, HashMap hmPnl) { BufferedReader reader = WFileUtil.openReadFile(strPath); boolean bFileEmpty = true; boolean bPart11Pnl = isPart11Pnl(); boolean bDefaultFile = isDefaultFile(); // if the file is empty, then create an empty set of textfields. if (reader == null) { // displayNewTxf("",""); return; } String strLine = null; StringTokenizer strTok; try { // read the file, and create a new set of textfields, // with the values from the file. while ((strLine = reader.readLine()) != null) { String strLabel = ""; String strValue = ""; bFileEmpty = false; if (strLine.startsWith("#") || strLine.startsWith("@") || strLine.startsWith("%") || strLine.startsWith("\"@")) continue; if (strLine.startsWith("\"")) strTok = new StringTokenizer(strLine, "\""); else strTok = new StringTokenizer(strLine, File.pathSeparator + ",\n"); if (!strTok.hasMoreTokens()) continue; strLabel = strTok.nextToken(); // the format for the part11 Default file is a little different // only parse out the part11Dir, and don't display other defaults if (bPart11Pnl && bDefaultFile) { if (!strLabel.equalsIgnoreCase("part11Dir")) continue; } if (strTok.hasMoreTokens()) { while (strTok.hasMoreTokens()) { strValue += strTok.nextToken(); if (strTok.hasMoreTokens()) strValue += " "; } } // append "/data/$name" to part11Dir if (bPart11Pnl && bDefaultFile && strLabel.equalsIgnoreCase("part11Dir")) { StringBuffer sbDir = new StringBuffer(strValue); if (sbDir.lastIndexOf(File.separator) < sbDir.length() - 1) sbDir.append(File.separator); sbDir.append("data" + File.separator + "$"); sbDir.append(WGlobal.NAME); strValue = sbDir.toString(); } // displayNewTxf(strLabel, strValue); if (strLabel != null && strLabel.trim().length() > 0) hmPnl.put(strLabel, strValue); } reader.close(); } catch (Exception e) { Messages.writeStackTrace(e); // e.printStackTrace(); Messages.postDebug(e.toString()); } }