Package org.apache.lenya.cms.publication

Examples of org.apache.lenya.cms.publication.ResourceType$Sample


                        Date date = new Date(document.getLastModified());
                        value = new SimpleDateFormat(DATE_FORMAT).format(date);
                    } else if (name.equals(PageEnvelope.DOCUMENT_MIME_TYPE)) {
                        value = document.getMimeType();
                    } else if (name.equals(PageEnvelope.DOCUMENT_TYPE)) {
                        ResourceType resourceType = document.getResourceType();
                        if (resourceType == null) {
                            value = null;
                        } else {
                            value = resourceType.getName();
                        }
                    }
                }
            }
        } catch (final Exception e) {
View Full Code Here


        try {
            Request request = ObjectModelHelper.getRequest(objectModel);
            Session session = RepositoryUtil.getSession(this.manager, request);

            ResourceType resourceType;
            Publication pub = null;
            String attribute;

            String[] steps = name.split(":");
            if (steps.length == 1) {
                DocumentFactory docFactory = DocumentUtil.createDocumentFactory(this.manager,
                        session);
                String webappUrl = ServletHelper.getWebappURI(request);
                Document document = docFactory.getFromURL(webappUrl);
                pub = document.getPublication();

                attribute = name;
                resourceType = document.getResourceType();
            } else {
                attribute = steps[1];
                String resourceTypeName = steps[0];

                ServiceSelector selector = null;
                try {
                    selector = (ServiceSelector) this.manager
                            .lookup(ResourceType.ROLE + "Selector");
                    resourceType = (ResourceType) selector.select(resourceTypeName);
                } finally {
                    this.manager.release(selector);
                }
            }

            if (attribute.startsWith("format-")) {
                String[] formatSteps = name.split("-");
                String format = formatSteps[1];
                value = resourceType.getFormatURI(format);
            } else if (attribute.equals(SCHEMA_URI)) {
                value = resourceType.getSchema().getURI();
            } else if (attribute.equals(HTTP_SCHEMA_URI)) {
                String uri = resourceType.getSchema().getURI();
                value = transformFallbackUriToHttp(pub.getId(), uri);
            } else if (attribute.equals(EXPIRES)) {
                Date expires = resourceType.getExpires();
                SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz");
                value = sdf.format(expires);
            } else if (attribute.equals(SUPPORTS_FORMAT)) {
                String format = steps[steps.length - 1];
                String[] formats = resourceType.getFormats();
                return Boolean.toString(Arrays.asList(formats).contains(format));
            } else {
                throw new ConfigurationException("Attribute [" + name + "] not supported!");
            }
View Full Code Here

            }



            // Try to clean the xml using xslt
            ResourceType resType = getSourceDocument().getResourceType();
            String[] formats = resType.getFormats();
            if (Arrays.asList(formats).contains(XSLT_CLEAN_FORMAT)) {
                StringWriter output = new StringWriter();
                StreamResult strResult = new StreamResult(output);
                TransformerFactory tfac = TransformerFactory.newInstance();
                try {
                    xsltSource = (ModifiableSource) resolver.resolveURI(resType
                            .getFormatURI(XSLT_CLEAN_FORMAT));
                    Transformer t = tfac.newTransformer(new StreamSource(xsltSource
                            .getInputStream()));
                    t.setOutputProperty(OutputKeys.ENCODING, encoding);
                    t.setOutputProperty(OutputKeys.INDENT, "yes");
                    t.setOutputProperty(OutputKeys.METHOD, "xml");
                    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                    xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());
                    t.transform(new DOMSource(xmlDoc.getDocumentElement()), strResult);

                    content = strResult.getWriter().toString();
                } catch (Exception e) {
                    addErrorMessage(e.getMessage());
                }

                saveXMLFile(encoding, content, getSourceDocument().getOutputStream());
            }
            // Convert URLs back to UUIDs. convert() does a save
            LinkConverter converter = new LinkConverter(this.manager, getLogger());
            converter.convertUrlsToUuids(getSourceDocument(),false);

            xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());

            if (xmlDoc != null) {
                ResourceType resourceType = getSourceDocument().getResourceType();
                Schema schema = resourceType.getSchema();

                ValidationUtil
                        .validate(this.manager, xmlDoc, schema, new UsecaseErrorHandler(this));

                if (!hasErrors()) {
View Full Code Here

     * @see Create#getDocumentTypeName()
     */
    protected String getDocumentTypeName() {
        if (this.documentTypeName == null && getSourceDocument() != null) {
            try {
                ResourceType type = getSourceDocument().getResourceType();
                this.documentTypeName = type.getName();

                List nonExistingLanguages = getNonExistingLanguages();
                setParameter(LANGUAGES, nonExistingLanguages
                        .toArray(new String[nonExistingLanguages.size()]));

View Full Code Here

                    Link link = getLink(linkUri, pubId, area);
                    LinkTarget target = IconUrlTransformer.this.linkResolver.resolve(
                            IconUrlTransformer.this.factory, link.getUri());
                    if (target.exists()) {
                        Document doc = target.getDocument();
                        ResourceType type = doc.getResourceType();
                        if (Arrays.asList(type.getFormats()).contains("icon")) {
                            name = type.getName();
                        }
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
View Full Code Here

        super.doExecute();

        // create new document
        DocumentManager documentManager = null;
        ServiceSelector selector = null;
        ResourceType resourceType = null;
        try {

            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);

            String language = getParameterAsString(LANGUAGE);
            Document initialDocument = getInitialDocument();

            Document document;

            String title = getDublinCoreParameter(DublinCore.ELEMENT_TITLE).trim();

            if (createVersion()) {
                document = documentManager.addVersion(initialDocument, getArea(), language, true);
                document.getLink().setLabel(title);
            } else {
                if (initialDocument == null) {
                    selector = (ServiceSelector) this.manager
                            .lookup(ResourceType.ROLE + "Selector");
                    resourceType = (ResourceType) selector.select(getDocumentTypeName());
                    String sampleName = getParameterAsString(SAMPLE, resourceType.getSampleNames()[0]);
                    ResourceType.Sample sample = resourceType.getSample(sampleName);
                    document = documentManager.add(getDocumentFactory(), resourceType, sample.getUri(),
                            getPublication(), getArea(), getNewDocumentPath(), language,
                            getSourceExtension(), title, getVisibleInNav());
                    document.setMimeType(sample.getMimeType());
                } else {
View Full Code Here

        }
    }

    protected void initSampleParameters() {
        ServiceSelector selector = null;
        ResourceType resourceType = null;
        try {
            selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
            resourceType = (ResourceType) selector.select(getDocumentTypeName());
            String[] samples = resourceType.getSampleNames();
            if (samples.length == 0) {
                addErrorMessage("The resource type [" + resourceType.getName()
                        + "] doesn't provide any samples!");
            } else {
                setParameter(SAMPLES, samples);
                String presetSample = getParameterAsString(SAMPLE);
                if (presetSample == null) {
View Full Code Here

TOP

Related Classes of org.apache.lenya.cms.publication.ResourceType$Sample

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.