Example usage for java.util Properties keySet

List of usage examples for java.util Properties keySet

Introduction

In this page you can find the example usage for java.util Properties keySet.

Prototype

@Override
    public Set<Object> keySet() 

Source Link

Usage

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Returns a Properties object as ";" separated string of name/value pairs.
 * @param props the properties object/*from   w  ww.ja v  a2 s  . com*/
 * @return the string representing it
 */
public String createNameValuePairs(final Properties props) {
    StringBuilder str = new StringBuilder();
    for (Object key : props.keySet()) {
        if (str.length() > 0) {
            str.append(';');
        }
        str.append(key.toString());
        str.append('=');
        str.append(props.get(key).toString());
    }
    return str.toString();
}

From source file:org.apache.maven.archetype.creator.FilesetArchetypeCreator.java

private void createArchetypePom(Model pom, File archetypeFilesDirectory, Properties pomReversedProperties,
        File initialPomFile, boolean preserveCData, boolean keepParent) throws IOException {
    File outputFile = FileUtils.resolveFile(archetypeFilesDirectory, Constants.ARCHETYPE_POM);

    if (preserveCData) {
        getLogger().debug("Preserving CDATA parts of pom");
        File inputFile = FileUtils.resolveFile(archetypeFilesDirectory, Constants.ARCHETYPE_POM + ".tmp");

        FileUtils.copyFile(initialPomFile, inputFile);

        Reader in = null;//from w w  w  .  j  av a  2  s . c  o  m
        Writer out = null;
        try {
            in = ReaderFactory.newXmlReader(inputFile);

            String initialcontent = IOUtil.toString(in);

            String content = getReversedContent(initialcontent, pomReversedProperties);

            outputFile.getParentFile().mkdirs();

            out = WriterFactory.newXmlWriter(outputFile);

            IOUtil.copy(content, out);
        } finally {
            IOUtil.close(in);
            IOUtil.close(out);
        }

        inputFile.delete();
    } else {
        if (!keepParent) {
            pom.setParent(null);
        }

        pom.setModules(null);
        pom.setGroupId("${" + Constants.GROUP_ID + "}");
        pom.setArtifactId("${" + Constants.ARTIFACT_ID + "}");
        pom.setVersion("${" + Constants.VERSION + "}");
        pom.setName(getReversedPlainContent(pom.getName(), pomReversedProperties));
        pom.setDescription(getReversedPlainContent(pom.getDescription(), pomReversedProperties));
        pom.setUrl(getReversedPlainContent(pom.getUrl(), pomReversedProperties));

        rewriteReferences(pom, pomReversedProperties.getProperty(Constants.ARTIFACT_ID),
                pomReversedProperties.getProperty(Constants.GROUP_ID));

        pomManager.writePom(pom, outputFile, initialPomFile);
    }

    Reader in = null;
    try {
        in = ReaderFactory.newXmlReader(initialPomFile);
        String initialcontent = IOUtil.toString(in);

        Iterator<?> properties = pomReversedProperties.keySet().iterator();
        while (properties.hasNext()) {
            String property = (String) properties.next();

            if (initialcontent.indexOf("${" + property + "}") > 0) {
                getLogger().warn("Archetype uses ${" + property + "} for internal processing, but file "
                        + initialPomFile + " contains this property already");
            }
        }
    } finally {
        IOUtil.close(in);
    }
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testNonConcreteTypeCreate() throws Exception {
    LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE NON CONCRETE TYPE CONTENT ~~~~~~~~~~~~~~~~~~~~~~~~~");
    WorkspaceFeedResource feedResource = setupCompositeWorkspace();
    final String[] invalidResources = new String[] { "composite/address-form.properties" };
    for (String resource : invalidResources) {
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader().getResourceAsStream(resource));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }/*from w  w  w  .  j a  v  a2 s . co  m*/
        try {
            feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                    ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
            Assert.fail("Invalid content should have failed for " + resource);
        } catch (Exception ex) {
            //Expected that creation fails
        }
    }
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testRequiredFieldValidationForCompositeField() throws Exception {
    LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~ MANDATORY COMPOSITE FIELD VALIDATION ~~~~~~~~~~~~~~~~~~~~~~~~~");
    WorkspaceFeedResource feedResource = setupCompositeWorkspace();
    final String[] resources = new String[] { "composite/form-value-invalid-collection.properties",
            "composite/form-value-invalid-complex.properties",
            "composite/form-value-invalid-composition.properties",
            "composite/form-value-invalid-content.properties" };
    for (String resource : resources) {
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader().getResourceAsStream(resource));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }/*from  ww w.ja  v  a 2s  .c om*/
        try {
            feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                    ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
            Assert.fail("Invalid content should have failed for " + resource);
        } catch (Exception ex) {
            //Expected that creation fails
        }
    }
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testCreateContentWithCompositeField() throws Exception {
    LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~ COMPOSITE CONTENT CREATION ~~~~~~~~~~~~~~~~~~~~~~~~~");
    WorkspaceFeedResource feedResource = setupCompositeWorkspace();
    final Properties properties = new Properties();
    properties.load(getClass().getClassLoader().getResourceAsStream("composite/form-value.properties"));
    Set<Object> formKeys = properties.keySet();
    FormDataMultiPart multiPart = new FormDataMultiPart();
    for (Object key : formKeys) {
        multiPart.field(key.toString(), properties.getProperty(key.toString()));
    }//from ww  w . j  ava2  s.co  m
    ClientResponse response = feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
            ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
    URI uri = response.getLocation();
    ContentResourceImpl resourceImpl = new ContentResourceImpl(feedResource, uri);
    final Content lastReadStateOfEntity = resourceImpl.getLastReadStateOfEntity();
    Assert.assertNotNull(lastReadStateOfEntity);
    Assert.assertEquals("i",
            ((CompositeFieldValue) lastReadStateOfEntity.getFieldsMap().get("billingAddress").getValue())
                    .getValues().get("astreet1").getValue().getValue());
    ContentResource resource = feedResource.getContents().createContentResource(lastReadStateOfEntity);
    Assert.assertNotNull(resource.getLastReadStateOfEntity());
    resource.update(lastReadStateOfEntity);
    resource.get();
    Assert.assertNotNull(resource.getLastReadStateOfEntity());
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testCustomFieldValidationForCompositeField() throws Exception {
    LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~ CUSTOM COMPOSITE FIELD VALIDATION ~~~~~~~~~~~~~~~~~~~~~~~~~");
    WorkspaceFeedResource feedResource = setupCompositeWorkspace();
    final String[] invalidResources = new String[] {
            "composite/form-value-invalid-custom_validation.properties" };
    for (String resource : invalidResources) {
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader().getResourceAsStream(resource));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }// w  w  w .j  a v  a2 s . co m
        try {
            feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                    ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
            Assert.fail("Invalid content should have failed for " + resource);
        } catch (Exception ex) {
            //Expected that creation fails
        }
    }
    final String[] validResources = new String[] { "composite/form-value-valid-custom_validation.properties" };
    for (String resource : validResources) {
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader().getResourceAsStream(resource));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }
        try {
            ClientResponse response = feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                    ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
            URI uri = response.getLocation();
            ContentResourceImpl resourceImpl = new ContentResourceImpl(feedResource, uri);
            final Content lastReadStateOfEntity = resourceImpl.getLastReadStateOfEntity();
            Assert.assertNotNull(lastReadStateOfEntity);
        } catch (Exception ex) {
            LOGGER.error(ex.getMessage(), ex);
            Assert.fail("Valid content should not have failed for " + resource);
        }
    }
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testCreateContentWithEnumField() throws Exception {
    LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~ ENUM CONTENT CREATION ~~~~~~~~~~~~~~~~~~~~~~~~~");
    WorkspaceFeedResource feedResource = setupEnumWorkspace();
    Properties properties = new Properties();
    properties.load(getClass().getClassLoader().getResourceAsStream("enum/form-value.properties"));
    Set<Object> formKeys = properties.keySet();
    FormDataMultiPart multiPart = new FormDataMultiPart();
    for (Object key : formKeys) {
        multiPart.field(key.toString(), properties.getProperty(key.toString()));
    }//from  w w  w  .jav  a2s .co  m
    ClientResponse response = feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
            ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
    URI uri = response.getLocation();
    ContentResourceImpl resourceImpl = new ContentResourceImpl(feedResource, uri);
    final Content lastReadStateOfEntity = resourceImpl.getLastReadStateOfEntity();
    Assert.assertNotNull(lastReadStateOfEntity);
    Field field = lastReadStateOfEntity.getFieldsMap().get("directEnumField");
    String val = field.getValue().getValue();
    Assert.assertEquals("1", val);
    field = ((CompositeFieldValue) lastReadStateOfEntity.getFieldsMap().get("compositedEnumField").getValue())
            .getValues().get("enumField");
    val = field.getValue().getValue();
    Assert.assertEquals("5", val);
    val = ((CollectionFieldValue) lastReadStateOfEntity.getFieldsMap().get("collectiveEnumField").getValue())
            .getValues().iterator().next().getValue();
    Assert.assertEquals("4", val);
    sleep();
    for (int i = 1; i < 5; ++i) {
        try {
            properties = new Properties();
            properties.load(getClass().getClassLoader()
                    .getResourceAsStream("enum/form-invalid-value-" + i + ".properties"));
            formKeys = properties.keySet();
            multiPart = new FormDataMultiPart();
            for (Object key : formKeys) {
                multiPart.field(key.toString(), properties.getProperty(key.toString()));
            }
            feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                    ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
            Assert.fail("Invalid content should have failed " + i);
        } catch (Exception ex) {
            //Expected that creation fails
        }
    }
}

