Search in sources :

Example 16 with Content

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

the class GetAllContent method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the ContentService.
    ContentServiceInterface contentService = adManagerServices.get(session, ContentServiceInterface.class);
    // Create a statement to get all content.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get content by statement.
        ContentPage page = contentService.getContentByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Content content : page.getResults()) {
                String contentBundleIds = content.getContentBundleIds() == null ? "[]" : Arrays.toString(content.getContentBundleIds());
                System.out.printf("%d) Content with ID %d and name '%s' belonging to bundle IDs %s was found.%n", i++, content.getId(), content.getName(), contentBundleIds);
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : ContentServiceInterface(com.google.api.ads.admanager.axis.v202111.ContentServiceInterface) Content(com.google.api.ads.admanager.axis.v202111.Content) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ContentPage(com.google.api.ads.admanager.axis.v202111.ContentPage)

Example 17 with Content

use of com.google.api.ads.admanager.axis.v202202.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.v202202.RequestPlatformTargeting) RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202202.RequestPlatformTargeting) ContentTargeting(com.google.api.ads.admanager.axis.v202202.ContentTargeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202202.Targeting) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202202.VideoPositionTargeting) LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) Size(com.google.api.ads.admanager.axis.v202202.Size) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem) ContentTargeting(com.google.api.ads.admanager.axis.v202202.ContentTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202202.VideoPositionTargeting) CustomCriteriaSet(com.google.api.ads.admanager.axis.v202202.CustomCriteriaSet) VideoPosition(com.google.api.ads.admanager.axis.v202202.VideoPosition) CreativePlaceholder(com.google.api.ads.admanager.axis.v202202.CreativePlaceholder) Money(com.google.api.ads.admanager.axis.v202202.Money) Goal(com.google.api.ads.admanager.axis.v202202.Goal) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) Random(java.util.Random) VideoPositionTarget(com.google.api.ads.admanager.axis.v202202.VideoPositionTarget) CmsMetadataCriteria(com.google.api.ads.admanager.axis.v202202.CmsMetadataCriteria)

Example 18 with Content

use of com.google.api.ads.admanager.axis.v202202.Content in project jspwiki by apache.

the class XHtmlElementToWikiTranslator method translateChildren.

public void translateChildren(final Element base) throws JDOMException {
    for (final Content c : base.getContent()) {
        if (c instanceof Element) {
            final Element e = (Element) c;
            final String n = e.getName().toLowerCase();
            switch(n) {
                case "h1":
                    syntax.h1(e);
                    break;
                case "h2":
                    syntax.h2(e);
                    break;
                case "h3":
                    syntax.h3(e);
                    break;
                case "h4":
                    syntax.h4(e);
                    break;
                case "p":
                    syntax.p(e);
                    break;
                case "br":
                    syntax.br(base, e);
                    break;
                case "hr":
                    syntax.hr(e);
                    break;
                case "table":
                    syntax.table(e);
                    break;
                case "tbody":
                    syntax.tbody(e);
                    break;
                case "tr":
                    syntax.tr(e);
                    break;
                case "td":
                    syntax.td(e);
                    break;
                case "thead":
                    syntax.thead(e);
                    break;
                case "th":
                    syntax.th(e);
                    break;
                case "a":
                    translateA(e);
                    break;
                case "b":
                case "strong":
                    syntax.strong(e);
                    break;
                case "i":
                case "em":
                case "address":
                    syntax.em(e);
                    break;
                case "u":
                    syntax.underline(e);
                    break;
                case "strike":
                    syntax.strike(e);
                    break;
                case "sub":
                    syntax.sub(e);
                    break;
                case "sup":
                    syntax.sup(e);
                    break;
                case "dl":
                    syntax.dl(e);
                    break;
                case "dt":
                    syntax.dt(e);
                    break;
                case "dd":
                    syntax.dd(e);
                    break;
                case "ul":
                    syntax.ul(e);
                    break;
                case "ol":
                    syntax.ol(e);
                    break;
                case "li":
                    syntax.li(base, e);
                    break;
                case "pre":
                    syntax.pre(e);
                    break;
                case "code":
                case "tt":
                    syntax.code(e);
                    break;
                case "img":
                    syntax.img(e);
                    break;
                case "form":
                    syntax.form(e);
                    break;
                case "input":
                    syntax.input(e);
                    break;
                case "textarea":
                    syntax.textarea(e);
                    break;
                case "select":
                    syntax.select(e);
                    break;
                case "option":
                    syntax.option(base, e);
                    break;
                default:
                    translate(e);
                    break;
            }
        } else {
            translate(c);
        }
    }
}
Also used : Content(org.jdom2.Content) Element(org.jdom2.Element)

