use of com.google.api.ads.admanager.axis.v202108.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);
}
use of com.google.api.ads.admanager.axis.v202108.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);
}
use of com.google.api.ads.admanager.axis.v202108.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);
}
}
}
use of com.google.api.ads.admanager.axis.v202108.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);
}
}
}
use of com.google.api.ads.admanager.axis.v202108.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;
}
Aggregations