use of org.jdom2.Text in project jspwiki by apache.
the class HtmlStringToWikiTranslator method translate.
/**
* Translates text from HTML into WikiMarkup using a specified configuration.
*
* @param html HTML text to translate
* @param config The configuration to use.
* @return WikiMarkup
*
* @throws JDOMException If parsing fails
* @throws IOException For other kinds of errors.
*/
public String translate(String html, XHtmlToWikiConfig config) throws JDOMException, IOException {
Element element = htmlStringToElement(html);
XHtmlElementToWikiTranslator xhtmlTranslator = new XHtmlElementToWikiTranslator(element, config);
String wikiMarkup = xhtmlTranslator.getWikiString();
return wikiMarkup;
}
use of org.jdom2.Text in project jspwiki by apache.
the class XhtmlUtil method img.
/**
* Return an XHTML <tt>img</tt> element with an required 'src' attribute
* and optional 'alt' alternative text value.
*
* @param src the required 'src' value.
* @param alt the optional 'alt' alternative text value.
* @return a JDOM2 Element.
*/
public static Element img(String src, String alt) {
Element img = element(XHTML.img);
if (src == null) {
throw new IllegalArgumentException("missing 'src' attribute value.");
}
img.setAttribute(XHTML.ATTR_src, src);
if (alt != null) {
img.setAttribute(XHTML.ATTR_alt, alt);
}
return img;
}
use of org.jdom2.Text in project jspwiki by apache.
the class SecurityVerifier method verifyPolicy.
/**
* Verfies the Java security policy configuration. The configuration is
* valid if value of the local policy (at <code>WEB-INF/jspwiki.policy</code>
* resolves to an existing file, and the policy file contained therein
* represents a valid policy.
*/
@SuppressWarnings("unchecked")
protected void verifyPolicy() {
// Look up the policy file and set the status text.
URL policyURL = AuthenticationManager.findConfigFile(m_engine, AuthorizationManager.DEFAULT_POLICY);
String path = policyURL.getPath();
if (path.startsWith("file:")) {
path = path.substring(5);
}
File policyFile = new File(path);
// Next, verify the policy
try {
// Get the file
PolicyReader policy = new PolicyReader(policyFile);
m_session.addMessage(INFO_POLICY, "The security policy '" + policy.getFile() + "' exists.");
// See if there is a keystore that's valid
KeyStore ks = policy.getKeyStore();
if (ks == null) {
m_session.addMessage(WARNING_POLICY, "Policy file does not have a keystore... at least not one that we can locate. If your policy file " + "does not contain any 'signedBy' blocks, this is probably ok.");
} else {
m_session.addMessage(INFO_POLICY, "The security policy specifies a keystore, and we were able to locate it in the filesystem.");
}
// Verify the file
policy.read();
List<Exception> errors = policy.getMessages();
if (errors.size() > 0) {
for (Exception e : errors) {
m_session.addMessage(ERROR_POLICY, e.getMessage());
}
} else {
m_session.addMessage(INFO_POLICY, "The security policy looks fine.");
m_isSecurityPolicyConfigured = true;
}
// Stash the unique principals mentioned in the file,
// plus our standard roles.
Set<Principal> principals = new LinkedHashSet<Principal>();
principals.add(Role.ALL);
principals.add(Role.ANONYMOUS);
principals.add(Role.ASSERTED);
principals.add(Role.AUTHENTICATED);
ProtectionDomain[] domains = policy.getProtectionDomains();
for (ProtectionDomain domain : domains) {
for (Principal principal : domain.getPrincipals()) {
principals.add(principal);
}
}
m_policyPrincipals = principals.toArray(new Principal[principals.size()]);
} catch (IOException e) {
m_session.addMessage(ERROR_POLICY, e.getMessage());
}
}
use of org.jdom2.Text in project ldapchai by ldapchai.
the class NmasResponseSet method readDisplayString.
private static String readDisplayString(final Element questionElement, final Locale locale) {
final Namespace xmlNamespace = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace");
// someday ResoureBundle won't suck and this will be a 5 line method.
// see if the node has any localized displays.
final List displayChildren = questionElement.getChildren("display");
// if no locale specified, or if no localized text is available, just use the default.
if (locale == null || displayChildren == null || displayChildren.size() < 1) {
return questionElement.getText();
}
// convert the xml 'display' elements to a map of locales/strings
final Map<Locale, String> localizedStringMap = new HashMap<Locale, String>();
for (final Object loopDisplayChild : displayChildren) {
final Element loopDisplay = (Element) loopDisplayChild;
final Attribute localeAttr = loopDisplay.getAttribute("lang", xmlNamespace);
if (localeAttr != null) {
final String localeStr = localeAttr.getValue();
final String displayStr = loopDisplay.getText();
final Locale localeKey = parseLocaleString(localeStr);
localizedStringMap.put(localeKey, displayStr);
}
}
final Locale matchedLocale = localeResolver(locale, localizedStringMap.keySet());
if (matchedLocale != null) {
return localizedStringMap.get(matchedLocale);
}
// none found, so just return the default string.
return questionElement.getText();
}
use of org.jdom2.Text in project omegat by omegat-org.
the class DefaultXMLDialect method constructShortcuts.
/**
* {@inheritDoc}
*/
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
protectedParts.clear();
StringBuilder r = new StringBuilder();
for (Element el : elements) {
String shortcut = el.toShortcut();
r.append(shortcut);
if (!(el instanceof Text)) {
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(el.toOriginal());
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(el.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
protectedParts.add(pp);
}
}
return r.toString();
}
Aggregations