Search in sources :

Example 11 with Content

use of com.google.api.ads.admanager.axis.v202108.Content in project mycore by MyCoRe-Org.

the class MCRXMLHelperTest method testList.

@Test
public void testList() throws Exception {
    Element child1 = new Element("child").setText("Hallo Welt");
    Element child2 = new Element("child").setText("hello world");
    Element child3 = new Element("child").setText("Bonjour le monde");
    List<Content> l1 = new ArrayList<>();
    l1.add(child1);
    l1.add(child2);
    l1.add(child3);
    Element root = new Element("root");
    root.addContent(l1);
    String formattedXML = "<root>\n<child>Hallo Welt</child>\n" + "<child>hello world</child>" + "<child>Bonjour le monde</child>\n</root>";
    SAXBuilder b = new SAXBuilder();
    Document doc = b.build(new ByteArrayInputStream(formattedXML.getBytes(Charset.forName("UTF-8"))));
    assertEquals("Elements should be equal", true, MCRXMLHelper.deepEqual(root, doc.getRootElement()));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Content(org.jdom2.Content) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) Test(org.junit.Test)

Example 12 with Content

use of com.google.api.ads.admanager.axis.v202108.Content in project mycore by MyCoRe-Org.

the class MCRWCMSDefaultSectionProvider method getContent.

/**
 * Returns the content of an element as string. The element itself
 * is ignored.
 *
 * @param e the element to get the content from
 * @return the content as string
 */
protected String getContent(Element e) throws IOException {
    XMLOutputter out = new XMLOutputter();
    StringWriter writer = new StringWriter();
    for (Content child : e.getContent()) {
        if (child instanceof Element) {
            out.output((Element) child, writer);
        } else if (child instanceof Text) {
            Text t = (Text) child;
            String trimmedText = t.getTextTrim();
            if (!trimmedText.equals("")) {
                Text newText = new Text(trimmedText);
                out.output(newText, writer);
            }
        }
    }
    return writer.toString();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Content(org.jdom2.Content) JsonElement(com.google.gson.JsonElement) Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 13 with Content

use of com.google.api.ads.admanager.axis.v202108.Content in project mycore by MyCoRe-Org.

the class MCRXSL2XMLTransformer method getDocument.

private Document getDocument(JDOMResult result) {
    Document resultDoc = result.getDocument();
    if (resultDoc == null) {
        // Sometimes a transformation produces whitespace strings
        // JDOM would produce a empty document if it detects those
        // So we remove them, if they exists.
        List<Content> transformResult = result.getResult();
        int origSize = transformResult.size();
        Iterator<Content> iterator = transformResult.iterator();
        while (iterator.hasNext()) {
            Content content = iterator.next();
            if (content instanceof Text) {
                String trimmedText = ((Text) content).getTextTrim();
                if (trimmedText.length() == 0) {
                    iterator.remove();
                }
            }
        }
        if (transformResult.size() < origSize) {
            JDOMFactory f = result.getFactory();
            if (f == null) {
                f = new DefaultJDOMFactory();
            }
            resultDoc = f.document(null);
            resultDoc.setContent(transformResult);
        }
    }
    return resultDoc;
}
Also used : DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) MCRContent(org.mycore.common.content.MCRContent) Content(org.jdom2.Content) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) JDOMFactory(org.jdom2.JDOMFactory) DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) Text(org.jdom2.Text) Document(org.jdom2.Document)

Example 14 with Content

use of com.google.api.ads.admanager.axis.v202108.Content in project mycore by MyCoRe-Org.

the class MCRMODSMetadataShareAgent method distributeMetadata.

/* (non-Javadoc)
     * @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject)
     */