Example 19 with Content

use of com.google.api.ads.admanager.axis.v202202.Content in project jspwiki by apache.

the class JSPWikiMarkupParser method paragraphify.

/**
 *  Checks out that the first paragraph is correctly installed.
 *
 *  @param rootElement
 */
private void paragraphify(final Element rootElement) {
    // 
    // Add the paragraph tag to the first paragraph
    // 
    final List<Content> kids = rootElement.getContent();
    if (rootElement.getChild("p") != null) {
        final ArrayList<Content> ls = new ArrayList<>();
        int idxOfFirstContent = 0;
        int count = 0;
        for (final Iterator<Content> i = kids.iterator(); i.hasNext(); count++) {
            final Content c = i.next();
            if (c instanceof Element) {
                final String name = ((Element) c).getName();
                if (isBlockLevel(name))
                    break;
            }
            if (!(c instanceof ProcessingInstruction)) {
                ls.add(c);
                if (idxOfFirstContent == 0)
                    idxOfFirstContent = count;
            }
        }
        // 
        if (ls.size() > 0) {
            final Element newel = new Element("p");
            for (final Iterator<Content> i = ls.iterator(); i.hasNext(); ) {
                final Content c = i.next();
                c.detach();
                newel.addContent(c);
            }
            // 
            if (!newel.getTextTrim().isEmpty() || !newel.getChildren().isEmpty())
                rootElement.addContent(idxOfFirstContent, newel);
        }
    }
}
Also used : Content(org.jdom2.Content) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 20 with Content

use of com.google.api.ads.admanager.axis.v202202.Content in project jspwiki by apache.

the class JSPWikiMarkupParser method handleHyperlinks.

/**
 *  Gobbles up all hyperlinks that are encased in square brackets.
 */
