List of usage examples for java.util Properties clear
@Override public synchronized void clear()
From source file:org.geoserver.catalog.impl.CatalogBuilderIntTest.java
private void createTimeMosaic(File mosaic, int fileCount) throws Exception { if (mosaic.exists()) { if (mosaic.isDirectory()) { FileUtils.deleteDirectory(mosaic); } else {//from w ww . j av a 2s .c o m mosaic.delete(); } } mosaic.mkdir(); System.out.println(mosaic.getAbsolutePath()); // build the reference coverage into a byte array GridCoverageFactory factory = new GridCoverageFactory(); BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR); ReferencedEnvelope envelope = new ReferencedEnvelope(0, 10, 0, 10, CRS.decode("EPSG:4326")); GridCoverage2D test = factory.create("test", bi, envelope); ByteArrayOutputStream bos = new ByteArrayOutputStream(); GeoTiffWriter writer = new GeoTiffWriter(bos); writer.write(test, null); writer.dispose(); // create the lot of files byte[] bytes = bos.toByteArray(); for (int i = 0; i < fileCount; i++) { String pad = ""; if (i < 10) { pad = "000"; } else if (i < 100) { pad = "00"; } else if (i < 1000) { pad = "0"; } File target = new File(mosaic, "tile_" + pad + i + ".tiff"); FileUtils.writeByteArrayToFile(target, bytes); } // create the mosaic indexer property file Properties p = new Properties(); p.put("ElevationAttribute", "elevation"); p.put("Schema", "*the_geom:Polygon,location:String,elevation:Integer"); p.put("PropertyCollectors", "IntegerFileNameExtractorSPI[elevationregex](elevation)"); FileOutputStream fos = new FileOutputStream(new File(mosaic, "indexer.properties")); p.store(fos, null); fos.close(); // and the regex itself p.clear(); p.put("regex", "(?<=_)(\\d{4})"); fos = new FileOutputStream(new File(mosaic, "elevationregex.properties")); p.store(fos, null); fos.close(); }
From source file:org.geoserver.importer.rest.ImporterIntegrationTest.java
@Test public void testImportGranuleInEmptyMosaic() throws Exception { Catalog catalog = getCatalog();/*ww w. j a v a2 s.co m*/ // prepare an empty mosaic File root = getTestData().getDataDirectoryRoot(); String mosaicName = "emptyMosaic"; File mosaicRoot = new File(root, mosaicName); ensureClean(mosaicRoot); File granulesRoot = new File(root, mosaicName + "_granules"); ensureClean(granulesRoot); Properties props = new Properties(); props.put("SPI", "org.geotools.data.h2.H2DataStoreFactory"); props.put("database", "empty"); try (FileOutputStream fos = new FileOutputStream(new File(mosaicRoot, "datastore.properties"))) { props.store(fos, null); } props.clear(); props.put("CanBeEmpty", "true"); try (FileOutputStream fos = new FileOutputStream(new File(mosaicRoot, "indexer.properties"))) { props.store(fos, null); } CatalogBuilder cb = new CatalogBuilder(catalog); WorkspaceInfo ws = catalog.getDefaultWorkspace(); cb.setWorkspace(ws); CoverageStoreInfo store = cb.buildCoverageStore(mosaicName); store.setURL("./" + mosaicName); store.setType("ImageMosaic"); catalog.save(store); // put a granule in the mosaic unpack("geotiff/EmissiveCampania.tif.bz2", granulesRoot); File granule = new File(granulesRoot, "EmissiveCampania.tif"); store = catalog.getCoverageStoreByName(mosaicName); // @formatter:off String contextDefinition = "{\n" + " \"import\": {\n" + " \"data\": {\n" + " \"type\": \"file\",\n" + " \"file\": \"" + jsonSafePath(granule.getAbsoluteFile()) + "\"\n" + " }," + " targetStore: {\n" + " dataStore: {\n" + " name: \"" + store.getName() + "\",\n" + " }\n" + " }\n" + " }\n" + "}"; // @formatter:on // sync execution JSONObject json = (JSONObject) json( postAsServletResponse("/rest/imports?exec=true", contextDefinition, "application/json")); // print(json); String state = json.getJSONObject("import").getString("state"); assertEquals("COMPLETE", state); // check the import produced a granule StructuredGridCoverage2DReader reader = (StructuredGridCoverage2DReader) store.getGridCoverageReader(null, null); GranuleSource granules = reader.getGranules(reader.getGridCoverageNames()[0], true); assertEquals(1, granules.getCount(Query.ALL)); // check we now also have a layer LayerInfo layer = catalog.getLayerByName(mosaicName); assertNotNull(layer); }
From source file:org.grlea.log.test.commons.TestOfCommonsLoggingAdapter.java
protected void setUp() throws Exception { outputStream = new ByteArrayOutputStream(512); SimpleLog simpleLog = SimpleLog.defaultInstance(); Properties simpleLogProperties = getLogProperties(simpleLog); simpleLogProperties.clear(); simpleLog.reloadProperties();/*from w ww. j ava2 s . co m*/ simpleLog.setWriter(new PrintWriter(outputStream, true)); System.setProperty("org.apache.commons.logging.Log", CommonsLoggingAdapter.class.getName()); }
From source file:org.gsweb.components.ui.ToolBar.java
private void setLabelNameFromProperties(Map<String, Object> params, String language) { String propFileName = "META-INF/resource/toolbar/ui.toolbar_" + language + ".properties"; InputStream is = null;/* w w w .j a v a2s . c om*/ is = TextBox.class.getClassLoader().getResourceAsStream(propFileName); if (is != null) { Properties prop = new Properties(); try { prop.load(is); params.put("createNewName", prop.get("createNewName")); params.put("saveName", prop.get("saveName")); params.put("exportName", prop.get("exportName")); params.put("importName", prop.get("importName")); params.put("refreshName", prop.get("refreshName")); params.put("cancelName", prop.get("cancelName")); params.put("fullscreenName", prop.get("fullscreenName")); } catch (IOException e1) { e1.printStackTrace(); } finally { try { is.close(); } catch (IOException e2) { e2.printStackTrace(); } } prop.clear(); prop = null; } is = null; }
From source file:org.hyperic.hq.plugin.vmware.VMwareDetector.java
private ServerResource getLinuxServer() throws PluginException { File config = new File("/etc/vmware/config"); if (!config.exists()) { return null; }//from w w w. j av a 2 s . c o m Properties props = loadProperties(config); String path = props.getProperty("defaultVMPath"); String port = props.getProperty(VMwareConnectParams.PROP_AUTHD_PORT); if (port == null) { //this is vmware workstation return null; } props.clear(); VMwareProductInfo info = getProductInfo(props); if (info == null) { return null; } if (isESX()) { if ((info.major == 3) && (info.minor > 0)) { //only 3.0.x and lower are supported log.warn(info.version + " not supported, see: " + "http://support.hyperic.com/display/hypcomm/VMware"); return null; } } if (path == null) { path = "/etc/vmware"; } ServerResource server = createServerResource(path); server.setProductConfig(new ConfigResponse(props)); server.setMeasurementConfig(); setCustomProperties(server, info); return server; }
From source file:org.itracker.web.util.ImportExportUtilities.java
private static void addIssueAttachments(XMLWriter writer, List<IssueAttachment> entities) throws IOException { if (entities.size() > 0) { Element elTmp;/*from w w w .j a va 2 s.co m*/ final DocumentFactory factory = getDocumentFactory(); final Element el = factory.createElement(TAG_ISSUE_ATTACHMENTS); writer.writeOpen(el); for (IssueAttachment c : entities) { elTmp = factory.createElement(TAG_ISSUE_ATTACHMENT); writer.writeOpen(elTmp); Properties pTmp = new Properties(); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_DESCRIPTION, ITrackerResources.escapeUnicodeString(c.getDescription(), false)); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_FILENAME, ITrackerResources.escapeUnicodeString(c.getFileName(), false)); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_ORIGFILE, ITrackerResources.escapeUnicodeString(c.getOriginalFileName(), false)); addCdataPropertyTags(writer, pTmp); pTmp.clear(); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_SIZE, String.valueOf(c.getSize())); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_TYPE, StringUtils.defaultString(c.getType(), "application/octet-stream")); pTmp.setProperty(TAG_ISSUE_ATTACHMENT_CREATOR, TAG_USER + c.getUser().getId()); addPropertyTags(writer, pTmp); writer.writeClose(elTmp); } writer.writeClose(el); } }
From source file:org.itracker.web.util.ImportExportUtilities.java
private static void getProjectXML(XMLWriter writer, Project project) throws IOException { Element elProject = getDocumentFactory().createElement(TAG_PROJECT); elProject.addAttribute(ATTR_ID, TAG_PROJECT + project.getId()); elProject.addAttribute(ATTR_SYSTEMID, String.valueOf(project.getId())); writer.writeOpen(elProject);/*from w w w .ja v a 2 s . com*/ Properties tags = new Properties(); tags.setProperty(TAG_PROJECT_NAME, ITrackerResources.escapeUnicodeString(project.getName(), false)); tags.setProperty(TAG_PROJECT_DESCRIPTION, ITrackerResources.escapeUnicodeString(project.getDescription(), false)); addCdataPropertyTags(writer, tags); tags.clear(); tags.setProperty(TAG_PROJECT_STATUS, ProjectUtilities.getStatusName(project.getStatus(), EXPORT_LOCALE)); tags.setProperty(TAG_PROJECT_OPTIONS, String.valueOf(project.getOptions())); addPropertyTags(writer, tags); addIdCollection(writer, project.getCustomFields(), TAG_PROJECT_FIELDS, TAG_PROJECT_FIELD_ID, TAG_CUSTOM_FIELD); addIdCollection(writer, project.getOwners(), TAG_PROJECT_OWNERS, TAG_PROJECT_OWNER_ID, TAG_USER); addProjectComponents(writer, project.getComponents()); addProjectVersions(writer, project.getVersions()); writer.writeClose(elProject); }
From source file:org.itracker.web.util.ImportExportUtilities.java
public static void getUserXML(XMLWriter writer, User user) throws IOException { Element elUser = getDocumentFactory().createElement(TAG_USER); elUser.addAttribute(ATTR_ID, TAG_USER + user.getId()); elUser.addAttribute(ATTR_SYSTEMID, String.valueOf(user.getId())); writer.writeOpen(elUser);/*from www. j a v a 2 s . c o m*/ Properties tags = new Properties(); tags.setProperty(TAG_LOGIN, ITrackerResources.escapeUnicodeString(user.getLogin(), false)); tags.setProperty(TAG_FIRST_NAME, ITrackerResources.escapeUnicodeString(user.getFirstName(), false)); tags.setProperty(TAG_LAST_NAME, ITrackerResources.escapeUnicodeString(user.getLastName(), false)); tags.setProperty(TAG_EMAIL, ITrackerResources.escapeUnicodeString(user.getEmail(), false)); addCdataPropertyTags(writer, tags); tags.clear(); tags.setProperty(TAG_USER_STATUS, String.valueOf(user.getStatus())); tags.setProperty(TAG_SUPER_USER, String.valueOf(user.isSuperUser())); addPropertyTags(writer, tags); writer.writeClose(elUser); }
From source file:org.itracker.web.util.ImportExportUtilities.java
private static void getCustomFieldsXML(XMLWriter writer, SystemConfiguration config) throws IOException { Properties tags = new Properties(); Element elCustomField = getDocumentFactory().createElement(TAG_CUSTOM_FIELDS); Element elTmp;//from w w w. j a v a2 s. co m writer.writeOpen(elCustomField); for (CustomField c : config.getCustomFields()) { tags.clear(); tags.setProperty(TAG_CUSTOM_FIELD_LABEL, ITrackerResources .escapeUnicodeString(CustomFieldUtilities.getCustomFieldName(c.getId()), false)); tags.setProperty(TAG_CUSTOM_FIELD_TYPE, String.valueOf(c.getFieldType().name())); tags.setProperty(TAG_CUSTOM_FIELD_REQUIRED, String.valueOf(c.isRequired())); tags.setProperty(TAG_CUSTOM_FIELD_DATEFORMAT, ITrackerResources.escapeUnicodeString(c.getDateFormat(), false)); tags.setProperty(TAG_CUSTOM_FIELD_SORTOPTIONS, String.valueOf(c.isSortOptionsByName())); tags.setProperty(TAG_CUSTOM_FIELD_LABEL, ITrackerResources .escapeUnicodeString(CustomFieldUtilities.getCustomFieldName(c.getId()), false)); elTmp = getDocumentFactory().createElement(TAG_CUSTOM_FIELD); elTmp.addAttribute(ATTR_ID, TAG_CUSTOM_FIELD + c.getId()); elTmp.addAttribute(ATTR_SYSTEMID, String.valueOf(c.getId())); writer.writeOpen(elTmp); addCdataPropertyTags(writer, tags); if (c.getFieldType() == CustomField.Type.LIST) { Element elOption; for (CustomFieldValue o : c.getOptions()) { elOption = getDocumentFactory().createElement(TAG_CUSTOM_FIELD_OPTION); elOption.addAttribute(ATTR_VALUE, ITrackerResources.escapeUnicodeString(o.getValue(), false)); elOption.add(getDocumentFactory().createCDATA(ITrackerResources .escapeUnicodeString(CustomFieldUtilities.getCustomFieldOptionName(o, null), false))); writer.write(elOption); } } writer.writeClose(elTmp); } writer.writeClose(elCustomField); }
From source file:org.jajuk.util.UpgradeManager.java
/** * For Jajuk < 1.9: bootstrap file is now in XML format * <br>//from www . ja v a2 s . c o m * If it exists and contains data in 1.7 or 1.8 format, it convert it to new XML * format (to handle backslashes properly, old format just drop them) * <br> * This method doesn't yet validate provided workspace paths but only the bootstrap file * structure itself. */ public static void upgradeBootstrapFile() { try { String KEY_TEST = "test"; String KEY_FINAL = "final"; File bootstrapOld = new File(SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD)); File bootstrapOldOldHome = new File(System.getProperty("user.home") + "/" + Const.FILE_BOOTSTRAP_OLD); File bootstrapNew = new File(SessionService.getBootstrapPath()); // Fix for #1473 : move the bootstrap file if required (See #1473) if (UtilSystem.isUnderWindows() && !bootstrapOld.equals(bootstrapOldOldHome) && !bootstrapOld.exists() && bootstrapOldOldHome.exists()) { try { FileUtils.copyFileToDirectory(bootstrapOldOldHome, new File(UtilSystem.getUserHome())); UtilSystem.deleteFile(bootstrapOldOldHome); } catch (IOException ex) { ex.printStackTrace(); } } if (bootstrapOld.exists() && !bootstrapNew.exists()) { Properties prop = null; // Try to load a bootstrap file using plain text old format prop = new Properties(); FileInputStream fis = new FileInputStream( SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD)); prop.load(fis); fis.close(); // If it exists and contains pre-1.7 bootstrap format (a single line with a raw path), // convert it to 1.7 format first if (prop.size() == 1) { // We get something like <... path ...> = <nothing> String path = (String) prop.keys().nextElement(); // we use this path for both test and final workspace prop.clear(); prop.put(KEY_TEST, path); prop.put(KEY_FINAL, path); } // Make sure to populate both test and final release if (!prop.containsKey(KEY_TEST)) { prop.put(KEY_TEST, UtilSystem.getUserHome()); } if (!prop.containsKey(KEY_FINAL)) { prop.put(KEY_FINAL, UtilSystem.getUserHome()); } // Write down the new bootstrap file SessionService.commitBootstrapFile(prop); // Delete old bootstrap file bootstrapOld.delete(); } } catch (Exception e) { // Do not throw any exception from here. display raw stack trace, Logs facilities // are not yet available. e.printStackTrace(); } }