Package org.zanata.rest.dto.resource

Examples of org.zanata.rest.dto.resource.TextFlow


      resource.setLang(LocaleId.EN_US);
      resource.setName("test");
      resource.setRevision(1);
      resource.setType(ResourceType.FILE);

      final TextFlow textFlow = new TextFlow();
      textFlow.setId("id");
      textFlow.setContent("Some text to be translated");
      textFlow.setLang(LocaleId.EN_US);
      textFlow.setRevision(1);

      resource.getTextFlows().add(textFlow);

      /* create a http client to supply the credentials */
      final HttpClient httpClient = new HttpClient();
View Full Code Here


        Resource entity = new Resource(doc.getDocId());
        log.debug("get resource details {}", entity.toString());
        resourceUtils.transferToResource(doc, entity);

        for (HTextFlow htf : doc.getTextFlows()) {
            TextFlow tf =
                    new TextFlow(htf.getResId(), doc.getLocale().getLocaleId());
            resourceUtils.transferToTextFlow(htf, tf);
            resourceUtils.transferToTextFlowExtensions(htf,
                    tf.getExtensions(true), extensions);
            entity.getTextFlows().add(tf);
        }

        // handle extensions
        resourceUtils.transferToResourceExtensions(doc,
View Full Code Here

                } else if (event.getEventType() == EventType.TEXT_UNIT) {
                    TextUnit tu = (TextUnit) event.getResource();
                    if (!tu.getSource().isEmpty() && tu.isTranslatable()) {
                        String content = getTranslatableText(tu);
                        if (!content.isEmpty()) {
                            TextFlow tf =
                                    new TextFlow(getIdFor(tu, content,
                                            subDocName), sourceLocale);
                            tf.setPlural(false);
                            tf.setContents(content);
                            if (shouldAdd(tf.getId(), tf, addedResources)) {
                                addedResources.put(tf.getId(), tf);
                                resources.add(tf);
                            }
                        }
                    }
                }
View Full Code Here

        // handle extensions
        this.transferToResourceExtensions(document, entity.getExtensions(true),
                extensions);

        for (HTextFlow htf : document.getTextFlows()) {
            TextFlow tf =
                    new TextFlow(htf.getResId(), document.getLocale()
                            .getLocaleId());
            this.transferToTextFlowExtensions(htf, tf.getExtensions(true),
                    extensions);
            this.transferToTextFlow(htf, tf);
            entity.getTextFlows().add(tf);
        }
View Full Code Here

        return resource;
    }

    public static TextFlow buildTextFlow(String resId, String... contents) {

        TextFlow textFlow = new TextFlow();
        textFlow.setId(resId);
        textFlow.setLang(LocaleId.EN_US);
        textFlow.setRevision(0);
        textFlow.setContents(contents);
        return textFlow;
    }
View Full Code Here

    @Test
    public void createResourceWithContentUsingPost() {
        Resource sr = createSourceResource("my.txt");

        TextFlow stf = new TextFlow("tf1", LocaleId.EN, "tf1");
        sr.getTextFlows().add(stf);

        ClientResponse<String> postResponse =
                sourceDocResource.post(sr, null, true);
        assertThat(postResponse.getResponseStatus(), is(Status.CREATED));
View Full Code Here

    @Test
    public void createResourceWithContentUsingPut() {
        Resource sr = createSourceResource("my.txt");

        TextFlow stf = new TextFlow("tf1", LocaleId.EN, "tf1");
        sr.getTextFlows().add(stf);

        ClientResponse<String> response =
                sourceDocResource.putResource("my.txt", sr, null);
        assertThat(response.getResponseStatus(), is(Status.CREATED));
View Full Code Here

    public void createPoResourceWithPoHeader() {
        String docName = "my.txt";
        String docUri = RestUtil.convertToDocumentURIId(docName);
        Resource sr = createSourceResource(docName);

        TextFlow stf = new TextFlow("tf1", LocaleId.EN, "tf1");
        sr.getTextFlows().add(stf);

        // @formatter:off
        /*
        TODO: move this into an AbstractResourceMeta test (PoHeader is valid for source documents, not target)
View Full Code Here

        String docUrl = RestUtil.convertToDocumentURIId(docName);
        Resource doc = createSourceDoc(docName, false);
        List<TextFlow> textFlows = doc.getTextFlows();

        for (int i = 0; i < 2; i++) {
            TextFlow textFlow = new TextFlow("tf1");
            textFlow.setContents("hello world!");
            textFlows.add(textFlow);
        }
        ClientResponse<?> response =
                sourceDocResource.putResource(docUrl, doc, null);
        assertThat(response.getStatus(), is(Status.BAD_REQUEST.getStatusCode()));
View Full Code Here

        Resource doc = createSourceDoc(docName, false);

        List<TextFlow> textFlows = doc.getTextFlows();
        textFlows.clear();

        TextFlow textFlow = new TextFlow("tf1");
        textFlow.setContents("hello world!");
        textFlows.add(textFlow);

        TextFlow tf3 = new TextFlow("tf3");
        tf3.setContents("more text");
        textFlows.add(tf3);

        // Marshaller m = null;
        // JAXBContext jc = JAXBContext.newInstance(Resource.class);
        // m = jc.createMarshaller();
        // m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        // m.marshal(doc, System.out);

        Response response = sourceDocResource.putResource(docUrl, doc, null);

        assertThat(response.getStatus(), is(Status.CREATED.getStatusCode()));
        assertThat(response.getMetadata().getFirst("Location").toString(),
                endsWith(RESOURCE_PATH + docUrl));

        ClientResponse<Resource> documentResponse =
                sourceDocResource.getResource(docUrl, null);

        assertThat(documentResponse.getResponseStatus(), is(Status.OK));

        doc = documentResponse.getEntity();

        assertThat(doc.getRevision(), is(1));

        assertThat("Should have textFlows", doc.getTextFlows(), notNullValue());
        assertThat("Should have 2 textFlows", doc.getTextFlows().size(), is(2));
        assertThat("Should have tf1 textFlow", doc.getTextFlows().get(0)
                .getId(), is("tf1"));
        assertThat("Container1 should have tf3 textFlow", doc.getTextFlows()
                .get(1).getId(), is(tf3.getId()));

        textFlow = doc.getTextFlows().get(0);
        textFlow.setId("tf2");

        response = sourceDocResource.putResource(docUrl, doc, null);
View Full Code Here

TOP

Related Classes of org.zanata.rest.dto.resource.TextFlow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.