Processes PDF syntax
@param contentBytes	the bytes of a content stream
@param resources		the resources that come with the content stream
544978
public void processContent(byte[] contentBytes, PdfDictionary resources) {
		this.resources.push(resources);
		try {
			PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes));
			ArrayList operands = new ArrayList();
			while (ps.parse(operands).size() > 0) {
				PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1);
				invokeOperator(operator, operands);
			}
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
		this.resources.pop();
	}
1209171
@Override
	public void writeHeader(OutputStream os) throws IOException {	
		os.write(ascii("Content-Disposition: form-data; name=\"" + enc(controlName)
				 + "\"" +
				((fileName != null) ? "; filename=\"" + enc(fileName) + "\"" : "") + "\r\n")); 
		wrappedContent.writeHeader(os);
	}
197269
public void output(Resource resource) throws IOException {
		OutputStream nullo = ByteStreams.nullOutputStream();
		CountingOutputStream co = new CountingOutputStream(nullo);
		try {
			StreamCopy.copy(resource.getInputStream(), co);
		} catch(GZIPFormatException e) {
			e.printStackTrace();
			return;
		}
		long bytes = co.getCount();
		if(bytes > 0) {
			LOG.info(bytes + " unconsumed bytes in Resource InputStream.");
		}
		try {
			MetaData m = resource.getMetaData().getTopMetaData();
			// URL DATE OURL MIME HTTP-CODE SHA1 META REDIR OFFSET LENGTH FILE

			String filename = getContainerFilename(m);
			String offset = getContainerOffset(m);
			String gzLen = getGZLength(m);
			String format = getEnvelopeFormat(m);
			String origUrl = "TBD";
			String date = "TBD";
			String canUrl = "TBD";

			String mime = "TBD";
			String httpCode = "TBD";
			String digest = "TBD";
			String meta = "TBD";
			String redir = "TBD";
			
			if(format.startsWith("WARC")) {
				origUrl = getWARCURL(m);
				date = getWARCDate(m);
				String type = getWARCType(m);
				if(type.equals("response")) {
					// is it http or DNS:
					String recType = getWARCContentType(m);
					if(recType.equals("text/dns")) {
						// hrmm..
						redir = "-";
						meta = "-";
						httpCode = "-";
						mime = recType;
						digest = getEnvelopeBlockDigest(m);

					} else if(recType.equals("application/http; msgtype=response")) {
						httpCode = getHTTPStatus(m);
						digest = getHTTPEntityDigest(m);
						JSONObject headers = JSONUtils.extractObject(m, "Envelope.Payload-Metadata.HTTP-Response-Metadata.Headers");
						mime = normalizeHTTPMime(scanHeadersLC(headers, "content-type", "unk"));
						redir = scanHeadersLC(headers, "location", "-");
						meta = scanHeadersLC(headers, X_ROBOTS_HTTP_HEADER, null);
						if(meta != null) {
							meta = parseRobotInstructions(meta);
						} else {
							meta = "-";
						}
						if(mime.toLowerCase().contains("html")) {
							if(redir.equals("-")) {
								// maybe an obvious meta-refresh?
								redir = extractHTMLMetaRefresh(origUrl,m);
							}
							if(meta.equals("-")) {
								// see if there are HTML robot instructions:
								meta = extractHTMLRobots(m);
							}
						}
					}
				} else if(type.equals("warcinfo")) {
					origUrl = "warcinfo:/" + filename + "/" + IAUtils.COMMONS_VERSION.replaceAll(" ", "_");
					redir = "-";
					meta = "-";
					httpCode = "-";
					mime = "warc-info";
					digest = getEnvelopeBlockDigest(m);
				
				} else if(type.equals("request")) {
					mime = "warc/request";
					redir = "-";
					meta = "-";
					httpCode = "-";
					digest = getEnvelopeBlockDigest(m);
				} else if(type.equals("metadata")) {
					// interesting...?
					mime = "warc/metadata";
					redir = "-";
					meta = "-";
					httpCode = "-";
					digest = getEnvelopeBlockDigest(m);
				} else if(type.equals("revisit")) {
					mime = "warc/revisit";
					redir = "-";
					meta = "-";
					httpCode = "-";
					digest = getWARCPayloadDigest(m);
				}
			} else if(format.equals("ARC")) {
				origUrl = getARCURL(m);
				date = getARCDate(m);
				if(origUrl.startsWith("filedesc:")) {
					// ARC header record:
					origUrl = "filedesc:/" +filename + "/" + IAUtils.COMMONS_VERSION.replaceAll(" ", "_");
					mime = "arc-filedesc";
					redir = "-";
					meta = "-";
					httpCode = "-";
					digest = getEnvelopeBlockDigest(m);
				} else {
					// either an alexa/dat, or an HTTP response (we hope):
					mime = getARCContentType(m);
					if(mime.equals("alexa/dat")) {
						redir = "-";
						meta = "-";
						httpCode = "-";
						digest = getEnvelopeBlockDigest(m);
					} else {

						httpCode = getHTTPStatus(m);
						digest = getHTTPEntityDigest(m);
						JSONObject headers = JSONUtils.extractObject(m, "Envelope.Payload-Metadata.HTTP-Response-Metadata.Headers");
						mime = normalizeHTTPMime(scanHeadersLC(headers, "content-type", "unk"));
						redir = scanHeadersLC(headers, "location", "-");
						meta = scanHeadersLC(headers, X_ROBOTS_HTTP_HEADER, null);
						if(meta != null) {
							meta = parseRobotInstructions(meta);
						} else {
							meta = "-";
						}
						if(mime.toLowerCase().contains("html")) {
							if(redir.equals("-")) {
								// maybe an obvious meta-refresh?
								redir = extractHTMLMetaRefresh(origUrl,m);
							}
							if(meta.equals("-")) {
								// see if there are HTML robot instructions:
								meta = extractHTMLRobots(m);
							}
						}

					}
				}
			}
			if(!redir.equals("-")) {
				redir = resolve(origUrl, redir);
			}
			canUrl = keyMaker.makeKey(origUrl);
			// URL DATE OURL MIME HTTP-CODE SHA1 META REDIR OFFSET LENGTH FILE
			if(dumpJSON) {
				out.format("%s %s %s %s %s %s %s %s %s %s %s %s\n", 
						canUrl, 
						date, 
						origUrl,
						mime,
						httpCode,
						digest,
						redir,
						meta,
						gzLen, 
						offset, 
						filename, 
						m.toString(1));
			} else {
				out.format("%s %s %s %s %s %s %s %s %s %s %s\n", 
						canUrl, 
						date, 
						origUrl,
						mime,
						httpCode,
						digest,
						redir,
						meta,
						gzLen, 
						offset, 
						filename);

			}
//			out.println(filename + " "+resource.getMetaData().getTopMetaData().toString(1));
		} catch (JSONException e) {
			throw new IOException(e);
		} catch (URISyntaxException e) {
			throw new IOException(e);
		}
		out.flush();
	}