From source file:org.apache.archiva.metadata.repository.file.FileMetadataRepository.java

@Override
public Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId,
        String projectVersion) throws MetadataResolutionException {
    try {//w  w w  .  j  a v a  2 s  . c o m
        Map<String, ArtifactMetadata> artifacts = new HashMap<>();

        File directory = new File(getDirectory(repoId), namespace + "/" + projectId + "/" + projectVersion);

        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);

        for (Map.Entry entry : properties.entrySet()) {
            String name = (String) entry.getKey();
            StringTokenizer tok = new StringTokenizer(name, ":");
            if (tok.hasMoreTokens() && "artifact".equals(tok.nextToken())) {
                String field = tok.nextToken();
                String id = tok.nextToken();

                ArtifactMetadata artifact = artifacts.get(id);
                if (artifact == null) {
                    artifact = new ArtifactMetadata();
                    artifact.setRepositoryId(repoId);
                    artifact.setNamespace(namespace);
                    artifact.setProject(projectId);
                    artifact.setProjectVersion(projectVersion);
                    artifact.setVersion(projectVersion);
                    artifact.setId(id);
                    artifacts.put(id, artifact);
                }

                String value = (String) entry.getValue();
                if ("updated".equals(field)) {
                    artifact.setFileLastModified(Long.parseLong(value));
                } else if ("size".equals(field)) {
                    artifact.setSize(Long.valueOf(value));
                } else if ("whenGathered".equals(field)) {
                    artifact.setWhenGathered(new Date(Long.parseLong(value)));
                } else if ("version".equals(field)) {
                    artifact.setVersion(value);
                } else if ("md5".equals(field)) {
                    artifact.setMd5(value);
                } else if ("sha1".equals(field)) {
                    artifact.setSha1(value);
                } else if ("facetIds".equals(field)) {
                    if (value.length() > 0) {
                        String propertyPrefix = "artifact:facet:" + id + ":";
                        for (String facetId : value.split(",")) {
                            MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
                            if (factory == null) {
                                log.error("Attempted to load unknown artifact metadata facet: " + facetId);
                            } else {
                                MetadataFacet facet = factory.createMetadataFacet();
                                String prefix = propertyPrefix + facet.getFacetId();
                                Map<String, String> map = new HashMap<>();
                                for (Object key : new ArrayList(properties.keySet())) {
                                    String property = (String) key;
                                    if (property.startsWith(prefix)) {
                                        map.put(property.substring(prefix.length() + 1),
                                                properties.getProperty(property));
                                    }
                                }
                                facet.fromProperties(map);
                                artifact.addFacet(facet);
                            }
                        }
                    }

                    updateArtifactFacets(artifact, properties);
                }
            }
        }
        return artifacts.values();
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}