@Override
public void distributeMetadata(MCRObject holder) throws MCRPersistenceException, MCRAccessException {
    MCRMODSWrapper holderWrapper = new MCRMODSWrapper(holder);
    List<MCRMetaLinkID> children = holder.getStructure().getChildren();
    if (!children.isEmpty()) {
        LOGGER.info("Update inherited metadata");
        for (MCRMetaLinkID childIdRef : children) {
            MCRObjectID childId = childIdRef.getXLinkHrefID();
            if (MCRMODSWrapper.isSupported(childId)) {
                LOGGER.info("Update: {}", childIdRef);
                MCRObject child = MCRMetadataManager.retrieveMCRObject(childId);
                MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
                inheritToChild(holderWrapper, childWrapper);
                LOGGER.info("Saving: {}", childIdRef);
                try {
                    MCRMetadataManager.update(child);
                } catch (MCRPersistenceException | MCRAccessException e) {
                    throw new MCRPersistenceException("Error while updating inherited metadata", e);
                }
            }
        }
    }
    Collection<String> recipientIds = MCRLinkTableManager.instance().getSourceOf(holder.getId(), MCRLinkTableManager.ENTRY_TYPE_REFERENCE);
    for (String rId : recipientIds) {
        MCRObjectID recipientId = MCRObjectID.getInstance(rId);
        if (MCRMODSWrapper.isSupported(recipientId)) {
            LOGGER.info("distribute metadata to {}", rId);
            MCRObject recipient = MCRMetadataManager.retrieveMCRObject(recipientId);
            MCRMODSWrapper recipientWrapper = new MCRMODSWrapper(recipient);
            for (Element relatedItem : recipientWrapper.getLinkedRelatedItems()) {
                String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
                if (holder.getId().toString().equals(holderId)) {
                    @SuppressWarnings("unchecked") Filter<Content> sharedMetadata = (Filter<Content>) Filters.element("part", MCRConstants.MODS_NAMESPACE).negate();
                    relatedItem.removeContent(sharedMetadata);
                    relatedItem.addContent(holderWrapper.getMODS().cloneContent());
                    LOGGER.info("Saving: {}", recipientId);
                    try {
                        MCRMetadataManager.update(recipient);
                    } catch (MCRPersistenceException | MCRAccessException e) {
                        throw new MCRPersistenceException("Error while updating shared metadata", e);
                    }
                }
            }
        }
    }
}
Also used : Element(org.jdom2.Element) MCRAccessException(org.mycore.access.MCRAccessException) MCRObject(org.mycore.datamodel.metadata.MCRObject) Filter(org.jdom2.filter.Filter) Content(org.jdom2.Content) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 15 with Content

use of com.google.api.ads.admanager.axis.v202108.Content in project googleads-java-lib by googleads.

