Search in sources :

Example 1 with CampaignURL

use of pcgen.cdom.content.CampaignURL in project pcgen by PCGen.

the class UrlToken method unparse.

@Override
public String[] unparse(LoadContext context, Campaign campaign) {
    Changes<CampaignURL> changes = context.getObjectContext().getListChanges(campaign, ListKey.CAMPAIGN_URL);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Collection<CampaignURL> added = changes.getAdded();
    if (added != null && !added.isEmpty()) {
        List<String> list = new ArrayList<>();
        for (CampaignURL curl : added) {
            StringBuilder sb = new StringBuilder();
            sb.append(curl.getUrlKind());
            sb.append(Constants.PIPE);
            sb.append(curl.getUri().toString());
            sb.append(Constants.PIPE);
            sb.append(curl.getUrlDesc());
        }
        return list.toArray(new String[list.size()]);
    }
    return null;
}
Also used : CampaignURL(pcgen.cdom.content.CampaignURL) ArrayList(java.util.ArrayList)

Example 2 with CampaignURL

use of pcgen.cdom.content.CampaignURL in project pcgen by PCGen.

the class UrlToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, Campaign campaign, String value) {
    final StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    if (tok.countTokens() != 3) {
        return new ParseResult.Fail("URL token requires three arguments. Link kind, " + "link and description.  : " + value, context);
    }
    String urlTypeName = tok.nextToken();
    String urlText = tok.nextToken();
    String urlDesc = tok.nextToken();
    CampaignURL.URLKind urlType;
    if (urlTypeName.equalsIgnoreCase(URL_KIND_NAME_WEBSITE)) {
        if (!urlTypeName.equals(URL_KIND_NAME_WEBSITE)) {
            Logging.log(Logging.LST_WARNING, "URL type should be WEBSITE in upper case : " + value);
        }
        urlType = CampaignURL.URLKind.WEBSITE;
        urlTypeName = "";
    } else if (urlTypeName.equalsIgnoreCase(URL_KIND_NAME_SURVEY)) {
        if (!urlTypeName.equals(URL_KIND_NAME_SURVEY)) {
            Logging.log(Logging.LST_WARNING, "URL type should be SURVEY in upper case : " + value);
        }
        urlType = CampaignURL.URLKind.SURVEY;
        urlTypeName = "";
    } else {
        urlType = CampaignURL.URLKind.PURCHASE;
    }
    URI uri;
    try {
        uri = new URI(urlText);
    } catch (URISyntaxException e) {
        return new ParseResult.Fail("Invalid URL (" + e.getMessage() + ") : " + value, context);
    }
    // Create URL object
    CampaignURL campUrl = new CampaignURL(urlType, urlTypeName, uri, urlDesc);
    // Add URL Object to campaign
    context.getObjectContext().addToList(campaign, ListKey.CAMPAIGN_URL, campUrl);
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) CampaignURL(pcgen.cdom.content.CampaignURL) ParseResult(pcgen.rules.persistence.token.ParseResult) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with CampaignURL

use of pcgen.cdom.content.CampaignURL in project pcgen by PCGen.

the class CampaignTest method testURL.