private Element handleHyperlinks(String linktext, final int pos) {
    final ResourceBundle rb = Preferences.getBundle(m_context, InternationalizationManager.CORE_BUNDLE);
    final StringBuilder sb = new StringBuilder(linktext.length() + 80);
    if (m_linkParsingOperations.isAccessRule(linktext)) {
        return handleAccessRule(linktext);
    }
    if (m_linkParsingOperations.isMetadata(linktext)) {
        return handleMetadata(linktext);
    }
    if (m_linkParsingOperations.isPluginLink(linktext)) {
        try {
            final PluginContent pluginContent = PluginContent.parsePluginLine(m_context, linktext, pos);
            // This might sometimes fail, especially if there is something which looks like a plugin invocation but is really not.
            if (pluginContent != null) {
                addElement(pluginContent);
                pluginContent.executeParse(m_context);
            }
        } catch (final PluginException e) {
            log.info(m_context.getRealPage().getWiki() + " : " + m_context.getRealPage().getName() + " - Failed to insert plugin: " + e.getMessage());
            // log.info( "Root cause:",e.getRootThrowable() );
            if (!m_wysiwygEditorMode) {
                final ResourceBundle rbPlugin = Preferences.getBundle(m_context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
                return addElement(makeError(MessageFormat.format(rbPlugin.getString("plugin.error.insertionfailed"), m_context.getRealPage().getWiki(), m_context.getRealPage().getName(), e.getMessage())));
            }
        }
        return m_currentElement;
    }
    try {
        final LinkParser.Link link = m_linkParser.parse(linktext);
        linktext = link.getText();
        String linkref = link.getReference();
        // 
        if (m_linkParsingOperations.isVariableLink(linktext)) {
            final Content el = new VariableContent(linktext);
            addElement(el);
        } else if (m_linkParsingOperations.isExternalLink(linkref)) {
            // It's an external link, out of this Wiki
            callMutatorChain(m_externalLinkMutatorChain, linkref);
            if (m_linkParsingOperations.isImageLink(linkref, isImageInlining(), getInlineImagePatterns())) {
                handleImageLink(linkref, linktext, link.hasReference());
            } else {
                makeLink(EXTERNAL, linkref, linktext, null, link.getAttributes());
                addElement(outlinkImage());
            }
        } else if (link.isInterwikiLink()) {
            // It's an interwiki link; InterWiki links also get added to external link chain after the links have been resolved.
            // FIXME: There is an interesting issue here:  We probably should
            // URLEncode the wikiPage, but we can't since some of the
            // Wikis use slashes (/), which won't survive URLEncoding.
            // Besides, we don't know which character set the other Wiki
            // is using, so you'll have to write the entire name as it appears
            // in the URL.  Bugger.
            final String extWiki = link.getExternalWiki();
            final String wikiPage = link.getExternalWikiPage();
            if (m_wysiwygEditorMode) {
                makeLink(INTERWIKI, extWiki + ":" + wikiPage, linktext, null, link.getAttributes());
            } else {
                String urlReference = m_engine.getInterWikiURL(extWiki);
                if (urlReference != null) {
                    urlReference = TextUtil.replaceString(urlReference, "%s", wikiPage);
                    urlReference = callMutatorChain(m_externalLinkMutatorChain, urlReference);
                    if (m_linkParsingOperations.isImageLink(urlReference, isImageInlining(), getInlineImagePatterns())) {
                        handleImageLink(urlReference, linktext, link.hasReference());
                    } else {
                        makeLink(INTERWIKI, urlReference, linktext, null, link.getAttributes());
                    }
                    if (m_linkParsingOperations.isExternalLink(urlReference)) {
                        addElement(outlinkImage());
                    }
                } else {
                    final Object[] args = { escapeHTMLEntities(extWiki) };
                    addElement(makeError(MessageFormat.format(rb.getString("markupparser.error.nointerwikiref"), args)));
                }
            }
        } else if (linkref.startsWith("#")) {
            // It defines a local footnote
            makeLink(LOCAL, linkref, linktext, null, link.getAttributes());
        } else if (TextUtil.isNumber(linkref)) {
            // It defines a reference to a local footnote
            makeLink(LOCALREF, linkref, linktext, null, link.getAttributes());
        } else {
            final int hashMark;
            // Internal wiki link, but is it an attachment link?
            String attachment = m_engine.getManager(AttachmentManager.class).getAttachmentInfoName(m_context, linkref);
            if (attachment != null) {
                callMutatorChain(m_attachmentLinkMutatorChain, attachment);
                if (m_linkParsingOperations.isImageLink(linkref, isImageInlining(), getInlineImagePatterns())) {
                    attachment = m_context.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), attachment);
                    sb.append(handleImageLink(attachment, linktext, link.hasReference()));
                } else {
                    makeLink(ATTACHMENT, attachment, linktext, null, link.getAttributes());
                }
            } else if ((hashMark = linkref.indexOf('#')) != -1) {
                // It's an internal Wiki link, but to a named section
                final String namedSection = linkref.substring(hashMark + 1);
                linkref = linkref.substring(0, hashMark);
                linkref = MarkupParser.cleanLink(linkref);
                callMutatorChain(m_localLinkMutatorChain, linkref);
                final String matchedLink = m_linkParsingOperations.linkIfExists(linkref);
                if (matchedLink != null) {
                    String sectref = "section-" + m_engine.encodeName(matchedLink + "-" + wikifyLink(namedSection));
                    sectref = sectref.replace('%', '_');
                    makeLink(READ, matchedLink, linktext, sectref, link.getAttributes());
                } else {
                    makeLink(EDIT, linkref, linktext, null, link.getAttributes());
                }
            } else {
                // It's an internal Wiki link
                linkref = MarkupParser.cleanLink(linkref);
                callMutatorChain(m_localLinkMutatorChain, linkref);
                final String matchedLink = m_linkParsingOperations.linkIfExists(linkref);
                if (matchedLink != null) {
                    makeLink(READ, matchedLink, linktext, null, link.getAttributes());
                } else {
                    makeLink(EDIT, linkref, linktext, null, link.getAttributes());
                }
            }
        }
    } catch (final ParseException e) {
        log.info("Parser failure: ", e);
        final Object[] args = { e.getMessage() };
        addElement(makeError(MessageFormat.format(rb.getString("markupparser.error.parserfailure"), args)));
    }
    return m_currentElement;
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) Content(org.jdom2.Content) ResourceBundle(java.util.ResourceBundle) AttachmentManager(org.apache.wiki.attachment.AttachmentManager)

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.v202202.AdUnitTargeting)1