Package org.apache.lenya.xml

Examples of org.apache.lenya.xml.NamespaceHelper


        if (loading || !changed) {
            return;
        }
        try {
            Node repoNode = getRepositoryNode();
            NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", "site");

            int revision = getRevision(repoNode) + 1;
            helper.getDocument().getDocumentElement().setAttribute("revision",
                    Integer.toString(revision));

            saveNodes(getRoot(), helper, helper.getDocument().getDocumentElement());
            helper.save(repoNode.getOutputStream());
            this.lastModified = repoNode.getLastModified();
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RepositoryException(e);
View Full Code Here


        load();
        this.includeItemNumber = number;
    }

    protected NamespaceHelper initializeNamespaceHelper() {
        NamespaceHelper helper = super.initializeNamespaceHelper();
        Element docElement = helper.getDocument().getDocumentElement();
        docElement.setAttribute(ATTRIBUTE_INCLUDE_ITEMS, Short.toString(getIncludeItemNumber()));
        return helper;
    }
View Full Code Here

            throws ServiceException, SourceNotFoundException, ParserConfigurationException,
            SAXException, IOException, TransformerConfigurationException, TransformerException,
            MalformedURLException {
        String configUri = "context://lenya/pubs/mock/config/publication.xml";
        Document dom = SourceUtil.readDOM(configUri, getManager());
        NamespaceHelper helper = new NamespaceHelper(PUBCONF_NAMESPACE, "", dom);

        Element proxies = helper.getFirstChild(dom.getDocumentElement(), "proxies");
        if (proxies == null) {
            proxies = helper.createElement("proxies");
            dom.getDocumentElement().appendChild(proxies);
        }

        addProxyElement(helper, proxies, area, proxyUrl, false);
        addProxyElement(helper, proxies, area, proxyUrl, true);
View Full Code Here

        SourceResolver resolver = null;
        Source source = null;
        try {

            NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "not", "message");
            Document doc = helper.getDocument();
            NamespaceHelper i18nHelper = new NamespaceHelper(I18nTransformer.I18N_NAMESPACE_URI,
                    "i18n", doc);

            Element docElement = doc.getDocumentElement();

            Element subjectElement = helper.createElement("subject");
            docElement.appendChild(subjectElement);
            Element i18nTranslateSubjectElement = i18nHelper.createElement("translate");
            subjectElement.appendChild(i18nTranslateSubjectElement);
            Element subjectI18nElement = i18nHelper.createElement("text", message.getSubject());
            i18nTranslateSubjectElement.appendChild(subjectI18nElement);

            String[] subjectParams = message.getSubjectParameters();
            for (int i = 0; i < subjectParams.length; i++) {
                Element paramElement = i18nHelper.createElement("param", subjectParams[i]);
                i18nTranslateSubjectElement.appendChild(paramElement);
            }

            Element bodyElement = helper.createElement("body");
            docElement.appendChild(bodyElement);
            Element i18nTranslateElement = i18nHelper.createElement("translate");
            bodyElement.appendChild(i18nTranslateElement);
            Element bodyI18nElement = i18nHelper.createElement("text", message.getBody());
            i18nTranslateElement.appendChild(bodyI18nElement);

            String[] msgParams = message.getBodyParameters();
            for (int i = 0; i < msgParams.length; i++) {
                Element paramElement = i18nHelper.createElement("param", msgParams[i]);
                i18nTranslateElement.appendChild(paramElement);
            }

            Session session = this.request.getSession();
            session.setAttribute("notification.dom", doc);

            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            source = resolver.resolveURI("cocoon://modules/notification/message/" + locale, null,
                    null);

            if (source.exists()) {
                doc = DocumentHelper.readDocument(source.getInputStream());
                helper = new NamespaceHelper(NAMESPACE, "not", doc);

                subjectElement = helper.getFirstChild(doc.getDocumentElement(), "subject");
                String subject = DocumentHelper.getSimpleElementText(subjectElement);

                bodyElement = helper.getFirstChild(doc.getDocumentElement(), "body");
View Full Code Here

    public void save() throws RepositoryException {
        if (!changed) {
            return;
        }
        try {
            NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", ELEMENT_METADATA);
            Collection namespaces = this.namespace2metamap.keySet();
            for (Iterator i = namespaces.iterator(); i.hasNext();) {
                String namespace = (String) i.next();

                Element setElement = helper.createElement(ELEMENT_SET);
                setElement.setAttribute(ATTRIBUTE_NAMESPACE, namespace);
                helper.getDocument().getDocumentElement().appendChild(setElement);

                Map map = getMetaDataMap(namespace);
                Collection keys = map.keySet();
                for (Iterator keyIterator = keys.iterator(); keyIterator.hasNext();) {
                    String key = (String) keyIterator.next();

                    Element elementElement = helper.createElement(ELEMENT_ELEMENT);
                    elementElement.setAttribute(ATTRIBUTE_KEY, key);

                    List values = (List) map.get(key);
                    for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
                        String value = (String) valueIterator.next();
                        if (!value.equals("")) {
                            Element valueElement = helper.createElement(ELEMENT_VALUE, value);
                            elementElement.appendChild(valueElement);
                        }
                    }
                    if (elementElement.hasChildNodes()) {
                        setElement.appendChild(elementElement);
                    }
                }
            }
            OutputStream oStream = this.sourceWrapper.getOutputStream();
            DocumentHelper.writeDocument(helper.getDocument(), oStream);
            if (oStream != null) {
                oStream.flush();
                try {
                    oStream.close();
                } catch (Throwable t) {
View Full Code Here

     * Loads the collection from its XML source.
     */
    protected final void load() {
        if (!this.isLoaded) {
            getLogger().debug("Loading: ");
            NamespaceHelper helper;
            try {
                helper = getNamespaceHelper();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
View Full Code Here

    /**
     * Saves the collection.
     */
    public final void save() {
        try {
            NamespaceHelper helper = getNamespaceHelper();
            saveXml(helper);
            DocumentHelper.writeDocument(helper.getDocument(), getDelegate().getOutputStream());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

     * @throws ServiceException
     */
    protected NamespaceHelper getNamespaceHelper() throws DocumentException,
            ParserConfigurationException, SAXException, IOException, ServiceException {

        NamespaceHelper helper;

        if (getDelegate().exists()) {
            org.w3c.dom.Document document = DocumentHelper.readDocument(getDelegate()
                    .getInputStream());
            helper = new NamespaceHelper(Collection.NAMESPACE, Collection.DEFAULT_PREFIX, document);
        } else {
            helper = initializeNamespaceHelper();
        }
        return helper;
    }
View Full Code Here

    /**
     * @return A new, empty namespace helper.
     */
    protected NamespaceHelper initializeNamespaceHelper() {
        NamespaceHelper helper;
        try {
            helper = new NamespaceHelper(Collection.NAMESPACE, Collection.DEFAULT_PREFIX,
                    ELEMENT_COLLECTION);
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
        return helper;
View Full Code Here

            if (SourceUtil.exists(this.sourceUri, this.manager)) {
                Document xml = SourceUtil.readDOM(this.sourceUri, this.manager);
                if (!xml.getDocumentElement().getNamespaceURI().equals(META_DATA_NAMESPACE)) {
                    loadLegacyMetaData(xml);
                } else {
                    NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", xml);
                    Element[] setElements = helper.getChildren(xml.getDocumentElement(),
                            ELEMENT_SET);
                    for (int setIndex = 0; setIndex < setElements.length; setIndex++) {
                        String namespace = setElements[setIndex].getAttribute(ATTRIBUTE_NAMESPACE);
                        Element[] elementElements = helper.getChildren(setElements[setIndex],
                                ELEMENT_ELEMENT);
                        Map element2values = new HashMap();
                        for (int elemIndex = 0; elemIndex < elementElements.length; elemIndex++) {
                            String key = elementElements[elemIndex].getAttribute(ATTRIBUTE_KEY);
                            Element[] valueElements = helper.getChildren(
                                    elementElements[elemIndex], ELEMENT_VALUE);
                            List values = new ArrayList();
                            for (int valueIndex = 0; valueIndex < valueElements.length; valueIndex++) {
                                String value = DocumentHelper
                                        .getSimpleElementText(valueElements[valueIndex]);
View Full Code Here

TOP

Related Classes of org.apache.lenya.xml.NamespaceHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.