public void testURL() throws Exception {
    final String eCommerceName = "Barcommerce";
    final String eCommerceURL = "http://www.barcommercesite.com/product_info.php?products_id=12345&affiliate_id=54321";
    final String eCommerceDesc = "Support PCGen by buying this source now!";
    assertEquals("No URLs in the campaign to start", true, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).isEmpty());
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(testCamp, "URL", "WEBSITE|http://pcgen.sf.net|PCGen Main Site");
    assertEquals("New URL in the campaign", 1, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    CampaignURL theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(0);
    assertEquals("Checking kind", CampaignURL.URLKind.WEBSITE, theURL.getUrlKind());
    assertEquals("Checking name", "", theURL.getUrlName());
    assertEquals("Checking URL", "http://pcgen.sf.net", theURL.getUri().toString());
    assertEquals("Checking description", "PCGen Main Site", theURL.getUrlDesc());
    context.unconditionallyProcess(testCamp, "URL", "SURVEY|http://pcgen.sf.net/survey|PCGen Survey");
    assertEquals("Second new URL in the campaign", 2, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(1);
    assertEquals("Checking kind", CampaignURL.URLKind.SURVEY, theURL.getUrlKind());
    assertEquals("Checking name", "", theURL.getUrlName());
    assertEquals("Checking URL", "http://pcgen.sf.net/survey", theURL.getUri().toString());
    assertEquals("Checking description", "PCGen Survey", theURL.getUrlDesc());
    context.unconditionallyProcess(testCamp, "URL", eCommerceName + "|" + eCommerceURL + "|" + eCommerceDesc);
    assertEquals("Third new URL in the campaign", 3, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(2);
    assertEquals("Checking kind", CampaignURL.URLKind.PURCHASE, theURL.getUrlKind());
    assertEquals("Checking name", eCommerceName, theURL.getUrlName());
    assertEquals("Checking URL", eCommerceURL, theURL.getUri().toString());
    assertEquals("Checking description", eCommerceDesc, theURL.getUrlDesc());
}
Also used : CampaignURL(pcgen.cdom.content.CampaignURL) LoadContext(pcgen.rules.context.LoadContext)

Example 4 with CampaignURL

use of pcgen.cdom.content.CampaignURL in project pcgen by PCGen.

the class Gui2CampaignInfoFactory method appendCampaignInfo.

private void appendCampaignInfo(Campaign aCamp, final HtmlInfoBuilder infoText) {
    infoText.appendLineBreak();
    if (aCamp.getSizeOfListFor(ListKey.FILE_COVER) > 0) {
        CampaignSourceEntry image = aCamp.getSafeListFor(ListKey.FILE_COVER).get(0);
        infoText.appendIconElement(image.getURI().toString());
    }
    if (aCamp.getSizeOfListFor(ListKey.FILE_LOGO) > 0) {
        CampaignSourceEntry image = aCamp.getSafeListFor(ListKey.FILE_LOGO).get(0);
        infoText.appendIconElement(image.getURI().toString());
    }
    if (aCamp.getSizeOfListFor(ListKey.FILE_COVER) > 0 || aCamp.getSizeOfListFor(ListKey.FILE_LOGO) > 0) {
        infoText.appendLineBreak();
    }
    String bString = SourceFormat.getFormattedString(aCamp, SourceFormat.MEDIUM, true);
    if (StringUtils.isEmpty(bString)) {
        bString = SourceFormat.getFormattedString(aCamp, SourceFormat.LONG, true);
    }
    //$NON-NLS-1$
    infoText.appendI18nElement("in_sumSource", bString);
    //$NON-NLS-1$
    infoText.appendI18nFormattedElement(//$NON-NLS-1$
    "in_infByPub", aCamp.getSafe(StringKey.PUB_NAME_LONG));
    infoText.appendLineBreak();
    // Add the data set release status
    Status status = aCamp.getSafe(ObjectKey.STATUS);
    //$NON-NLS-1$
    infoText.appendI18nElement(//$NON-NLS-1$
    "in_infStatus", //$NON-NLS-1$ //$NON-NLS-2$
    "<font color=\"#" + Integer.toHexString(status.getColor()) + "\">" + status + //$NON-NLS-1$
    "</font>");
    infoText.appendLineBreak();
    String descr = aCamp.get(StringKey.DESCRIPTION);
    if (descr != null) {
        //$NON-NLS-1$
        infoText.appendI18nElement("in_infDesc", descr);
        infoText.appendLineBreak();
    }
    // Add the website URLs
    List<CampaignURL> webURLs = getUrlListForKind(aCamp, URLKind.WEBSITE);
    if (!webURLs.isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nElement("in_infWebsite", buildURLListString(webURLs));
        infoText.appendLineBreak();
    }
    if (!aCamp.getType().isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nElement("in_infType", aCamp.getType());
        infoText.appendSpacer();
    }
    infoText.appendI18nElement("in_infRank", String.valueOf(//$NON-NLS-1$
    aCamp.getSafe(IntegerKey.CAMPAIGN_RANK)));
    if (!StringUtil.join(aCamp.getSafeListFor(ListKey.GAME_MODE), ", ").isEmpty()) {
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_infGame", StringUtil.join(aCamp.getSafeListFor(ListKey.GAME_MODE), ", "));
    }
    infoText.appendLineBreak();
    // Add the purchase URLs
    List<CampaignURL> purchaseURLs = getUrlListForKind(aCamp, URLKind.PURCHASE);
    if (!purchaseURLs.isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nElement("in_infPurchase", buildURLListString(purchaseURLs));
        infoText.appendLineBreak();
    }
    // Add the survey URLs
    List<CampaignURL> surveyURLs = getUrlListForKind(aCamp, URLKind.SURVEY);
    if (!surveyURLs.isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nElement("in_infSurvey", buildURLListString(surveyURLs));
        infoText.appendLineBreak();
    }
    String preString = PrerequisiteUtilities.preReqHTMLStringsForList(null, null, aCamp.getPrerequisiteList(), false);
    if (!preString.isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nFormattedElement("in_InfoRequirements", preString);
    }
    boolean infoDisplayed = false;
    List<String> info = aCamp.getListFor(ListKey.INFO_TEXT);
    if (info != null) {
        if (!infoDisplayed) {
            infoText.appendLineBreak();
        }
        //$NON-NLS-1$
        infoText.appendSmallTitleElement(LanguageBundle.getString("in_infInf"));
        infoText.appendLineBreak();
        for (String infotext : info) {
            infoText.append(infotext);
            infoText.appendLineBreak();
        }
        infoDisplayed = true;
    }
    List<String> copyright = aCamp.getListFor(ListKey.SECTION_15);
    if (copyright != null) {
        if (!infoDisplayed) {
            infoText.appendLineBreak();
        }
        //$NON-NLS-1$
        infoText.appendSmallTitleElement(LanguageBundle.getString("in_infCopyright"));
        infoText.appendLineBreak();
        for (String license : copyright) {
            infoText.append(license);
            infoText.appendLineBreak();
        }
    }
    List<Campaign> subCampaigns = aCamp.getSubCampaigns();
    List<CampaignSourceEntry> notFoundSubCampaigns = aCamp.getNotFoundSubCampaigns();
    if (subCampaigns != null && notFoundSubCampaigns != null && (!subCampaigns.isEmpty() || !notFoundSubCampaigns.isEmpty())) {
        infoText.appendLineBreak();
        infoText.appendSmallTitleElement(LanguageBundle.getString(//$NON-NLS-1$
        "in_infIncludedCampaigns"));
        infoText.appendLineBreak();
        for (Campaign subCamp : subCampaigns) {
            infoText.append(subCamp.getDisplayName());
            infoText.appendLineBreak();
        }
        for (CampaignSourceEntry subCse : notFoundSubCampaigns) {
            infoText.append(LanguageBundle.getFormattedString("in_infMissingCampaign", subCse.getURI()));
            infoText.appendLineBreak();
        }
    }
    infoText.appendLineBreak();
    infoText.appendI18nElement("in_infPccPath", aCamp.getSourceURI().getPath());
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Status(pcgen.cdom.enumeration.Status) CampaignURL(pcgen.cdom.content.CampaignURL) Campaign(pcgen.core.Campaign)

Example 5 with CampaignURL

use of pcgen.cdom.content.CampaignURL in project pcgen by PCGen.

the class Gui2CampaignInfoFactory method buildURLListString.

/**
	 * Builds a html display string based on the list of campaign urls.
	 * 
	 * @param urlList the list of urls
	 * 
	 * @return the display string
	 */
private static String buildURLListString(List<CampaignURL> urlList) {
    StringBuilder sb = new StringBuilder(250);
    boolean first = true;
    for (CampaignURL campaignURL : urlList) {
        if (first) {
            first = false;
        } else {
            sb.append(" | ");
        }
        sb.append("<a href=\"").append(campaignURL.getUri().toString());
        sb.append("\">").append(campaignURL.getUrlDesc());
        sb.append("</a>");
    }
    return sb.toString();
}
Also used : CampaignURL(pcgen.cdom.content.CampaignURL)

Aggregations

CampaignURL (pcgen.cdom.content.CampaignURL)5 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Status (pcgen.cdom.enumeration.Status)1 Campaign (pcgen.core.Campaign)1 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)1 LoadContext (pcgen.rules.context.LoadContext)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1