Search in sources :

Example 76 with Text

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;
}
Also used : Element(org.jdom2.Element)

Example 77 with Text

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;
}
Also used : Element(org.jdom2.Element)

Example 78 with Text

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());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProtectionDomain(java.security.ProtectionDomain) IOException(java.io.IOException) KeyStore(java.security.KeyStore) URL(java.net.URL) JDOMException(org.jdom2.JDOMException) WikiException(org.apache.wiki.api.exceptions.WikiException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InternalWikiException(org.apache.wiki.InternalWikiException) AccessControlException(java.security.AccessControlException) File(java.io.File) PolicyReader(org.freshcookies.security.policy.PolicyReader) Principal(java.security.Principal)

Example 79 with Text

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();
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) List(java.util.List) Namespace(org.jdom2.Namespace)

Example 80 with Text

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();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) Element(org.omegat.filters3.Element) Text(org.omegat.filters3.Text)

Aggregations

Element (org.jdom2.Element)83 Document (org.jdom2.Document)36 File (java.io.File)21 ProcessingInstruction (org.jdom2.ProcessingInstruction)17 IOException (java.io.IOException)14 Text (org.jdom2.Text)12 Attribute (org.jdom2.Attribute)11 XMLOutputter (org.jdom2.output.XMLOutputter)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 XmlFile (jmri.jmrit.XmlFile)9 ArrayList (java.util.ArrayList)6 JDOMException (org.jdom2.JDOMException)6 StringWriter (java.io.StringWriter)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)5 FileOutputStream (java.io.FileOutputStream)4 LinkedHashMap (java.util.LinkedHashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 Locale (java.util.Locale)3