1373209
public CmsXmlContentErrorHandler validateContent(Map<String, String> contentValues) throws CmsUgcException {

        checkNotFinished();
        try {
            CmsFile file = m_cms.readFile(m_editResource);
            CmsXmlContent content = addContentValues(file, contentValues);
            return content.validate(m_cms);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
            throw new CmsUgcException(e, CmsUgcConstants.ErrorCode.errMisc, e.getLocalizedMessage());
        }
    }
27432
@Override
    public void setContent(final InputStream content, final String contentType,
                           final Collection<URI> checksums, final String originalFileName,
                           final StoragePolicyDecisionPoint storagePolicyDecisionPoint)
            throws InvalidChecksumException {

        // Clear the wrapped binary object prior to setting the content
        wrappedBinary = null;
        // Need to pass the new filename to get the correct implementation.
        getBinary().setContent(content, contentType, checksums, originalFileName,
                storagePolicyDecisionPoint);
    }
1012556
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            log.severe("Binary content has been requested");
        
        String repository = request.getParameter("repository");
        String workspace = request.getParameter("workspace");
        String path = request.getParameter("path");
        String property = request.getParameter("property");

        Connector connector = (Connector) request.getSession().getAttribute("connector");
        try {
            Session session = connector.find(repository).session(workspace);
            Node node = session.getNode(path);

            Property p;
            try {
                p = node.getProperty(property);
            } catch (PathNotFoundException e) {
                response.setContentType("text/html");
                PrintWriter writer = response.getWriter();
                writer.write("<html>");
                writer.write("<p>Content not found or recently removed</p>");
                writer.write("</html>");
                return;
            }
            
            Binary binary = p.getBinary();


            InputStream in = binary.getStream();
            String contentType = node.getProperty("jcr:mimeType").getString();

            response.setContentType(contentType);

            int b;
            while ((b = in.read()) != -1) {
                response.getOutputStream().write(b);
            }

            log.severe("Sent binary content");
            binary.dispose();

        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
146956
@Override
	public InputStream getResourceAsStream(String resourceName, boolean processingBundle) {

		String path = resourceName;
		GeneratorRegistry generatorRegistry = jawrConfig.getGeneratorRegistry();
		if (generatorRegistry.isGeneratedBinaryResource(path)) {
			path = path.replace(':', '/');
			path = JawrConstant.SPRITE_GENERATED_IMG_DIR + path;
		}

		return ((StreamResourceReader) resourceReader).getResourceAsStream(path, processingBundle);
	}
119493
public static void checkContentResourceType(NodeType contentNodeType) throws NoSuchNodeTypeException
   {
      if (!contentNodeType.isNodeType(WebDavConst.NodeTypes.NT_RESOURCE))
      {
         throw new NoSuchNodeTypeException("Content-Node type " + contentNodeType.getName()
            + " must extend nt:resource.");
      }
   }
1247286
public final void setContent(ContentPart<?>[] content)
    {
        //clear non relevant flags
        this.contentString=null;
        this.contentBinary=null;
        this.contentType=ContentType.MULTI_PART;

        if(content==null)
        {
            this.contentParts=null;
        }
        else
        {
            this.contentParts=content.clone();
        }
    }
671009
protected void rewriteContent(CmsFile file, Collection<CmsRelation> relations) throws CmsException {

        LOG.info("Rewriting in-content links for " + file.getRootPath());
        CmsPair<String, String> contentAndEncoding = decode(file);

        String content = "";

        if (OpenCms.getResourceManager().getResourceType(file) instanceof CmsResourceTypeXmlContent) {
            CmsXmlContent contentXml = CmsXmlContentFactory.unmarshal(m_cms, file);
            try {
                contentXml.validateXmlStructure(new CmsXmlEntityResolver(m_cms));
            } catch (CmsException e) {
                LOG.info("XML content was corrected automatically for resource " + file.getRootPath());
                contentXml.setAutoCorrectionEnabled(true);
                contentXml.correctXmlStructure(m_cms);
                try {
                    content = new String(contentXml.marshal(), contentAndEncoding.getSecond());
                } catch (UnsupportedEncodingException e1) {
                    //
                }
            }
        }

        if (content.isEmpty()) {
            content = contentAndEncoding.getFirst();
        }
        String encodingForSave = contentAndEncoding.getSecond();
        String newContent = rewriteContentString(content);
        byte[] newContentBytes;
        try {
            newContentBytes = newContent.getBytes(encodingForSave);
        } catch (UnsupportedEncodingException e) {
            newContentBytes = newContent.getBytes();
        }
        file.setContents(newContentBytes);
        m_cms.writeFile(file);

    }
103321
public void setContent(final byte[] content,
                         final String contentType) throws HttpException {
    if (!(method instanceof HttpEntityEnclosingRequestBase)) {
      throw new HttpException("Invalid operation for method " +
                               method.getMethod());
    }

    final HttpEntityEnclosingRequestBase eem = (HttpEntityEnclosingRequestBase)method;

    ByteArrayEntity entity = new ByteArrayEntity(content);
    entity.setContentType(contentType);
    eem.setEntity(entity);
  }
677644
@Override
	public boolean process(ContentEvent event) {
		if (event instanceof InstanceContentEvent) {
			this.processInstanceEvent((InstanceContentEvent) event);
		}
		else if (event instanceof PredicateContentEvent) {
			PredicateContentEvent pce = (PredicateContentEvent) event;
			if (pce.getRuleSplitNode() == null) {
				this.updateLearningNode(pce);
			}
			else {
				this.updateRuleSplitNode(pce);
			}
		}
		else if (event instanceof RuleContentEvent) {
			RuleContentEvent rce = (RuleContentEvent) event;
			if (rce.isRemoving()) {
				this.removeRule(rce.getRuleNumberID());
			}
			else {
				addRule(rce.getRule());
			}
		}
		return true;
	}
26826
private void writeResources(List<Resource> resources)
            throws JsonGenerationException, IOException {

        PolicyUtils.validateResourceList(resources);
        List<String> resourceStrings = new ArrayList<String>();

        for (Resource resource : resources) {
            resourceStrings.add(resource.getId());
        }

        // all resources are validated to be of the same type, so it is safe to take the type of the first one
        if (resources.get(0).isNotType()) {
            writeJsonArray(JsonDocumentFields.NOT_RESOURCE, resourceStrings);
        } else {
            writeJsonArray(JsonDocumentFields.RESOURCE, resourceStrings);
        }
    }
1013611
public final void setContent(String content)
    {
        //clear non relevant flags
        this.contentBinary=null;
        this.contentParts=null;
        this.contentType=ContentType.STRING;

        this.contentString=content;
    }
1363183
@Override
    protected void initContent() {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        // get the default encoding
        String content = getParamContent();
        if (CmsStringUtil.isNotEmpty(content)) {
            // content already read, must be decoded
            setParamContent(decodeContent(content));
            return;
        } else {
            content = "";
        }

        try {
            // lock resource if autolock is enabled
            checkLock(getParamResource());
            CmsFile editFile = getCms().readFile(getParamResource(), CmsResourceFilter.ALL);
            content = CmsEncoder.createString(editFile.getContents(), getFileEncoding());
        } catch (CmsException e) {
            // reading of file contents failed, show error dialog
            try {
                showErrorPage(this, e);
            } catch (JspException exc) {
                // should usually never happen
                if (LOG.isInfoEnabled()) {
                    LOG.info(exc);
                }
            }
        }
        setParamContent(content);
    }
1248737
private boolean writeContent(CmsObject cmsObject, I_CmsReport report, CmsFile file, byte[] content) {

        boolean success = true;

        // get current lock from file
        try {
            // try to lock the resource
            if (!lockResource(cmsObject, file, report)) {
                report.println(
                    Messages.get().container(Messages.RPT_SOURCESEARCH_LOCKED_FILE_0, cmsObject.getSitePath(file)),
                    I_CmsReport.FORMAT_ERROR);
                success = false;
            }
        } catch (CmsException e) {
            report.println(
                Messages.get().container(Messages.RPT_SOURCESEARCH_LOCKED_FILE_0, cmsObject.getSitePath(file)),
                I_CmsReport.FORMAT_ERROR);
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getMessageContainer(), e);
            }
            success = false;
        }

        // write the file content
        try {
            file.setContents(content);
            cmsObject.writeFile(file);
        } catch (Exception e) {
            m_errorUpdate += 1;
            report.println(
                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0),
                I_CmsReport.FORMAT_ERROR);
            if (LOG.isErrorEnabled()) {
                LOG.error(e.toString());
            }
            success = false;
        }

        // unlock the resource
        try {
            cmsObject.unlockResource(cmsObject.getSitePath(file));
        } catch (CmsException e) {
            m_errorUpdate += 1;
            report.println(
                Messages.get().container(Messages.RPT_SOURCESEARCH_UNLOCK_FILE_0),
                I_CmsReport.FORMAT_WARNING);
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getMessageContainer(), e);
            }
            success = false;
        }

        if (success) {
            // successfully updated
            report.println(
                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                I_CmsReport.FORMAT_OK);
        }

        return success;
    }