From source file:com.smartitengineering.cms.client.impl.AppTest.java

@Test
public void testCreateContentWithContentCoProcessors() throws Exception {
    WorkspaceFeedResource feedResource = setupContentCoProcessorExecWorkspace();
    ClientConfig config = new DefaultClientConfig();
    config.getClasses().add(JacksonJsonProvider.class);
    config.getClasses().add(TextURIListProvider.class);
    config.getClasses().add(FeedProvider.class);
    Client client = Client.create(config);

    {/*w  w w . j  av  a  2  s  .  c o m*/
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader()
                .getResourceAsStream("contentcoprocessors/form-value-write.properties"));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }
        ClientResponse response = feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
        URI uri = response.getLocation();
        ContentResourceImpl resourceImpl = new ContentResourceImpl(feedResource, uri);
        final Content lastReadStateOfEntity = resourceImpl.getLastReadStateOfEntity();
        Assert.assertNotNull(lastReadStateOfEntity);
        Assert.assertNotNull(lastReadStateOfEntity.getFieldsMap().get("directEnumFieldCopy"));
        Assert.assertNotNull(lastReadStateOfEntity.getFieldsMap().get("dynaField"));
        Assert.assertEquals(lastReadStateOfEntity.getFieldsMap().get("directEnumField").getValue().getValue(),
                lastReadStateOfEntity.getFieldsMap().get("directEnumFieldCopy").getValue().getValue());
        String dynaField = lastReadStateOfEntity.getFieldsMap().get("dynaField").getValue().getValue();
        sleep();
        final Content reReadStateOfEntity = client.resource(resourceImpl.getUri())
                .accept(MediaType.APPLICATION_JSON).header("Pragma", "no-cache").get(Content.class);
        Assert.assertEquals(dynaField,
                reReadStateOfEntity.getFieldsMap().get("dynaField").getValue().getValue());
    }

    {
        final Properties properties = new Properties();
        properties.load(getClass().getClassLoader()
                .getResourceAsStream("contentcoprocessors/form-value-read.properties"));
        Set<Object> formKeys = properties.keySet();
        FormDataMultiPart multiPart = new FormDataMultiPart();
        for (Object key : formKeys) {
            multiPart.field(key.toString(), properties.getProperty(key.toString()));
        }
        ClientResponse response = feedResource.getContents().post(MediaType.MULTIPART_FORM_DATA, multiPart,
                ClientResponse.Status.CREATED, ClientResponse.Status.ACCEPTED, ClientResponse.Status.OK);
        URI uri = response.getLocation();
        ContentResourceImpl resourceImpl = new ContentResourceImpl(feedResource, uri);
        final Content lastReadStateOfEntity = resourceImpl.getLastReadStateOfEntity();
        Assert.assertNotNull(lastReadStateOfEntity);
        Assert.assertNotNull(lastReadStateOfEntity.getFieldsMap().get("directEnumFieldCopy"));
        Assert.assertNotNull(lastReadStateOfEntity.getFieldsMap().get("dynaField"));
        Assert.assertEquals(lastReadStateOfEntity.getFieldsMap().get("directEnumField").getValue().getValue(),
                lastReadStateOfEntity.getFieldsMap().get("directEnumFieldCopy").getValue().getValue());
        String dynaField = lastReadStateOfEntity.getFieldsMap().get("dynaField").getValue().getValue();
        sleep();
        final Content reReadStateOfEntity = client.resource(resourceImpl.getUri())
                .accept(MediaType.APPLICATION_JSON).header("Pragma", "no-cache").get(Content.class);
        Assert.assertFalse(
                dynaField.equals(reReadStateOfEntity.getFieldsMap().get("dynaField").getValue().getValue()));
    }

    sleep();
}