the class CreateVideoLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param orderId the ID of the order that the line item will belong to.
 * @param targetedVideoAdUnitId the ID of the d unit that the line item will target.
 * @param contentId the ID of the video content that the line item will target.
 * @param contentBundleId the ID of the video content bundle that the line item will target.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long orderId, String targetedVideoAdUnitId, long contentId, long contentBundleId, long cmsMetadataValueId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create content targeting.
    ContentTargeting contentTargeting = new ContentTargeting();
    contentTargeting.setTargetedContentIds(new long[] { contentId });
    contentTargeting.setTargetedVideoContentBundleIds(new long[] { contentBundleId });
    // Target only video players
    RequestPlatformTargeting requestPlatformTargeting = new RequestPlatformTargeting();
    requestPlatformTargeting.setTargetedRequestPlatforms(new RequestPlatform[] { RequestPlatform.VIDEO_PLAYER });
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { new AdUnitTargeting(targetedVideoAdUnitId, true) });
    // Create video position targeting.
    VideoPosition videoPosition = new VideoPosition();
    videoPosition.setPositionType(VideoPositionType.PREROLL);
    VideoPositionTarget videoPositionTarget = new VideoPositionTarget();
    videoPositionTarget.setVideoPosition(videoPosition);
    VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting();
    videoPositionTargeting.setTargetedPositions(new VideoPositionTarget[] { videoPositionTarget });
    // Create custom targeting for CmsMetadataValues.
    CmsMetadataCriteria contentCustomCriteria = new CmsMetadataCriteria();
    contentCustomCriteria.setCmsMetadataValueIds(new long[] { cmsMetadataValueId });
    contentCustomCriteria.setOperator(CmsMetadataCriteriaComparisonOperator.EQUALS);
    CustomCriteriaSet customCriteriaSet = new CustomCriteriaSet();
    customCriteriaSet.setChildren(new CustomCriteriaNode[] { contentCustomCriteria });
    customCriteriaSet.setLogicalOperator(CustomCriteriaSetLogicalOperator.AND);
    // Create targeting.
    Targeting targeting = new Targeting();
    targeting.setContentTargeting(contentTargeting);
    targeting.setInventoryTargeting(inventoryTargeting);
    targeting.setVideoPositionTargeting(videoPositionTargeting);
    targeting.setRequestPlatformTargeting(requestPlatformTargeting);
    targeting.setCustomTargeting(customCriteriaSet);
    // Create local line item object.
    LineItem lineItem = new LineItem();
    lineItem.setName("Video line item #" + new Random().nextInt(Integer.MAX_VALUE));
    lineItem.setOrderId(orderId);
    lineItem.setTargeting(targeting);
    // Allow the line item to be booked even if there is not enough inventory.
    lineItem.setAllowOverbook(true);
    // Set the line item type to SPONSORSHIP.
    lineItem.setLineItemType(LineItemType.SPONSORSHIP);
    // Set the environment type to video.
    lineItem.setEnvironmentType(EnvironmentType.VIDEO_PLAYER);
    // Set the creative rotation type to optimized.
    lineItem.setCreativeRotationType(CreativeRotationType.OPTIMIZED);
    // Create the master creative placeholder.
    CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder();
    creativeMasterPlaceholder.setSize(new Size(640, 360, false));
    // Create companion creative placeholders.
    CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder();
    companionCreativePlaceholder.setSize(new Size(300, 250, false));
    // Set companion creative placeholders.
    creativeMasterPlaceholder.setCompanions(new CreativePlaceholder[] { companionCreativePlaceholder });
    // Set the size of creatives that can be associated with this line item.
    lineItem.setCreativePlaceholders(new CreativePlaceholder[] { creativeMasterPlaceholder });
    // Set delivery of video companions to optional.
    lineItem.setCompanionDeliveryOption(CompanionDeliveryOption.OPTIONAL);
    // Set the maximum video creative length for this line item to 15 seconds.
    lineItem.setVideoMaxDuration(15000L);
    // Set the length of the line item to run.
    lineItem.setStartDateTimeType(StartDateTimeType.IMMEDIATELY);
    lineItem.setEndDateTime(DateTimes.toDateTime(Instant.now().plus(Duration.standardDays(30L)), "America/New_York"));
    // Set the cost per day to $1.
    lineItem.setCostType(CostType.CPD);
    lineItem.setCostPerUnit(new Money("USD", 1000000L));
    // Set the percentage to be 100%.
    Goal goal = new Goal();
    goal.setGoalType(GoalType.DAILY);
    goal.setUnits(100L);
    lineItem.setPrimaryGoal(goal);
    // Create the line item on the server.
    LineItem[] lineItems = lineItemService.createLineItems(new LineItem[] { lineItem });
    for (LineItem createdLineItem : lineItems) {
        System.out.printf("A video line item with ID %d and name '%s' was created.%n", createdLineItem.getId(), createdLineItem.getName());
    }
}
Also used : RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202108.RequestPlatformTargeting) Targeting(com.google.api.ads.admanager.axis.v202108.Targeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202108.AdUnitTargeting) RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202108.RequestPlatformTargeting) ContentTargeting(com.google.api.ads.admanager.axis.v202108.ContentTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202108.InventoryTargeting) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202108.VideoPositionTargeting) LineItemServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface) Size(com.google.api.ads.admanager.axis.v202108.Size) LineItem(com.google.api.ads.admanager.axis.v202108.LineItem) ContentTargeting(com.google.api.ads.admanager.axis.v202108.ContentTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202108.InventoryTargeting) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202108.VideoPositionTargeting) CustomCriteriaSet(com.google.api.ads.admanager.axis.v202108.CustomCriteriaSet) VideoPosition(com.google.api.ads.admanager.axis.v202108.VideoPosition) CreativePlaceholder(com.google.api.ads.admanager.axis.v202108.CreativePlaceholder) Money(com.google.api.ads.admanager.axis.v202108.Money) Goal(com.google.api.ads.admanager.axis.v202108.Goal) AdUnitTargeting(com.google.api.ads.admanager.axis.v202108.AdUnitTargeting) Random(java.util.Random) VideoPositionTarget(com.google.api.ads.admanager.axis.v202108.VideoPositionTarget) CmsMetadataCriteria(com.google.api.ads.admanager.axis.v202108.CmsMetadataCriteria)

Aggregations

Content (org.jdom2.Content)12 Element (org.jdom2.Element)8 ArrayList (java.util.ArrayList)3 Document (org.jdom2.Document)3 Text (org.jdom2.Text)3 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)2 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)2 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)2 Content (com.google.api.ads.admanager.axis.v202108.Content)2 ContentPage (com.google.api.ads.admanager.axis.v202108.ContentPage)2 ContentServiceInterface (com.google.api.ads.admanager.axis.v202108.ContentServiceInterface)2 Content (com.google.api.ads.admanager.axis.v202111.Content)2 ContentPage (com.google.api.ads.admanager.axis.v202111.ContentPage)2 ContentServiceInterface (com.google.api.ads.admanager.axis.v202111.ContentServiceInterface)2 Content (com.google.api.ads.admanager.axis.v202202.Content)2 ContentPage (com.google.api.ads.admanager.axis.v202202.ContentPage)2 ContentServiceInterface (com.google.api.ads.admanager.axis.v202202.ContentServiceInterface)2 JsonElement (com.google.gson.JsonElement)2 Random (java.util.Random)2 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)1