196748
public void setContent(Object content, String contentType)
			throws UnsupportedEncodingException {
		// https://code.google.com/p/sipservlets/issues/detail?id=202
		if(getSipSession().getProxy() == null) {
			checkMessageState();
		}
		checkContentType(contentType);
		checkCommitted();

		if(contentType != null && contentType.length() > 0) {
			this.addHeader(ContentTypeHeader.NAME, contentType);
			ContentTypeHeader contentTypeHeader = (ContentTypeHeader)this.message.getHeader(ContentTypeHeader.NAME);
			String charset = this.getCharacterEncoding();
			try {
			    // https://code.google.com/p/sipservlets/issues/detail?id=169
				if(contentType.contains(CONTENT_TYPE_MULTIPART) && content instanceof Multipart) {
					// Fix for Issue 2667 : Correct Handling of MimeMultipart
					Multipart multipart = (Multipart) content;
					OutputStream os = new ByteArrayOutputStream();
					multipart.writeTo(os);
					this.message.setContent(os.toString(), contentTypeHeader);
				} else {
					Object tmpContent = content;
					if(tmpContent instanceof String  && charset != null) {
						//test for unsupportedencoding exception
						new String("testEncoding".getBytes(charset));
						tmpContent = new String(((String)tmpContent).getBytes());
					}
					this.message.setContent(content, contentTypeHeader);
				}
			} catch (UnsupportedEncodingException uee) {
				throw uee;
			} catch (Exception e) {
				throw new IllegalArgumentException("Parse error reading content " + content + " with content type " + contentType, e);
			}
		}
	}